[Haskell-cafe] Substituting values
Petr P
petr.mvd at gmail.com
Sat Dec 22 15:52:09 CET 2012
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 <radical at google.com>
> 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20121222/056dd6da/attachment.htm>
More information about the Haskell-Cafe
mailing list