F#类型定义语法 [英] F# type definition syntax

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

问题描述

我正在研究'99 F#问题',看到了 NestedList 的以下定义:

I'm working on the '99 problems of F#', and saw the following definition of NestedList:

type 'a NestedList = List of 'a NestedList list | Elem of 'a

我对这里的语法有些困惑,因为通常在 type 之后只有一个类型名称.有人可以澄清吗?谢谢!

I'm a little confused by the syntax here, as normally there is only a type name after the type. Can someone clarify it? Thanks!

推荐答案

这是简明的联盟.您也可以将其编写为:

This is a discriminated union in a condensed syntax. You can also write it as:

type 'a NestedList =
    | List of 'a NestedList list
    | Elem of 'a

type NestedList<'a> =
    | List of NestedList<'a> list
    | Elem of 'a

这是使用泛型,其中类型本身正在将另一种类型用作参数.

This is using generics, where the type itself is taking another type as an argument.

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

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