sml中的mutual recursion

在ML中使用and连接两个相互调用的函数,这样不会出现找不到定义的情况。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
fun match xs =
let fun s_need_one xs =
case xs of
[]=>true
| 1::xs' => s_need_two xs'
| _ => false
and s_need_two xs =
case xs of
[]=>false
| 2::xs' => s_need_one xs'
| _ => false
in
s_need_one xs
end