mult
is defined as a curried function:
mult :: Int -> Int -> Int
mult x = \y -> x * y
In mult (1+2) (2+3)
,
- what are the redex's. and are they
mult(1+2)
,1+2
and2+3
? - What is the outermost redex, and is it
2+3
?
Innermost evaluation works on the expression as following, according to Programming in Haskell by Hutton:
mult (1+2) (2+3)
= { applying the first + }
mult 3 (2+3)
= { applying mult }
(\y -> 3 * y) (2+3)
= { applying + }
(\y -> 3 * y) 5
= { applying the lambda }
3 * 5
= { applying * }
15
How does outermost evaluation work on mult (1+2) (2+3)
?
Does outermost evaluation works as the following?
mult (1+2) (2+3)
= mult (1+2) 5
= (\y -> (1+2) * y) 5
= (1+2) * 5 // Is (1+2) evaluated before (1+2) * 5, because builtin function "*" is strict, i.e. application of builtin function always happen after evaluation of its args?
= 3*5
= 15
Thanks.