[
  {
    "path": ".gitignore",
    "content": "*.swp\n*.hi\n*.o\nmuesli\n"
  },
  {
    "path": "Database.hs",
    "content": "{-# OPTIONS_GHC -fno-warn-tabs #-}\nmodule Database where\n\nimport qualified Data.Vector.Fixed as F\n\nimport DatabaseTools\nimport Types\n\n-- nuts:prote,\tfat,\tcarbs,\tfiber,\n-- elem:potass,\tsodium,\tcalciu,\tmagnes,\tphosph,\tiron,\tiodine,\tzinc,\tseleni,\tcopper,\tchromi,\tmangane,molybde,chlorid,fluoride,\n-- vita:a,\tc,\td,\te,\tk,\tthiami,\tribofl,\tniacin,\tpantot,\tb6,\tbiotin,\tfolate,\tb12,\tcholine,omega3,\tomega6,\n-- e aa:His,\tIle,\tLeu,\tLys,\tMet,\tPhe,\tThr,\tTrp,\tVal,\n-- o aa:Ala,\tArg,\tAsn,\tAsp,\tCys,\tGlu,\tGln,\tGly,\tOrn,\tPro,\tSel,\tSer,\tTyr\n-- e fa:ALA,\tEPA,\tDPA,\tDHA,\tLA,\tGLA,\tAA\n--                               ↘per 100g\nraisins = Source \"raisin\" $ Substance 100 $ usda $ mkL\n\t3\t0.5\t79\t5\t-- USDA 09299 + http://www.whfoods.com/genpage.php?tname=nutrientprofile&dbid=24 + 09298\n\t0.773\t0.017\t0.044\t0.032\t0.097\t2.1e-3\tidk\t240e-6\t0.63e-6\t328e-6\tidk\t0.29e-3\tidk\tidk\t220e-6\n\t0\t3.6e-3\t0\t120e-6\t3.5e-6\t75e-6\t166e-6\t1e-3\t93e-6\t228e-6\t2e-6\t3.7e-6\t0\t11.1e-3\t0\t1e-3\n\t7.20e-2\t5.70e-2\t9.60e-2\t8.40e-2\t7.70e-2\t6.50e-2\t7.70e-2\t5.00e-2\t8.30e-2\t1.05e-1\t4.13e-1\tidk\t1.10e-1\t1.90e-2\t1.64e-1\tidk\t8.00e-2\tidk\t2.54e-1\tidk\t7.00e-2\t1.20e-2\n\tidk\t0.000e0\t0.000e0\t0.000e0\tidk\tidk\tidk\n\nundevit = Source \"undevit\" $ Pill $ mkL\n\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t1e-3\t75e-3\t0\t10e-3\t0\t2e-3\t2e-3\t20e-3\t3e-3\t3e-3\t0\t70e-6\t2e-6\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\nundevitmar = Source \"undevit\" $ Pill $ mkL\n\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t435e-6\t60e-3\t0\t10e-3\t0\t1.4e-3\t1.6e-3\t18e-3\t6.5e-3\t2e-3\t0\t200e-6\t1e-6\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\ngendevit = Source \"gendevit\" $ Pill $ mkL\n\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t1e-3\t75e-3\t6.25e-6\t5e-3\t0\t1.5e-3\t1.5e-3\t10e-3\t3e-3\t2e-3\t0\t300e-6\t10e-6\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\n\nsunflowerOil = Source \"sunfloweroil\" $ Substance 100 $ usda $ mkL\t-- USDA 04506, manually corrected assuming 18:2 is LA\n\t0.00e0\t100.00e0\t0.00e0\t0.0e0\t0e-3\t0e-3\t0e-3\t0e-3\t0e-3\t0.00e-3\tidk\t0.00e-3\t0.0e-6\t0.000e-3\tidk\tidk\tidk\tidk\tidk\t0e-6\t0.0e-3\t0.0e-6\t41.08e-3\t5.4e-6\t0.000e-3\t0.000e-3\t0.000e-3\t0.000e-3\t0.000e-3\tidk\t0e-6\t0.00e-6\t0.2e-3\t0.0\t65.7\n\t0.000e0\t0.000e0\t0.000e0\t0.000e0\t0.000e0\t0.000e0\t0.000e0\t0.000e0\t0.000e0\t0.000e0\t0.000e0\tidk\t0.000e0\t0.000e0\t0.000e0\tidk\t0.000e0\tidk\t0.000e0\tidk\t0.000e0\t0.000e0\n\tidk\t0.000e0\t0.000e0\t0.000e0\t65.7\tidk\tidk\nbrazilNuts = Source \"brazilnuts\" $ Substance 100 $ usda $ mkL\t-- USDA 12078\n\t14.32e0\t67.10e0\t11.74e0\t7.5e0\t659e-3\t3e-3\t160e-3\t376e-3\t725e-3\t2.43e-3\tidk\t4.06e-3\t1917.0e-6\t1.743e-3\tidk\t1.223e-3\tidk\tidk\tidk\t0e-6\t0.7e-3\t0.0e-6\t5.65e-3\t0.0e-6\t0.617e-3\t0.035e-3\t0.295e-3\t0.184e-3\t0.101e-3\tidk\t22e-6\t0.00e-6\t28.8e-3\t1.8e-2\t23.877000000000002\n\t0.409e0\t0.518e0\t1.190e0\t0.490e0\t0.365e0\t0.639e0\t0.365e0\t0.135e0\t0.760e0\t0.609e0\t2.140e0\tidk\t1.325e0\t0.306e0\t3.190e0\tidk\t0.733e0\tidk\t0.706e0\tidk\t0.676e0\t0.416e0\n\t0.018e0\t0.000e0\t0.000e0\t0.000e0\t23.859e0\t0.018e0\tidk\noat = Source \"oat\" $ Substance 100 $ usda $ mkL\t-- USDA 08120 + http://www.whfoods.com/genpage.php?tname=nutrientprofile&dbid=109\n\t13.15e0\t6.52e0\t67.70e0\t10.1e0\n\t362e-3\t6e-3\t52e-3\t138e-3\t410e-3\t4.25e-3\tidk\t3.64e-3\t28.9e-6\t0.391e-3\tidk\t3.630e-3\tidk\tidk\tidk\n\t0e-6\t0.0e-3\t0.0e-6\t0.42e-3\t2.0e-6\t0.460e-3\t0.155e-3\t1.125e-3\t1.120e-3\t0.100e-3\tidk\t32e-6\t0.00e-6\t40.4e-3\t0.0\t0.0\n\t0.405e0\t0.694e0\t1.284e0\t0.701e0\t0.575e0\t0.895e0\t0.575e0\t0.234e0\t0.937e0\t0.881e0\t1.192e0\tidk\t1.448e0\t0.408e0\t3.712e0\tidk\t0.841e0\tidk\t0.934e0\tidk\t0.750e0\t0.573e0\n\tidk\tidk\tidk\tidk\tidk\tidk\tidk\nbuckwheat = Source \"buckwheat\" $ Substance 100 $ usda $ mkL\t-- USDA 20008\n\t13.25e0\t3.40e0\t71.50e0\t10.0e0\t460e-3\t1e-3\t18e-3\t231e-3\t347e-3\t2.20e-3\tidk\t2.40e-3\t8.3e-6\t1.100e-3\tidk\t1.300e-3\tidk\tidk\tidk\t0e-6\t0.0e-3\t0.0e-6\tidk\tidk\t0.101e-3\t0.425e-3\t7.020e-3\t1.233e-3\t0.210e-3\tidk\t30e-6\t0.00e-6\tidk\tidk\tidk\t0.309e0\t0.498e0\t0.832e0\t0.672e0\t0.506e0\t0.520e0\t0.506e0\t0.192e0\t0.678e0\t0.748e0\t0.982e0\tidk\t1.133e0\t0.229e0\t2.046e0\tidk\t1.031e0\tidk\t0.507e0\tidk\t0.685e0\t0.241e0\n\tidk\t0.000e0\t0.000e0\t0.000e0\tidk\tidk\tidk\nbuckwheatFlakes = Source \"buckwheatflakes\" $ Substance 100 $ usda $ mkL\t-- same as buckwheat\n\t13.25e0\t3.40e0\t71.50e0\t10.0e0\t460e-3\t1e-3\t18e-3\t231e-3\t347e-3\t2.20e-3\tidk\t2.40e-3\t8.3e-6\t1.100e-3\tidk\t1.300e-3\tidk\tidk\tidk\t0e-6\t0.0e-3\t0.0e-6\tidk\tidk\t0.101e-3\t0.425e-3\t7.020e-3\t1.233e-3\t0.210e-3\tidk\t30e-6\t0.00e-6\tidk\tidk\tidk\t0.309e0\t0.498e0\t0.832e0\t0.672e0\t0.506e0\t0.520e0\t0.506e0\t0.192e0\t0.678e0\t0.748e0\t0.982e0\tidk\t1.133e0\t0.229e0\t2.046e0\tidk\t1.031e0\tidk\t0.507e0\tidk\t0.685e0\t0.241e0\n\tidk\t0.000e0\t0.000e0\t0.000e0\tidk\tidk\tidk\nparsley = Source \"parsley\" $ Substance 100 $ usda $ mkL\t-- USDA 11297\n\t2.97e0\t7.90e-1\t6.33e0\t3.30e0\n\t5.54e-1\t5.60e-2\t1.38e-1\t5.00e-2\t5.80e-2\t6.20e-3\tidk\t1.07e-3\t1.00e-7\t1.49e-4\tidk\t1.60e-4\tidk\tidk\tidk\n\t4.21e-4\tidk\t0.00e0\t7.50e-4\t1.64e-3\t8.60e-5\t9.80e-5\t1.31e-3\t4.00e-4\t9.00e-5\tidk\t1.52e-4\t0.00e0\t12.8e-3\t8e-3\t118e-3\t-- http://nutritiondata.self.com/facts/vegetables-and-vegetable-products/2513/2\n\t6.10e-2\t1.18e-1\t2.04e-1\t1.81e-1\t1.22e-1\t1.45e-1\t1.22e-1\t4.50e-2\t1.72e-1\t1.95e-1\t1.22e-1\tidk\t2.94e-1\t1.40e-2\t2.49e-1\tidk\t1.45e-1\tidk\t2.13e-1\tidk\t1.36e-1\t8.20e-2\n\tidk\t0.000e0\t0.000e0\t0.000e0\tidk\tidk\tidk\nparsleyDried = Source \"parsleydried\" $ Substance 100 $ usda $ mkL\t-- USDA 02029\n\t26.63e0\t5.48e0\t50.64e0\t26.7e0\t2683e-3\t452e-3\t1140e-3\t400e-3\t436e-3\t22.04e-3\tidk\t5.44e-3\t14.1e-6\t0.780e-3\tidk\t9.810e-3\tidk\tidk\tidk\t97e-6\t125.0e-3\t0.0e-6\t8.96e-3\t1359.5e-6\t0.196e-3\t2.383e-3\t9.943e-3\t1.062e-3\t0.900e-3\tidk\t180e-6\t0.00e-6\t97.1e-3\t1.86\t1.264\n\t0.718e0\t1.546e0\t2.794e0\t2.098e0\t1.193e0\t1.712e0\t1.193e0\t0.475e0\t2.021e0\t1.778e0\t1.756e0\tidk\t3.169e0\t0.298e0\t3.688e0\tidk\t1.756e0\tidk\t2.010e0\tidk\t1.159e0\t1.159e0\n\t1.860e0\t0.000e0\t0.000e0\t0.000e0\t1.248e0\t0.016e0\tidk\nflaxseedOil = Source \"flaxseedoil\" $ Substance 100 $ usda $ mkL\t-- USDA 42231\n\t0.11e0\t99.98e0\t0.00e0\t0.0e0\t0e-3\t0e-3\t1e-3\t0e-3\t1e-3\t0.00e-3\tidk\t0.07e-3\t0.0e-6\t0.000e-3\tidk\t0.000e-3\tidk\tidk\tidk\t0e-6\t0.0e-3\t0.0e-6\t0.47e-3\t9.3e-6\t0.000e-3\t0.000e-3\t0.000e-3\tidk\t0.000e-3\tidk\t0e-6\t0.00e-6\t0.2e-3\t53.368\t14.246\n\tidk\tidk\tidk\tidk\tidk\tidk\tidk\tidk\tidk\tidk\tidk\tidk\tidk\tidk\tidk\tidk\tidk\tidk\tidk\tidk\tidk\tidk\n\t53.368e0\t0.000e0\t0.000e0\t0.000e0\t14.246e0\t0.000e0\tidk\nfishOilCodLiver = Source \"codliveroil\" $ Substance 100 $ usda $ mkL\t-- USDA 04589\n\t0.00e0\t100.00e0\t0.00e0\t0.0e0\t0e-3\t0e-3\t0e-3\t0e-3\t0e-3\t0.00e-3\tidk\t0.00e-3\t0.0e-6\t0.000e-3\tidk\t0.000e-3\tidk\tidk\tidk\t30000e-6\t0.0e-3\t250.0e-6\tidk\tidk\tidk\t0.000e-3\t0.000e-3\t0.000e-3\t0.000e-3\tidk\t0e-6\t0.00e-6\tidk\t18.801000000000002\t0.0\n\tidk\tidk\tidk\tidk\tidk\tidk\tidk\tidk\tidk\tidk\tidk\tidk\tidk\tidk\tidk\tidk\tidk\tidk\tidk\tidk\tidk\tidk\n\tidk\t6.898e0\t0.935e0\t10.968e0\tidk\tidk\tidk\neggHardboiled = Source \"egghardboiled\" $ Substance 100 $ usda $ mkL\t-- USDA 01129\n\t12.58e0\t10.61e0\t1.12e0\t0.0e0\t126e-3\t124e-3\t50e-3\t10e-3\t172e-3\t1.19e-3\tidk\t1.05e-3\t30.8e-6\t0.013e-3\tidk\t0.026e-3\tidk\tidk\t4.8e-6\t149e-6\t0.0e-3\t2.2e-6\t1.03e-3\t0.3e-6\t0.066e-3\t0.513e-3\t0.064e-3\t1.398e-3\t0.121e-3\tidk\t44e-6\t1.11e-6\t293.8e-3\t4.3e-2\t0.0\n\t0.298e0\t0.686e0\t1.075e0\t0.904e0\t0.604e0\t0.668e0\t0.604e0\t0.153e0\t0.767e0\t0.700e0\t0.755e0\tidk\t1.264e0\t0.292e0\t1.644e0\tidk\t0.423e0\tidk\t0.501e0\tidk\t0.936e0\t0.513e0\n\tidk\t0.005e0\t0.000e0\t0.038e0\tidk\tidk\tidk\nsoyflourdefatted = Source \"soyflourdefatted\" $ Substance 100 $ usda $ mkL\t-- USDA 16117\n\t51.46e0\t1.22e0\t33.92e0\t17.5e0\n\t2384e-3\t20e-3\t241e-3\t290e-3\t674e-3\t9.24e-3\tidk\t2.46e-3\t1.7e-6\t4.065e-3\tidk\t3.018e-3\tidk\tidk\tidk\n\t2e-6\t0.0e-3\t0.0e-6\t0.12e-3\t4.1e-6\t0.698e-3\t0.253e-3\t2.612e-3\t1.995e-3\t0.574e-3\tidk\t305e-6\t0.00e-6\t11.3e-3\t0.0\t0.0\n\t1.268e0\t2.281e0\t3.828e0\t3.129e0\t2.042e0\t2.453e0\t2.042e0\t0.683e0\t2.346e0\t2.215e0\t3.647e0\tidk\t5.911e0\t0.757e0\t9.106e0\tidk\t2.174e0\tidk\t2.750e0\tidk\t2.725e0\t1.778e0\n\tidk\t0.000e0\t0.000e0\t0.000e0\tidk\tidk\tidk\n\nnaCl = Source \"nacl\" $ Substance 100 $ mkL\n\t0\t0\t0\t0\n\t0\t39.32\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t60.68\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\nnaClI = Source \"nacl\" $ Substance 100 $ mkL\n\t0\t0\t0\t0\n\t0\t39.32\t0\t0\t0\t0\t2.5e-3\t0\t0\t0\t0\t0\t0\t60.68\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\nkCl = Source \"kcl\" $ Substance 100 $ mkL\n\t0\t0\t0\t0\n\t52.41\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t47.6\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\nkCitrateH2O = Source \"kcitrate\" $ Substance 100 $ mkL\t-- K3C6H7O8\n\t0\t0\t0\t0\n\t36.111\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\nkSelenate = Source \"kselenate\" $ Substance 100 $ mkL\t-- K2SeO4\n\t0\t0\t0\t0\n\t35.294\t0\t0\t0\t0\t0\t0\t0\t35.747\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\ncaCl = Source \"cacl\" $ Substance 100 $ mkL\n\t0\t0\t0\t0\n\t0\t0\t36.1\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t63.9\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\ncaCl2x2H2O = Source \"cacl2x2h2o\" $ Substance 100 $ mkL\n\t0\t0\t0\t0\n\t0\t0\t27.21\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t48.3\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\nca2CO3 = Source \"chalk\" $ Substance 100 $ mkL\n\t0\t0\t0\t0\n\t0\t0\t57.1\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\nnaI = Source \"nai\" $ Substance 1 $ mkL\n\t0\t0\t0\t0\n\t0\t0.1534\t0\t0\t0\t0\t0.8466\t0\t0\t0\t0\t0\t0\t60.68\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\n\nascorbicAcid = Source \"ascorbica\" $ Substance 100 $ mkL\n\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t100\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\nd3 = Source \"d3\" $ Substance 100 $ mkL\n\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t100\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\nvigantol = Source \"vigantol\" $ Pill $ mkL\n\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t12.5e-6\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\nnowD35000 = Source \"nowd3-5000\" $ Pill $ mkL\n\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t125e-6\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\ncholineBitartrate = Source \"cholinebitartrate\" $ Substance 100 $ mkL\n\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t41.1\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\nsnK = Source \"sourcenaturalsk\" $ Pill $ mkL\n\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0.5e-3\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n\t0\t0\t0\t0\t0\t0\t0\n"
  },
  {
    "path": "DatabaseTools.hs",
    "content": "{-# LANGUAGE DataKinds, FlexibleContexts, TypeFamilies #-}\n{-# OPTIONS_GHC -fno-warn-tabs #-}\nmodule DatabaseTools where\n\nimport Data.Proxy\nimport qualified Data.Vector.Fixed as F\nimport qualified Data.Vector.Fixed.Cont as C\n\nimport Types\n\nmkL = F.mkN (Proxy :: Proxy Nutrients)\n\n-- TODO a better value that taints the calculation\nidk :: Double\nidk = 0\n\n-- Put 'nan' when the value is unspecified or irrelevant in the target daily uptakes\nnan = 0/0\n\n-- Put 'todo' when the value is to be fetched\ntodo = idk\n\n-- USDA considers fiber a carbohydrate, we don't\nusda v = F.set (Proxy :: Proxy 2) ((F.index v (Proxy :: Proxy 2)) - (F.index v (Proxy :: Proxy 3))) v\n"
  },
  {
    "path": "LICENSE",
    "content": "            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE\n                    Version 2, December 2004\n\n Copyright (C) 2004 Sam Hocevar\n  22 rue de Plaisance, 75014 Paris, France\n Everyone is permitted to copy and distribute verbatim or modified\n copies of this license document, and changing it is allowed as long\n as the name is changed.\n\n            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE\n   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n\n  0. You just DO WHAT THE FUCK YOU WANT TO.\n\n"
  },
  {
    "path": "Main.hs",
    "content": "module Main where\nimport qualified Muesli\nmain = Muesli.main\n"
  },
  {
    "path": "Muesli.hs",
    "content": "#!/usr/bin/env runhaskell\n{-# LANGUAGE TemplateHaskell, DataKinds, FlexibleContexts #-}\n{-# OPTIONS_GHC -fno-warn-tabs #-}\n\nmodule Muesli where\n\nimport Control.Exception\nimport Control.Monad\nimport Data.List\nimport Data.Maybe\nimport Data.Vector.Fixed ((!))\nimport qualified Data.Vector.Fixed as F\nimport Data.Vector.Fixed.Boxed as V\nimport System.Console.ANSI\nimport System.Console.GetOpt\nimport System.Environment\nimport System.IO\nimport Text.Printf\n\nimport Database\nimport DatabaseTools\nimport Types\n\nfromRecipe :: Recipe -> [(Amount, Source)]\nfromRecipe (Recipe a b) = a ++ b\n\ndef :: Nutrients\ndef = F.replicate 0\n\ngetNutrients :: Component -> Nutrients\ngetNutrients (Substance _ n) = n\ngetNutrients (Pill n) = n\n\nisPill :: Component -> Bool\nisPill (Pill _) = True\nisPill _ = False\n\n-- target daily energy value\n-- TODO fix the values hardcoded elsewhere\nenergy :: Kcal\nenergy = 2000\n\n-- Calculate the energetic value\ncal :: Nutrients -> Kcal\ncal x = 4 * x!0 + 9 * x!1 + 4 * x!2\n\namountify :: Component -> Amount -> Component\namountify (Pill x) a = Pill $ F.map (* a) x\namountify (Substance mass x) a = Substance (mass * a) $ F.map (* a) x\n\nsumNutrients :: [(Amount, Source)] -> Nutrients\nsumNutrients as = foldl (\\tsum cnut -> F.zipWith (+) tsum cnut) def $ nutrientify as\n\nnutrientify :: [(Amount, Source)] -> [Nutrients]\nnutrientify as = map (\\(amount, (Source _ comp)) -> getNutrients $ amountify comp amount) as\n\nenergyMultiplier :: Nutrients -> Double\nenergyMultiplier n = energy / (cal n)\n\npills :: Recipe -> [(Amount, Source)]\npills r = filter (isPill . sComponent . snd) $ rFoods r\nsubstances :: Recipe -> [(Amount, Source)]\nsubstances r = filter (not . isPill . sComponent . snd) $ rFoods r\n\nnormalizeRecipe :: Recipe -> Recipe\nnormalizeRecipe r = let\tmult = energyMultiplier $ sumNutrients $ substances r in\n\t\tRecipe ((map (\\(amount, source) -> (mult * amount, source)) (substances r)) ++ (pills r)) $ rSupplements r\n\n\n-- daily intakes, g at 2Mcal\nfdardi = mkL\n\t50\t78\t275\t28\n\t4.7\t2.3\t1.3\t0.42\t1.25\t18e-3\t150e-6\t11e-3\t55e-6\t0.9e-3\t35e-6\t2.3e-3\t45e-6\t2.3\t4e-3\n\t0.9e-3\t0.09\t20e-6\t15e-3\t120e-6\t1.2e-3\t1.3e-3\t16e-3\t5e-3\t1.7e-3\t30e-6\t0.4e-3\t2.4e-6\t0.55\tnan\tnan\n\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\n\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\n\tnan\tnan\tnan\tnan\tnan\tnan\tnan\niomdrirda = mkL\n\tnan\tnan\tnan\tnan\n\t4.7\t1.5\t1\t0.4\t0.7\t15e-3\t150e-6\t11e-3\t55e-6\t0.9e-3\t35e-6\t2.3e-3\t45e-6\t2.3\t4e-3\n\t0.9e-3\t0.09\t15e-6\t15e-3\t120e-6\t1.2e-3\t1.3e-3\t16e-3\t5e-3\t1.3e-3\t30e-6\t0.4e-3\t2.4e-6\t0.55\t1.6\t17\n\t0.91\t1.235\t2.730\t2.470\t1.235\t2.145\t1.3\t0.325\t1.56\n\tnan\tnan\tnan\tnan\t1.235\tnan\tnan\tnan\tnan\tnan\tnan\tnan\t2.145\n\tnan\tnan\tnan\tnan\tnan\tnan\tnan\niomdriul = mkL\n\tnan\tnan\tnan\tnan\n\tnan\t2.3\t2.5\t0.7\t4\t45e-3\t1.1e-3\t40e-3\t400e-6\t10e-3\tnan\t11e-3\t2e-3\t3.6\t10e-3\n\t3e-3\t2\t100e-6\t1\tnan\tnan\tnan\t35e-3\tnan\t100e-3\tnan\t1e-3\tnan\t3.5\tnan\tnan\n\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\n\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\n\tnan\tnan\tnan\tnan\tnan\tnan\tnan\n\n-- calculated for 65kg 18-29yo sedentary male 2450kcal\nрсн = mkL\n\t59\t66\t292\t16\t-- balanced for 2000kcal\n\t2.5\t1.3\t1\t0.4\t0.8\t10e-3\t150e-6\t12e-3\t70e-6\t1e-3\t50e-6\t2e-3\t70e-6\t2.3\t4e-3\n\t900e-6\t90e-3\t10e-6\t15e-3\t120e-6\t1.5e-3\t1.8e-3\t20e-3\t5e-3\t2e-3\t50e-6\t400e-6\t3e-6\t0.5\t1.6\t7\n\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\n\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\n\tnan\tnan\tnan\tnan\tnan\tnan\tnan\n\n-- nuts:prote,\tfat,\tcarbs,\tfiber,\n-- elem:potass,\tsodium,\tcalciu,\tmagnes,\tphosph,\tiron,\tiodine,\tzinc,\tseleni,\tcopper,\tchromi,\tmangane,molybde,chlorid,fluoride,\n-- vita:a,\tc,\td,\te,\tk,\tthiami,\tribofl,\tniacin,\tpantot,\tb6,\tbiotin,\tfolate,\tb12,\tcholine,omega3,\tomega6,\n-- e aa:His,\tIle,\tLeu,\tLys,\tMet,\tPhe,\tThr,\tTrp,\tVal,\n-- o aa:Ala,\tArg,\tAsn,\tAsp,\tCys,\tGlu,\tGln,\tGly,\tOrn,\tPro,\tSel,\tSer,\tTyr\n-- e fa:ALA,\tEPA,\tDPA,\tDHA,\tLA,\tGLA,\tAA\n-- the difference against iom rda as seen in https://lpi.oregonstate.edu/publications/rx-health\nlpi = mkL\n\tnan\tnan\tnan\tnan\n\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\n\tnan\t0.4\t50e-6\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\n\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\n\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\tnan\n\tnan\tnan\tnan\tnan\tnan\tnan\tnan\n\nattenuate :: [(Amount, Source)] -> Double -> [(Amount, Source)]\nattenuate l z = map (\\(x, y) -> (x * z, y)) l\n\n-- Specify the mix\n-- Syntax: (\n-- \t[(fraction, product)],\t-- meals\n-- \t[(grams, product)]\t-- supplements\n-- \t)\n-- WARNING: supplements must not seriously affect the energy value of the mix as they're omitted from the energy calculations\nfatsOilsM = [\n\t\t(0.065, sunflowerOil),\n\t\t(0.025, flaxseedOil)\n\t]\nplantM fats bulk = [\n\t\t(0.695, bulk),\n\t\t(0.195, raisins),\n\t\t(0.02, parsleyDried)\n\t] ++ fats\n-- TODO fix the /100 kludge\nelectrolytesS = [\n\t\t(5/100, naClI),\n\t\t(7/100, kCitrateH2O),\n\t\t(2/100, ca2CO3)\n\t]\nelectrolytesClS = [\n\t\t(4/100, naClI),\n\t\t(3/100, kCl),\n\t\t(2.5/100, caCl2x2H2O)\n\t]\npPharmaS = [\n\t\t(0.3/100, ascorbicAcid),\n\t\t(2, undevit) -- two pills\n\t]\nmyPharmaS = (3/100, fishOilCodLiver) : pPharmaS\npharmaS = (1/100, cholineBitartrate) : myPharmaS\nseNutsS = (7/100, brazilNuts)\nkSelenateS = (250e-6/100, kSelenate)\nvigantolS = (10, vigantol) -- ten drops of vigantol on days w/o at least half an hour of good uvb light exposure\nnowD3S = (1, nowD35000)\niodineS = (200e-6, naI)\ndefaultS selenium = nowD3S : selenium : electrolytesS ++ pharmaS\n\nsimpleR bulk selenium = Recipe (plantM fatsOilsM bulk) (defaultS selenium)\n\nl29ah :: Recipe\nl29ah = Recipe\n\t\t((0.82, oat)\n\t\t:(0.15, soyflourdefatted)\n\t\t:fatsOilsM)\n\n\t\t(vigantolS\n\t\t:kSelenateS\n\t\t:(1, snK)\n\t\t:iodineS\n\t\t:electrolytesClS\n\t\t++pPharmaS)\n\nrecipes :: [(RecipeName, Recipe)]\nrecipes =\n\t[(\"l29ah-raisins\", Recipe\n\t\t((0.81, oat)\n\t\t:(0.1, raisins)\n\t\t:fatsOilsM)\n\n\t\t(vigantolS\n\t\t:kSelenateS\n\t\t:(1, snK)\n\t\t:electrolytesClS\n\t\t++pPharmaS))\n\t,(\"l29ah\", l29ah)\n\t,(\"l29ah-nosoy\", Recipe\n\t\t((0.91, oat)\n\t\t:fatsOilsM)\n\n\t\t(vigantolS\n\t\t:kSelenateS\n\t\t:(1, snK)\n\t\t:electrolytesClS\n\t\t++pPharmaS))\n\t,(\"l29ah-choline\", Recipe ((0.3, eggHardboiled) : attenuate (plantM fatsOilsM oat) 0.7) (vigantolS : kSelenateS : electrolytesClS ++ pPharmaS))\n\t,(\"default\", l29ah)\n\t,(\"default-choline\", simpleR oat kSelenateS)\n\t,(\"gluten-soy-free\", Recipe\n\t\t((0.94, buckwheatFlakes)\n\t\t:fatsOilsM)\n\n\t\t(vigantolS\n\t\t:kSelenateS\n\t\t:(1, snK)\n\t\t:electrolytesClS\n\t\t++pPharmaS))\n\t,(\"gluten-free\", Recipe\n\t\t((0.88, buckwheatFlakes)\n\t\t:(0.07, soyflourdefatted)\n\t\t:fatsOilsM)\n\n\t\t(vigantolS\n\t\t:kSelenateS\n\t\t:(1, snK)\n\t\t:electrolytesClS\n\t\t++pPharmaS))\n\t,(\"r2\", Recipe (plantM fatsOilsM buckwheat) (nowD3S : kSelenateS : electrolytesClS ++ pPharmaS))\n\t]\n\nreferences :: [Nutrients]\nreferences = [рсн, fdardi, iomdrirda, iomdriul, lpi]\n\n-- Compare the mix against the reference\ncomp :: Nutrients -> Nutrients -> Nutrients\ncomp p ref = F.zipWith (/) p ref\n\n-- Compare the recipe against references\ntbl :: Recipe -> [Nutrients]\ntbl r = let nuts = sumNutrients $ fromRecipe r in\n\tnuts : map (\\ref -> comp nuts ref) references\n\n-- Some pretty-printing\nprintMass :: Double -> String\nprintMass x\n\t| x > 2     = printf \"%4.1f  g\" x\n\t| x > 2e-3  = printf \"%4.1f mg\" $ x * 1e3\n\t| otherwise = printf \"%4.1f µg\" $ x * 1e6\n\nprintPercent :: Bool -> (Double -> Color) -> Double -> String\nprintPercent useColors schema x\n\t| isNaN x = printf \"       \"\n\t| otherwise = let value = (printf \"%6.0f%%\" x) in if useColors then colorify schema x value else value\n\ncolorify :: (Double -> Color) -> Double -> String -> String\ncolorify schema x s =\n\t\tconcat [\n\t\t\tsetSGRCode [SetConsoleIntensity BoldIntensity, -- to be parseable by ansi2html and vivid in a real terminal emulator\n\t\t\t\tSetColor Foreground Dull (schema x)],\n\t\t\ts,\n\t\t\tsetSGRCode [Reset]]\n\ngood x = if x < 75 then Red else if x < 125 then Yellow else Green\nbad x = if x < 75 then Green else if x < 125 then Yellow else Red\n\nreport :: Bool -> Recipe -> String\nreport useColors rec = let [\n\t\t\t\tpr, fa, carb, fib,\n\t\t\t\tk, na, ca, mg, ph, fe, i, zn, se, cu, cr, mn, mo, cl, fl,\n\t\t\t\tvA, vC, vD, vE, vK, thi, rib, nia, pant, vB6, bio, fol, vB12, cho, o3, o6,\n\t\t\t\this, ile, leu, lys, met, phe, thr, trp, val,\n\t\t\t\tala, arg, asn, asp, cys, glu, gln, gly, orn, pro, sel, ser, tyr,\n\t\t\t\talaa, epa, dpa, dha, la, gla, aa\n\t\t\t\t] = map (\\(x:xs) -> x : map (* 100) xs) $ transpose $ map F.toList $ tbl rec in\n\t(printf \"%-26s %14s %7s %7s %7s %7s %7s\\n\" (\"\" :: String) (\"mass\" :: String) (\"РСН\" :: String) (\"FDA RDI\" :: String) (\"DRI RDA\" :: String) (\"LPI\" :: String) (\"DRI UL\" :: String)) ++\n\tconcatMap (\\(a, [w, b, c, d, e, lpi]) -> printf \"%-26s %14s %s %s %s %s %s\\n\" a (printMass w) (printPercent useColors good b) (printPercent useColors good c) (printPercent useColors good d) (printPercent useColors good lpi) (printPercent useColors bad e)) ([\n\t\t(\"Protein\", pr),\n\t\t(\"Fat\", fa),\n\t\t(\"Carbohydrates\", carb),\n\t\t(\"Dietary fiber\", fib),\n\n\t\t(\"Potassium\", k),\n\t\t(\"Sodium\", na),\n\t\t(\"Calcium\", ca),\n\t\t(\"Magnesium\", mg),\n\t\t(\"Phosphorus\", ph),\n\t\t(\"Iron\", fe),\n\t\t(\"Iodine\", i),\n\t\t(\"Zinc\", zn),\n\t\t(\"Selenium\", se),\n\t\t(\"Copper\", cu),\n\t\t(\"Chromium (*)\", cr),\n\t\t(\"Manganese (*)\", mn),\n\t\t(\"Molybdenum (*)\", mo),\n\t\t(\"Chlorine\", cl),\n\t\t(\"Fluoride (*)\", fl),\n\n\t\t(\"Vitamin A\", vA),\n\t\t(\"Vitamin C (*)\", vC),\n\t\t(\"Vitamin D (*)\", vD),\n\t\t(\"Vitamin E\", vE),\n\t\t(\"Vitamin K\", vK),\n\t\t(\"Thiamin\", thi),\n\t\t(\"Riboflavin\", rib),\n\t\t(\"Niacin\", nia),\n\t\t(\"Pantothenic acid\", pant),\n\t\t(\"Vitamin B6\", vB6),\n\t\t(\"Biotin (*)\", bio),\n\t\t(\"Folate\", fol),\n\t\t(\"Vitamin B12\", vB12),\n\t\t(\"Choline\", cho),\n\t\t(\"Omega-3 fats\", o3),\n\t\t(\"Omega-6 fats\", o6),\n\n\t\t(\"Histidine\", his),\n\t\t(\"Isoleucine\", ile),\n\t\t(\"Leucine\", leu),\n\t\t(\"Lysine\", lys),\n\t\t(\"Methionine (a)\", met),\n\t\t(\"Phenylalanine (b)\", phe),\n\t\t(\"Threonine\", thr),\n\t\t(\"Tryptophan\", trp),\n\t\t(\"Valine\", val),\n\n\t\t(\"Alanine\", ala),\n\t\t(\"Arginine\", arg),\n\t\t(\"Asparagine\", asn),\n\t\t(\"Aspartic acid\", asp),\n\t\t(\"Cysteine (a)\", cys),\n\t\t(\"Glutamic acid\", glu),\n\t\t(\"Glutamine\", gln),\n\t\t(\"Glycine\", gly),\n\t\t(\"Ornithine\", orn),\n\t\t(\"Proline\", pro),\n\t\t(\"Selenocysteine\", sel),\n\t\t(\"Serine\", ser),\n\t\t(\"Tyrosine (b)\", tyr),\n\n\t\t(\"ALA (18:3 n-3)\", alaa),\n\t\t(\"EPA (20:5 n-3)\", epa),\n\t\t(\"DPA (22:5 n-3)\", dpa),\n\t\t(\"DHA (22:6 n-3)\", dha),\n\t\t(\"LA (18:2 n-6)\", la),\n\t\t(\"GLA (18:3 n-6)\", gla),\n\t\t(\"AA (20:4 n-6)\", aa)\n\t\t] :: [(String, [Double])]) ++\n\t\"(*) - see README\\n\" ++\n\t\"(<letter>) - specified as the sum of components in IOM RDA\"\n\nprintRecipeItem :: (Amount, Source) -> String\nprintRecipeItem (amount, (Source name cmp)) = printf \"%-26s %14s\\n\" name (if isPill cmp then show amount else printMass $ amount * sServingMass cmp)\n\nprintRecipe :: Recipe -> Double -> String\nprintRecipe r days = \"Recipe for \" ++ show days ++ \" days:\\n\" ++\n\t(concatMap printRecipeItem  $ attenuate (fromRecipe r) days)\n\nusage = do\n\tpn <- getProgName\n\tputStr $ usageInfo (\"Usage: \" ++ pn ++ \" <recipe name>\\navailable recipes:\\n\\n\" ++ (unlines $ map fst $ recipes)) options\n\ndata Flag = FReport | FColors | FDays Double deriving (Eq, Show)\n\noptions :: [OptDescr Flag]\noptions =\n\t[ Option ['r']\t[\"report\"]\t(NoArg\tFReport)\t\t\"print the nutrients report table\"\n\t, Option ['c']\t[\"colors\"]\t(NoArg\tFColors)\t\t\"forcefully enable ANSI-colored output\"\n\t, Option ['d']\t[\"days\"]\t(ReqArg (FDays . read) \"DAYS\")\t\"print the sources' masses counted for DAYS of consumption\"\n\t]\n\nmain = do\n\targs <- getArgs\n\tlet (opts, strings, errs) = getOpt RequireOrder options args\n\tsupportsColors <- hSupportsANSI stdout\n\tlet useColors = or [supportsColors, elem FColors opts]\n\tfromMaybe usage $ do\n\t\trecipename <- listToMaybe strings\n\t\trec <- lookup recipename recipes\n\t\tlet nrec = normalizeRecipe rec\n\t\treturn $ do\n\t\t\tputStrLn $ report useColors nrec\n\t\t\tlet days = maybe 1 (\\(FDays d) -> d) $ find (\\x -> case x of FDays _ -> True; _ -> False) opts\n\t\t\twhen (notElem FReport opts) $ putStrLn $ '\\n' :\n\t\t\t\t(printRecipe nrec days) ++\n\t\t\t\t(\"\\nApproximate mass: \" ++ (printMass $ (days *) $ sum $ map (\\(amount, (Source _ cmp)) -> if isPill cmp then amount else amount * sServingMass cmp) $ fromRecipe nrec))\n"
  },
  {
    "path": "README.md",
    "content": "# muesli\n\nA muesli calculator. Prints a recipe and its nutritional value. Brought up because i'm not much into spreadsheets and hoped to write some clever algo to sort the mix out for me someday.\n\nThis project aims to provide one with nutritionally complete and easy to make food that needs to be chewed considerably to be consumed to trigger the corresponding digestive responses in one's body. There were also ideas about making it less bland for people unused to spice-free food, but i concluded it's quite individual stuff; i found sweeteners (like aspartame and sucralose), vanillin, apple flavoring, garlic or chili powder doing the job. It consumes about $1 and 15mins per day, excluding the research, for me. I believe in dogfooding, so you can check out the recipe i'm using at the moment by hitting `./Muesli.hs l29ah`.\n\n[ansi2html'ed snapshot of the recipe](http://muesli.l29ah.blasux.ru/muesli-dump.html)\n\nThe current requirements are optimized for a median male. A female (or a frequent blood donor, or otherwise a person who loses erythrocytes quickly) would need to supplement iron additionally. TODO: requirement profiles\n\nIf you found it useful, you're eating the muesli for a long time, or having any problems with it, drop me a line.\n\n## Installation:\n\n* install ghc (9.2.0 or newer) and cabal-install\n* `cabal update && cabal install ansi-terminal fixed-vector`\n\n## Usage:\n\nTo see the nutrient profile and the current recipe, call:\n\n\n```\n$ ./Muesli.hs default\n```\n\n# What does it look like\n\nRaw:\n![raw muesli](http://muesli.l29ah.blasux.ru/a.jpeg)\nCooked:\n![cooked muesli](http://muesli.l29ah.blasux.ru/b.jpeg)\n\n# Sources\n* [The original Soylent prototype](https://web.archive.org/web/20170305070025/http://robrhinehart.com/?p=424)\n* https://www.bestpravo.com/federalnoje/bz-dokumenty/c5o/index.htm\n* https://fdc.nal.usda.gov/fdc-app.html#/?query=\n* https://lpi.oregonstate.edu/publications/rx-health\n* Protein\n  * should be 1,3-1,7g/kg body weight\n    * 10.1123/ijsn.5.s1.s39\n    * https://www.ncbi.nlm.nih.gov/pubmed/16779921\n* Calcium\n  * [Calcium Supplementation in Clinical Practice: A Review of Forms, Doses, and Indications](https://onlinelibrary.wiley.com/doi/full/10.1177/0115426507022003286)\n  * [Stimulates gastric acid secretion](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1411522/)\n* Magnesium\n  * The IOM DRI UL is way too conservative, since at doses <2.5g the only side effect is possible mild diarrhea in some populations when supplemented\n    * https://www.sciencedirect.com/science/article/pii/S2161831323013352\n    * https://ec.europa.eu/food/fs/sc/scf/out105_en.pdf\n* Potassium\n  * https://www.nal.usda.gov/sites/default/files/fnic_uploads/water_full_report.pdf\n* Sodium\n  * https://www.nal.usda.gov/sites/default/files/fnic_uploads/water_full_report.pdf\n* Chloride\n  * no proper data from IOM\n  * https://www.ahajournals.org/doi/full/10.1161/01.HYP.0000158264.36590.19 suggests chloride intake doesn't matter for blood pressure\n* Manganese\n  * Opinion of the scientific committee on food on the tolerable upper intake level of manganese 19.10.2009\n    * manganese supplements are evil but no evidence of any damage from excessive intake from the food sources in diets of up to 20mg daily\n  * https://discourse.soylent.com/t/have-you-asked-yourself-why-upper-limit-of-manganese-is-11mg-day/7660\n  * https://lpi.oregonstate.edu/mic/minerals/manganese#toxicity\n  * I got 8µg/L whole blood Mn while consuming 20.1mg Mn from oats per day\n* Vitamin A\n  * 1 IU = 300ng of retinol\n  * EFSA [recommends 750μg retinol a day for adult men and 1300 for lactating women](https://efsa.onlinelibrary.wiley.com/doi/epdf/10.2903/j.efsa.2015.4028)\n  * Dietary carotenoid bioavailability and conversion [is likely to be poor](https://pmc.ncbi.nlm.nih.gov/articles/PMC10261660/)\n* Vitamin K\n  * green veggies\n* Vitamin C\n  * https://academic.oup.com/ajcn/article/69/6/1086/4714888/\n  * ascorbic acid also retards fat rancidification\n* Vitamin D\n  * comes from sunlight and supplements only, basically\n  * quite a lot of inconclusive studies regarding cancer\n  * amount\n    * 1µg cholecalciferol = 40IU\n    * https://www.sciencedaily.com/releases/2015/03/150317122458.htm\n    * or even higher https://www.ncbi.nlm.nih.gov/m/pubmed/28768407/\n    * my own experience re D3 -> 25(OH)D3: https://bnw.im/p/0DLNGK\n* Biotin\n  * Produced by body and generally abundant\n  * https://en.wikipedia.org/wiki/Biotin_deficiency\n* Chromium\n  * No cases of deficiency if not on long-term i/v feeding\n    * https://en.wikipedia.org/wiki/Chromium#Biological_role\n* Molybdenum\n  * Deficiency only on i/v feeding or in molybdenum-poor soils (northen China to Iran)\n    * https://en.wikipedia.org/wiki/Molybdenum#Human_dietary_intake_and_deficiency\n* Iodine\n  * Salt form is unnecessary, molecular iodine is okay\n    * https://www.zrtlab.com/blog/archive/guide-how-to-treat-iodine-deficiency/\n    * 200µg I2 per 3L of water is 15-150 times less than used for drinking water disinfection\n* Fluoride\n  * Controversial\n  * https://en.wikipedia.org/wiki/Fluoride_deficiency\n  * No effect on bone strength\n    * https://www.ncbi.nlm.nih.gov/pubmed/8897754\n  * Seems to induce dental fluorosis at recommended dosages\n    * https://www.ncbi.nlm.nih.gov/pubmed/2129630\n  * Likely neurotoxic when present in drinking water\n    * https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6923889/\n    * https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3491930/\n* Choline\n  * synthesized by body in small amounts\n  * i didn't observe the signs of deficiency myself although being low on it for like the whole life; tried refilling it with eggs for two weeks, didn't notice anything interesting\n* Fats\n  * Polyunsaturated fatty acids\n    * The oil should be unrefined, since refining converts some PUFAs into trans-isomeres.\n    * https://www.sciencedirect.com/science/article/pii/S016378271300057X\n    * https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4179179/\n    * n-3\n      * https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4179179/\n      * https://www.ncbi.nlm.nih.gov/pubmed/16841858\n      * DHA\n        * brain (at least early and elderly); produced in small quantites from ALA in young females only\n        * especially vulnerable to peroxidation in vivo: https://www.ncbi.nlm.nih.gov/pubmed/11110863\n  * Refined oil has a lower degree of peroxidation\n    * https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4486537/\n  * Refined oil has much more trans fats\n    * https://www.scielo.br/pdf/aabc/v79n2/a15v79n2.pdf\n"
  },
  {
    "path": "Setup.lhs",
    "content": "#!/usr/bin/env runhaskell\n\n> import Distribution.Simple\n> main = defaultMain\n"
  },
  {
    "path": "Types.hs",
    "content": "{-# LANGUAGE DataKinds, TypeFamilies, UndecidableInstances #-}\n{-# OPTIONS_GHC -fno-warn-tabs #-}\nmodule Types where\n\nimport Data.Vector.Fixed.Boxed as V\n\ntype Kcal = Double\ntype Grams = Double\ntype Elements = 64\ntype Nutrients = V.Vec Elements Grams\n\ndata Component = Substance\n\t{ sServingMass :: Grams\t-- the total mass of the component described by sNutrients\n\t, sNutrients :: Nutrients\n\t} | Pill\n\t{ pNutrients :: Nutrients\n\t} deriving Show\n\ndata Source = Source\n\t{ sProdName :: String\n\t, sComponent :: Component\n\t} deriving Show\n\ntype RecipeName = String\ntype Amount = Double\ndata Recipe = Recipe\n\t{ rFoods :: [(Amount, Source)]\n\t, rSupplements :: [(Amount, Source)]\n\t} deriving Show\n"
  },
  {
    "path": "mktable.hs",
    "content": "#!/usr/bin/runhaskell\n{-# OPTIONS_GHC -fno-warn-tabs #-}\nimport Data.List\nimport Text.CSV\n\nllookup :: String -> [[String]] -> [String]\n--llookup hx [] = [\"\",\"g\",\"WTF \" ++ hx]\nllookup hx [] = []\nllookup hx list = let (x:xs):ls = list in\n\tif x == hx then x:xs else llookup hx ls\n\nutoe \"g\" = \"e0\"\nutoe \"mg\" = \"e-3\"\nutoe \"µg\" = \"e-6\"\n\ntablify :: [String] -> String\ntablify (name:unit:amount:_) = amount ++ utoe unit\ntablify [] = \"idk\"\n\nlookups csv components = map (\\c -> tablify $ llookup c csv) components\n\n-- Assume idk = 0\nlookupFatty csv = sum . map (read :: String -> Double) . filter (/= \"idk\") . lookups csv\n\ncomponents1 = [\"Protein\", \"Total lipid (fat)\", \"Carbohydrate, by difference\", \"Fiber, total dietary\"]\ncomponents2 = [\"Potassium, K\", \"Sodium, Na\", \"Calcium, Ca\", \"Magnesium, Mg\", \"Phosphorus, P\", \"Iron, Fe\", \"Iodine, I\", \"Zinc, Zn\", \"Selenium, Se\", \"Copper, Cu\", \"Chromium, Cr\", \"Manganese, Mn\", \"Molybden, Md\", \"Chloride, Cl\", \"Fluoride, F\"]\ncomponentsPreFat = [\"Vitamin A, RAE\", \"Vitamin C, total ascorbic acid\", \"Vitamin D (D2 + D3)\", \"Vitamin E (alpha-tocopherol)\", \"Vitamin K (phylloquinone)\", \"Thiamin\", \"Riboflavin\", \"Niacin\", \"Pantothenic acid\", \"Vitamin B-6\", \"Biotin\", \"Folate, total\", \"Vitamin B-12\", \"Choline, total\"]\ncomponentsPostFat = [\"Histidine\", \"Isoleucine\", \"Leucine\", \"Lysine\", \"Threonine\", \"Phenylalanine\", \"Threonine\", \"Tryptophan\", \"Valine\", \"Alanine\", \"Arginine\", \"Asparagine\", \"Aspartic acid\", \"Cystine\", \"Glutamic acid\", \"Glutamine\", \"Glycine\", \"Ornithine\", \"Proline\", \"Selenocysteine\", \"Serine\", \"Tyrosine\"]\n\nomega3 = [\"18:3 n-3 c,c,c (ALA)\", \"20:5 n-3 (EPA)\", \"22:5 n-3 (DPA)\", \"22:6 n-3 (DHA)\"]\nomega6 = [\"18:2 n-6 c,c\", \"18:3 n-6 c,c,c\", \"20:4 n-6\"]\n\nsep = \"\\t\"\nformat comp csv = intercalate sep $ lookups csv comp\n\nmain = do\n\tc <- getContents\n\tlet cp = parseCSV \"\" c\n\teither\n\t\tprint\n\t\t(\\r -> do\n\t\t\tputStrLn $ format components1 r\n\t\t\tputStrLn $ format components2 r\n\t\t\tputStrLn $ (intercalate sep $ concat [\n\t\t\t\tlookups r componentsPreFat,\n\t\t\t\t[show $ lookupFatty r omega3, show $ lookupFatty r omega6]])\n\t\t\tputStrLn $ (intercalate sep $ lookups r componentsPostFat)\n\t\t\tputStrLn $ intercalate sep $ concat [\n\t\t\t\tlookups r omega3,\n\t\t\t\tlookups r omega6]\n\t\t)\n\t\tcp\n"
  },
  {
    "path": "mktable.sh",
    "content": "#!/bin/sh\n# Usage: $0 http://ndb.nal.usda.gov/ndb/foods/show/738?manu=&fgcd=\ncurl -s 'https://ndb.nal.usda.gov/ndb/foods/show/'`echo \"$1\" | sed -e 's#[^0-9]*\\([0-9]*\\).*#\\1#'`'?format=Full&reportfmt=csv' | iconv -f cp1251 | sed -e 's#^([^)]*)##' | ./mktable.hs\n"
  },
  {
    "path": "muesli.cabal",
    "content": "Name:           muesli\nVersion:        0\n\nLicense:        OtherLicense\nLicense-file:   LICENSE\n\n\nBuild-Type:     Simple\nCabal-Version:  >= 1.2\nTested-With:    GHC == 8.10.3\n\nExecutable      Muesli\n        Main-is:        Main.hs\n        ghc-options:    -fno-warn-tabs\n        other-modules:  Database, DatabaseTools, Types, Muesli\n        Build-depends:\n                        base >= 4 && < 5,\n                        ansi-terminal >= 0.6.2.1 && < 0.12,\n                        fixed-vector >= 1.1 && < 1.3\n"
  }
]