Haskell Survik 'oop'

Run Settings
LanguageHaskell
Language Version
Run Command
{-# LANGUAGE RecordWildCards #-} module Main where import Control.Monad.State data Item = Item { name :: String, description :: String, useTime :: Int, useCount :: Int } type TotalItemsCreated = Int useItem :: Item -> State TotalItemsCreated String useItem item@Item{..} = do modify (+1) return $ "Používá se " ++ name ++ " (" ++ description ++ "), což trvá " ++ show useTime ++ " sekund. Počet použití: " ++ show (useCount + 1) data Survik = Survik { survikName :: String, item :: Item } useSurvikItem :: Survik -> State TotalItemsCreated String useSurvikItem Survik{..} = do itemLine <- useItem item return $ survikName ++ " používá " ++ name item ++ ": " ++ itemLine main :: IO () main = do let baterka = Item "Baterka" "osvětluje cestu" 0 0 lekarnicka = Item "Lékárnička" "léčí zranění" 20 0 pepa = Survik "Pepik the survik" baterka let (result, totalItems) = runState (useSurvikItem pepa >> useSurvikItem (pepa { item = lekarnicka })) 0 putStrLn result print totalItems
Editor Settings
Theme
Key bindings
Full width
Lines