Re: [Haskell-cafe] The Riddle of the Buddhist Monk

On 21/12/2011, at 4:34 AM, Patrick Browne wrote:
I have simplified the code using constructors and export. I can evalute the qualified expressions but I do not get the expected results.
module MONKONMOVE (module MONKONMOVE)where
When I see "MONKONMOVE" I think "what's a MONKON?" Even the Java designers say "if you paste together several words all in capitals, put underscores between them". So is it MONKON_MOVE, MONK_ONMOVE, MONK_ON_MOVE (what does that mean?) or something else? The classic puzzle has nothing to do with monks, Buddhist or otherwise. It goes something like this: "One morning you start climbing a mountain at 8am and reach the top by 6pm. You stay there overnight. Next morning, you start down on the same path at 8am and reach the bottom by 6pm. Prove that there is some time of day 8am <= t <= 6pm such that you are at the same place at time t on both days." The solution as given by Lewis Carroll is "Pretend there are two people doing the trip, one up and one down, on the same day. Clearly they must meet. QED." So what exactly is the program supposed to do? The problem lacks the information from which a specific value of t can be computed; all that can be determined is that *some* value of t must exist. However, that proof depends on the *continuity* of the time->place mappings: if f, g: [0,1] -> [0,1] are continuous functions and f(0) = 0, f(1) = 1, g(0) = 1, g(1) = 0 then there exists t in [0,1] such that f(t) = g(t) and I don't see anything in the code that talks about continuity. It should be clear that daredevils going up and down the mountain on sufficiently springy pogo sticks (or electrons jumping in their insouciant quantum way) need *not* meet.

On Wed, Dec 21, 2011 at 10:12 AM, Patrick Browne
On 21/12/11, *Richard O'Keefe *
wrote: So what exactly is the program supposed to do?
I am trying to see whether Haskell modules can be used for blending[1]. The original MAUDE [2,3] program just sets up an arbitrary meeting point, which is assumed to be time-2 and location-2. Then in MONK_MEETS_HIMSELF the up and down versions of these are made match. To do this I wish to declare the function location in MONK_ON_MOVE. Then I require different equations for that same location function in MONK_ON_MOVE_DOWN and MONK_ON_MOVE_UP both of which import MONK_ON_MOVE. Finally, I wish to import MONK_ON_MOVE_DOWN and MONK_ON_MOVE_UP into MONK_MEETS_HIMSELF and use the combined set of equations to check locations.
You can't do that in Haskell. All equations defining a function must occur contiguously in the same Haskell module. You've actually defined two separate functions, MONK_ON_MOVE_DOWN.location and MONK_ON_MOVE_UP.location. If you want to define a single function that blends their behaviors, you need to do that explicitly. For example, you might define these as partial functions, returning type "Maybe LocationOnPath", and then try each implementation (in your case, 2 tries), until one of them returns a non-Nothing result. You could use type classes with overlapping instances to try to merge two different definitions of location, but it wouldn't work the way you want. The compiler would statically choose one implementation of location that would be used for a given type, rather than trying equations from both (as you desire, and as would happen in Maude). So far I cannot figure out how the location function and the constructors
can be shared in this way using Haskell modules.
I have tried various combination import/export options, type classes, and newtype. I have also tried to use Strings instead of constructors.
I had trouble using Haskell equations with pure constructors. Due to my ignorance of Haskell semantics I am not sure what Constructor1 = Constructor2 means. But in the original Maude there are constructor only equations such as Timed2 = Timeu2 which in Maude means that the constructor Timed2 could be replaced with Timeu2. I wrote Haskell functions to try to achieve a similar effect e.g.
timed2 :: TimeOfDay -> TimeOfDay
timed2 Timed2 = Timeu2
I'm not sure why top-level equations like "Timed2 = Timeu2" (or even "Just () = Nothing") aren't an error in GHC (or even a -Wall warning), but, as you've observed, this won't cause Timed2 to rewrite to Timeu2. Constructors in Haskell truly are constructors, they don't rewrite to something else (similar to the intention of the [ctor] annotation in Maude). To make it work, you'd have to manually separate out which of your terms are truly constructors and which ones are functions. Then write equations defining the functions. Be sure that all equations for a given function are in a given place. You could of course implement a rewrite system on top of Haskell, and the syntax probably wouldn't be that bad (someone's probably already done it). But you can't directly write Maude-style rewrite systems in Haskell; the two languages just work differently. [1] http://cseweb.ucsd.edu/~goguen/pps/taspm.pdf
[2] http://lists.cs.uiuc.edu/pipermail/maude-help/2010-December/000456.html [3] http://lists.cs.uiuc.edu/pipermail/maude-help/2010-December/000462.html
participants (3)
-
Patrick Browne
-
Richard O'Keefe
-
Sameer Sundresh