You are on page 1of 2

Lecture 5

• Failure rate of software projects in India is 95%


• You need a very solid foundation because they’ll replace you with a 20
year old that will do your work for half your pay
• We do proofs and assertion because if you don’t know it you’ll spend most
of your time debugging.
• You need to give your computer exhaustive instructions - Murphy’s law,
everything that can go wrong will
• A program (especially a small one) should already be a proof
(Haskell was made by a mostly musician)
LISP → Scheme
Haskell

Functional languages that are actually used


Erlang → Elixer
(Not be touching C for this course, but learning it makes you know a lot about
the computer) (Prof will give resources at the end)

Simple functions to teach you SML


Function 1
fun sum(a,b) =
if a>b then 0
else sum(a,b-1)+b
What you get when the function runs:
sum(3, 8)
= sum(3, 7) + 8
= sum(3, 6) + 7 + 8
=3+4+5+6+7+8

Function 2
We want to do this

f (x, y) = (1 − xy)2 (2 − xy)(xy + x2 y)

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)

Case 2 Assuming we have a function fun prime(x) that returns true or


false
We can write this to count the number of prime numbers between two numbers

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.

You might also like