Identify the form (normal form, weak head normal form, or redex) of each of the following expressions:
23
(2,3)
\x -> 2 + 3
(\x -> x + 2) 3
(\x -> \y -> x + y) 2
2 + 3
(2 + 2, 3 + 3)
Just (2 + 3)
Just 5
[1,2,3] ++ [4,5,6]
Just $ [1,2,3] ++ [4,5,6]
[Just 1, Just 2, Just (2 + 3)]
[Just (1,2), Just (2,3), Just (4,5)]
\x -> \y -> \z -> x + y(z)
\x -> ((\y -> y + 1) 1) + x
[[1,2,3]]
[1,2,3] : []
[1 + 1]
[1] ++ []
(+) 1
(+) 1 2
print
div (1 + 2 * 3 - 4)
(+ 2)
(- 3)
Replace the parentheses with the $
operator in the following expressions:
take 1 (drop 1 [1..10])
fst (swap (swap (2,3)))
unwords (words (str ++ "!"))
intersect (nub (union [1,2,2,3,4,5,5,5,6,6,7] [2,4,6,8])) [2,4,6,8]
map snd (zip (zipWith ($) [(+3),(+2),(+1)] [1,2,3]) "abc")
Rewrite the following let
expressions to use where
instead.
whiteLines colors = let w = "white" in intersperse w colors
abs n = let n' = negate n in if n < 0 then n' else n
f x y z = let a = x * (y - z) in a <= 0