From 0c891ed95c6b4d655e6f0dc93fca9468ba6e6096 Mon Sep 17 00:00:00 2001 From: Yan Wittmann <2121578@stud.hs-mannheim.de> Date: Mon, 7 Nov 2022 09:13:20 +0100 Subject: [PATCH] Lists length/contains Signed-off-by: Skyball2000 --- aufgaben/src/Test03/ListStuff.elm | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 aufgaben/src/Test03/ListStuff.elm diff --git a/aufgaben/src/Test03/ListStuff.elm b/aufgaben/src/Test03/ListStuff.elm new file mode 100644 index 0000000..26d8fe0 --- /dev/null +++ b/aufgaben/src/Test03/ListStuff.elm @@ -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))