Haskell Flashcards
Dot operator type
(b -> c) -> (a -> b) -> a -> c
exOr x y =
(x || y) && not(x && y)
Offset between a lowercase character and its uppercase counterpart
32
ord ‘a’ = 97; ord ‘A’ = 65
Read and show
Read: convert from a string to a value
Show: Convert from a value to a string
C enumeration vs Java enumeration
C: Integers and enum types can be mixed freely
Java: Defines a new type
Switch case in Java, C, C++
Default is to fall through. Prevented by ‘break’
Switch case in Prolog, C#
Cannot fall through. permitted by ‘next’
Evaluate the inline conditional expression: (x % 2 == 0 ? “even” : “odd)
if (x % 2 == 0) {“even”}
else {“odd”}
What is an Ivalue in C++
An Ivalue is an expression that yields an object reference
T-square evolution algorithm
- Start with a square
- At each convex corner, place another square, centered at the corner, with half the side length of the previous square
- Repeat step 2
T-square evolution recursive parameters
Width decreased by 1/2, Step is decreased by 1, Fill the square
Functions used on tuples of size 2 (pairs)
‘fst’ to retrieve first element
‘snd’ to retrieve second element
Lists in Haskell vs. Arrays in C/C++/Java
Memory in arrays is contiguous;
Any element can be accessed in constant time
head :: [a] -> a
Returns the first element in a list
tail :: [a] -> [a]
Returns a list with all elements in a list except for the first element