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 reverse(nil) = nil | |
| reverse(x::xs) = reverse(xs)@[x]; | |
fun revrev(nil) = nil | |
| revrev(x::xs) = revrev(xs)@[reverse(x)]; |
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 rotate(L) = | |
if L=nil then nil | |
else tl(L) @ [hd(L)]; |
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 smult(nil, q) = nil | |
| smult((p:real)::ps, q) = (p*q)::smult(ps, q); |
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 split(nil) = (nil, nil) | |
| split([a]) = ([a], nil) | |
| split(a::b::cs) = | |
let | |
val (M, N) = split(cs) | |
in | |
(a::M, b::N) | |
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 square(0) = 0 | |
| square(n) = square(n-1) + 2 * n - 1; |
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 memq(x, nil) = false | |
| memq(x, y::ys) = | |
if x = y then true | |
else memq(x, ys); | |
fun subset(nil, ys) = true | |
| subset(x::xs, ys) = | |
if memq(x, ys) = false | |
then false | |
else subset(xs, 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
datatype 'label btree = | |
Empty | | |
Node of 'label * 'label btree * 'label btree; | |
fun sumBinTree(Empty) = 0 | |
| sumBinTree(Node(a, left, right)) = | |
a + sumBinTree(left) + sumBinTree(right); |
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 sumEach(nil) = (0, 0) | |
| sumEach((x, y)::xs) = | |
let | |
val (s1, s2) = sumEach(xs) | |
in | |
(x + s1, y + s2) | |
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 sumLists(nil) = 0 | |
| sumLists(nil::YS) = sumLists(YS) | |
| sumLists((x::xs)::YS) = x + sumLists(xs::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 sumPairs(nil) = 0 | |
| sumPairs((x,y)::zs) = x + y + sumPairs(zs); |