< 99 Elm Problems < Problem 4

Solution 1: Recursive version

myLength list =
  case list of
    [] -> 0
    head :: tail -> 1 + myLength tail

Solution 2: Using List.foldl

myLength = List.foldl (\_ b -> b + 1) 0
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.