Home
Browse
Create
Search
Log in
Sign up
Upgrade to remove ads
Only $2.99/month
FP
STUDY
Flashcards
Learn
Write
Spell
Test
PLAY
Match
Gravity
Terms in this set (91)
operators
functions whose name is exclusively made out of symbols (&&, || etc.)
infixr
declares (right) precedence for specified operator
infixl
declares (left) precedence for specified operator
parse error
code does not follow syntax
polymorphism
function which type contains one or more type variables and thus can be substituted for specific types
parametric
functions that work for any type
ad-hoc
functions that work for a subset of types (ex. Num a)
recursion
defining something in terms of itself
Hutton's recipe for recursion
1. define type
2. enumerate cases
3. define base cases
4. define other recursive cases
5. generalize and simplifies
5.1 remove duplicate equations
5.2 pattern match only as necessary
5.3 infer more general type
accumulation
using local definition with additional parameter (accumulator)
1. accumulator contains solution for elements seen so far
2. return accumulator in base case
3. update accumulator in recursion
higher-order functions
functions which use functions as arguments
anonymous functions (lambda expressions)
\arguments -> code
combinator
function which returns a function
parantheses in function associatest to the ...
right
function application
white spaces between the arguments
partially applied function
haskell functions take one argument at a time, thus we can provide less than the ones stated
eta reduction
leaving out argument in a function (ex. func = map g)
sections
shorthand for partial application of operators
1. (x #) = \y -> x # y
2. (# y) = \x -> x # y
point-free
use of function compositions
monoids
ensure that the direction of folding does not matter (initial value does not affect outcome, paranthesizing does not affect outcome)
Curried functions
functions which return functions
list
sequences of unknown length, but uniform type
tuple
sequences of known length, but can be different type
Int
integer with fixed range
Integer
integer with unlimited range
float
single-precision decimal number
double
double-precision decimal number
Num
type class of numerical values
Eq
type class for types with equality checks
Ord
type class for types with an ordering
Show
type class which turns things into strings
Foldable
data types that can be folded
constructors
value options for declared data type (seperated by |)
enumeration
all constructors of a data type
value parameter
value which must be given with use of the data type (ex Float in: data Point = Pt Float Float )
type parameter
type which must be given with use of data type (ex a in: data Maybe a = Just a | Nothing)
type constructor
data type which uses a type parameter (ex Maybe in: data Maybe a = Just a | Nothing)
null
tells whether list is empty :: [a] -> Bool
head
returns first ekement in list (fails if empty) :: [a] -> a
tail
returns everything but first element in list (fails if empty) :: [a] -> [a]
(:)
append element at beginning of list :: a -> [a] -> [a]
where
local function definition which is only executed once
flip
takes a function and swaps argument order :: (a -> b -> c) -> (b -> a -> c)
length
returns length of sequence :: [a] -> Int
sum
sums all elements in a list :: Num a => [a] -> a
reverse
takes a list and reverses it :: [a] -> [a]
replicate
creates a list with n elements of the given element :: Int -> a -> [a]
map
applies a function over every element in a list :: (a -> b) -> [a] -> [b]
filter
returns a list of the elements in a list which satisfy the given predicate :: (a -> Bool) -> [a] -> [a]
(.)
function composition :: (b -> c) -> (a -> b) -> (a -> c)
foldr
iteratively applies a function over a list :: (a -> b -> b) -> b -> [a] -> b
foldl
same as foldr but paranthesizes to the left
foldl'
computes value on the go (instead of at the end)
(..)
enumerate from _ to _ :: Enum a => a -> a -> [a]
enumFromTo
enumerate from _ to _ :: Enum a => a -> a -> [a]
enumFrom
enumerate from _ to infinitiy :: Enum a => a -> [a]
enumFromThenTo
enumerate from 1st argument to 3rd argument in steps of size (2nd arg - 1st arg.) :: Enum a => a -> a -> a -> [a]
id
identity function :: a -> a
concat
concats a list of lists :: [[a]] -> [a]
const
constant function :: a -> b -> a
fst
returns first element of tuple :: (a,b) -> a
snd
returns second element of tuple :: (a,b) -> b
elem
determines if the value is an element of the list :: Eq a => a -> [a] -> Bool
take
creates a new list from an old list by specifying how many elements to take from the old list :: Int -> [a] -> [a]
drop
removes n elements at the beginning of a list :: Int -> [a] -> [a]
dropWhile
drop elements at beginning of list while the predicate remains true :: (a -> Bool) -> [a] -> [a]
takeWhile
creates a new list from old list, by taking elements at the beginning of the list as long as the predicate remains true :: (a -> Bool) -> [a] -> [a]
(++)
concat two lists :: [a] -> [a] -> [a]
lookup
treats a list of tuples as a dictionary and looks up a specific key and returns a value if the key exists :: Eq a => a -> [(a,b)] -> Maybe b
succ
successor of a value :: Enum a => a -> a
pred
predecessor of a value ::Enum a => a -> a
max
returns the maximum of two values :: Ord a => a -> a -> a
min
returns the minimum of two values :: Ord a => a -> a -> a
(!!)
takes the element at given index of a list :: [a] -> Int -> a
intercalate
equivalent to (concat (intersperse xs xss)) :: [a] -> [[a]] -> [a]
intersperse
takes an element and a list and inserts that element between the elements of the list :: a -> [a] -> [a]
transpose
transposes rows and columns :: [[a]] -> [[a]]
guards
shorthand for conditionals, each guards checks a condition, last condition is otherwise
conditional
if _ then _ else
let _ = _ in
local definition but before instead of after function
_
wildcard expression
==
compare two values (more expensive than pattern matching)
infix / infixr / infixl
declares associativity (0 = weakest, 9 = highest precedence)
infix
declares non-associativity (must use brackets instead)
list comprehension
build new list from old list : [expr | x <- list] or [expr | x <- list, condition] or [expr | pattern <- list]
=>
1. in a type: constraint of polymorphic function
2. in class declaration: introduction of a super class
3. in instance declaration: defines requisite
superclass
a class which demands that another class is implemented
nominal typing
you cannot use a structurally equal type in place of another type
persistent data structures
data structures in which old versions are available (preserves previous version when modified)
ephemeral data structures
traditional data structures
red black trees
1. Every node is Red or Black
2. The root is Black
3. Leaves are black
4. Red nodes have black children
5. Every path from a node to leaves contain the same number of black nodes
YOU MIGHT ALSO LIKE...
CS21: Chapter 7; Lists and Tuples
31 terms
Starting Out with Python, 3e Ch 7
48 terms
CSC 309
28 terms
CSC 141 Ch.5 Vocab
56 terms
OTHER SETS BY THIS CREATOR
Webtech2
54 terms
Violin Notes
20 terms
ModLog
38 terms
werk
20 terms