The expressiveness of Haskell – Split a List.

Just recently playing around with one of the excellent Advent of Code problems (specifically 2015 question 6 ) a possible solution involved splitting a list into two parts where the first element goes into the first part, the second element into the second part and so on. For example [1, 2, 3, 4, 5, 6] -> [1, 3, 5], [2, 4, 6] So, in terms of function signatures we can write splitList :: [a] -> ([a], [a]) Notice there’s no constraint on the type in the list, it’s a very general function. One way of doing this is is to make use of pattern matching Read More

ˆ Back To Top