Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
pp:2023:haskell:l09 [2023/04/30 12:24] bogdan.deac |
pp:2023:haskell:l09 [2023/05/02 22:15] (current) bogdan.deac |
||
---|---|---|---|
Line 53: | Line 53: | ||
instance Show a => Show (Maybe a) where | instance Show a => Show (Maybe a) where | ||
show Nothing = "Nothing" | show Nothing = "Nothing" | ||
- | Show (Just x) = "Just " ++ show x | + | show (Just x) = "Just " ++ show x |
</code> | </code> | ||
Line 66: | Line 66: | ||
**9.1.1** Let's implement a ''ChessResult'' data type. In chess, a game result can be either a Win, a Draw or a Loss. | **9.1.1** Let's implement a ''ChessResult'' data type. In chess, a game result can be either a Win, a Draw or a Loss. | ||
<code haskell> | <code haskell> | ||
- | data ChessResult = ??? deriving Show | + | data ChessResult = ??? |
</code> | </code> | ||
- | **9.1.2** We want to be able to print a ''ChessResult''. For this, we could do ''deriving Show'' to let GHC derive the implementation, but let's do it ourselves. | + | **9.1.2** We want to be able to show a ''ChessResult''. For this, we could do ''deriving Show'' to let GHC derive the implementation, but let's do it ourselves. |
<code haskell> | <code haskell> | ||
instance Show ChessResult where | instance Show ChessResult where | ||
Line 104: | Line 104: | ||
We also want to model a chess tournament. We'll represent it as a binary tree. | We also want to model a chess tournament. We'll represent it as a binary tree. | ||
<code Haskell> | <code Haskell> | ||
- | data player = Player { ??? } | + | data Player = Player { ??? } |
data Tree a = ??? deriving Show | data Tree a = ??? deriving Show | ||
type Tournament = Tree Player | type Tournament = Tree Player |