This page is no longer maintained — Please continue to the home page at www.scala-lang.org

pattern matching problem

1 reply
beloved
Joined: 2009-01-08,
User offline. Last seen 42 years 45 weeks ago.
hello, I can't figure out what's going on in following code:
object HistoryGeneratorCase {

  def main(args: Array[String]) {
        var t = List("0", "Na Archivaciu", "Na Archivaciu", "UHR_A", new Date().toString, new Date().toString)
    t match {
      //case "0" :: "Vratene FA" :: _ => print("SendToLiquid")
      case "0" :: SaveAndFlowCond(x)  => print("csave")
      //case ::("0", SaveAndFlowCond(s)) => print("csave")
      case _ => print("no match")
    }
    
  }

  object SaveAndFlowCond {

     def unapply(next : List[String]) = {
       print("aa")
       next match {
         case "1" :: _ =>  Some(List("aa","bb"))
         case _ =>Some(List("aa","bb "))
       }
     }

  }
  

}
when run, it prints: aacsave which is what I would expect
but when I uncomment line:
//case "0" :: "Vratene FA" :: _ => print("SendToLiquid")
it prints: no match which I don't understand I would still expect aacsave as a result

Thanks.
Peter Lopen
View this message in context: pattern matching problem
Sent from the Scala mailing list archive at Nabble.com.
extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: pattern matching problem

On Wed, Mar 11, 2009 at 07:55:50AM -0700, beloved wrote:
> I can't figure out what's going on in following code:

It's a bug in the pattern matcher. I wish I could say I'm surprised,
but there are a whole pile of issues in the matcher when you start doing
"interesting" things - in this case, mixing case classes with
extractors. This is almost surely subsumed in some open bug, let's see
here... yes, I believe it's a variation on this one.

http://lampsvn.epfl.ch/trac/scala/ticket/1697

That the bugs aren't fixed does not reflect a lack of interest in doing
so, but the difficulty of fully understanding the pattern matcher.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland