Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
pp:2024:l10 [2024/05/09 16:19] mihai.udubasa |
pp:2024:l10 [2024/05/13 16:12] (current) mihai.udubasa |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Lab 10. Algebraic Data Types ====== | ====== Lab 10. Algebraic Data Types ====== | ||
| - | Types are an essential component in haskell. They start with capital letters, like ''Int''. We have multiple ways of customizing data types. | + | Types are an essential component in Haskell. They start with capital letters, like ''Int''. We have multiple ways of customizing data types. |
| ===== Type Aliases ===== | ===== Type Aliases ===== | ||
| Line 11: | Line 11: | ||
| type Name = String | type Name = String | ||
| type PhoneNumber = String | type PhoneNumber = String | ||
| - | PhoneBook = Map Name PhoneNumber | + | type PhoneBook = Map Name PhoneNumber |
| </code> | </code> | ||
| Line 129: | Line 129: | ||
| - | After the lab, you can take a look at some more cool stuff related to data types in haskell and functional types in general: | + | After the lab, you can take a look at some more cool stuff related to data types in Haskell and functional types in general: |
| [[https://wiki.haskell.org/Unboxed_type|Unboxed types]] | [[https://wiki.haskell.org/Unboxed_type|Unboxed types]] | ||
| Line 182: | Line 182: | ||
| instance Ord Player where | instance Ord Player where | ||
| (<=) = ??? | (<=) = ??? | ||
| - | -- haskell can infer implementations for all other operations if the implementation for (<=) is given. | + | -- Haskell can infer implementations for all other operations if the implementation for (<=) is given. |
| </code> | </code> | ||
| Line 237: | Line 237: | ||
| playElimination :: [Player] -> Tree Player | playElimination :: [Player] -> Tree Player | ||
| playElimination = ??? | playElimination = ??? | ||
| + | </code> | ||
| + | |||
| + | **10.1.11.** While the ''Tree'' representation may be useful, we will require the final ranking to be in a list format. For each player, keep only the top entry (which will be up-to date in terms of match history). (you can consider all player names to be unique). | ||
| + | |||
| + | <code haskell> | ||
| + | eliminationResults :: Tree Player -> [Player] | ||
| + | eliminationResults = ??? | ||
| + | </code> | ||
| + | |||
| + | **10.1.12.** Finally, it's time to put everything together: | ||
| + | * split the players into ''m'' groups (you choose how this is done) | ||
| + | * simulate the group stage, selecting ''n'' players from each group | ||
| + | * simulate the elimination stage | ||
| + | * return a ranking of all players, sorted in order of descending scores | ||
| + | |||
| + | note: ''n'' and ''m'' should be powers of 2 to properly create the elimination phase. | ||
| + | <code haskell> | ||
| + | runTournament :: [Player] -> Int -> Int -> [Player] | ||
| + | runTournament players n m = ??? | ||
| </code> | </code> | ||