January 2018

S M T W T F S
  123456
78910111213
14151617181920
21222324252627
28293031   

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Wednesday, March 5th, 2008 11:28 pm
By the way, here's what an argmunger looks like in Arc:
(def argmunge (munger victim) (fn args (apply victim (map args munger))))
It's used like so:
arc> ((argmunge '(1 0) cons) 'x 'y)
(y . x)
arc> ((argmunge '(2 3 1 1 0 3 2) list) 'a 'b 'c 'd 'e 'f 'g)
(c d b b a d c)
That took a couple of minutes to write, and worked first time. Sw33t! Though I thought I'd got it wrong at first, as there was a bug in my test code :-) Note, by the way, that I'm mapping one list over another, to get the moral equivalent of Perl's list-slicing: this is a spin-off of the way that Arc treats function calls and data-structure indexing as indistinguishable. I'd hoped that I could write an argmunger that could be handed either a list or a function as its munger and Do The Right Thing, but unfortunately I don't think there's any way of determining the domain of an Arc function (the equivalent of the list's length) automatically.

I've changed the method signature so the munger is the first argument: that's because (argmunge m1 (argmunge m2 f)) is equal to (argmunge m1:m2 f). It's usual in operad theory to have the munging functions acting on the right: this is because they usually only consider munging functions which are invertible (ie, permutations), and use the definition (sticking with Lisp notation):
((argmunge' f m) x(m 0) x(m 1) ...) = (f x0 x1 ...)
So (argmunge' f m) is equal to (argmunge m-1 f). With this definition (which is fine if you only allow permutations) then (argmunge' (argmunge' f m1) m2) is equal to (argmunge' f m1:m2), so it makes more sense for the arguments to be that way round. But when you allow your munging function to be noninvertible, you have to use the definition I gave, and then it makes more sense to have the mungers acting on the left.
Thursday, March 6th, 2008 09:38 am (UTC)
Now you mention operads. Nice!

I've been wishing to bring up operads as a semantic tool for CS for quite some time now - it seems that things like the highly functional programming languages would benefit deeply from getting described with something like an operad of functions - in these things like flip and (argmunge . permutation) would just be the "obvious" way to thread in a symmetric structure.
Thursday, March 6th, 2008 10:18 am (UTC)
Yes - I was going to tie yesterday's post into operad theory (I'm sure you can see how), but just writing the argmunger and writing up my development process (hey, I found it hard, so probably someone else would have too...) took me most of the day. I'll try and write the rest of the post later today.

Operads and/or multicategories are a pretty natural approach to semantics and APIs in general, I think.