Journal Entry #3: 06/15/2015-06/19/2015


Working with Lists in Elm is particularly diffcult. Elm uses many techniques inorder to define a list. These list can be checked by recursion. This will make the function or procedure repeat, until the solution or problem has been found or is resolved. I have came to the understanding that Elm has made the code more concise and short for clear understanding of what is going on. For example, it is clear that to define a Lists of data one must define an variable name and label that variable's data type as a list of strings. In the example provided below, one will see the different ways to use Lists of strings in order to check whether the list of strings for various qualities. These qualities consists of lengths, exsistance, and removals of strings from the desired list.

import Graphics.Element exposing (..) import Text instructor_emails : List String instructor_emails = [ "sweirich@cis.upenn.edu", "tgarsys@seas.upenn.edu", "lankas@sas.upenn.edu" ] subscribe : String -> List String -> List String subscribe email list = email :: list isEmpty : List String -> Bool isEmpty list = case list of [] -> True head :: tail -> False length : List String -> Int length list = case list of [] -> 0 head :: tail -> 1 + length tail contains : String -> List String -> Bool contains str list = case list of [] -> False head :: tail -> if str == head then True else contains str tail compose : String -> List String -> List String compose msg list = case list of [] -> [] email :: tail -> ("to: " ++ email ++ " ; " ++ msg) :: compose msg tail remove_instructors : List String -> List String -> List String remove_instructors instrs allemails = case allemails of [] -> [] email :: tail -> let l = remove_instructors instrs tail in if contains email instrs then l else email :: l main : Element main = flow down [ display "subscribe leondra" (subscribe "leondra@upenn.edu") instructor_emails, display "isEmpty" isEmpty [], display "isEmpty" isEmpty instructor_emails, display "length" length [], -- 0 display "length" length instructor_emails, display "contains sweirich" (contains "sweirich@cis.upenn.edu") instructor_emails, -- True display "contains leondra" (contains "leondra@upenn.edu") instructor_emails, display "compose Emergency!" (compose "Emergency!") instructor_emails, display "remove_instructors instructor_emails" (remove_instructors instructor_emails) ["sweirich@cis.upenn.edu", "leondra@upenn.edu"] ] display : String -> (List a -> b) -> List a -> Element display name f value = name ++ " (" ++ toString value ++ ") ⇒\n " ++ toString (f value) |> Text.fromString |> Text.monospace |> leftAligned