[Haskell-cafe] Generalized partial application (again)

Felipe Lessa felipe.lessa at gmail.com
Mon Jan 12 14:33:11 EST 2009


How about using "let"s?

2009/1/12 Peter Verswyvelen <bugfact at gmail.com>:
> e = trace "e"
> op = (+)
> a1 = let f = (op (e 1)) in (f 10, f 100)
> a2 = let f = (\x -> op (e 1) x) in (f 10, f 100)
> a1 and a2 are operationally not the same: a1 will evaluate (e 1) once, a2

a3 = let f = (let y = e 1 in (\x -> op y x)) in (f 10, f 100)

> e1 x = trace "e1" x
> e2 x = trace "e2" x
> op2 :: Int -> Int -> Int -> Int
> op2 x y z = x+10*y+100*z
> z1 = let f = (flip3_12 op2) (e1 1) (e2 2) in (f 3, f 4)
> z2 = let f = (flip3_13 op2) (e1 1) (e2 2) in (f 3, f 4)
> z3 = let f = (flip3_23 op2) (e1 1) (e2 2) in (f 3, f 4)

z1' = let f = (let y1 = e1 1; y2 = e2 2 in (\x -> op2 y2 y1 x)) in (f 3, f 4)

-- 
Felipe.


More information about the Haskell-Cafe mailing list