[Haskell-cafe] Pattern matching does not work like this?

Miguel Mitrofanov miguelimo38 at yandex.ru
Wed Jul 15 08:14:17 EDT 2009


No. Most constructors are functions, e.g. Just :: a -> Maybe a - a function.

On the other hand, Nothing :: Maybe a is a constructor, but not a function.

Andrew Wagner wrote:
> Err, technically, aren't functions and constructors mutually exclusive? 
> So if something is a function, it's, by definition, not a constructor?
> 
> On Wed, Jul 15, 2009 at 6:25 AM, Eugene Kirpichov <ekirpichov at gmail.com 
> <mailto:ekirpichov at gmail.com>> wrote:
> 
>     Technically, the reason is not that (++) is a function, but that it is
>     not a constructor of the [] type.
> 
>     And, not only is it not a constructor, but it also *can't* be one,
>     because the main characteristic of pattern matching in Haskell is that
>     it is (contrary to Prolog's unification) unambiguous (unambiguity of
>     constructors is guaranteed by the semantics of Haskell's algebraic
>     datatypes).
> 
>     If ++ could be pattern matched, what should have been the result of
>     "let (x++y)=[1,2,3] in (x,y)"?
> 
>     2009/7/15 minh thu <noteed at gmail.com <mailto:noteed at gmail.com>>:
>      > 2009/7/15 Magicloud Magiclouds <magicloud.magiclouds at gmail.com
>     <mailto:magicloud.magiclouds at gmail.com>>:
>      >> Hi,
>      >>  I do not notice this before. "fun ([0, 1] ++ xs) = .." in my code
>      >> could not be compiled, parse error.
>      >
>      > ++ is a function; you can't pattern-match on that.
>      >
>      > Cheers,
>      > Thu
>      > _______________________________________________
>      > Haskell-Cafe mailing list
>      > Haskell-Cafe at haskell.org <mailto:Haskell-Cafe at haskell.org>
>      > http://www.haskell.org/mailman/listinfo/haskell-cafe
>      >
> 
> 
> 
>     --
>     Eugene Kirpichov
>     Web IR developer, market.yandex.ru <http://market.yandex.ru>
>     _______________________________________________
>     Haskell-Cafe mailing list
>     Haskell-Cafe at haskell.org <mailto:Haskell-Cafe at haskell.org>
>     http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe


More information about the Haskell-Cafe mailing list