|
pattern matching works strange for an O'Caml programmer: msg#00241lang.scala
Hello. At first, I had this: abstract class Expr { def eval: int = this match { case Number(n) => n case Sum(e1, e2) => e1.eval + e2.eval } } case class Number(n: int) extends Expr case class Sum(e1: Expr, e2: Expr) extends Expr It works great and makes perfect sense to me. Later, I made it into this: abstract class Expr { def eval: int = this match { case Number(n) => n //case Sum(e1, e2) => e1.eval + e2.eval } } case class Number(n: int) extends Expr case class Sum(e1: Expr, e2: Expr) extends Expr The warning I expected to receive didn't show up, that was first thing that upset me. Even later, I made it into this: abstract class Expr { def eval: int = this match { case Number(n) => n case Sum(x, 0) => 0 } } case class Number(n: int) extends Expr case class Sum(e1: Expr, e2: Expr) extends Expr The type error didn't showed up either. These two errors are one of the most common mistakes that I make during development, that's why I do love O'Caml. Is there possibility that those errors/warnings will be implemented in Scala? I really need them. -- WBR, Alexander Sergeev. |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Tail recursion -> while (?): 00241, Tony Morris |
|---|---|
| Next by Date: | Re: pattern matching works strange for an O'Caml programmer: 00241, Daniel Bünzli |
| Previous by Thread: | How to get objects from java lists/list iterators?i: 00241, Warren Henning |
| Next by Thread: | Re: pattern matching works strange for an O'Caml programmer: 00241, Daniel Bünzli |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |