[Haskell-beginners] Pattern matching is actually about matching constructors??

Olumide 50295 at web.de
Tue Dec 22 10:53:51 UTC 2015


Petr,

Of course you are right. :-: is a value constructor (function) albeit 
declared in the infix style a :-: (List a).

Thanks,

- Olumide

On 21/12/15 19:00, Petr Vápenka wrote:
> Hello,
>
> actually the definition with data keyword is right there:
>
> infixr 5 :-:
> data List a = Empty | a :-: (List a) deriving (Show, Read, Eq, Ord)
>
> it could be written in prefix form as
>
> data List a = Empty | Cons a (List a) deriving (....)
>
>
> Petr
>
>
>
>
> On Mon, Dec 21, 2015 at 7:56 PM, Olumide <50295 at web.de
> <mailto:50295 at web.de>> wrote:
>
>     Hello,
>
>     On chapter 7 of LYH there's an example of a user-defined operator .++
>
>     infixr 5  .++
>     (.++) :: List a -> List a -> List a
>     Empty .++ ys = ys
>     (x :-: xs) .++ ys = x :-: (xs .++ ys)
>
>     which is used as follows
>
>     let a = 3 :-: 4 :-: 5 :-: Empty
>     let b = 6 :-: 7 :-: Empty
>     a .++ b
>     (:-:) 3 ((:-:) 4 ((:-:) 5 ((:-:) 6 ((:-:) 7 Empty))))
>
>     Following this the text reads:
>
>     "Notice how we pattern matched on (x :-: xs). That works because
>     pattern matching is actually about matching constructors. We can
>     match on :-: because it is a constructor for our own list type ..."
>     Source:
>     http://learnyouahaskell.com/making-our-own-types-and-typeclasses#recursive-data-structures
>
>     Is the operator :-: a constructor? I'm confused because the
>     definition of :-: is not prefixed by the data keyword?
>
>     - Olumide
>
>     _______________________________________________
>     Beginners mailing list
>     Beginners at haskell.org <mailto:Beginners at haskell.org>
>     http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
>
>


More information about the Beginners mailing list