This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun fibonacci(n) = | |
| if n = 1 then 1 | |
| else if n = 2 then 1 | |
| else fibonacci(n-1) + fibonacci(n-2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun fib n = | |
| let | |
| fun fib1 1 = (1, 0) | |
| | fib1 n = | |
| let | |
| val (l, m) = fib1 (n-1) | |
| in | |
| (l + m, l) | |
| end | |
| in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun filter(P, nil) = nil | |
| | filter(P, x::xs) = | |
| if P(x) | |
| then x::filter(P,xs) | |
| else filter(P,xs); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| datatype 'a btree = Empty | Node of 'a * 'a btree * 'a btree; | |
| fun find_in_btree(x, Empty) = false | |
| | find_in_btree(x, Node(a, l, r)) = | |
| x = a orelse find_in_btree(x, l) orelse find_in_btree(x, r); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun flatten(nil) = nil | |
| | flatten(nil::ys) = flatten(ys) | |
| | flatten((xa as x::xs)::ys) = xa @ flatten(ys); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun flatten nil = nil | |
| | flatten (x::xs) = x @ flatten(xs); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| exception NotFound; | |
| fun getID(person, nil) = raise NotFound | |
| | getID(person, (x as {name=p, ...})::xs) = | |
| if p = person then | |
| #ID(x:{name:string, ID:int, courses:string list}) | |
| else getID(person, xs); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| datatype 'label btree = | |
| Empty | | |
| Node of 'label * 'label btree * 'label btree; | |
| fun height(Empty) = 0 | |
| | height(Node(x, l, r)) = | |
| let | |
| val hl = height(l); | |
| val hr = height(r) | |
| in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun hundredthPower(x:real) = | |
| let | |
| val four = x*x*x*x; | |
| val twenty = four*four*four*four*four | |
| in | |
| twenty*twenty*twenty*twenty*twenty | |
| end; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun identity(x) = x; |