[from now] 2014/04/10 04:07:13

[36mdiff --git a/src/Data/Calorie.hs b/src/Data/Calorie.hs[m
[36mnew file mode 100644[m
[36mindex 0000000..4948c26[m
[36m--- /dev/null[m
[36m+++ b/src/Data/Calorie.hs[m
[34m@@ -0,0 +1,3 @@[m
[4m+[m[4mmodule Data.Calorie (Calorie) where[m
[4m+[m
[4m+[m[4mtype Calorie = Maybe Float[m
[36mdiff --git a/src/Main b/src/Main[m
[36mnew file mode 100755[m
[36mindex 0000000..d792366[m
Binary files /dev/null and b/src/Main differ
[36mdiff --git a/src/Main.hs b/src/Main.hs[m
[36mindex f2b3707..c801a5e 100644[m
[36m--- a/src/Main.hs[m
[36m+++ b/src/Main.hs[m
[34m@@ -1,17 +1,22 @@[m
[32m module Main where[m
[32m [m
[32m import Meal[m
[4m+[m[4mimport Workout[m
[4m+[m[4m--import Data.Time[m
[4m+[m[4m--import Data.Time.Lens[m
[32m [m
[32m [m
[1m-mm :: Num a => Maybe a -> Maybe a -> Maybe a[m
[1m-Nothing `mm` _ = Nothing[m
[1m-_ `mm` Nothing = Nothing[m
[1m-Just a `mm` Just b = Just $ a + b[m
[1m-[m
[32m [m
[4m+[m[4mmain :: IO ()[m
[32m main = do[m
[32m   let breakFirst = defaultNutrient {calorie = Just 334, protein = Just 7.5, fat = Just 5.4, carbon = Just 63.4}[m
[32m   let lunch = defaultNutrient {calorie = Just 308, protein = Just 44.1, fat = Just 2.4, carbon = Just 26.9}[m
[1m-  putStrLn . show $ breakFirst[m
[1m-  putStrLn . show $ lunch[m
[1m-  putStrLn . show $ breakFirst `nAdd` lunch[m
[4m+[m[4m  let dinner1 = defaultNutrient {calorie = Just 298, protein = Just 4.6, fat = Just 15.0 , carbon = Just 36.1}[m
[4m+[m[4m  let dinner2 = defaultNutrient {calorie = Just 176.4, protein = Just 33, fat = Just 2.208, carbon = Just 3.675}[m
[4m+[m[4m  let total = foldl1 nAdd [ breakFirst, lunch, dinner1, dinner2 ][m
[4m+[m[4m  putStrLn . show $ total[m
[4m+[m[4m  putStrLn . ("protein is " ++) . show . calorieCal Protein $ protein total[m
[4m+[m[4m  putStrLn . ("carbon is " ++) . show . calorieCal Carbon $ carbon total[m
[4m+[m[4m  putStrLn . ("Fat is " ++) . show . calorieCal Fat $ fat total[m
[4m+[m[4m  putStrLn . show $ lossCalorie Run 65 14[m
[4m+[m[4m  putStrLn . show $ total `cMinus` lossCalorie Run 65 14[m
[36mdiff --git a/src/Meal.hs b/src/Meal.hs[m
[36mindex 97d00a8..42a5182 100644[m
[36m--- a/src/Meal.hs[m
[36m+++ b/src/Meal.hs[m
[34m@@ -1,10 +1,21 @@[m
[1m-module Meal (Nutrient, calorie, protein, fat, carbon, NutrientQuantity, defaultNutrient, Meal, nAdd) where[m
[4m+[m[4mmodule Meal ([m
[4m+[m[4m            Nutrient(..)[m
[4m+[m[4m            , NurietKind(..)[m
[4m+[m[4m            , Meal(..)[m
[4m+[m[4m            , NutrientQuantity[m
[4m+[m[4m            , defaultNutrient[m
[4m+[m[4m            , defaultMeal[m
[4m+[m[4m            , calorieCal[m
[4m+[m[4m            , nAdd[m
[4m+[m[4m            , cMinus[m
[4m+[m[4m            ) where[m
[32m [m
[1m-import Data.Monoid[m
[4m+[m[4mimport Data.Monoid()[m
[32m import Control.Applicative[m
[4m+[m[4mimport Data.Calorie[m
[32m [m
[32m type NutrientQuantity = Maybe Float[m
[1m-data Nutrient = Nutrient{calorie :: NutrientQuantity[m
[4m+[m[4mdata Nutrient = Nutrient{calorie :: Calorie[m
[32m                         , protein :: NutrientQuantity[m
[32m                         , fat :: NutrientQuantity[m
[32m                         , carbon :: NutrientQuantity}[m
[34m@@ -13,13 +24,32 @@[m[32m [m[33mdata Nutrient = Nutrient{calorie :: NutrientQuantity[m
[32m nAdd :: Nutrient -> Nutrient -> Nutrient[m
[32m a `nAdd` b = Nutrient{calorie  = cal, protein = p, fat = f, carbon = c}[m
[32m     where[m
[1m-        a ++ b = (+) <$> a <*> b[m
[1m-        cal = calorie a ++ calorie b[m
[1m-        p = protein a ++ protein b[m
[1m-        f = fat a ++ fat b[m
[1m-        c = carbon a ++ carbon b[m
[4m+[m[4m        nAdd' :: NutrientQuantity -> NutrientQuantity -> NutrientQuantity[m
[4m+[m[4m        m1 `nAdd'` m2 = (+) <$> m1 <*> m2[m
[4m+[m[4m        nAdd'' :: Calorie -> Calorie -> Calorie[m
[4m+[m[4m        nAdd'' = nAdd'[m
[4m+[m[4m        cal = calorie a `nAdd''` calorie b[m
[4m+[m[4m        p = protein a `nAdd'` protein b[m
[4m+[m[4m        f = fat a `nAdd'` fat b[m
[4m+[m[4m        c = carbon a `nAdd'` carbon b[m
[32m [m
[1m-data Meal = Meal{name :: String, nutrient :: Nutrient, date :: String} deriving(Show, Eq, Read, Ord)[m
[4m+[m[4mcMinus :: Nutrient -> Calorie -> Calorie[m
[4m+[m[4mcMinus nu c = calorie nu `nMinus'` c[m
[4m+[m[4m    where[m
[4m+[m[4m      m1 `nMinus'` m2  =  (-) <$> m1 <*> m2[m
[4m+[m
[4m+[m
[4m+[m[4mdata NurietKind = Protein | Carbon | Fat deriving Eq[m
[4m+[m[4mcalorieCal :: NurietKind -> NutrientQuantity -> NutrientQuantity[m
[4m+[m[4mcalorieCal _ Nothing = Nothing[m
[4m+[m[4mcalorieCal Protein (Just n) = Just ( 4 * n )[m
[4m+[m[4mcalorieCal Carbon (Just n) = Just ( 4 * n )[m
[4m+[m[4mcalorieCal Fat (Just n) = Just ( 9 * n )[m
[32m [m
[32m defaultNutrient :: Nutrient[m
[32m defaultNutrient = Nutrient{calorie = Nothing, protein = Nothing, fat = Nothing, carbon = Nothing}[m
[4m+[m
[4m+[m[4mdata Meal = Meal{name :: String, nutrient :: Maybe Nutrient, date :: String} deriving(Show, Eq, Read, Ord)[m
[4m+[m[4mdefaultMeal :: Meal[m
[4m+[m[4mdefaultMeal = Meal{name = "",  nutrient = Nothing, date = ""}[m
[7m+[m
[36mdiff --git a/src/workout.hs b/src/workout.hs[m
[36mnew file mode 100644[m
[36mindex 0000000..e9189e6[m
[36m--- /dev/null[m
[36m+++ b/src/workout.hs[m
[34m@@ -0,0 +1,11 @@[m
[4m+[m[4mmodule Workout([m
[4m+[m[4m              Workout(..)[m
[4m+[m[4m              , lossCalorie[m
[4m+[m[4m              , ) where[m
[4m+[m
[4m+[m[4mimport Data.Calorie[m
[4m+[m
[4m+[m[4mdata Workout = Run | Swim | Bike | Walk deriving Eq[m
[4m+[m[4mlossCalorie :: Workout -> Float -> Float -> Calorie[m
[4m+[m[4mlossCalorie Run weight km = Just $ weight * km[m
[4m+[m[4mlossCalorie _ _ _  = Nothing[m