[Haskell-beginners] Noobie attempt to process log output into dependency graph
magnus at therning.org
Sat Dec 17 01:03:21 UTC 2016
John Lusk <john-haskell at how-hard-can-it-be.com> writes:
> 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.)
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` :)
Magnus Therning OpenPGP: 0x927912051716CE39
email: magnus at therning.org jabber: magnus at therning.org
twitter: magthe http://therning.org/magnus
The early bird may get the worm, but the second mouse gets the cheese.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 832 bytes
Desc: not available
More information about the Beginners