[Haskell-cafe] Substituting values

Radical radical at google.com
Tue Dec 25 21:01:08 CET 2012


Hey Petr,

On Sat, Dec 22, 2012 at 9:52 AM, Petr P <petr.mvd at gmail.com> wrote:
>
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20121225/746fcf44/attachment.htm>


More information about the Haskell-Cafe mailing list