functional script
parent
74a832ff24
commit
e6ab8cddc7
@ -1,34 +1,50 @@
|
||||
#! /usr/bin/env runhaskell
|
||||
|
||||
type Ingredient = (String, Double, Double)
|
||||
data Ingredient = Ingredient { ingredientName :: String
|
||||
, unit_cost :: Double
|
||||
}deriving (Show)
|
||||
|
||||
type Recette = ( String, [Ingredient], Double, Double)
|
||||
data UsedIngredient = UsedIngredient { ingredient :: Ingredient, quantityUsed :: Double }deriving (Show)
|
||||
|
||||
ingredientsLessive :: [Ingredient]
|
||||
ingredientsLessive = ( "Lessive"
|
||||
, [ ("Eau", 0.003, 2.5)
|
||||
, ("Savon de Marseille", 3.36, 0.1)
|
||||
, ("Bicarbonate de soude", 3.81, 0.016)
|
||||
, ("Vinaigre blanc", 0.36, 0.03)
|
||||
]
|
||||
, 2.5
|
||||
, 30
|
||||
)
|
||||
data Recipe = Recipe { recipeName :: String
|
||||
, billOfMaterial :: [ UsedIngredient ]
|
||||
, finalQuantity :: Double
|
||||
, useNumber :: Double
|
||||
}deriving (Show)
|
||||
|
||||
quantiteLessive = 2.5
|
||||
nombreUtilisations = 30
|
||||
recipeCost :: Recipe -> Double
|
||||
recipeCost (Recipe _ bom _ _) = sum . map ingredientCost $ bom
|
||||
|
||||
prixTotal ingredientsLessive = sum . map (\ (_, x, y) -> x * y) $ ingredientsLessive
|
||||
ingredientCost :: UsedIngredient -> Double
|
||||
ingredientCost (UsedIngredient (Ingredient _ uCost) qtt) = uCost * qtt
|
||||
|
||||
prixLitre prixTotal quantiteLessive = prixTotal / quantiteLessive
|
||||
|
||||
prixUtilisation prixTotal quantiteLessive = prixTotal / nombreUtilisations
|
||||
|
||||
eau = Ingredient "Eau" 0.003
|
||||
savonMarseille = Ingredient "Savon de Marseille" 3.36
|
||||
bicarbonate = Ingredient "Bicarbonate de soude" 3.81
|
||||
vinaigreBlanc = Ingredient "Vinaigre blanc" 0.36
|
||||
|
||||
lessive :: Recipe
|
||||
lessive = Recipe "Lessive"
|
||||
[ UsedIngredient eau 2.5
|
||||
, UsedIngredient savonMarseille 0.1
|
||||
, UsedIngredient bicarbonate 0.016
|
||||
, UsedIngredient vinaigreBlanc 0.03
|
||||
]
|
||||
2.5
|
||||
30
|
||||
|
||||
quantiteLessive = 2.5
|
||||
nombreUtilisations = 30
|
||||
|
||||
main = do
|
||||
putStrLn "Calcul du coût des recettes\n"
|
||||
putStrLn "* Lessive :"
|
||||
print ingredientsLessive
|
||||
putStrLn $ " * Prix Total = " ++ show prixTotal ++ "€"
|
||||
putStrLn $ " * Prix au litre = " ++ show prixLitre ++ "€"
|
||||
putStrLn $ " * Prix par utilisation = " ++ show prixUtilisation ++ "€"
|
||||
print lessive
|
||||
putStrLn $ " * Prix Total = " ++ show (recipeCost lessive) ++ "€"
|
||||
-- putStrLn $ " * Prix au litre = " ++ show prixLitre ++ "€"
|
||||
-- putStrLn $ " * Prix par utilisation = " ++ show prixUtilisation ++ "€"
|
||||
|
||||
|
Loading…
Reference in New Issue