F# signature file error

大兔子大兔子 提交于 2019-12-12 19:27:13

问题


I was trying to use a fsi file to allow mutually recursive classes in separate files, but my fsi file did not compile. Below is a simple example which demonstrates the problem.

File program.fs:

module mod1
type first =
    |zero = 0

File File1.fs:

module mod2
type second =
    |zero2 = 0

Compiling with --sig:signature.fsi produces:

#light

module mod1
type first =
  |  zero  =  0

module mod2
type second =
  |  zero2  =  0

Which has an error on the line

type second

Which is

Error   1   Unexpected keyword 'type' in signature file. Expected ':', '=' or other token.

回答1:


You'd think that this is what signature files are for (like C++ header files), but it's not. At least, that's what I thought at first.

The only way to define mutually recursive types in F# is to put them in the same source file and use the and keyword:

module mod1_mod2
    type first =
      | zero = 0

    and second =
      | zero2 = 0


来源:https://stackoverflow.com/questions/1866231/f-signature-file-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!