[Haskell-cafe] Partial pattern matching
Jochem Berndsen
jochem at functor.nl
Mon Mar 9 12:33:45 EDT 2009
Peter Verswyvelen wrote:
> 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?
>
What would be the type of firstCoord?
Typically, you'd use
data Pair a b = P { firstCoord :: a
, secondCoord :: b
}
or
firstCoord (P x _) = x
secondCoord (P _ y) = y
Regards,
--
Jochem Berndsen | jochem at functor.nl
GPG: 0xE6FABFAB
More information about the Haskell-Cafe
mailing list