natefaubion/purescript-variant

Using singleton records instead of tuples

Closed this issue · 4 comments

This depends on having records lib in core.

What's the motivation for this? They should be exactly the same, except with Tuple you don't have to do low-level property testing to determine the tag of an object.

That's just an idea. This might have some advantages with records lib ready. Feel free to close this if you don't like it

I think the main problem is that we have to forget that it's a record, so a hypothetical purescript-record API isn't very helpful. If we have { foo: 42 } as the representation, and we coerce it to a Variant, there's no way to recover the record. It's representation would have to be Foreign. Say we are doing record dispatch. With the Tuple representation, I can immediately get the tag, and lookup the corresponding property. When using a singleton record, there would be know way to do that. We'd have to iterate over the Foreign keys and pull out the first one.

Makes sense