[Haskell-cafe] eta-expansion and cost of extra thunk on ghc

Ruben Astudillo ruben.astud at gmail.com
Sun May 14 17:40:01 UTC 2017

Dear list

On a class, we recently discussed the join function for a (State s)
value (we where implementation Monad passing through Functor)

    join :: State s (State s a) -> State s a
    join outstate =
        State $ \s0 ->
            let (innerstate, s1) = runState outstate s0
            in  runState innerstate s1

On this, we eta-expand outstate to in a sense "pattern match" on what we
know about it. We were thinking on the cost of the extra wrapping we do
here for this "pattern matching". Because eta-expanding is one a of the
3 primitive operations on lambda calculus, we concluded it should be
free (modulo presence of seq). Is this true on ghc?

-- Ruben

More information about the Haskell-Cafe mailing list