Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data NonEmptyList a = Element a (NonEmptyList a) | LastElement a deriving Show
- length:: NonEmptyList a -> Int
- length (LastElement _) = 1
- length (Element _ list) = 1 + Main.length list
- map:: (a->b)->NonEmptyList a->NonEmptyList b
- map f (LastElement a) = LastElement (f a)
- map f (Element a list) = Element (f a) (Main.map f list)
- foldl:: (a->a->a)->a->NonEmptyList a->a
- foldl f acc (LastElement a) = f acc a
- foldl f acc (Element a list) = Main.foldl f (f acc a) list
- foldr:: (a->a->a)->a->NonEmptyList a->a
- foldr f acc (LastElement a) = f acc a
- foldr f acc (Element a list) = f a (Main.foldr f acc list)
- infixr 5 .++
- (.++):: NonEmptyList a -> NonEmptyList a -> NonEmptyList a
- (LastElement first) .++ second = Element first second
- (Element first firstList) .++ other = Element first (firstList .++ other)
- elem:: Eq a=>a->NonEmptyList a->Bool
- elem a (LastElement b) = (a==b)
- elem a (Element head list) = (a==head) || Main.elem a list
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement