This page describes the subset of Haskell accepted by the Haskelite interpreter.
Integers, characters, strings (i.e. lists of characters), variables, arithmetic operations (+, -, *, div, mod), comparisons (==, <=, etc.), tuples, lists, enumerations (e.g. [1..10]), lambda-expressions, sections, let and where local bindings, case expressions.
Let and where bindings can only define single variables, not patterns.
Haskell-98 like data
and type
declarations; no record syntax, existentials or GADTs;
no deriving
(because there are no typeclasses); no
higher-kinded types.
Data types have structural equality and order (similar to derived Eq and Ord); note that comparisions can fail at runtime (e.g. when attempting to compare functions).
You can define functions using multiple equations with pattern matching over integers, characters, lists and tuples, boolean guards, and recursive definitions.
Data.List
are provided. Note that functions based on
equality or ordering have an overly polymorphic type (they should
really have a typeclass restriction); they will fail at runtime if you
apply them to function values.
even, odd :: Int -> Bool max, min :: a -> a -> a -- too polymorphic; may fail at runtime! compare :: a -> a -> Ordering fst :: (a,b) -> a snd :: (a,b) -> b (&&), (||) :: Bool -> Bool -> Bool head :: [a] -> a tail :: [a] -> [a] (++) :: [a] -> [a] -> [a] (!!) :: [a] -> Int -> a length :: [a] -> Int reverse :: [a] -> [a] -- defined using an accumulator init :: [a] -> [a] last :: [a] -> a sum, product :: [Int] -> Int and, or :: [Bool] -> Bool take, drop :: Int -> [a] -> [a] maximum, minimum :: [a] -> a -- too polymorphic! concat :: [[a]] -> [a] repeat :: a -> [a] replicate :: Int -> a -> [a] cycle :: [a] -> [a] iterate :: (a -> a) -> a -> [a] map :: (a -> b) -> [a] -> [b] filter :: (a -> Bool) -> [a] -> [a] foldr :: (a -> b -> b) -> b -> [a] -> b foldl :: (a -> b -> a) -> a -> [b] -> a foldl' :: (a -> b -> a) -> a -> [b] -> a -- strict version of foldl (.) :: (b -> c) -> (a -> b) -> a -> c ($), ($!) :: (a -> b) -> a -> b -- $! is the strict application zip :: [a] -> [b] -> [(a,b)] zipWith :: (a -> b -> c) -> [a] -> [b] -> [c] takeWhile, dropWhile :: (a -> Bool) -> [a] -> [a] any, all :: (a -> Bool) -> [a] -> Bool chr :: Int -> Char ord :: Char -> Int isAlpha, isDigit, isAlphaNum, isUpper, isLower :: Char -> Bool show :: Int -> String -- only for integers
You can force evaluation to weak normal form using bang patterns (!) in variable patterns. Alternatively, to force evaluation to full normal form you can use the following built-in function:
force :: a -> a -- evaluate to full normal form
This behaves like identity function, except that it evaluates the argument fully.
Note that force
will loose sharing in normal forms,
e.g. a pair (x,x)
with two identical (shared) values
will be expanded into a pair with copies of the normal form of x
.