编译器无法识别定义的类型

埃比·波伦(Ebbe Bollen)

由于某种原因,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

pointcolour工种很好,但是当我尝试编译像一个函数:

let testFig : figure =
    (50,50), 45, (255,0,0)

编译器将引发fs001异常,并说它是预期的figure但是得到了(int*int) * int * (int*int*int)(这是图形的一部分!)。

我有点迷茫,看不清为什么它不起作用。

托马斯·佩特里切克(Tomas Petricek)

要创建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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章