[Haskell-cafe] Partial pattern matching
Peter Verswyvelen
bugfact at gmail.com
Mon Mar 9 12:57:04 EDT 2009
Yes of course, P x is a function, and you can't pattern match against
functions, I knew that. How silly of me, I could have guessed that myself.
On Mon, Mar 9, 2009 at 5:43 PM, Daniel Fischer <daniel.is.fischer at web.de>wrote:
> Am Montag, 9. März 2009 17:30 schrieb Peter Verswyvelen:
> > 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?
>
> For one, the type. If x :: a, then P x :: b -> Pair a b, so we'd have
>
> firstCoord :: (b -> Pair a b) -> a
>
> But you can pattern-match only on constructors of the appropriate type. P
> is
> not a constructor of (b -> Pair a b) (function types don't have
> constructors), so you can't match on a partially applied constructor.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090309/470d48eb/attachment.htm
More information about the Haskell-Cafe
mailing list