0
我有一个字符列表[#"h", #"i", #" ", #"h", #"i"]
,我想从中获取第一个字(每个空格之前的第一个字符序列)。试图从字符列表中获取第一个字
我写了一个函数,它给了我这样的警告:
标准输入:13.1-13.42警告:因为价值 限制型乏不是一概而论的实例化虚拟类型(X1,X2,... 。)
这里是我的代码:
fun next [] = ([], [])
| next (hd::tl) = if(not(ord(hd) >= 97 andalso ord(hd) <= 122)) then ([], (hd::tl))
else
let
fun getword [] = [] | getword (hd::tl) = if(ord(hd) >= 97 andalso ord(hd) <= 122) then [hd]@getword tl else [];
in
next (getword (hd::tl))
end;
编辑:
预期的输入和输出
next [#"h", #"i", #" ", #"h", #"i"] => ([#"h", #"i"], [#" ", #"h", #"i"])
任何人可以帮助我解决?谢谢!
目标是不使用常见的ML函数,我们必须递归地完成整个事情。 但是你的建议真的很好!谢谢 – madcrazydrumma