
John Lusk
Thanks, all, that gives me something to chew on.
It occurred to me (during my 45-minute commute to work) that all Haskell programs (listen to the noob <eyeroll/>) have the following structure (modulo my fractured syntax):
main :: IO() main = do inputs <- getInputs doOutput $ f inputs initialState
f :: [input] -> state -> outputs
f [] state = transformToOutputs state
f (input:inputs) state = f inputs (newState state input)
doOutput :: [output] -> IO()
doOutput outputs = do putStr $ unlines outputs
So all I have to do is write newState and I'm good! ^_^
(transformToOutputs will, of course, be a snap.)
Right?
Very many do, yes. One thing though, it is worth thinking about the order of arguments. I often order it f state [] = ... f state (x:xs) = ... because that fits better with `foldl` and `map` :) /M -- Magnus Therning OpenPGP: 0x927912051716CE39 email: magnus@therning.org jabber: magnus@therning.org twitter: magthe http://therning.org/magnus The early bird may get the worm, but the second mouse gets the cheese.