[Haskell-beginners] pattern matching on function names or algebraic type data constructors
Daniel Trstenjak
daniel.trstenjak at gmail.com
Sun Jun 23 14:43:51 CEST 2013
Hi TP,
> What is the reason for this message?
'f' and 'g' in the 'case' expression are local names/bindings
and have nothing in common with the 'f' and 'g' functions.
It's the same like introducing names/bindings with the 'let' expression:
let f = ...
g = ...
in ...
The bindings are overlapping, because both match all the time and
GHC will always use the first one.
> Why does it not work? If Mult and Plus are functions, then I should not need
> to put their arguments in pattern matching.
'Mult' and 'Plus' are data constructors which both expect one argument: a 'Float'.
You also can't match the data constructors against a function, but only
against a value of its type.
pat :: Foobar -> Bool
pat t = case t of
Mult f -> True
Plus f -> False
Greetings,
Daniel
More information about the Beginners
mailing list