| Safe Haskell | None |
|---|
Prelude.Week1
Contents
- type Char = Char
- type String = [Char]
- type Int = Int
- type Double = Double
- data Bool
- (+) :: Int -> Int -> Int
- (-) :: Int -> Int -> Int
- (*) :: Int -> Int -> Int
- mod :: Int -> Int -> Int
- (>) :: Int -> Int -> Bool
- (<) :: Int -> Int -> Bool
- (>=) :: Int -> Int -> Bool
- (<=) :: Int -> Int -> Bool
- (==) :: Int -> Int -> Bool
- (/=) :: Int -> Int -> Bool
- (+.) :: Double -> Double -> Double
- (-.) :: Double -> Double -> Double
- (*.) :: Double -> Double -> Double
- (>.) :: Double -> Double -> Bool
- (<.) :: Double -> Double -> Bool
- (>=.) :: Double -> Double -> Bool
- (<=.) :: Double -> Double -> Bool
- (==.) :: Double -> Double -> Bool
- (/=.) :: Double -> Double -> Bool
- doubleToString :: Double -> String
- intToString :: Int -> String
- charToString :: Char -> String
- intToDouble :: Int -> Double
- intToChar :: Int -> Char
- charToInt :: Char -> Int
- data IORequest
- = PrintString String
- | Exit
- | ReadString
- | ReadFile String
- data IOResponse
- = Success
- | FileContents String
- | NextLine String
- run :: ([IOResponse] -> [IORequest]) -> IO ()
- (<>) :: String -> String -> String
- (.) :: (b -> c) -> (a -> b) -> a -> c
- trace :: String -> a -> a
- (++) :: [a] -> [a] -> [a]
- head :: [a] -> a
- last :: [a] -> a
- tail :: [a] -> [a]
- init :: [a] -> [a]
- null :: [a] -> Bool
- length :: [a] -> Int
- map :: (a -> b) -> [a] -> [b]
- reverse :: [a] -> [a]
- intersperse :: a -> [a] -> [a]
- intercalate :: [a] -> [[a]] -> [a]
- foldl :: (a -> b -> a) -> a -> [b] -> a
- foldl1 :: (a -> a -> a) -> [a] -> a
- foldr :: (a -> b -> b) -> b -> [a] -> b
- foldr1 :: (a -> a -> a) -> [a] -> a
- concat :: [[a]] -> [a]
- concatMap :: (a -> [b]) -> [a] -> [b]
- and :: [Bool] -> Bool
- or :: [Bool] -> Bool
- any :: (a -> Bool) -> [a] -> Bool
- all :: (a -> Bool) -> [a] -> Bool
- iterate :: (a -> a) -> a -> [a]
- repeat :: a -> [a]
- replicate :: Int -> a -> [a]
- cycle :: [a] -> [a]
- take :: Int -> [a] -> [a]
- drop :: Int -> [a] -> [a]
- splitAt :: Int -> [a] -> ([a], [a])
- takeWhile :: (a -> Bool) -> [a] -> [a]
- dropWhile :: (a -> Bool) -> [a] -> [a]
Basic Types
Arithmetic arithmetic and comparison
Integer arithmetic and comparison
Double arithmetic and comparison
Type conversion functions
doubleToString :: Double -> StringSource
intToString :: Int -> StringSource
charToString :: Char -> StringSource
intToDouble :: Int -> DoubleSource
IO Requests and responses
Constructors
| PrintString String | |
| Exit | |
| ReadString | |
| ReadFile String |
run :: ([IOResponse] -> [IORequest]) -> IO ()Source
String operations
Other convenient operators
(.) :: (b -> c) -> (a -> b) -> a -> c
Function composition.
The trace function outputs the trace message given as its first argument,
before returning the second argument as its result.
For example, this returns the value of f x but first outputs the message.
trace ("calling f with x = " ++ show x) (f x)
The trace function should only be used for debugging, or for monitoring
execution. The function is not referentially transparent: its type indicates
that it is a pure function but it has the side effect of outputting the
trace message.
List operators
These should cover everything you implemented in the first assignment.
(++) :: [a] -> [a] -> [a]
Append two lists, i.e.,
[x1, ..., xm] ++ [y1, ..., yn] == [x1, ..., xm, y1, ..., yn] [x1, ..., xm] ++ [y1, ...] == [x1, ..., xm, y1, ...]
If the first list is not finite, the result is the first list.
head :: [a] -> a
Extract the first element of a list, which must be non-empty.
last :: [a] -> a
Extract the last element of a list, which must be finite and non-empty.
tail :: [a] -> [a]
Extract the elements after the head of a list, which must be non-empty.
init :: [a] -> [a]
Return all the elements of a list except the last one. The list must be non-empty.
O(n). length returns the length of a finite list as an Int.
It is an instance of the more general genericLength,
the result type of which may be any kind of number.
map :: (a -> b) -> [a] -> [b]
map f xs is the list obtained by applying f to each element
of xs, i.e.,
map f [x1, x2, ..., xn] == [f x1, f x2, ..., f xn] map f [x1, x2, ...] == [f x1, f x2, ...]
intersperse :: a -> [a] -> [a]
The intersperse function takes an element and a list and
`intersperses' that element between the elements of the list.
For example,
intersperse ',' "abcde" == "a,b,c,d,e"
intercalate :: [a] -> [[a]] -> [a]
intercalate xs xss is equivalent to (.
It inserts the list concat (intersperse xs xss))xs in between the lists in xss and concatenates the
result.
foldl :: (a -> b -> a) -> a -> [b] -> a
foldl, applied to a binary operator, a starting value (typically
the left-identity of the operator), and a list, reduces the list
using the binary operator, from left to right:
foldl f z [x1, x2, ..., xn] == (...((z `f` x1) `f` x2) `f`...) `f` xn
The list must be finite.
foldl1 :: (a -> a -> a) -> [a] -> a
foldr :: (a -> b -> b) -> b -> [a] -> b
foldr, applied to a binary operator, a starting value (typically
the right-identity of the operator), and a list, reduces the list
using the binary operator, from right to left:
foldr f z [x1, x2, ..., xn] == x1 `f` (x2 `f` ... (xn `f` z)...)
foldr1 :: (a -> a -> a) -> [a] -> a
concat :: [[a]] -> [a]
Concatenate a list of lists.
concatMap :: (a -> [b]) -> [a] -> [b]
Map a function over a list and concatenate the results.
iterate :: (a -> a) -> a -> [a]
iterate f x returns an infinite list of repeated applications
of f to x:
iterate f x == [x, f x, f (f x), ...]
replicate n x is a list of length n with x the value of
every element.
It is an instance of the more general genericReplicate,
in which n may be of any integral type.
cycle :: [a] -> [a]
cycle ties a finite list into a circular one, or equivalently,
the infinite repetition of the original list. It is the identity
on infinite lists.
take n, applied to a list xs, returns the prefix of xs
of length n, or xs itself if n > :
length xs
take 5 "Hello World!" == "Hello" take 3 [1,2,3,4,5] == [1,2,3] take 3 [1,2] == [1,2] take 3 [] == [] take (-1) [1,2] == [] take 0 [1,2] == []
It is an instance of the more general genericTake,
in which n may be of any integral type.
drop n xs returns the suffix of xs
after the first n elements, or [] if n > :
length xs
drop 6 "Hello World!" == "World!" drop 3 [1,2,3,4,5] == [4,5] drop 3 [1,2] == [] drop 3 [] == [] drop (-1) [1,2] == [1,2] drop 0 [1,2] == [1,2]
It is an instance of the more general genericDrop,
in which n may be of any integral type.
splitAt :: Int -> [a] -> ([a], [a])
splitAt n xs returns a tuple where first element is xs prefix of
length n and second element is the remainder of the list:
splitAt 6 "Hello World!" == ("Hello ","World!")
splitAt 3 [1,2,3,4,5] == ([1,2,3],[4,5])
splitAt 1 [1,2,3] == ([1],[2,3])
splitAt 3 [1,2,3] == ([1,2,3],[])
splitAt 4 [1,2,3] == ([1,2,3],[])
splitAt 0 [1,2,3] == ([],[1,2,3])
splitAt (-1) [1,2,3] == ([],[1,2,3])
It is equivalent to ( when take n xs, drop n xs)n is not _|_
(splitAt _|_ xs = _|_).
splitAt is an instance of the more general genericSplitAt,
in which n may be of any integral type.