"type": "split",
"children": [
{
- "id": "226611ae14e85609",
+ "id": "c663d0c432405846",
"type": "tabs",
"children": [
{
- "id": "3e78d839de43b5f0",
+ "id": "d08e3f89f9fa8c53",
"type": "leaf",
"state": {
"type": "markdown",
"state": {
- "file": "4th and 5th Gen Fighters/Grippen and F-35 Deep Dive.md",
+ "file": "University/Functional Programming/Functional Programming Round 2 Full Notes.md",
"mode": "source",
"source": false,
"backlinks": true,
}
},
"icon": "lucide-file",
- "title": "Grippen and F-35 Deep Dive"
- }
- },
- {
- "id": "c7759456ba31ed51",
- "type": "leaf",
- "state": {
- "type": "release-notes",
- "state": {
- "currentVersion": "1.11.4"
- },
- "icon": "lucide-book-up",
- "title": "Release Notes 1.11.4"
+ "title": "Functional Programming Round 2 Full Notes"
}
}
- ],
- "currentTab": 1
+ ]
}
],
"direction": "vertical"
}
],
"direction": "horizontal",
- "width": 300
+ "width": 300,
+ "collapsed": true
},
"right": {
"id": "52c8cd2985704b8e",
"pdf-plus:PDF++: Toggle auto-paste": false
}
},
- "active": "c7759456ba31ed51",
+ "active": "d08e3f89f9fa8c53",
"lastOpenFiles": [
+ "University/Functional Programming/test.hs~",
+ "University/Functional Programming/test.hs",
+ "University/Functional Programming/Functional Programming Introduction.md",
+ "University/Functional Programming/Functional Programming Round 2 Full Notes.md",
+ "University/Functional Programming/Lecture 2.md",
"University/Algorithm Design/Full Notes - Run 2.md",
"Robert's Opsec Policy/Robert's Opsec Policy.md",
"Robert's Opsec Policy",
"Nebulous Command/ANS/My Fleets/ANS Dedicated/Stat Sheet.md",
"Nebulous Command/ANS/My Fleets/ANS Dedicated/Battle Report 2.md",
"Nebulous Command/ANS/My Fleets/ANS Dedicated/Battle Report 1.md",
- "Nebulous Command/ANS/My Fleets/ANS Dedicated",
"List of things to do.md",
"Diary and thoughts/Untitled.md",
"AI/References on AI.md",
"Blog/Saalbach.dev and experiences writing that software.md",
"Blog/sis50.nl Experiences Writing that Software.md",
"WT Skins.md",
- "University/Machine Learning/Full Notes.md",
- "Watchlist & Do List.md",
- "Untitled 1.md",
- "Untitled.md",
"Pasted image 20251106230015.png",
"Pasted image 20251106225651.png",
"Pasted image 20251106225645.png",
--- /dev/null
+Programming in Haskell by Graham Hutton
+
+35% Project
+Rest is Exam (open resources, weblab)
+
+Functional Languages work through the application of _functions_.
+Functional code can be:
+- shorter
+- easier to understand
+- easier to refactor
+- easier to reason about
+
+Haskell:
+- Statically Typed - means all types are checked at compile time, but are still inferred
+- Lazy Evaluation - means inputs are ecaluated on demand
+- Purity - functiosn do not have side effects (like modding global vars)
+
+Hackage and Hoogle, very practical, should use
+
+:t for type
+:l to load file
+:q to quit
+
+# Haskell Syntax
+
+## Naming Rules
+Names of constructors start with a _capital_ letter. (True, False)
+Names of functions and variables start with a _small_ letter. (not, length)
+Names of concrete types start with a _capital_ letter. (Bool, Int)
+Names of type variables start with a _small_ letter. (a, t)
+
+Comments start with --, or {- -} for multi-line.
+
+Let Binding:
+```haskell
+cylinderSurfaceArea r h =
+ let sideArea = 2 * pi * r * h
+ topArea = pi * r ^2
+ in sideArea + 2 * topArea
+```
+
+Each definition can have an optional _type_ signature. (`f :: ...`)
+A definition consists of one or more _clauses_ (`f x = ...`)
+`where` block for helper functions
+```haskell
+doubleSmallNumber :: Int -> Int
+doubleSmallNumber x =
+ if isSmall x then 2 * x else
+ where
+ isSmall = x < 10
+```
+
+`where` and `let` mostly interchangeable
+`let ... in ...` is just an expression, but `where` always has to be at the top level of the defintion as it has to be attached to a clause.
+
+Indentation matters! Same level of indentation = same block
+
+A _type_ is a name for a collection of values
+You can write typing `True :: Bool` almost anywhere.
+
+Basic Types
+Bool: True / False
+Int: (64 bit integer)
+Integer (arb. size integers)
+Float: etc. // TODO: on slides
+
+There is also tuples (a,b) is the type of tuples (x,y) where x :: a, and y :: b
+
+## Functions with Several Arguments
+there are 2 main ways:
+```haskell
+add1 :: (Int, Int) -> Int -- Uncommon
+add2 :: Int -> (Int -> Int) -- More common
+add2 :: Int -> Int -> Int -- most common way to write it
+```
+
+add2 is called "currying", as a convention haskell functions with multiple arguments are usually curried.
+
+Function arrow -> associates to the right
+Int -> Bool -> Char
+= Int -> (Bool -> Char)
+
+Function application associates to the left:
+f x y = (f x) y
+
+[t] is the type of (singly-linked) lists [x1, x2, ... , xn] with elements of type t
+
+```haskell
+type String = [Char]
+```
+
+They can be used interchangeably. ['a'..'z'] will give you the abc.
+
+List can have any lenght, while a tuple's size is fixed.
+
+All elements in a list must have the _same_ type. Tuples may have different type elements.
+Range syntax: `[i..j]`, will give you first to last (inclusive). If you do `[10..1]` it will give you an empty list.
+If you do `[42..42] = [42]`, and then `[10, 8,..1] = [10, 8, 6, 4, 2]` (i.e. if you indicate the jump length)
+
+
+## List Comprehensions
+```haskell
+[ x * x | x <- [1..5] ]
+```
+Create a new list, given an existing list.
+
+`x <- [1..5]` is a _generator_. You can have multiple generators.
+
+The order of generators matters! (for the ordering of the resulting list)
+Outer vs. inner loop kinda principle.
+
+Later generators may depend on previous ones.
+`[ 10 * x + y | x <- [1..3], y <- [x..3] ]`
+
+filtering lists also works:
+we can select only elements that satisfy a boolean predicate
+`[x | x <- [1..10], even x]`
+