由于某种原因,F#无法识别我定义的类型。我有几种类型:
type point = int * int
type colour = int * int * int
type figure =
| Circle of point * int * colour
| Rectangle of point * point * colour
| Mix of figure * figure
在point
和colour
工种很好,但是当我尝试编译像一个函数:
let testFig : figure =
(50,50), 45, (255,0,0)
编译器将引发fs001
异常,并说它是预期的figure
但是得到了(int*int) * int * (int*int*int)
(这是图形的一部分!)。
我有点迷茫,看不清为什么它不起作用。
要创建figure
值,您需要指定要创建的案例的名称。例如,如果要创建,则Circle
需要编写:
let testFig : figure =
Circle((50,50), 45, (255,0,0))
如果没有Circle
构造函数,则只需创建一个(50,50), 45, (255,0,0)
具有type的值(int * int) * int * (int * int * int)
。这与point * int * color
(因为point
并且color
仅仅是别名)相同。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句