Re:Things Java Programmers can learn from Clojure
by tomjen3 on Thursday March 07, 2013 @01:44AM
(#5336469)
I have hacked Haskell just to be able to see what goes on inside a particular method chain.
[ Parent
| on HN ]
Re:Things Java Programmers can learn from Clojure
by calopetreep on Thursday March 07, 2013 @04:43AM
(#5336890)
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.)
Re:Things Java Programmers can learn from Clojure
by seanmcdirmid on Thursday March 07, 2013 @01:54AM
(#5336494)
We call this trading one hell (direct mutability) for another worse hell (Indirect mutability).