Developer_1987
Developer_1987

Reputation: 1

How can I use a map function in SML to implement this code?

fun add nil = nil    
 | add ((a ,b) :: c) = (a+b) :: (add c);

I've just started learning SML, and the map function is new to me.

How can I use a map function in SML to implement this code?

Upvotes: 0

Views: 192

Answers (1)

user15270287
user15270287

Reputation: 1153

-val a = [(1, 2), (2, 3), (3, 4)];
val a = [(1,2),(2,3),(3,4)] : (int * int) list
- map (fn (x, y) => x + y) a;
val it = [3,5,7] : int list

Upvotes: 2

Related Questions