Data.List
v11.3.15 • Parameterized Lists
Church-encoded linked lists. Functional operations are implemented using Church folds.
Types
List :: * -> *
Parameterized linked list. Church-encoded by the compiler.
Implementationdata List A = Nil | Cons A (List A)
Foreigns
No foreign functions defined in this module.
Functions
head :: List A -> Maybe A
Safely retrieve the head of a list.
Implementationhd xs = case xs of
Nil -> Nothing
Cons h t -> Just h
foldr :: (A -> B -> B) -> B -> List A -> B
Right-associative fold. In Church encoding, t is the IH result.
foldr f z xs = case xs of
Nil -> z
Cons h t -> f h t
map :: (A -> B) -> List A -> List B
Apply a function to every element.
Implementationmap f xs = case xs of
Nil -> Nil
Cons h t -> Cons (f h) t
append :: List A -> List A -> List A
Concatenates two lists.
Implementationappend xs ys = case xs of
Nil -> ys
Cons h t -> Cons h t
length :: List A -> Nat
Calculates the size of the list.
Implementationlength xs = case xs of
Nil -> Zero
Cons h t -> Succ t