Professional Documents
Culture Documents
Lecture 5
Lecture 5
Function 2
We want to do this
So we write this
1
fun blah(x,y)=
let
val a = x*y
in (1-a)*(1-a)*(2-a)(a+x*a)
(* we use a instead of xy to avoid the same calculation over and over again *)
end;
Function 3
Case 1 Assuming we have a function fun prime(x) that returns 0 or 1
We can write this to count the number of prime numbers between two numbers
fun cp(a,b)=
if a>b then 0
else prime(b) + cp(a,b-1)
fun cp(a,b)=
if a>b then 0
else if prime(b) then 1+cp(a,b-1)
else cp(a,b-1)
Post
Abstraction and Encapsulation are things that are asked in interviews.