Skip to content

Commit

Permalink
reverse list
Browse files Browse the repository at this point in the history
  • Loading branch information
nmheim committed Apr 9, 2024
1 parent d5fae0f commit 1318e8c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lectures/lecture08.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,21 @@ instance Show a => Show (List a) where

which will result in lists printed like below
```haskell
𝝺> (Cons 1 (Cons 2 (Cons 3 Nil)))
𝝺> lst = (Cons 1 (Cons 2 (Cons 3 Nil)))
<1,2,3>
```

Let's do something useful with our list and reverse it!
```haskell
rev :: List a -> List a
rev lst = iter lst Nil where
iter Nil acc = acc
iter (Cons x l) acc = iter l (Cons x acc)

𝝺> rev lst
<3,2,1>
```

### Arithmetic Expressions

Another example that will prepare you for your [homework](/homework/hw03) is a simple expression
Expand Down

0 comments on commit 1318e8c

Please sign in to comment.