lex(explode "one fine day") = [["o","n","e"], ["f","i","n","e"], ["d","a","y"]]
fun firstWord nil = nil | firstWord(h::t) = if h=hd (explode " ") then nil else h::firstWord t; fun butFirstWord nil = nil | butFirstWord(h::t)= if h=hd (explode " ") then t else butFirstWord t; fun lex nil = nil | lex l = firstWord l :: lex(butFirstWord l); |
franglais "dog" = "chien" scots "lives" = "bides"
fun franglais "house" = "maison" | franglais "dog" = "chien" | franglais "beware" = "regarde" | franglais "at" = "dans" | franglais "the" = "le" | franglais x = x; |
fun trans f s = let val EnglishWordList = map implode (lex(explode s)); val ForeignWordList = map f EnglishWordList; fun addSpace s = s^" "; in concat(map addSpace ForeignWordList) end; |
fun alpha s = (s>= #"A" andalso s<= #"Z") orelse
(s>= #"a" andalso s<= #"z");
fun takewhile f nil = nil
| takewhile f (h::t) = if f h then h::(takewhile f t)
else nil;
fun dropwhile f nil = nil
| dropwhile f (h::t) = if f h then dropwhile f t else h::t;
fun lex nil = nil
| lex l = (takewhile alpha l)::
(takewhile (not o alpha) (dropwhile alpha l))::
(lex (dropwhile (not o alpha) (dropwhile alpha l)));
fun trans f = (foldr (op ^) "") o map (f o implode) o lex o explode;

Thanks to Tim Larson for the corrections.