本文介绍了F#签名文件错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用fsi文件在单独的文件中允许相互递归的类,但是我的fsi文件未编译.下面是一个简单的示例,演示了此问题.

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.

文件program.fs:

File program.fs:

module mod1
type first =
    |zero = 0

文件File1.fs:

File File1.fs:

module mod2
type second =
    |zero2 = 0

使用--sig:signature.fsi编译会产生:

#light

module mod1
type first =
  |  zero  =  0

module mod2
type second =
  |  zero2  =  0

线路上有错误

type second

哪个

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

推荐答案

您会认为这是签名文件的用途(例如C ++头文件),但不是.至少那是我最初的想法.

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.

在F#中定义相互递归类型的唯一方法是将它们放在相同的源文件中,并使用and关键字:

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

这篇关于F#签名文件错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 12:20