Title: Theory / Unimportant / CS / Programming / Haskell / Yet another tutorial
Tags: seen_description automatedNewLineAfterCommaSpace FromInstruction comment computer_to_instruction declaration hasNotNewEffectReturnsMeaning some_instruction todo_declaration
On every note of this deck, unless a note says otherwise:
Language: Haskell

Instruction: import moduleName hiding (
  typeOne,TypeTwo,... ,
  valueOne,ValueTwo...
)
Page: 70
Effect: Import the types and values from the module name, except the one in parenthesis
Chapter: 6

Name: Referential transparency
Definition: if two functions f and g produce the same values for the same arguments, then we may replace f with g (and vice-versa).
Page: 13
Chapter: 3

Name: A destructive update
Definition: The update of a part of a value, in which some oth
Page: 13
Chapter: 3

Instruction: Char.toUpper
Page: 18
Chapter: 3
Section: 3.2
Returns: The input character, upper cased

Instruction: Char.isLower
Page: 18
Chapter: 3
Section: 3.2
Returns: The input character, upper cased

Question: Which of foldr and foldl works on infinite list
Answer: The input character, upper cased
Page: 20
Chapter: 3
Section: 3.2

Question: Which of foldr and foldl is usually more efficient
Answer: foldl (because it is tail recursive)
Page: 20
Chapter: 3
Section: 3.2

Instruction: main
Page: 20
Chapter: 3
Section: 3.2
Returns: The function executed when the program is called

Instruction: Main
Page: 20
Chapter: 3
Section: 3.2
Returns: The module which should contains the main

Question: Where are braces automatically inserted by Haskell
Answer: after "where", "let", "do", "of"
Page: 24
Chapter: 3
Section: 5
Context: Interpreter

Question: Where are semicolumns automatically inserted by Haskell
Answer: before every new line indented
Page: 24
Chapter: 3
Section: 5
Context: Interpreter

Name: Overlapping pattern
Definition: A pattern which can only match values matched by a
Page: 25
Chapter: 3
Section: 5
Context: pattern matching

Name: Incomplete patterns
Definition: A list of pattern matching values of type t which does not match some values of type t
Page: 25
Chapter: 3
Section: 5
Context: pattern matching

Language: Haskell
Instruction: -- foo
Other fields (not shown on cards):
Chapter: 3
Page: 28
Section: 5

Instruction: return
Page: 65
Effect: Transform a standard haskell value into one which can be used by
Context: IO
Chapter: 5
Section: 4
Typ: a -> IO a

Extension: lhs
Description: haskel in literate programming
Means: Literate haskell
Other fields (not shown on cards):
Page: 81
Chapter: 6
Section: 4

Name: Literate programming
Definition: Programming file in which default is comment, and code is introduced in a special way
Page: 71
Chapter: 6
Section: 4

Name: Bird scripts
Definition: A script where code line starts with a > and every other line
Page: 71
Chapter: 6
Section: 4

Name: LaTeX-script
Definition: A script where code is in a
Page: 71
Chapter: 6
Section: 4
Context: Haskell

Instruction: \foo -> bar
Page: 71
Chapter: 7
Section: 1
Returns: Function taking as argument a variable foo and returning bar

Instruction: uncurry
Page: 78
Chapter: 7
Section: 3
Returns: given a function f: a -> b -> c, returns the same function with type (a, b)->c

Instruction: curry
Page: 78
Chapter: 7
Section: 3
Returns: given a function f: (a, b) -> c, returns the same function with type a -> b -> c

Instruction: flip
Page: 78
Chapter: 7
Section: 3
Returns: given a function f: a -> b -> c, returns the same function with type b -> a -> c

Typ: Eq
Function: One of == or /=
Page: 78
Chapter: 7
Section: 3

Typ: Show
Function: Either show: a->String or showsPrec Int->a ->String->String
Page: 86
Chapter: 7
Section: 6,2

Typ: Ord
Function: compare: a->a->Ordering
Page: 86
Chapter: 7
Section: 6,2

Typ: Enum
Function: toEnum:: Int -> a and fromEnum:: a -> Int
Page: 88
Function2: pred and succ :: a -> a
Chapter: 7
Axiom: toEnum . FromEnum is identity if defined
Function3: enumFrom :: a -> [a] elements starting at a up to the end
enumFromThen a -> int -> [a] same as enumFrom, with step between elements
enumFromTo :: a -> a -> [a] enumerate betweenn from and to elements
Axiom2: FromEnum . toEnum is identity
Intuition: Set of elements with successor and predecesor

Typ: Num
Function: -, *, + :: a -> a -> a
negate, signum, abs :: a -> a
fromInteger :: Integer -> a
Page: 88
Chapter: 7

Typ: Read
Function: readsPrec :: Int -> String -> [(a, String)]
Page: 88
Function2: read = fst . head . readsPrec 0
Chapter: 7

Instruction: data name....
   deriving (
  typeClass1,
  ..., typeClassn
)
Page: 89
Meaning: Ensure that the data type name currently defined automatically derived all methods from typeClasses typeClassn
Language: Haskell
Chapter: 7
Section: 6.5

Typ: data name
   | Foo1 type11 ... type1n_1
   | ...
   | Foom typem1 ... typemn_m
Meaning: Introduce a type name with m constructors Fooi, which takes m_i parameters, of type typeij
Page: 90
Language: Haskell
Chapter: 7

Typ: data Name
   Name { param1 :: type1,
               ...,
               paramn :: typen }
Meaning: Introduce a type Name with constructor Name and n values, named parami of type typei
Page: 90
Language: Haskell
Chapter: 7

Instruction: parami var
Page: 90
Chapter: 7
Returns: The value associated to param parami in varible var
Variables: data TypeName
   Name { param1 :: type1,
               ...,
               paramn :: typen }
var: TypeName

Instruction: TypeName expr1 ... exprn
Page: 90
Chapter: 7
Returns: A value of type TypeName and n parameters expri
Variables: data TypeName
   Name { param1 :: type1,
               ...,
               paramn :: typen }

Instruction: val{parami=expri}
Page: 90
Chapter: 7
Returns: A value, similar to val, with parami of type expri
Variables: data TypeName
   Name { param1 :: type1,
               ...,
               paramn :: typen }
val: TypeName
expri: typei

Instruction: TypeName { param1= expr1, ... , paramn=exprn}
Page: 90
Chapter: 7
Returns: A value of type TypeName whose parami has the value of expri
Variables: data TypeName
   Name { param1 :: type1,
               ...,
               paramn :: typen }

Instruction: unzip
Page: 94
Chapter: 7
Section: 8
Returns: Takes a list of pairs, return a pair of list containing the same elements

Instruction: array (
  min,
  max
) l
Page: 96
Chapter: 7
Section: 9
Returns: An array with inputs between min and max, whose i-th value is chosen according to the associating list l

Instruction: listArray (
  min,
  max
) l
Page: 96
Chapter: 7
Section: 9
Returns: An array with inputs between min and max, whose i-th value is l[i]

Instruction: ar ! i
Page: 96
Chapter: 7
Section: 9
Returns: The i-th element of ar
Variables: ar an array

Instruction: ar // [
  (pos1, val1),
  ...,
  (posn, valn)
]
Page: 96
Chapter: 7
Section: 9
Returns: Array, similar to ar, with posith value vali
Variables: ar an array

Instruction: bounds ar
Page: 96
Chapter: 7
Section: 9
Returns: The bounds of ar
Variables: ar an array

Instruction: indices ar
Page: 96
Chapter: 7
Section: 9
Returns: The indices of ar
Variables: ar an array

Instruction: elems ar
Page: 96
Chapter: 7
Section: 9
Returns: The list of values in the array ar in order
Variables: ar an array

Instruction: assocs ar
Page: 96
Chapter: 7
Section: 9
Returns: The array as an association list
Variables: ar an array

Typ: FiniteMap
Meaning: Type of balanced tree used as mapping
Page: 96
Language: Haskell
Chapter: 7
Section: 9

Instruction: emptyFM
Page: 98
Chapter: 7
Section: 9
Returns: An empty finite map

Instruction: addToFm fm key elt
Page: 98
Chapter: 7
Section: 9
Returns: A new finite map, corresponding to the same mapping as fm, except that key is associated to elt
Variables: fm a Finitemap

Instruction: delFromFm fm key
Page: 98
Chapter: 7
Section: 9
Returns: A new finite map, corresponding to the same mapping as fm, except that key is not associated anymore
Variables: fm a Finitemap

Instruction: elemFM fm key
Page: 98
Chapter: 7
Section: 9
Returns: Whether there is a value associated to key in the map fm
Variables: fm a Finitemap

Instruction: lookupFM fm key
Page: 98
Chapter: 7
Section: 9
Returns: The value associated to key in the map fm
Variables: fm a Finitemap

Instruction: fmToList fm
Page: 98
Chapter: 7
Section: 9
Returns: The associating list, in creasing order, represented by fm
Variables: fm a Finitemap

Instruction: listToFM [
  (key1, elt1),
  ...,
  (keyn, eltn)
]
Page: 98
Chapter: 7
Section: 9
Returns: A finite map associating to keyi the value elti

Typ: FiniteMapkeyelt
Page: 98
Chapter: 7
Section: 9
Subtype of: Ord
Intuition: type of key of finite map

Typ: type Foo a  .. z = Bar(a, .., z)
Meaning: Introduce Foo a ... z as an abbreviation for type Bar which have variable types a to z
Page: 103
Language: Haskell
Chapter: 8
Section: 1

Instruction: ConstructorName foo
Page: 105
Chapter: 8
Section: 1
Returns: A value of type NewTypeName with same value as foo
Variables: newtype NewTypeName = ConstructorName OldType

Instruction: !type
Page: 105
Context: data definition
Chapter: 8
Section: 1
Returns: State that the type is interpreted strictly. If it's argument is bottom, the whole structure is bottom. Arguments are evaluated while defining the data's value

Name: Context
Definition: Something of the form
ClassName var =>
Page: 114
Chapter: 8
Section: 5
Context: Haskell

Name: Closed world assumption
Definition: The assumption that all known instances of a class is known
Page: 114
Chapter: 8
Section: 5
Context: Haskell

Name: Open world assumption
Definition: The assumption that there may be arbitrary instances of a typeclass
Page: 114
Chapter: 8
Section: 5
Context: Haskell

Name: Kind
Page: 114
Chapter: 8
Section: 6
Context: Haskell
Intuition: Type of a type

Definition: The kind of types which can be instantiated
Page: 114
Chapter: 8
Section: 6
Context: Haskell Kind
Notation: *

Definition: Kind which takes two kinds, and returns the kind of function from first kind to second one
Page: 114
Chapter: 8
Section: 6
Context: Haskell Kind
Notation: ->

Typ: Monad m
Function: return a->m a (transform a standard value into one usable by a monad, equal to pure)
Page: 120
Function2: fail: String -> m a (Transform an error message into something usable by the monad)
Chapter: 9
Axiom: (return =>) = id
(=> return) = id
(return is identity of =>)
Function3: (>>=) :: m a -> (a -> m b) -> m b apply a function taking a normal value to values in a monad
Subtype of: Applicative
Axiom2: (g >=> h) >=> k  =  g >=> (h >=> k)
(>=> is associative)
Function4: x >> y defined as x >>= (const y)
Function5: Or fmap and `join:: m (m a) -> m a` instead of the last one

Instruction: do {e; es}
Page: 121
Effect: e >> do {es}
Chapter: 9

Instruction: do {let decls; es}
Page: 121
Effect: let decls in do {es}
Chapter: 9

Instruction: do {p<- e; es}
Page: 121
Effect: let ok p = do {es}; ok _= fail "..." in e >>= ok
I.e. If pattern matches, execute es, where p is interpreted as the result of e. Otherwise, just fail.
Chapter: 9
Intuition: Depending on the definition of >=>.
Essentially, p takes each values of e, assuming they all matches the pattern, and apply the computation for all of them

Question: what means the instruction:
do {e}
Answer: e
Page: 121
Chapter: 9
Context: Haskell

Instruction: =<<
Page: 131
Chapter: 9
Returns: flip (>>=)

Instruction: foldM f init l
Page: 134
Chapter: 9
Section: 5
Returns: Same as fold, but function and result have their result in a monad
Typ: (a -> b -> m a) -> a -> [b] -> m a

Instruction: sequence_ l
Page: 134
Chapter: 9
Section: 5
Returns: Execute each instruction of the input list, ignore the result
Typ: [m a] -> m ()

Instruction: when prop expr
Page: 135
Chapter: 9
Section: 5
Returns: Execute expr only if prop holds
Typ: Bool -> m() -> m()

Typ: MonadPlus
Function: mplus :: m a -> m a -> m a
Page: 135
Function2: mzero :: m a
Context: Haskell
Chapter: 9
Section: 5
Axiom: (mplus mzero) = id
((flip mplus) mzero) = id
Subtype of: Monad
French: join