Commit f64c8750 authored by Job Cuppen's avatar Job Cuppen

ex 8.3 first half

parent 8ec770c0
......@@ -10,6 +10,7 @@ module genericMap
import StdEnv, StdGeneric
generic gMap a b :: a -> b
gMap{|Int|} x = x
gMap{|Real|} x = x
......@@ -24,5 +25,19 @@ gMap{|OBJECT|} f (OBJECT x) = OBJECT (f x)
t = Bin (Bin Leaf 1 Leaf) 2 (Bin (Bin Leaf 3 Leaf) 4 Leaf)
l = [1..7]
Start = (l, t)
derive gMap Bin, [], (,)
fac :: Int -> Int
fac n = foldr (*) 1 [1..n]
tuplize :: Int -> (Int, Int)
tuplize n = (n, fac n)
// apply the factorial to all elements of t
//Start = gMap{|*->*|} fac t
// turn each integer i in list l to a tuple (i, fac i);
//Start = gMap{|*->*|} tuplize l
// apply the factorial function to all integers in (l, t).
//Start = gMap{|*->*->*|} (gMap{|*->*|} fac) (gMap{|*->*|} fac) (l,t)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment