Tree navigation
type t = specify here a type to test
fun ( x :[Any*]):[t*] =
let f( x :[Any*]):[t*]) = ...
Note here that the recursive function f is wrapped by a second anonymous function so that it does not expose the recursion variable.
fun (e : [Any*]):[ T*] =
let f( accu :[T*] , x :[Any*]):[T*] =
match x with
[ h&T&<_ ..>(k&[Any*]) ;t] -> f( accu@[h], k@t)
| [ <_ ..>(k&[Any*]) ;t] -> f( accu, k@t)
| [ h&T ;t] -> f( accu@[h], t)
| [ _ ;t] -> f( accu, t)
| [] -> accu
in f ([], e);;
Note that this implementation may generate empty branch warnings in particular - for the first branch if T&<_ ..>(k&[Any*]) is Empty
- for the second branch if <_ ..>(k&[Any*]) is smaller than T&<_>(k&[Any*])
- for the first branch if t is smaller than <_ ..>(k&[Any*])
Patterns
let sortAlg (n :Int):Latin1 =
match string_of n with
[ (s0::'0' | s1::'1' | s2::'2' | s3::'3' | s4::'4' |
s5::'5' | s6::'6' | s7::'7' | s8::'8' | s9::'9')+ ] ->
s0 @ s1 @ s2 @ s3 @ s4 @ s5 @ s6 @ s7 @ s8 @ s9
| _ -> raise "Invalid argument for sortAlg."
;;
|