0
votes

I'm trying to get a better understanding of monads. So I'm trying to write return, join, and bind implementations for several monads.

However when coming to two-kinded monads, I'm kind of confused

join :: m (m a) -> m a

m (m a) Implies monad wrapped inside of monad, but what value is implied if using two-kinded monads. For example with the State Monad: s or a? What would the correct signature of join for the State Monad look like?

1
There is no such thing as a "two-kinded" Monad. All Monad instances are of kind * -> *. - Rein Henrichs
Like function application, type constructors associate left. So if you have type Foo a b c dthen e.g. Foo Int Char Bool would have kind * -> * and you could define instance Monad (Foo Int Char Bool). You can write types with redundant parens if you want, like :: (((Foo Int) Char) Bool) Baz - jberryman
@ReinHeinrichs Read "two-kinded data types that have a Monad instance" - hgiesel
@hgiesel Is "two-kinded data types that have a Monad instance" a blog post or something? If so, you should give us a link; Google doesn't turn up anything when I try. - Daniel Wagner
So to be clear, we don't have instance Monad State where ... since State has kind * -> * -> *. It is instance Monad (State s) where ... - jberryman

1 Answers

10
votes

The state monad type is declared as State s a; it only unifies with m a if m ~ State s.

join :: State s (State s a) -> State s a