[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Associative tuples
- From: Gavin Wraith <gavin@...>
- Date: Sat, 13 Jan 2018 13:35:57 GMT
In message <CABcj=tnmEOBpJ_GFd9h7BeBJkL+zf+-fFFPJw2YmDj-tvy1qiQ@mail.gmail.com>
Dirk Laurie <dirk.laurie@gmail.com> wrote:
> If just '==' is good enough, then a metamethod does it.
>
> If you need to use tuples as an index into a table, raw equality
> is needed. This can be done in many ways, such as memoizing,
> serializing etc, but all the approaches work on the metatable of
> the table, not of the tuple.
I was musing in a vague way about the "duality" between functions
f(...), with their fixed space but variable time cost, and tables
f[...] with their fixed time but variable space cost. The symmetry
is broken by the fact that tables do not have multi-indices, but
can be restored by the use of tuples. But tuples are not fully
privileged citizens in Lua (and I am not arguing that they should be),
unlike Haskell. The use of metatables for tables can provide a sort of
dual to the process of memoization, which can be thought of as letting
the programmer trade between space costs and time costs.
--
Gavin Wraith (gavin@wra1th.plus.com)
Home page: http://www.wra1th.plus.com/