functional programming - Standard ML: Operator and Operand Don't Agree (Circularity) -
i'm trying write function in sml flip alternate elements of list. here's function:
fun flipalternate(nil) = nil | flipalternate([x]) = x | flipalternate(x::y::xs) = y::x::flipalternate(xs);
when go use file (ullman.sml) in interactive interpreter, compilation error:
- use "ullman.sml"; [opening ullman.sml] ullman.sml:5.31-5.54 error: operator , operand don't agree [circularity] operator domain: 'z list * 'z list list operand: 'z list * 'z list in expression: x :: flipalternate xs
so sml saying requires list of lists of integers i'm giving pair of lists of integers?
i'm bit lost here appreciated.
thanks, bclayman
your second case wrong; want
fun flipalternate(nil) = nil | flipalternate([x]) = [x] | flipalternate(x::y::xs) = y::x::flipalternate(xs);
sml looking @ second case , concluding
flipalternate :: 'z list list -> 'z list
which isn't compatible recursion in third case.
edit: knows result list
first case, , concludes argument has 1 more list
result second case.
Comments
Post a Comment