The standard SML Basis list is defined as
datatype 'a list = [] | :: of 'a * 'a list
However, I get this error when I try to create my own list data type:
- datatype 'a mylist = [] | mycons of 'a * 'a mylist
Error: syntax error found at LBRACKET
However, this works:
- datatype 'a mylist = Nil | mycons of 'a * 'a mylist;
datatype 'a mylist = Mycons of 'a * 'a mylist | Nil
But due to the lack of square brackets, this verson doesn't produce very list-like output:
- Mycons (1,Nil);
val it = Mycons (1,Nil) : int mylist
- Mycons (1, Mycons (1,Nil));
val it = Mycons (1,Mycons (1,Nil)) : int mylist
Why isn't SML accepting my original attempt with []?