You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.0 KiB
Haskell

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