Search code examples
haskellseq

`seq` on partially applied functions


Lets say I have the following:

f :: a -> b -> c
g :: b -> c
g = f 10

Now lets say f is actually:

f x y = f1 x + y

Would:

g `seq` ...

actually evaluate f1 10, so later when running

g 9

it's actually just a simple addition?

If not, is there a way to "evaluate" parts of a partially applied function?

I'm looking for a generic solution, one that doesn't depend on knowing how f and g work.


Solution

  • seq is shallow:

    Prelude> let f1 = undefined
    Prelude> let f = \x -> \y -> f1 x + y
    Prelude> let g = f 10
    Prelude> g `seq` 1
    1
    Prelude> g 9
    *** Exception: Prelude.undefined
    Prelude>
    

    I'd take a look at Control.DeepSeq: http://hackage.haskell.org/packages/archive/deepseq/1.2.0.1/doc/html/Control-DeepSeq.html