[haskell-cafe] Monad and kinds

Jake Mcarthur jake.mcarthur at gmail.com
Tue Sep 2 09:46:56 EDT 2008


On Sep 2, 2008, at 8:34 AM, Ramin wrote:

>   instance Monad Query where
>       return (initState, someRecord) = Query (initState, someRecord)
>       {- code for (>>=) -}
> GHC gives an error, "Expected kind `* -> *', but `Scanlist_ctrl' has  
> kind `* -> * -> *' ".

I believe you understand the problem with the above code, judging from  
your attempt to fix it below.

> If I try this:
>   instance Monad (Query state) where
>       return (initState, someRecord) = Query (initState, someRecord)
>       {- code for (>>=) -}
> GHC give an error, "Occurs check: cannot construct the infinite  
> type: a = (s, a) when trying to generalise the type inferred for  
> `return' ".

The problem is your type for the return function. The way you have  
written it, it would be `return :: (state, rec) -> Query state rec`.  
Perhaps it would be easier to see the problem if we defined `type M =  
Query MyState`. Then you have `return :: (MyState, rec) -> M rec`.  
Compare this to the type it must be unified with: `return :: a -> m  
a`. The two 'a's don't match! The type you are after is actually  
`return :: rec -> M rec` or `return :: rec -> Query state rec`.

I hope this helps lead you in the right direction. I'm not giving you  
the solution because it sounds like you want to solve this for  
yourself and learn from it.

- Jake McArthur


More information about the Haskell-Cafe mailing list