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

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -