Monads with "The" contexts?

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 Earth mass.
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 81 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' 27 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' 16 is not 9. That's another story, I said! Thanks in advance. -- Takayuki MURANUSHI The Hakubi Center for Advanced Research, Kyoto University http://www.hakubi.kyoto-u.ac.jp/02_mem/h22/muranushi.html

Hi, Takayuki Muranushi 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.
This might be related to the problem adressed by Sebastian Fischer, Oleg Kiselyov and Chung-chieh Shan in their ICFP 2009 paper on purely functional lazy non-deterministic programming. http://www.cs.rutgers.edu/~ccshan/rational/lazy-nondet.pdf An implementation seems to be available on hackage. http://hackage.haskell.org/package/explicit-sharing Tillmann

On Thu, Jul 12, 2012 at 11:01 AM, Takayuki Muranushi
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 ;)

Thank you Tillman, and Oleg, for your advices! Since ICFP contest is starting in a few hours, I will make a quick response with gratefulness and will read the full paper later.... Let me guess a few things, please tell me am I right. The share :: m a -> m (m a) is almost the thing I am looking for. I have independently (believe me!) invented an equivalent, "bind trick," for my DSL: http://nushisblogger.blogspot.jp/2012/06/builder-monad.html but am now enlighted with what it really meant. Still, `share` cannot bring the shared binding to global scope (e.g. it doesn't allow place sunMass, earthMass, marsMass in separate modules) I guess, my original question is ill-posed, since all the values in Haskell are pure, so in the following trivial example
earthCopyMass = earthMass
there is no way to distinguish two masses, thus there's no telling if Earth and EarthCopy is two reference to one planet or two distinct planets. I don't know if memo can solve this problem. I have to test. I'll try implement `memo` in your JFP paper section 4.2 Memoization; seems like it's not in explicit-sharing hackage. I'm vaguely foreseeing, that like in memoized (f2 0, f2 1, f2 0, f2 1) we need to pass around some `world` among it. That will be random generator seeds if our continuous-nondeterminism is an MonadIO when we perform Monte-Carlo simulations; or it's a virtual `world` if we make Gaussian approximation of probabilistic density functions. To Ben: Thank you for your comments anyway! But since I'm not going to use the List monad (the use of List was just for explanation,) the discreteness is not an issue here. That's my intent when I said "another story." Sorry for confusion! All the best, Takayuki
participants (3)
-
Ben Doyle
-
Takayuki Muranushi
-
Tillmann Rendel