[Haskell-cafe] Monads with "The" contexts?
Ben Doyle
benjamin.peter.doyle at gmail.com
Thu Jul 12 22:05:58 CEST 2012
On Thu, Jul 12, 2012 at 11:01 AM, Takayuki Muranushi <muranushi at gmail.com>wrote:
> > sunPerMars :: [Double]
> > sunPerMars = (/) <$> sunMass <*> marsMass
>
> Sadly, this gives too many answers, and some of them are wrong because
> they assume different Earth mass in calculating Sun and Mars masses,
> which led to inconsistent calculation.
>
I think what you want to do is factor out the Earth's mass, and do your
division first:
> sunPerMars'' = (/) <$> sunMassCoef <*> marsMassCoef
The mass of the earth cancels.
That gives a list of length 9, where your approach gave 16 distinct
results. But I think that's just floating point rounding noise. Try the
same monadic calculation with integers and ratios.
The moral? Using numbers in a physics calculation should be your last
resort ;)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120712/76fdc74a/attachment.htm>
More information about the Haskell-Cafe
mailing list