【发布时间】:2017-02-07 21:19:57
【问题描述】:
我有以下两个“函数”:is_three 和 SOME
fun is_three(number) =
case numbers of
3 => true
| _ => false
当我写下以下两个语句时,我得到了这个:
is_three;
val it = fn : int -> bool
SOME;
val it = fn : 'a -> 'a option
从表面上看,它们似乎都是返回值的函数。但是,如果我尝试在 case 语句中使用 is_three,我会得到以下信息:
stdIn:20.9-20.19 Error: non-constructor applied to argument in pattern: is_three
fun are_threes(numbers) =
case numbers of
[] => true
| is_three(x)::xs => true andalso are_threes(xs)
- case语句如何区分什么是构造函数和什么是函数
- 为什么不能在 case 语句中使用函数?
【问题讨论】:
标签: pattern-matching sml