Given this code in module X,

> type RM s a = s -> a

> instance Functor ((->) s) where
>   map f m = \s -> f (m s)

> instance Monad ((->) s) where
>   return a = \s -> a
>   m >>= k  = \s -> k (m s) s

> getStateRM f = \s -> s


which is imported in module Y, and used eg

> foo = getStateRM >>= \x -> return (x + x) :: RM Int Int 



THEN ghc (versions 2.10, 3.02, 4.01) complain

    No instance for `Monad (-> Int)'
        arising from use of `return' at <FILE & LINE>


But the problem is cured by adding this line in the module which won't
compile

> {-#SPECIALISE instance Monad ((->) Int) #-}


So, is there a bug with calculation of instances?

(Hugs is quite happy with such constructions.)

Thanks,

Paul Callaghan

Durham

Reply via email to