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