
Hey Petr,
On Sat, Dec 22, 2012 at 9:52 AM, Petr P
I think you need something wha Scala has - the ability to create a partial function from a case expression. In Scala you could write
def update[A](f: PartialFunction[A,A])(v: A): A = f.orElse({ case x => x } : PartialFunction[A,A]).apply(v);
and then use it like
update[Int]({ case Foo => Bar })
Thanks for the pointer. One distinction I remember from dabbling in Scala some years ago is that Scala seems to formalize partiality whereas, if I'm not mistaken, Haskell doesn't (though perhaps there are libraries that let you do that). That is, to me a partial function in Haskell is almost uniformly an error, whereas in Scala it's a somewhat common pattern.
But AFAIK there is nothing like this in Haskell. Maybe separating 'of' from 'case' would be the way to extend Haskell with such a feature < http://www.haskell.org/pipermail/haskell-cafe/2012-November/104884.html>
Does Haskell have a way to query at runtime whether a function is partial? (Not in the full sense, since it would be necessary to prove totality, but in the sense that a case expression is not exhaustive.) Otherwise, I'm not sure how you could use a partial lambda without reaching `undefined`. (I guess you could catch the exception.)
Thanks, Alvaro