如何使用SML中的记录创建数据类型的实例?

时间:2014-10-03 01:48:05

标签: record sml ml

例如,如果你有

datatype 'a DT =
   thingy of {field1: int, field2: int}
| Empty DT;

你怎么能够创造" thingy"在功能中填写其字段?假设您拥有每个字段所需的值。

1 个答案:

答案 0 :(得分:0)

- datatype 'a DT = thingy of {x: int, y: int} | Empty; datatype 'a DT = Empty | thingy of {x:int, y:int} - thingy {x = 5, y = 4}; val it = thingy {x=5,y=4} : 'a DT - fun f x y = thingy {x = x, y = y}; val f = fn : int -> int -> 'a DT