【发布时间】:2018-12-26 10:25:06
【问题描述】:
标准SML基础list定义为
datatype 'a list = [] | :: of 'a * 'a list
但是,当我尝试创建自己的列表数据类型时出现此错误:
- datatype 'a mylist = [] | mycons of 'a * 'a mylist
Error: syntax error found at LBRACKET
但是,这是可行的:
- datatype 'a mylist = Nil | mycons of 'a * 'a mylist;
datatype 'a mylist = Mycons of 'a * 'a mylist | Nil
但由于缺少方括号,此版本不会产生非常类似于列表的输出:
- Mycons (1,Nil);
val it = Mycons (1,Nil) : int mylist
- Mycons (1, Mycons (1,Nil));
val it = Mycons (1,Mycons (1,Nil)) : int mylist
为什么 SML 不接受我最初使用 [] 的尝试?
【问题讨论】: