Skip to content
Browse files

More work on slides.

  • Loading branch information...
1 parent 0683a53 commit 6bb03db482b0cdf3bfa9c9a70c34bd2d8bc7c6c6 @tomlokhorst committed Feb 5, 2010
View
1 presentation/ArithExpr.lhs
@@ -1,4 +1,5 @@
%include polycode.fmt
+%include code.fmt
%if style == newcode
View
58 presentation/BoolLike.lhs
@@ -1,8 +1,9 @@
%include polycode.fmt
+%include code.fmt
%if style == newcode
-> {-# OPTIONS_GHC -F -pgmF lhs2tex -optF --pre #-}
+> {-# OPTIONS_GHC -F -pgmF lhs2TeX -optF --pre #-}
> module BoolLike where
> import Expr
@@ -14,8 +15,6 @@
%if style /= newcode
-> (+) :: Num a => a -> a -> a
-
> (==) :: Eq a => a -> a -> Bool
\pause
@@ -34,7 +33,11 @@
> true :: b
> bool :: a -> a -> b -> a
-\begin{overlayarea}{\textwidth}{0.2\textheight}
+\pause
+
+%if style /= newcode
+
+\begin{overlayarea}{\textwidth}{0.3\textheight}
\only<2>{
> instance BoolLike Bool where
@@ -45,14 +48,57 @@
}
\only<3>{
-> instance BoolLike (Expr Bool) where
+> instance BoolLike Expr where
> false = ConFalse
> true = ConTrue
> bool x y b = If b y x
}
\end{overlayarea}
-
+
+%endif
+
\end{frame}
+\begin{frame}
+
+%if style /= newcode
+
+> (&&) :: Bool -> Bool -> Bool
+> (||) :: Bool -> Bool -> Bool
+> not :: Bool -> Bool
+
+
+\pause
+
+\begin{overlayarea}{\textwidth}{0.5\textheight}
+\only<2>{
+
+> (&&) :: BoolLike b => b -> b -> b
+> WhiteSpace
+
+> (||) :: BoolLike b => b -> b -> b
+> WhiteSpace
+
+> not :: BoolLike b => b -> b
+> WhiteSpace
+
+}
+\only<3>{
+
+> (&&) :: BoolLike b => b -> b -> b
+> (&&) x y = bool x y x
+
+> (||) :: BoolLike b => b -> b -> b
+> (||) x y = bool y x x
+
+> not :: BoolLike b => b -> b
+> not x = bool true false x
+
+}
+\end{overlayarea}
+
+%endif
+
+\end{frame}
View
59 presentation/Expr.lhs
@@ -1,8 +1,9 @@
%include polycode.fmt
+%include code.fmt
%if style == newcode
-> {-# OPTIONS_GHC -F -pgmF lhs2tex -optF --pre #-}
+> {-# OPTIONS_GHC -F -pgmF lhs2TeX -optF --pre #-}
> module Expr where
@@ -21,30 +22,35 @@
\pause
-> data Expr a where
-> Con :: Int -> Expr Int
-> Add :: Expr Int -> Expr Int -> Expr Int
-> Mul :: Expr Int -> Expr Int -> Expr Int
-> ConFalse :: Expr Bool
-> ConTrue :: Expr Bool
-> Eq :: Expr Int -> Expr Int -> Expr Bool
-> If :: Expr Bool -> Expr a -> Expr a -> Expr a
+> data Expr where
+> Con :: Int -> Expr
+> Add :: Expr -> Expr -> Expr
+> Mul :: Expr -> Expr -> Expr
+> ConFalse :: Expr
+> ConTrue :: Expr
+> Eq :: Expr -> Expr -> Expr
+> If :: Expr -> Expr -> Expr -> Expr
\end{frame}
\begin{frame}
-> eval :: Expr a -> a
-> eval (Con x) = x
-> eval (Add x y) = eval x + eval y
-> eval (Mul x y) = eval x * eval y
-> eval (ConFalse) = False
-> eval (ConTrue) = True
-> eval (Eq x y) = eval x == eval y
-> eval (If p x y) = if eval p
-> then eval x
-> else eval y
+> eval :: Expr -> Either Bool Int
+> eval (Con x) = Right x
+> eval (Add x y) = let (Right x') = eval x
+> (Right y') = eval y
+> in Right (x' + y')
+> eval (Mul x y) = let (Right x') = eval x
+> (Right y') = eval y
+> in Right (x' * y')
+> eval (ConFalse) = Left False
+> eval (ConTrue) = Left True
+> eval (Eq x y) = Left (eval x == eval y)
+> eval (If p x y) = let (Left p') = eval p
+> in if p'
+> then eval x
+> else eval y
\end{frame}
@@ -59,10 +65,10 @@
\pause
-\begin{overlayarea}{\textwidth}{0.2\textheight}
+\begin{overlayarea}{\textwidth}{0.3\textheight}
\only<2>{
-> x :: Expr Int
+> x :: Expr
> x = If (Eq (Add (Con 2) (Con 3))
> (Con 5))
> (Con 1)
@@ -71,14 +77,13 @@
}
\only<3>{
-> x :: Expr Int
+> x :: Expr
> x = If (Eq (2 + 3) 5) (1) (0)
}
-%format == = "=="
\only<4>{
-> x :: Expr Int
+> x :: Expr
> x = If (2 + 3 == 5) (1) (0)
}
@@ -88,7 +93,7 @@
%if style == newcode
-> instance Show (Expr a) where
+> instance Show Expr where
> show (Con x) = "Con " ++ show x
> show (Add x y) = "Add (" ++ show x ++ ") (" ++ show y ++ ")"
> show (Mul x y) = "Mul (" ++ show x ++ ") (" ++ show y ++ ")"
@@ -97,13 +102,13 @@
> show (Eq x y) = "Eq (" ++ show x ++ ") (" ++ show y ++ ")"
> show (If p x y) = "If (" ++ show p ++ ") (" ++ show x ++ ") (" ++ show y ++ ")"
-> instance Eq (Expr a) where
+> instance Eq Expr where
> Con x == Con y = x == y
> Add x y == Add x' y' = x == x' && y == y'
> Mul x y == Mul x' y' = x == x' && y == y'
> _ == _ = False
-> instance Num (Expr Int) where
+> instance Num Expr where
> fromInteger = Con . fromIntegral
> x + y = Add x y
> x * y = Mul x y
View
6 presentation/Makefile
@@ -1,4 +1,4 @@
-SRC = presentation.tex ArithExpr.tex Expr.tex BoolLike.tex
+SRC = presentation.tex ArithExpr.tex Expr.tex BoolLike.tex RealExpr.tex
.PHONY : clean $(SRC:%.tex=ghci-%)
@@ -12,9 +12,9 @@ presentation.pdf : $(SRC)
lhs2TeX -o $@ $<
preview :
- latexmk -pdf -pvc thesis
+ latexmk -pdf -pvc presentation
clean :
latexmk -C
for file in $(SRC:%.tex=%.lhs); do if [ -e $$file ]; then rm -f $${file%lhs}tex; fi; done
- rm -f thesis.ptb
+ rm -f presentation.ptb
View
117 presentation/RealExpr.lhs
@@ -0,0 +1,117 @@
+%include polycode.fmt
+%include code.fmt
+
+%if style == newcode
+
+> {-# OPTIONS_GHC -F -pgmF lhs2tex -optF --pre #-}
+
+> module Expr where
+
+%endif
+
+
+\begin{frame}
+
+%if style /= newcode
+
+> if 2 + 3 == 5
+> then 1
+> else 0
+
+%endif
+
+\pause
+
+> data Expr a where
+> Con :: Int -> Expr Int
+> Add :: Expr Int -> Expr Int -> Expr Int
+> Mul :: Expr Int -> Expr Int -> Expr Int
+> ConFalse :: Expr Bool
+> ConTrue :: Expr Bool
+> Eq :: Expr Int -> Expr Int -> Expr Bool
+> If :: Expr Bool -> Expr a -> Expr a -> Expr a
+
+\end{frame}
+
+
+\begin{frame}
+
+> eval :: Expr a -> a
+> eval (Con x) = x
+> eval (Add x y) = eval x + eval y
+> eval (Mul x y) = eval x * eval y
+> eval (ConFalse) = False
+> eval (ConTrue) = True
+> eval (Eq x y) = eval x == eval y
+> eval (If p x y) = if eval p
+> then eval x
+> else eval y
+
+\end{frame}
+
+
+\begin{frame}
+
+%if style /= newcode
+
+> if 2 + 3 == 5
+> then 1
+> else 0
+
+\pause
+
+\begin{overlayarea}{\textwidth}{0.2\textheight}
+\only<2>{
+
+> x :: Expr Int
+> x = If (Eq (Add (Con 2) (Con 3))
+> (Con 5))
+> (Con 1)
+> (Con 0)
+
+}
+\only<3>{
+
+> x :: Expr Int
+> x = If (Eq (2 + 3) 5) (1) (0)
+
+}
+%format == = "=="
+\only<4>{
+
+> x :: Expr Int
+> x = If (2 + 3 == 5) (1) (0)
+
+}
+\end{overlayarea}
+
+%endif
+
+%if style == newcode
+
+> instance Show (Expr a) where
+> show (Con x) = "Con " ++ show x
+> show (Add x y) = "Add (" ++ show x ++ ") (" ++ show y ++ ")"
+> show (Mul x y) = "Mul (" ++ show x ++ ") (" ++ show y ++ ")"
+> show (ConFalse) = "ConFalse"
+> show (ConTrue) = "ConTrue"
+> show (Eq x y) = "Eq (" ++ show x ++ ") (" ++ show y ++ ")"
+> show (If p x y) = "If (" ++ show p ++ ") (" ++ show x ++ ") (" ++ show y ++ ")"
+
+> instance Eq (Expr a) where
+> Con x == Con y = x == y
+> Add x y == Add x' y' = x == x' && y == y'
+> Mul x y == Mul x' y' = x == x' && y == y'
+> _ == _ = False
+
+> instance Num (Expr Int) where
+> fromInteger = Con . fromIntegral
+> x + y = Add x y
+> x * y = Mul x y
+> abs = undefined
+> signum = undefined
+
+%endif
+
+\end{frame}
+
View
22 presentation/code.fmt
@@ -1,8 +1,18 @@
-%format module = "\stress{\textbf{module}}"
-%format where = "\stress{\textbf{where}}"
-%format import = "\stress{\textbf{import}}"
-%format instance = "\stress{\textbf{instance}}"
-%format class = "\stress{\textbf{class}}"
-%format data = "\stress{\textbf{data}}"
+%format module = "\stress{\textbf{module}}"
+%format where = "\stress{\textbf{where}}"
+%format import = "\stress{\textbf{import}}"
+%format instance = "\stress{\textbf{instance}}"
+%format class = "\stress{\textbf{class}}"
+%format data = "\stress{\textbf{data}}"
+%format if = "\stress{\textbf{if}}"
+%format then = "\stress{\textbf{then}}"
+%format else = "\stress{\textbf{else}}"
+%format let = "\stress{\textbf{let}}"
+%format in = "\stress{\textbf{in}}"
+%format == = "=="
+%format && = "\&\&"
+%format || = "||"
+%format not = "not"
+%format WhiteSpace = "\;"
View
15 presentation/presentation.lhs
@@ -6,6 +6,13 @@
%include polycode.fmt
%include code.fmt
+%if style == newcode
+
+> {-# OPTIONS_GHC -F -pgmF lhs2TeX -optF --pre #-}
+
+%endif
+
+
\setbeamersize{text margin left=.5cm}
\setbeamersize{text margin right=.5cm}
\setbeamertemplate{navigation symbols}{}
@@ -46,11 +53,13 @@
\end{frame}
-%include ArithExpr.lhs
+\include{ArithExpr}
+
+\include{Expr}
-%include Expr.lhs
+\include{BoolLike}
-%include BoolLike.lhs
+\include{RealExpr}
\end{document}

0 comments on commit 6bb03db

Please sign in to comment.
Something went wrong with that request. Please try again.