Ocaml推理类型int列表而不是'列表

ale*_*308 3 ocaml types type-inference

let rec getElement list index = match list with
| [] -> raise OutOfBoundException
| first::elems -> if index = 0 then first else getElement elems index-1;;
Run Code Online (Sandbox Code Playgroud)

我不明白为什么这个函数有类型(int list - > int - > int)而不是('list - > int - >'a).我需要编写返回列表中第n个元素的函数,它具有泛型类型(由用户定义类型exp:http://pastebin.com/UefshcLa).

我该怎么写这个功能?为什么Ocaml推断列表是int列表而不是'列表?

zak*_*kki 10

OCaml解释(getElement elems index) - 1,因为函数应用程序强于-.

let rec getElement list index = match list with
| [] -> raise OutOfBoundException
| first::elems -> if index = 0 then first else getElement elems (index-1);;
Run Code Online (Sandbox Code Playgroud)