
Hi Alvaro,
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 })
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>
Best regards,
Petr
2012/12/21 Radical
Sometimes I'll need something like:
if value == Foo then Bar else value
Or some syntactic variation thereof:
case value of { Foo -> Bar; _ -> value }
Is there a better/shorter way to do it? I'm surprised that it's more complicated to substitute a value on its own than e.g. in a list, using filter. Or perhaps I'm missing the right abstraction?
Thanks,
Alvaro
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe