Lists length/contains

Signed-off-by: Skyball2000 <thomas3654william@gmail.com>
main
Yan Wittmann 2022-11-07 09:13:20 +01:00 committed by Skyball2000
parent 7dc8a2f21e
commit 0c891ed95c
1 changed files with 28 additions and 0 deletions

View File

@ -0,0 +1,28 @@
module Test03.ListStuff exposing (..)
import Html
contains : List comparable -> comparable -> Bool
contains list element =
case list of
head :: tail -> if head == element then True else contains tail element
[] -> False
length : List x -> Int
length x =
case x of
[] -> 0
head :: tail -> 1 + length tail
length1 : List x -> Int -> Int
length1 x i =
case x of
[] -> i
head :: tail -> length1 tail (i + 1)
l = List.range 1 10000000
main = Html.text (Debug.toString (length1 l 0))
--main = Html.text (Debug.toString (contains l 23))