Skip to content

Commit

Permalink
More tweaks to Course 5
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc committed Oct 11, 2024
1 parent 5c6db88 commit e0ccae5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions slides/course-05.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ GADTs to the rescue!
data Expr t where
IntExpr :: Int -> Expr Int
BoolExpr :: Bool -> Expr Bool
Pair :: Expr a -> Expr b -> Expr (a, b)
IfThenElse :: Expr Bool -> Expr a -> Expr a -> Expr a
PairExpr :: Expr a -> Expr b -> Expr (a, b)
IfThenElseExpr :: Expr Bool -> Expr a -> Expr a -> Expr a

eval :: Expr a -> a
```
Expand Down
8 changes: 4 additions & 4 deletions tps/Scratch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,16 @@ monadWriterExample = do
data Expr t where
IntExpr :: Int -> Expr Int
BoolExpr :: Bool -> Expr Bool
Pair :: Expr a -> Expr b -> Expr (a, b)
IfThenElse :: Expr Bool -> Expr a -> Expr a -> Expr a
PairExpr :: Expr a -> Expr b -> Expr (a, b)
IfThenElseExpr :: Expr Bool -> Expr a -> Expr a -> Expr a


eval :: Expr a -> a
eval = \case
IntExpr x -> x
BoolExpr x -> x
Pair a b -> (eval a, eval b)
IfThenElse cond a b -> if eval cond then eval a else eval b
PairExpr a b -> (eval a, eval b)
IfThenElseExpr cond a b -> if eval cond then eval a else eval b

-- data Expr a b =
-- IntExpr Int
Expand Down

0 comments on commit e0ccae5

Please sign in to comment.