[Haskell-cafe] Function composition
roma at ro-che.info
Sat Dec 27 04:33:22 EST 2008
* Oscar Picasso <oscarpicasso at gmail.com> [2008-12-26 22:37:26-0500]
> I can write:
> *Main> let yes = not . not
> *Main> :t yes
> yes :: Bool -> Bool
> But not:
> *Main> let isNotEqual = not . (==)
> Couldn't match expected type `Bool'
> against inferred type `a -> Bool'
> Probable cause: `==' is applied to too few arguments
> In the second argument of `(.)', namely `(==)'
> In the expression: not . (==)
You might want to read about currying. This will explain why (==)
does not take a pair of values, it rather takes one value and then
another, and that's why it is not composable in the way you want.
What you're trying to do is easier to do with uncurried functions:
Prelude> let isNotEqual = not . uncurry (==)
Prelude> :t isNotEqual
isNotEqual :: (Eq a) => (a, a) -> Bool
Prelude> isNotEqual (3,4)
Prelude> isNotEqual (3,3)
(note that -XNoMonomorphismRestriction is used here)
Roman I. Cheplyaka :: http://ro-che.info/
"Don't let school get in the way of your education." - Mark Twain
More information about the Haskell-Cafe