Search code examples
listhaskellvariable-length

Checking the length of multiple lists


length' :: [[Int]] -> [Int]
length' [(x:xs)] = map length'[(x:xs)]

The code I have currently prints out the length over one inputted list. How do I go around finding the length for multiple lists.

E.g. Input:  [[2,3,4], [2]] Output: [3,1] 

Solution

  • You can just call length on each inputted list using map.

    length' :: [[a]] -> [Int]
    length' = map length