Log in

No account? Create an account

Multi-culturalism - John C. Kirk — LiveJournal

Oct. 11th, 2006

12:55 am - Multi-culturalism

Previous Entry Share Next Entry


[User Picture]
Date:October 11th, 2006 03:42 pm (UTC)
If we're going to get geeky/formal about it.... ;)

data Social = Pub 
            | Curry 
            | Ordering Social Social
              deriving (Eq, Show)

pre :: Social -> Social -> Social
pre x y = Ordering y x

Which allows us to do the original thing (remove the parens), so long as we have access to $ and flip:

Main> flip pre Pub $ pre Pub Curry 
Ordering Pub (Ordering Curry Pub)

...which is (one reason) why haskell doesn't have all those brackets :)

As for your "pre pre pre curry pub pub pre curry pre curry pub pub" thing - I notice (with a little help from hugs, I'm afraid) that there are 7 Socials in the phrase, and only 5 "pre" statements... Since every pre takes two Socials and returns one Social, and our goal is to have one Social, we need n-1 "pre"s for every "n" Socials...

So, not ambiguous, certainly confusing, and unfortunately not well formed :/
(Reply) (Parent) (Thread)
[User Picture]
Date:October 11th, 2006 03:53 pm (UTC)
Oh - it's possibly worth noting that "pub pre pre pub curry" does an implicit flip of the type I showed here - it's not (just) the infixing that makes it work, it's (also) a redefinition of pre := flip pre.

I was going to say that the infixing just makes it obvious that it doesn't parse any other way. Unfortunately, it does parse another way:
Main> pre Pub (pre Pub Curry)
Ordering (Ordering Curry Pub) Pub

Perhaps it's that we're assuming that one has no need for pre Pub Pub, since one's already in the Pub. Or perhaps there's some weird rule about how native english speakers flip this arguments of their functions when they turn them infix...
(Reply) (Parent) (Thread)
[User Picture]
Date:October 11th, 2006 04:11 pm (UTC)
Damn, you're right. Remove the final "pub", and I think we're in business.

I'm well impressed with you writing a subsys-evening-out parser so quickly, though :-)
(Reply) (Parent) (Thread)
[User Picture]
Date:October 12th, 2006 09:57 am (UTC)
Yup - here we go :)
Main> pre (pre (pre Curry Pub) Pub) (pre Curry (pre Curry Pub))
Ordering (Ordering (Ordering Pub Curry) Curry) (Ordering Pub (Ordering Pub Curry))

...and I think that is a unique legal parsing. Haskell won't find it for me by default though, because it's more useful to have
pre pre -> _|_
than do embark on a search of possible application orders till you find one that works. Perhaps perl 7 will do that though ;)

Oh - and I didn't write a parser - just a type and a function, as you see above. All the parsing you see here was done either by hugs trying to evaluate expressions containing that function, or by hand. Or a sort of trial and error combination of the two. I actually tried about three paren-combinations before realising that the previous expression was invalid for example ;)

Does this count as a night-out DSL implemented in haskell?
(Reply) (Parent) (Thread)