SML: Error: operator and operand don't agree [tycon mismatch] -
i'm trying write sml function has 2 argument, first int , second list of lists. objective insert first argument onto front of every list in second arguemnt. example, append_to_front(1,[[3,4],[6,8],[]]) should return [[1,3,4],[1,6,8],[1]].
i have code:
fun append_to_front(a:int, l:int list list) = if l = [] [] else a::hd(l)::append_to_front(a, tl(l)); and error message: error: operator , operand don't agree [tycon mismatch]. why?
the cons operator :: has type 'a * 'a list -> 'a list, is, requires element on left , list on right. moreover, right-associative, i.e., a::b::c = a::(b::c).
in case, a has type int, b , c both have type int list. consequently, second use of :: isn't well-typed, because has list on both sides. use list concatenation @ in place instead.
Comments
Post a Comment