【发布时间】:2017-10-13 05:14:18
【问题描述】:
我是 SML 的新手,我想编写一个函数 splitup :int list -> int list * int list 给定一个整数列表,它从两个整数列表创建,一个包含非负条目,另一个包含负条目。
这是我的代码:
fun splitup (xs :int list) =
if null xs
then ([],[])
else if hd xs < 0
then hd xs :: #1 splitup( tl xs)
else hd xs :: #2 splitup( tl xs)
这是我得到的警告:
ERROR : operator and operand don't agree
ERROR : types of if branches do not agree
函数 splitup(tl xs) 应该返回 int list * int list 所以我认为我的递归应该没问题。
有什么问题,我该如何解决?
【问题讨论】:
标签: functional-programming sml smlnj