Safe Haskell | None |
---|---|
Language | Haskell2010 |
Definitions found in Haskell's Data.List.
This module should be imported qualified to avoid clashes with standard Haskell definitions.
- nil :: Program
- concat2 :: Program
- reverse :: Program
- foldl :: Program
- foldl' :: Program
- foldr :: Program
- iterate :: Program
- cycle :: Program
- take :: Program
- filter :: Program
- partition :: Program
- repeat :: Program
- replicate :: Program
- sort :: Program
- naiveSort :: Program
- map :: Program
- equals_List_Int :: Program
- length :: Program
- zip :: Program
- zipWith :: Program
- forceSpine :: Program
Documentation
Lazy left list fold. Provided mostly for seeing how it causes stack overflows.
foldl : (b -> a -> b) -> b -> [a] -> b
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
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]
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 n elements form the beginning of a list.
take 3 [1..] = [1,2,3]
take : Int -> [a] -> [a]
Keep only the elements for which a predicate holds.
filter even [1..] = [2, 4, 6, ...]
filter : (a -> Bool) -> [a] -> [a]
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 a single element infinitely.
repeat 1 = [1, 1, 1, ...]
repeat : a -> [a]
Repeat a single element a number of times.
replicate 3 1 = [1, 1, 1]
replicate : Int -> a -> [a]
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]
That Haskell sort function often misleadingly referred to as "quicksort".
naiveSort : [Int] -> [Int]
equals_List_Int :: Program Source #
Equality of lists of integers.
equals_List_Int : [Int] -> [Int] -> Bool
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)]
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]