stgi-1.1: Educational implementation of the STG (Spineless Tagless G-machine)

Safe HaskellNone
LanguageHaskell2010

Stg.Prelude.List

Description

Definitions found in Haskell's Data.List.

This module should be imported qualified to avoid clashes with standard Haskell definitions.

Synopsis

Documentation

nil :: Program Source #

The empty list as a top-level closure.

nil : [a]

concat2 :: Program Source #

Concatenate two lists. Haskell's (++).

concat2 : [a] -> [a] -> [a]

reverse :: Program Source #

reverse a list.

reverse [1,2,3] = [3,2,1]
reverse : [a] -> [a]

foldl :: Program Source #

Lazy left list fold. Provided mostly for seeing how it causes stack overflows.

foldl : (b -> a -> b) -> b -> [a] -> b

foldl' :: Program Source #

Strict left list fold.

Careful: the STG only supports primitive and algebraic case scrutinees. As a result, you can only hand primitive or algebraic b values to this function or it will fail!

foldl' : (b -> a -> b) -> b -> [a] -> b

foldr :: Program Source #

Right list fold.

foldr : (a -> b -> b) -> b -> [a] -> b

iterate :: Program Source #

Build a list by repeatedly applying a function to an initial value.

iterate f x = [x, f x, f (f x), ...]
iterate : (a -> a) -> a -> [a]

cycle :: Program Source #

Infinite list created by repeating an initial (non-empty) list.

cycle [x,y,z] = [x,y,z, x,y,z, x,y,z, ...]
cycle : [a] -> [a]

take :: Program Source #

Take n elements form the beginning of a list.

take 3 [1..] = [1,2,3]
take : Int -> [a] -> [a]

filter :: Program Source #

Keep only the elements for which a predicate holds.

filter even [1..] = [2, 4, 6, ...]
filter : (a -> Bool) -> [a] -> [a]

partition :: Program Source #

Separate a list into parts that do and do not satisfy a predicate.

partition even [1..6] = ([2,4,6], [1,3,5])
partition : (a -> Bool) -> [a] -> ([a], [a])

repeat :: Program Source #

Repeat a single element infinitely.

repeat 1 = [1, 1, 1, ...]
repeat : a -> [a]

replicate :: Program Source #

Repeat a single element a number of times.

replicate 3 1 = [1, 1, 1]
replicate : Int -> a -> [a]

sort :: Program Source #

Haskell's Prelude sort function at the time of implementing this. Not quite as pretty as the Haskell version, but functionally equivalent. :-)

This implementation is particularly efficient when the input contains runs of already sorted elements. For comparison, sorting [1..100] takes 6496 steps, whereas naiveSort requires 268082.

sort : [Int] -> [Int]

naiveSort :: Program Source #

That Haskell sort function often misleadingly referred to as "quicksort".

naiveSort : [Int] -> [Int]

map :: Program Source #

Apply a function to each element of a list.

map : (a -> b) -> [a] -> [b]

equals_List_Int :: Program Source #

Equality of lists of integers.

equals_List_Int : [Int] -> [Int] -> Bool

length :: Program Source #

Length of a list.

length : [a] -> Int

zip :: Program Source #

Zip two lists into one. If one list is longer than the other ignore the exceeding elements.

zip [1,2,3,4,5] [10,20,30] ==> [(1,10),(2,20),(3,30)]

zip xs ys = zipWith Pair xs ys
zip : [a] -> [b] -> [(a,b)]

zipWith :: Program Source #

Zip two lists into one using a user-specified combining function. If one list is longer than the other ignore the exceeding elements.

zipWith (+) [1,2,3,4,5] [10,20,30] ==> [11,22,33]

zipWith f xs ys = map f (zip xs ys)
zipWith : (a -> b -> c) -> [a] -> [b] -> [c]

forceSpine :: Program Source #

Force the spine of a list.

forceSpine :: [a] -> [a]