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 printList(nil) = () | |
| printList(x::xs) = | |
(print(Int.toString(x)); | |
print("\n"); | |
printList(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 proportional(x, i) = | |
if i=0 | |
then 1 | |
else x * proportional(x, i-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
exception EmptyList; | |
fun reduce(F, nil) = raise EmptyList | |
| reduce(F, [a]) = a | |
| reduce(F, x::xs) = F(x, reduce(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 remove_second(L) = | |
if List.length(L) < 2 then nil else hd(L) :: tl(tl(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 removeeven(nil) = nil | |
| removeeven(x::xs) = | |
if x mod 2 = 0 | |
then removeeven(xs) | |
else x::removeeven(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 removex n nil = nil | |
| removex n (x::xs) = | |
(if n=x then (fn y => y) | |
else (fn y => (x::y))) (removex 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 replaceZero(L) = | |
map(fn n => if n<0 then 0 else n, 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 reverse(nil) = nil | |
| reverse(x::xs) = reverse(xs) @ [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 reverse(nil) = nil | |
| reverse(x::xs) = reverse(xs) @ [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 reverse L = | |
let | |
fun rev1 nil L = L | |
| rev1 (x::xs) L = rev1 xs (x::L) | |
in | |
rev1 L nil | |
end; |