99 Elm Problems/Problem 3

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Problem 3: Implement the function nth to return the n-th element of a list.

import Html exposing (text)
import List exposing (head, length)
import Maybe

nth: Int -> List a -> Maybe a
-- your implementation goes here

main =
  case (nth 2 (List.range 1 4)) of
    Just a -> text (toString a)
    Nothing -> text "No element found"