4 ms·
I have hacked Haskell just to be able to see what goes on inside a particular method chain.
by tomjen3 14y ago
I have hacked Haskell just to be able to see what goes on inside a particular method chain.
- seanmcdirmid 14y agoWe call this trading one hell (direct mutability) for another worse hell (Indirect mutability).
- calopetreep 14y agoDo you mean you have trouble with seeing what's going on inside a long function composition? I wrote a cool function to examine it with almost no code changes: module TraceCompose where import Debug.Trace -- | Trace a value, resulting in the value itself idTrace :: Show a => a -> a idTrace x = trace (show x) x traceCompose :: (Show a, Show b, Show c) => (b -> c) -> (a -> b) -> a -> c traceCompose f g = h f . h g . h id where h f x = idTrace (f $ seq x x) -- Replace "normal" function composition using traceCompose. test = (+1) . (*10) $ 4 where (.) = traceCompose When you run "test", it will print: 4 40 41 (i.e., the outputs of each function at each point in the composition in order of execution.)