F#前向类型声明 [英] F# forward type declarations

查看:103
本文介绍了F#前向类型声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我偶然发现了F#中的这个问题.假设我想声明两个互相引用的类型:

I stumbled across this problem in F#. Suppose, I want to declare two types that reference each other:


type firstType = 
     | T1 of secondType
     //................

type secondType =
     | T1 of firstType  
     //................    

我该怎么做,这样编译器不会生成错误?

How do I do that, so the compiler does not generate an error?

推荐答案

您使用'and':

type firstType = 
     | T1 of secondType

and secondType =
     | T1 of firstType

这篇关于F#前向类型声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆