On Thu, 27 Nov 2003 14:56:03 +0000 Graham Klyne <[EMAIL PROTECTED]> wrote:
(perhaps a more serious and to the point reply later) > But not all cases I encounter involve lists or monads. A different > case might look like this: Are you sure this doesn't involve monads? > > eval :: (b->c->d) -> (a->b) -> (a->c) -> (a->d) > > eval f g1 g2 a = f (g1 a) (g2 a) eval :: Monad m => (b -> c -> d) -> m b -> m c -> m d eval = liftM2 > So, for example, a function to test of the two elements of a pair are > the same might be: > > > pairSame = eval (==) fst snd > > giving: > > > pairSame (1,2) -- false > > pairSame (3,3) -- true > > > Or a function to subtract the second and subsequent elements of a list > from the first: > > > firstDiffRest = eval (-) head (sum . tail) > > > firstDiffRest [10,4,3,2,1] -- 0 (these work fine with a Monad instance ((->) r) which is a Reader monad) _______________________________________________ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
