logo       

Fwd: Multi-parameter case classes: msg#00251

lang.scala

Subject: Fwd: Multi-parameter case classes

sorry, meant to write to the list too

---------- Forwarded message ----------
From: Burak Emir <burak.emir@xxxxxxxxx >
Date: Jan 22, 2007 11:26 AM
Subject: Re: Multi-parameter case classes
To: Tony Morris <tmorris@xxxxxxxxxxx>

Only the first parameter section is matched for a curried case class constructor.

That way, one can have case classes and still hide certain arguments.

If that is annoying, you can define all your parameters in the first section, and add a curried constructor function with the same name somewhere else.

cheers,
Burak


On 1/22/07, Tony Morris < tmorris@xxxxxxxxxxx> wrote:
I am trying to write a case class that can be partially applied, but get
a compile-time error when I try to case match. Here is a trivialised
example of what I am trying to do:

sealed abstract class S {

}

case object T extends S {

}

final case class U(xs: String)(ys: String) extends S {

}

object X {
  def f(s: S): Unit = s match {
    case T => Console.println("t")
    // COMPILE-TIME ERROR
    // case U(xs)(ys) => Console.println("u " + xs + " " + ys)
  }
}

How do I do what it is that I wanna do?
Cheers for any tips.

--
Tony Morris
http://tmorris.net/







--
Burak Emir
Research Assistant / PhD Candidate
Programming Methods Group
EPFL, 1015 Lausanne, Switzerland
http://lamp.epfl.ch/~emir


--
Burak Emir
Research Assistant / PhD Candidate
Programming Methods Group
EPFL, 1015 Lausanne, Switzerland
http://lamp.epfl.ch/~emir
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise