1

Given the following Typeclassopedia exercise:

--Implement join :: M (N (M (N a))) -> M (N a), 
--given distrib :: N (M a) -> M (N a) and 
--assuming M and N are instances of Monad.

distrib :: (Monad m, Monad n) => n (m a) => m (n a)
distrib = undefined

I get the following compile-time error.

ghci> :l MonadTransformers.hs
[1 of 1] Compiling Main             ( MonadTransformers.hs, interpreted )

MonadTransformers.hs:7:34:
    Expected a constraint, but `n (m a)' has kind `*'
    In the type signature for `distrib':
      distrib :: (Monad m, Monad n) => n (m a) => m (n a)
Failed, modules loaded: none.

How can I resolve it?

Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384

1 Answers1

3

That should be

distrib :: (Monad m, Monad n) => n (m a) -> m (n a)

=> comes between the constraint and the rest of the type.

-> is the infix type constructor for functions.

For example

(+) :: Num a => a -> a -> a
       -----     \  /      \
        \         arguments result
         constraint
rampion
  • 87,131
  • 49
  • 199
  • 315