Safe Haskell | None |
---|---|
Language | Haskell2010 |
- maybe :: Program
- nothing :: Program
- 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
- length :: Program
- zip :: Program
- zipWith :: Program
- forceSpine :: Program
- equals_List_Int :: Program
- fst :: Program
- snd :: Program
- curry :: Program
- uncurry :: Program
- swap :: Program
- equals_Pair_Int :: Program
- and2 :: Program
- or2 :: Program
- not :: Program
- bool :: Program
- eq_Bool :: Program
- add :: Program
- sub :: Program
- mul :: Program
- div :: Program
- mod :: Program
- eq_Int :: Program
- lt_Int :: Program
- leq_Int :: Program
- gt_Int :: Program
- geq_Int :: Program
- neq_Int :: Program
- min :: Program
- max :: Program
- seq :: Program
- id :: Program
- const :: Program
- compose :: Program
- fix :: Program
- force :: Program
Maybe
Lists
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]
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]
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]
Force the spine of a list.
forceSpine :: [a] -> [a]
equals_List_Int :: Program Source
Equality of lists of integers.
equals_List_Int : [Int] -> [Int] -> Bool
Tuples
Convert an uncurried function to a curried one.
curry : ((a, b) -> c) -> a -> b -> c
Convert a curried function to an uncurried one.
uncurry : (a -> b -> c) -> (a, b) -> c
Boolean
Boolean deconstructor.
bool f _ False = f bool _ t True = t
bool : a -> a -> Bool -> a
Numbers
Arithmetic
Comparisons
Other
Functions
Finally I can define seq
directly! :-)
Note that this function is less powerful than GHC's seq
, since STG
does not have a rule to force functions, only expressions that reduce to an
algebraic or primitive value. This leads to the fact that STG's seq
is less
powerful than Haskell's, since in Haskell
seq (const ()) () = ()
whereas in the STG
constUnit = (x) -> Unit (); seq (constUnit, Unit) = ERROR
Helpers
Force a value to normal form and return it.
This function makes heavy use of the fact that the STG is untyped. It currently supports the following types:
- Unit (Unit)
- Maybe (Just, Nothing)
- Bool (True, False)
- Int (Int#)
- Either (Left, Right)
- Tuples (Pair, Triple)
- List (Nil, Cons)
Everything else will run into an error.