[Haskell-cafe] "Wrong kind" when attempting to build a monad for a
circular list of functions
Aaron Altman
aaltman at pdx.edu
Thu Feb 28 02:28:03 EST 2008
Hi everybody. I'm working towards a better understanding of Haskell
monads the only way I know how: by working through an example.
I am working on an AI agent that will perform a finite series of actions
before starting the sequence over again. I figured a circular list of
functions that shifts as you apply them would be the way to do it. Here
is my test code:
-----------------------------
import Control.Monad
runActionAndIterate :: [a -> a] -> a -> (a, [a -> a])
runActionAndIterate (currentAction:actionList) actionInput =
(currentAction actionInput, concat [actionList, [currentAction]])
shiftActionList :: [a -> a] -> [a -> a]
shiftActionList (currentHead:rest) = concat [rest, [currentHead]]
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
-----------------------------
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?
Thanks,
Aaron Altman
More information about the Haskell-Cafe
mailing list