On 16 Apr 2008, at 15:22, Daniel Fischer wrote:
The point is the

instance Monad ((->) a) where
    return x = const x
    f >>= g = \x -> g (f x) x

which is defined in Control.Monad.Instances...

Thank you. I suspected there was an instance somewhere, and I wanted to know where it is defined.

  (try in GHCI:
Prelude> let f x y = x >>= (return y)
Prelude> :t f
f :: (Monad ((->) a), Monad m) => m a -> m b -> m b
).

It works in Hugs too. If I don't import Control.Monad.State, then
  f :: (Monad a, Monad ((->) b)) => a b -> a c -> a c

This is imported into Control.Monad.State and hence the instance is
visible.

By the type of (>>=), (return y) must have type (a -> m b), on the other hand, if y has type c, then (return y) has type (m' c) for some monad m'. Unifying
m' c and a -> m b gives then m' === ((->) a) and c === m b.
Now according to the instance, return y === const y, so f is the same as
g x y = x >>= (const y).

Good to know the details. Thanks.

  Hans


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to