[Haskell-cafe] Monads with "The" contexts?
muranushi at gmail.com
Thu Jul 12 17:01:47 CEST 2012
tl;dr: Is there any way to pass the Supercombinator level names (the
names in haskell source codes with zero indent) as context to a Monad
so that it will read from "The" context?
Hello, everyone. I'm thinking of representing our knowledge about our
life, the universe and everything as Haskell values. I'd also like to
address the uncertainties in our knowledge. The uncertainties are
usually continuous (probabilistic distributions) but that's another
story. Please forget about it for a while.
We learned that List is for nondeterministic context.
> earthMass, sunMass, marsMass :: [Double]
Let's pretend that there are large uncertainty in our knowledge of the
> earthMass = [5.96e24, 5.97e24, 5.98e24]
Let's also pretend that we can measure the other bodys' masses only by
their ratio to the earth mass, and the measurements have large uncertainties.
> sunMass = (*) <$> [2.5e5, 3e5, 4e5] <*> earthMass
> marsMass = (*) <$> [0.01, 0.1, 1.0] <*> earthMass
Then, how many Mars mass object can we create by taking the sun apart?
> 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.
*Main> length $ sunPerMars
We had to do this way;
> sunMass' e = map (e*) [2.5e5, 3e5, 4e5]
> marsMass' e = map (e*) [0.01, 0.1, 1.0]
> sunPerMars' :: [Double]
> sunPerMars' = do
> e <- earthMass
> (/) <$> sunMass' e <*> marsMass' e
to have correct candidates (with duplicates.)
*Main> length $ sunPerMars'
The use of (e <- earthMass) seems inevitable for representing that the
two Earth masses are taken from the same source of nondeterminism.
However, as the chain of the reasoning grows, we can easily imagine
the function arguments will grow impractically large. To get the Higgs
mass, we will need to feed them all the history of research that led
to the measurement of it.
There is "the" source of nondeterminism for Earth mass we will always use.
Is there a way to represent this? For example, can we define
earthMass'' , sunMass'' , marsMass'' all in separate modules, and yet
have (length $ sunPerMars'' == 27) ?
By the way,
*Main> length $ nub $ sort sunPerMars'
is not 9. That's another story, I said!
Thanks in advance.
The Hakubi Center for Advanced Research, Kyoto University
More information about the Haskell-Cafe