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 interleave n nil = [[n]] | |
| interleave n (L as x::xs) = (n::L) :: map (fn L => x::L) (interleave n 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
fun intersect(nil, _) = nil | |
| intersect(_, nil) = nil | |
| intersect(xa as x::xs, ya as y::ys) = | |
if x = y then x::intersect(xs, ys) | |
else if x < y then intersect(xs, ya) | |
else intersect(xa, ys) (* x > y *); |
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 length(nil) = 0 | |
| length(x::xs) = 1 + length(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
fun map(F, nil) = nil | |
| map(F, x::xs) = F(x)::map(F,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
fun maxList(L) = | |
if tl(L) = nil | |
then hd(L) | |
else | |
let | |
val x = hd(L); | |
val y = maxList(tl(L)) | |
in | |
if x<y then y else x | |
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 merge(nil, M) = M | |
| merge(L, nil) = L | |
| merge(x::xs, y::ys) = | |
if (x:int) < y then x::merge(xs, y::ys) | |
else y::merge(x::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 merge(nil, M) = M | |
| merge(L, nil) = L | |
| merge(L as x::xs, M as y::ys) = | |
if (x:int) < y then x::merge(xs, M) | |
else y::merge(L, 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 mergeSort(nil) = nil | |
| mergeSort([a]) = [a] | |
| mergeSort(L) = | |
let | |
val (M, N) = split(L); | |
val M = mergeSort(M); | |
val N = mergeSort(N); | |
in | |
merge(M, 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 millionPower(x:real) = | |
let | |
val four = x*x*x*x; | |
val twenty = four*four*four*four*four; | |
val hundred = twenty*twenty*twenty*twenty*twenty; | |
val fivehundred = hundred*hundred*hundred*hundred*hundred | |
in | |
fivehundred*fivehundred | |
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 min3(a:int, b, c) = | |
if a<b then | |
if a<c then a | |
else c | |
else | |
if b<c then b | |
else c; |