|
There has been a recent exchange on [EMAIL PROTECTED] about expressing
composition of functions where the inner function takes more than one argument.
(When the inner function takes a single argument, the (.) operator does
quite nicely, of course.) Here's a way, using Haskell language extensions
(options "-98" for Hugs, "-fglasgow-exts" for GHC) to express such composition:
class Composable f g r | f g -> r where
instance Composable (a->z) a z
notelem :: (Eq a) => a -> [a] -> Bool
However, I don't understand why the following fails to compile: instance Composable (c->d->z) (a->b->(c,d)) (a->b->z)
f1, g1 :: a -> a -> (a,a)
Hugs reports: ERROR "Composition.hs" (line 52): Cannot justify constraints in explicitly
typed binding
GHC's report is wordier but seems to be saying about the same thing. Anyone have any ideas? --Dean Herington
John Hughes wrote: Simple! notelem = (not.) . elem (opinions differ on whether or not this is readable...) John Hughes |
- Re: using composition with multiple argument functions Dean Herington
- Re: using composition with multiple argument functions Ashley Yakeley
- Re: using composition with multiple argument funct... Dean Herington
