twentefp-number-0.1.0.2: Lab Assignments Environment at Univeriteit Twente

Safe HaskellSafe-Inferred
LanguageHaskell98

FPPrac

Synopsis

Documentation

module Prelude

length :: [a] -> Number Source

O(n). length returns the length of a finite list as a Number.

(!!) :: [a] -> Number -> a infixl 9 Source

List index (subscript) operator, starting from 0.

replicate :: Number -> a -> [a] Source

replicate n x is a list of length n with x the value of every element.

Fails when n is not an integral number

take :: Number -> [a] -> [a] Source

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] == []

Fails when n is not an integral number

drop :: Number -> [a] -> [a] Source

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]

Fails when n is not an integral number

splitAt :: Number -> [a] -> ([a], [a]) Source

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 (take n xs, drop n xs) when n is not _|_ (splitAt _|_ xs = _|_).

Fails when n is not an integral number