[Haskell-cafe] Partial pattern matching
Luke Palmer
lrpalmer at gmail.com
Mon Mar 9 13:31:40 EDT 2009
On Mon, Mar 9, 2009 at 10:37 AM, Eugene Kirpichov <ekirpichov at gmail.com>wrote:
> I mean, there is no way to write a firstCoord function so that it
> would work, for example, on '\y -> P 42 y' and yield 42.
>
> Except for this one:
>
> firstCoord proj = case (proj undefined) of P x y -> x
>
> However, this requires proj to be non-strict in its remaining argument.
> But this will actually work if you pass "P x" to it for some x,
> because it *is* non-strict in the remaining argument.
That's brilliant. Any function which behaves like "P x" but is strict in
the second argument is in fact a different function. So this trick is a
semidecidable pattern for this function.
Bring in the unamb, so we can do interesting things with semidecidable
predicates :-) (I still don't like the proof obligation of unamb, and
would like to see it picked up to a higher level of abstraction where the
usage is always correct)
Luke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090309/cbd994bb/attachment-0001.htm
More information about the Haskell-Cafe
mailing list