ocaml 类型构造函数参数 [英] ocaml type constructor arguments
本文介绍了ocaml 类型构造函数参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我这样定义了一个 AVL 树,其中 'a -> 'a -> int 是比较函数
I defined an AVL tree as such, with 'a -> 'a -> int being the comparison function
type 'a t = Empty of ('a -> 'a -> int)
| Node of 'a * 'a t * 'a t * ('a -> 'a -> int)
我正在尝试使用此 AVL 模块在单独的模块中实现优先级队列.
I'm trying to use this AVL module to implement a priority queue in a separate module.
type 'a t = Queue of (Avl.t * int)
但是当我尝试编译时出现此错误:
But when I try to compile I get this error:
Error: The type constructor Avl.t expects 1 argument(s),
but is here applied to 0 argument(s)
它在谈论什么参数,队列类型中的语法应该是什么?
What argument is it talking about and what's should the syntax be in the queue type?
推荐答案
您的 AVL 树由节点中的类型 ('a
) 参数化.所以你应该可以说
Your AVL tree is parameterized by the type in the nodes ('a
). So you should be able to say
type 'a t = Queue of ('a Avl.t * int)
这篇关于ocaml 类型构造函数参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文