程序代写代做代考 Java Haskell Functional Programming

Functional Programming

First Comparsion: Java – Haskell
Summing the integers 1 to 10 in Java:
total = 0;
for (i = 1; i  10; ++i)
total = total+i;
The computation method is variable assignment.
*

First comparison: Java – Haskell
Summing the integers 1 to 10 in Haskell:
sum [1..10]
The computation method is function application.
[Better examples to come. ]
*

A Taste of Haskell
f [] = []
f (x:xs) = f ys ++ [x] ++ f zs
where
ys = [a | a  xs, a  x]
zs = [b | b  xs, b > x]
?
*

Here two simpler programs:

double :: Int -> Int
double x = x + x

*

Here two simpler programs:

average :: Float -> Float -> Float
average x y = (x + y) / 2
*