2015-10-12 16:46:15 +00:00
|
|
|
module SublistExample where
|
|
|
|
import List exposing (..)
|
|
|
|
import String
|
|
|
|
|
|
|
|
sublist : List a -> List a -> String
|
|
|
|
sublist alist blist =
|
|
|
|
if alist == blist then "Equal" else
|
2015-10-13 18:31:18 +00:00
|
|
|
if inList alist blist then "Superlist" else
|
|
|
|
if inList blist alist then "Sublist" else "Unequal"
|
2015-10-12 16:46:15 +00:00
|
|
|
|
|
|
|
inList : List a -> List a -> Bool
|
|
|
|
inList alist blist =
|
|
|
|
let getLastInList sublist =
|
|
|
|
case (List.tail sublist) of
|
|
|
|
Just list -> list
|
|
|
|
Nothing -> []
|
|
|
|
|
|
|
|
in
|
|
|
|
if (List.length alist) < (List.length blist) then False else
|
|
|
|
if (List.take (List.length blist) alist) == blist then True else
|
|
|
|
inList (getLastInList alist) blist
|