Home

About

Advanced Search

Browse by Discipline

Scientific Societies

E-print Alerts

Add E-prints

E-print Network
FAQHELPSITE MAPCONTACT US


  Advanced Search  

 
Solution Proposal Functional Programming Sheet 10 let sumTree (Node x ts) = x + sumForest ts
 

Summary: Solution Proposal Functional Programming ­ Sheet 10
Exercise 1
let sumTree (Node x ts) = x + sumForest ts
sumForest Nil = 0
sumForest (Cons t ts) = sumTree t + sumForest ts
in sumTree (Node 2 (Cons (Node 7 Nil) Nil))
-- Rule (1)
let sumTree = \y -> case y of Node x ts -> x + sumForest ts
sumForest Nil = 0
sumForest (Cons t ts) = sumTree t + sumForest ts
in sumTree (Node 2 (Cons (Node 7 Nil) Nil))
-- Rule (1)
let sumTree = \y -> case y of Node x ts -> x + sumForest ts
sumForest = \z -> case z of
Nil -> 0
Cons t ts -> sumTree t + sumForest ts
in sumTree (Node 2 (Cons (Node 7 Nil) Nil))
-- Rule (11)
let (sumTree, sumForest) =
( \y -> case y of Node x ts -> x + sumForest ts,

  

Source: Ábrahám, Erika - Fachgruppe Informatik, Rheinisch Westfälische Technische Hochschule Aachen (RWTH)

 

Collections: Computer Technologies and Information Sciences