99 道 Elm 難題/問題 3
外觀
問題 3:實現函式 nth,以返回列表的第 n 個元素。
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"
結果
3