1. Perl
2. Rust
3. Go
4. Scala
5. Julia
6. Lisp
7. Lua
8. Prolog
9. Cobol
10. Pascal
11. F#
# Lab 4b Debrief
# Questions
## ...about anything?
# Algebraic Datatypes
## Algebraic Datatypes
- Recall that we can create our own types like this:
```haskell
data Color = RGB Int Int Int deriving (Show, Eq)
```
-
Or using record syntax:
```haskell
data Color = RGB { red :: Int
, green :: Int
, blue :: Int }
deriving (Show, Eq)
```
## Recursive Datatypes
- We can even define recursive `Tree` data structures:
```haskell
data Tree a = EmptyTree | Node a (Tree a) (Tree a)
```
-
Or with record syntax:
```haskell
data Tree a = EmptyTree
| Node { value :: a
, leftChild :: Tree a
, rightChild :: Tree a }
deriving (Show, Eq)
```
## Type Aliasing
- To improve the readability of our code, it can be helpful to create a **type alias** using the `type` keyword
```haskell
type String = [Char]
```
-
Now `String` and `[Char]` can be used interchangeably
## Type Aliasing
- Consider the following function header:
```haskell
substring :: [Char] -> Int -> Int -> [Char]
```
-
If we had an alias for `Int` such as:
```haskell
type Index = Int
```
then we could write it in this equivalent way:
```haskell
substring :: String -> Index -> Index -> String
```
# Exercises
## Exercise 1
```haskell
data Tree a = Empty | Node a (Tree a) (Tree a)
deriving (Show, Eq)
```
---
- Write a function `toList` that turns a tree into a list:
```haskell
toList :: Tree a -> [a]
```
## Exercise 2
- An element of a tree can be specified with a **path** from the root to the element
-
Given the following datatypes:
```haskell
data Step = StepL | StepR
deriving (Show, Eq)
type Path = [Step]
```
write a function `walk` that returns the element specified by the path
```haskell
walk :: Path -> Tree a -> Maybe 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