Skip to content

Instantly share code, notes, and snippets.

@sshine
Created January 8, 2022 01:57
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 sshine/1c909e27149dfd6081e99ef39cb3a7e1 to your computer and use it in GitHub Desktop.
Save sshine/1c909e27149dfd6081e99ef39cb3a7e1 to your computer and use it in GitHub Desktop.
-- A ConcatList is just a fancy way to divide lists using 'Concat' instead of
-- 'Cons'. Where 'Cons' took one element on the left, and a list on the right,
-- 'Concat' takes a list on both sides.
data ConcatList a
= Nil
| Single a
| Concat (ConcatList a) (ConcatList a)
deriving (Show)
-- The length of a list is the length of its sub-lists
myLength :: ConcatList a -> Int
myLength Nil = undefined
myLength (Single x) = undefined
myLength (Concat xs ys) = undefined
-- The sum of a list is the sum of all of its elements
mySum :: Num a => ConcatList a -> a
mySum Nil = undefined
mySum (Single x) = undefined
mySum (Concat xs ys) = undefined
-- The depth of a list is the most possible steps to reach a 'Nil'.
myDepth :: ConcatList a -> Int
myDepth Nil = undefined
myDepth (Single x) = undefined
myDepth (Concat xs ys) = undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment