2. Standard Collections

Created Saturday 23 August 2014

Overview

Functional Collections

data List a = Empty | Cons a (List a)
updateFirst :: List a -> a -> List a
updateFirst Empty y = Empty
updateFirst (Cons x xs) y = Cons y xs

Set

Set restrictions

Map

Seq

Seq Pattern Matching

View Patterns

length :: Seq a -> Int
length (viewl -> EmptyL) = 0
length (viewl -> x :< xs) = 1 + length xs

viewl :: Seq a -> ViewL a

data ViewL a
= EmptyL
| a :< (Seq a)

length' :: Seq a -> Int
length' (viewr -> EmptyR) = 0
length' (viewr -> xs :> x) = 1 + length' xs



Backlinks: