1. Javascript
2. Perl
3. Ruby
4. C++
5. Rust
6. Swift
7. Kotlin
8. Go
9. Scala
10. Julia
11. Lisp
12. Lua
13. C#
14. Prolog
15. Fortran
16. Cobol
17. Pascal
18. F#
## Format of Presentations
- Your group will select a language and prepare the following:
---
1.
A "cheatsheet" for the class about the language
2.
A 10-minute presentation about the language
# Lab 3 Debrief
# Questions
## ...about anything?
# Type Classes
## Type Classes
- Typeclasses are like **Java interfaces**
+ They constrain an generic type to support certain operations
```haskell
sort :: Ord a => [a] -> [a]
sort [] = []
sort (x:xs) = left ++ [x] ++ right
where left = sort (filter (<=x) xs)
right = sort (filter (>x) xs)
```
# Folding
## Folding
- Many functions take a list as input and "smashes the elements together" into a single return value
-A fold on lists has the following type:
```haskell
foldr :: (a -> b -> b) -> b -> [a] -> b
```
## Fold Right
```haskell
foldr :: (a -> b -> b) -> b -> [a] -> b
foldr f z [] = z
foldr f z (x:xs) = f x (foldr f z xs)
```
- Suppose I call the above function with:
```haskell
foldr f z [1,2,3,4,5]
```
-
The above implementation would produce:
![Right Fold Tree](https://wiki.haskell.org/wikiupload/3/3e/Right-fold-transformation.png)
## Fold Left
- We could have implemented the folding operation in a different way:
![Left Fold Tree](https://wiki.haskell.org/wikiupload/5/5a/Left-fold-transformation.png)
```haskell
foldl :: (b -> a -> b) -> b -> [a] -> b
foldl f z [] = z
foldl f x (x:xs) = foldl f (f z x) xs
```
## Foldable Type Class
- This "foldable" property doesn't only apply to lists, but all sorts of data structures, such as trees
-
As a result, the true type of `foldr` is:
```haskell
Foldable t => (a -> b -> b) -> b -> t a -> b
```
# The `$` Operator
## The `$` Operator
- You may notice the operator `$` used in Haskell code-bases, which is used to reduce the number of parentheses in code:
-
The following two expressions are equivalent:
```haskell
head (reverse "abcd")
head $ reverse "abcd"
```
-
Haskell is *left associative* by default, but the `$` is *right associative*, so it effectively evaluates the right-hand side first, even if there are no parentheses there
# Self Checks
### Check 3
What is the type of:
```haskell
\t -> (fst . fst $ t, (snd . fst $ t, snd t))
```
1. `(a, (b, c)) -> (a, (b, c))`
2. `(a, (b, c)) -> ((a, b), c)`
3. `((a, b), c) -> (a, (b, c))`
### Check 7
What is the type of:
```haskell
\x -> case x of
(True, "Foo") -> show True ++ "Foo"
```
1. `Either Bool String -> String`
2. `(Bool, String) -> String`
3. `Show a => (Bool, String) -> a`
## Lab Time
- Please turn on your camera when in a breakout session if possible
-
Some students are hard of hearing and rely on lip-reading to follow along in conversation