Files
recipe-cost/RecipeCost.hs

31 lines
1.0 KiB
Haskell
Executable File

module RecipeCost where
-- * Data types definition
data Ingredient = Ingredient { ingredientName :: String
, unit_cost :: Double
}deriving (Show)
data UsedIngredient = UsedIngredient { ingredient :: Ingredient, quantityUsed :: Double }deriving (Show)
data Recipe = Recipe { recipeName :: String
, billOfMaterial :: [ UsedIngredient ]
, finalQuantity :: Double
, useNumber :: Double
}deriving (Show)
-- * Calculations
recipeCost :: Recipe -> Double
recipeCost (Recipe _ bom _ _) = sum . map ingredientCost $ bom
ingredientCost :: UsedIngredient -> Double
ingredientCost (UsedIngredient (Ingredient _ uCost) qtt) = uCost * qtt
unitCost :: Recipe -> Double -> Double
unitCost (Recipe _ _ qtt _) totalCost = totalCost / qtt
useCost :: Recipe -> Double -> Double
useCost (Recipe _ _ _ uses) totalCost = totalCost / uses
() :: Ingredient -> Double -> UsedIngredient
() ingredient qtt = UsedIngredient ingredient qtt