【发布时间】:2016-11-05 14:34:01
【问题描述】:
我有以下代码:
type 'v state = {
visited: string list;
unvisited: string list;
value: 'v;}
type ('a,'b) parser =
| Parser of ('a state -> 'b state list)
type 'a result =
| Ok of 'a
| Err
let parseString x = Ok x
let parseInt x = Ok (int_of_string x)
let custom = fun stringToSomething ->
Parser (fun { visited; unvisited; value } ->
match unvisited with
| [] -> []
| next::rest ->
(match stringToSomething next with
| Ok (nextValue) ->
[{
visited = (next :: visited);
unvisited = rest;
value = (value nextValue)
}]
| Err -> [])))
let stringp = custom parseString
let intp = custom parseInt
当我尝试编译我的程序时,custom parseString 出现以下错误:
Error: The type of this expression, (string -> '_a, '_a) parser,
contains type variables that cannot be generalized
这个错误是什么意思?
【问题讨论】:
标签: ocaml