Last active
January 11, 2017 08:25
-
-
Save turanct/a2a54dcc2ad8718eaed4cf7efee962e6 to your computer and use it in GitHub Desktop.
Haskell Coffee Run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
InventoryItem "Lungo" 220 | |
InventoryItem "Espresso" 200 | |
InventoryItem "Latte" 270 | |
InventoryItem "LatteXL" 350 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Shop | |
main = do | |
contents <- getContents | |
let | |
inventory1 = inventoryFromFile contents | |
shop1 = Shop "Simon Says" inventory1 | |
putStrLn $ show shop1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Main: *.hs | |
ghc --make *.hs | |
clean: | |
rm Main *.hi *.o | |
run: | |
cat inventory.txt | ./Main | |
.PHONY: clean run |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Shop where | |
type ShopName = String | |
type ProductName = String | |
type ProductPrice = Int | |
data InventoryItem = InventoryItem ProductName ProductPrice deriving (Show, Read) | |
type Inventory = [InventoryItem] | |
data Shop = Shop ShopName Inventory deriving (Show, Read) | |
inventoryItemFromLine :: String -> InventoryItem | |
inventoryItemFromLine line = read line | |
inventoryFromFile :: String -> Inventory | |
inventoryFromFile file = map inventoryItemFromLine $ lines file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@hansott it compiles 💯 🚀