Skip to content

Instantly share code, notes, and snippets.

@tai2
Last active July 18, 2017 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tai2/225f66abbbbe9069f7e9102594ed02c6 to your computer and use it in GitHub Desktop.
Save tai2/225f66abbbbe9069f7e9102594ed02c6 to your computer and use it in GitHub Desktop.
module Hello exposing (..)
import Html exposing (text)
import List exposing (take, drop, head)
indexOf : a -> List a -> Int
indexOf target list =
let
f target n list =
case head (drop n list) of
Just h ->
if h == target then
n
else
f target (n + 1) list
Nothing ->
-1
in
f target 0 list
main =
let
i =
indexOf "c" [ "a", "b", "c" ]
in
text (toString i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment