Skip to content

Instantly share code, notes, and snippets.

@turanct
Last active January 11, 2017 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save turanct/a2a54dcc2ad8718eaed4cf7efee962e6 to your computer and use it in GitHub Desktop.
Save turanct/a2a54dcc2ad8718eaed4cf7efee962e6 to your computer and use it in GitHub Desktop.
Haskell Coffee Run
InventoryItem "Lungo" 220
InventoryItem "Espresso" 200
InventoryItem "Latte" 270
InventoryItem "LatteXL" 350
import Shop
main = do
contents <- getContents
let
inventory1 = inventoryFromFile contents
shop1 = Shop "Simon Says" inventory1
putStrLn $ show shop1
Main: *.hs
ghc --make *.hs
clean:
rm Main *.hi *.o
run:
cat inventory.txt | ./Main
.PHONY: clean run
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
@turanct
Copy link
Author

turanct commented Jan 10, 2017

@hansott it compiles 💯 🚀

@hansott
Copy link

hansott commented Jan 11, 2017

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment