[Ur] Ur record types as sets of fields

Adam Chlipala adamc at csail.mit.edu
Fri Nov 3 08:29:10 EDT 2017


On 11/03/2017 08:22 AM, Anthony Clayden wrote:
>> On 4/11/2017, at 12:57 AM, Adam Chlipala <adamc at csail.mit.edu> wrote:
>>
>>> On 11/02/2017 09:51 PM, Anthony Clayden wrote:
>>> I'm curious what the full signature would look like. Here's my guess:
>>>
>>>      fun natJoin [ t1' :: {Type} ] [ t1_2 :: {Type} ] [ t2' :: {Type} ]
>>>                      [ t1' ~ t1_2 ] [ t1' ~ t2' ] [ t1_2 ~ t2' ]
>>>                      ( t1 : $( t1' ++ t1_2 ) )  ( t2 : $( t1_2 ++ t2' ) )
>>>                      = ??
>> One possibility is:
>>      t1 ++ (t2 --- t1_2)
> IIUC that's merely projecting away the t1_2 attributes from t2; then cross-multiplying with t1(?) What it needs is matching records type t1 with records type t2 that have the same values in the fields in common -- i.e. in their t1_2 fields. That's typically implemented as a record-by-record fold over one argument.
>
>> It's not clear to me what result type you expect, though.
>>
> Oh, that was in the earlier message: [ t1' ++ t1_2 ++ t2' ]

Oh, you meant the brackets to signify a list, Haskell-style?  But then 
the argument types don't make sense, as they only give single records, 
not lists or sets of records.

In real Ur/Web code, such a function would be a bad smell, since SQL 
queries do all this natively.



More information about the Ur mailing list