[Haskell-cafe] Partial pattern matching
ekirpichov at gmail.com
Mon Mar 9 12:37:17 EDT 2009
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.
2009/3/9 Eugene Kirpichov <ekirpichov at gmail.com>:
> P x is indistinguishable neither in compile-time nor in run-time from
> the value \y -> P x y.
> And pattern matching and equality on functions is, of course, undecidable.
> 2009/3/9 Peter Verswyvelen <bugfact at gmail.com>:
>> In Haskell, a data constructor can be used partially applied:
>> data Pair a b = P a b
>> f = P 1
>> however, I cannot do "partial pattern matching", e.g
>> firstCoord (P x) = x
>> does not work.
>> I guess a very important reason must exist why this is the case?
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
> Eugene Kirpichov
> Web IR developer, market.yandex.ru
Web IR developer, market.yandex.ru
More information about the Haskell-Cafe