|
|
|
|
|
by calopetreep
4852 days ago
|
|
Do 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.) |
|