[Haskell-cafe] "Wrong kind" when attempting to build a monad for a circular list of functions

Luke Palmer lrpalmer at gmail.com
Thu Feb 28 02:37:43 EST 2008

On Thu, Feb 28, 2008 at 7:28 AM, Aaron Altman <aaltman at pdx.edu> wrote:
>  newtype CircularFuncList funcList arg = CircularFuncList (funcList ->
>  arg -> (arg, funcList))
>  instance Monad (CircularFuncList funcList arg) where
>   return a = CircularFuncList (\funcList a -> (a, funcList))
>   CircularFuncList currentFuncList currentArg >>= argTransform =
>     let result = argTransform $ (head currentFuncList) currentArg
>         newFuncList = map argTransform $ shiftActionList currentFuncList
>     in CircularFuncList newFuncList result

So some standard monads are:

  instance Monad [] where ...
  instance Monad Maybe where ...

Note how they are all "missing" a type argument, i.e. not:

  instance Monad (Maybe Int) where ...

So your monad needs to be, say:

  instance Monad (CircularFuncList funcList) where ...

But see below...

>  -----------------------------
>  I get an error that CircularFuncList funcList arg has kind * while Monad
>  is looking for * -> *.  This is a first attempt so it may be I'm a ways
>  off from a monad that implements a circular list of functions.  That is
>  the goal though.  What advice can you offer?

I'm not sure how CircularFuncList is a monad.  In fact it doesn't even
look like a Functor (because arg appears both as an argument and a
return in your data type definition).  How do you intend your monad to
be used?  That is, when a user writes:

foo :: CircularFuncList func a
foo = do
    x <- ...
    y <- ... x

What are the primitive operations (the ...s here) and what does it
mean to sequence them like this?  Describing this in words might help
you implement this, or more likely, help you realize that a monad
isn't what you thought it is :-)


More information about the Haskell-Cafe mailing list