lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I was interested to read in http://lua-users.org/wiki/SimpleTuples
about defining pairing functions satisfying the mathematically
necessary condition
  pair (x,x') == pair (y,y') <==> x == y and x' == y'
To recapitulate, we have:

local pair
do -------------------
 local m = function (a) return {
         __index = function (t,b)
                local p = function ( ) return a,b end
                t[b] = p
                return p end }
 local meta = { __index = function (t,a)
                   local v = setmetatable ({ }, m (a))
                   t[a] = v
                   return v end }
 local P = setmetatable ({ }, meta)
 pair = function (x, y) return P[x][y] end
end -----------------

If we then define:

  tuple = function (...)
    local n = select ('#', ...)
    if n < 1 then return end
    if n < 2 then return ... end
    return pair (..., tuple (select (2, ...))) end

we have
   tuple (1,2,3) == tuple (1, tuple (2,3)) --> true
by definition but, alas,
   tuple (1,2,3) == tuple (tuple (1,2), 3) --> false
So are there any associative tupling functions?
<muttering aside>
We probably need to be able to hash not just single items
on the stack but tuples of items, in an associative way. I tried
googling "hashing and tupling" but that particular cast of the
net brought up no relevant research papers as far as I could see.
As a good category theorist I should not be asking for equalities
but for invertible associator functions that satisfy naturality
and MacLane's pentagonal condition; but then monoidal categories
are monoidally equivalent to strict monoidal categories.</muttering>
--
Gavin Wraith (gavin@wra1th.plus.com)
Home page: http://www.wra1th.plus.com/