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

Olumide 50295 at web.de
Mon Dec 21 18:56:36 UTC 2015


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



More information about the Beginners mailing list