| 1 = 1 | 2 = 2 ... | n = n where { } ==> FOR YOU TO DO Desugar: while test f x | b = while test f (f x) | otherwise = x where b = test x ------------------------------------------ ------------------------------------------ SYNTACTIC SUGAR FOR IF if 1 then 2 else 3 ==> case 1 of True -> 2 False -> 3 ------------------------------------------ ------------------------------------------ MULTIPLE BINDING IS SUGAR FOR CASE Function binding form:

11 ...

1n = 1 ...

m1 ...

mn = m ==> FOR YOU TO DO desugar the following > name 0 = "zero" > name 1 = "one" > name n = "many" ------------------------------------------ ------------------------------------------ FUNCTION DEFINITION SUGAR FOR LAMBDA x1 ... xn = E ==> Example: compose (f,g) x = f (g x) ==> ------------------------------------------ ------------------------------------------ GETTING PATTERNS OUT OF LAMBDAS ucompose (f,g) x = f (g x) ==> ucompose = \ (f,g) -> \ x -> f (g x) ==> ------------------------------------------ C. Naming and Scoping in the core of Haskell 1. Haskell's core ------------------------------------------ THE CORE OF HASKELL Patterns in top-level declarations boil down to single name declartions of the form x = e Functions delcaration sugars boil down to declarations of the form f = (\ x -> e) Pattern matching boils down to case expressions of the form case x of

1 -> 1

2 -> 2 Thus declaration of identifiers occurs in - top-level declarations x = - lambda expressions (\ x -> ) - case expressions case v of

1 -> 1

2 -> 2 ------------------------------------------ 2. simultaneous binding, lexical scope (Davie 2.4) ------------------------------------------ SCOPE FOR DECLARATIONS AND LET > x = u + v > y = u - v > (u,v) = (4,5) let x1 = u1 + v y1 = u1 - v u1 = 4 v1 = 5 in [x1,y1,u1,v1] ------------------------------------------ What will that expression's value be? ------------------------------------------ DESUGARING OF LET (dynamic behavior, not typing) > -- fix point operator, for use below > fix :: (a -> a) -> a > fix f = f (fix f) let

1 = 1 ...

n = n in 0 ==> let (~

1, ..., ~

n) = (1, ..., n) in 0 let

= 1 in 0 ==> let

= fix (\ ~

-> 1) in 0 let

= 1 in 0 -- if no in