开发者

How can I create a type with multiple parameters in OCaml?

开发者 https://www.devze.com 2022-12-12 19:40 出处:网络
I\'m trying to create a type that has multiple type para开发者_运维问答meters.I know how to make a type with one parameter:

I'm trying to create a type that has multiple type para开发者_运维问答meters. I know how to make a type with one parameter:

type 'a foo = 'a * int

But I need to have two parameters, so that I can parameterize the 'int' part. How can I do this?


The way to do this is:

type ('a, 'b) foo = 'a * 'b

Type parameters aren't curried, so you need to provide them in tuple form as a single parameter. A good example of this is the Hashtbl module:

type ('a, 'b) t 

The type of hash tables from type 'a to type 'b.


# type ('a, 'b) couple = 'a * 'b ;;

For instance...

0

精彩评论

暂无评论...
验证码 换一张
取 消