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.

Implementation
data 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.

Implementation
hd 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.

Implementation
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.

Implementation
map f xs = case xs of
    Nil      -> Nil
    Cons h t -> Cons (f h) t

append :: List A -> List A -> List A

Concatenates two lists.

Implementation
append xs ys = case xs of
    Nil      -> ys
    Cons h t -> Cons h t

length :: List A -> Nat

Calculates the size of the list.

Implementation
length xs = case xs of
    Nil      -> Zero
    Cons h t -> Succ t