The following code will complete the task:
map head [[1,2,3],[4,5,6]]
mapis one of the most useful features in haskell (and other functional programming languages). Given a list [a,b,c,d]and function f, map f [a,b,c,d]will return a list [f a, f b, f c, f d]. The function headretrieves the first element of the list. That's why
map head [[1,2,3],[4,5,6]] ->
[head [1,2,3], head [4,5,6]] ->
[1,4]
Jonas source
share