[Haskell-beginners] function parameter types after flip

Daniel Seidel seideld at tcs.inf.tu-dresden.de
Thu Aug 13 11:35:22 EDT 2009


Robert Ziemba wrote:
> Can anyone help me understand the behavior of the following
> expressions in ghci?  I was trying to construct a flipped function
> 'elem' that would accept a list of characters first but I ran into
> this problem with the type signature. Thank you.
> 
> Prelude Data.List Data.Char> :t elem
> elem :: (Eq a) => a -> [a] -> Bool              -- OK
> Prelude Data.List Data.Char> :t (flip elem)
> (flip elem) :: (Eq a) => [a] -> a -> Bool       -- OK this is what I want
> Prelude Data.List Data.Char> let fElem = (flip elem)
> Prelude Data.List Data.Char> :t fElem
> fElem :: [()] -> () -> Bool                           -- ?? Function
> will not accept a [Char]

I think its due to the monomorphism restriction.
If you define it like

Prelude> let fElem x = (flip elem) x
Prelude> :t fElem
fElem :: (Eq a) => [a] -> a -> Bool

it works. For the details look at

http://haskell.org/haskellwiki/Monomorphism_restriction

... or wait for another answer (which I think will come).

Daniel.


> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners



More information about the Beginners mailing list