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

Aaron Altman aaltman at pdx.edu
Sun Mar 2 02:16:53 EST 2008


A big thanks to you all for the discussion.  I have determined that a 
monad is actually not the best representation of a circular list of 
functions.  I was able to implement it without any special syntax or 
unusual typing.  For the curious:

--------------------------------------------------

funcList :: [Int -> Int]
funcList = [\_ -> 1, \_ -> 2, \_ -> 3]

iterateCircularFL :: [a -> b] -> (a -> b, [a -> b])
iterateCircularFL (x:xs) = (x, concat [xs, [x]])

applyCircularFL :: a -> [a -> b] -> (b, [a -> b])
applyCircularFL arg fList =
  let
    (currentFunc, iteratedList) = iterateCircularFL fList
  in (currentFunc arg, iteratedList)

testTraversal i l
  |  i == 0 = putStr "Done."
  |  i > 0 = do {
                putStr "Execution ";
                putStr (show i);
                putStr " returned ";
                putStr (show val);
                putStr ".\n";
                testTraversal (i - 1) newList
             }
               where (val, newList) = applyCircularFL i l

main = do
  testTraversal 5 funcList


More information about the Haskell-Cafe mailing list