amit-singhs / test-elm

This is a test elm repository.
test-elm-git-master.amit-singhs.vercel.app
0 stars 0 forks source link

listLength : List a -> Int #5

Open renovatorruler opened 3 years ago

renovatorruler commented 3 years ago

Create a function called listLength which will take a List a and return the number of elements in the list.

λ> listLength [123, 456, 789]
3
λ> listLength "Hello, world!"
13
amit-singhs commented 3 years ago
listLength : List a -> Int
listLength xs =
  case xs of
    [] -> 0
    head :: tail -> 1+listLength tail