Hacker News new | past | comments | ask | show | jobs | submit login

I have hacked Haskell just to be able to see what goes on inside a particular method chain.



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.)


We call this trading one hell (direct mutability) for another worse hell (Indirect mutability).




Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: