Re: Idle musings on doing E over again
Thomas Leonard <tal-v5nx5w6akNyLE8xUarVfuPLx9OUvmyODWmv/[email protected]> Mon, 15 Oct 2012 11:46:19 +0100
| Newsgroups | gmane.comp.lang.e.general |
|---|---|
| Message-ID | <[email protected]> |
On 2012-10-13 15:49, Kevin Reid wrote:
> On Oct 12, 2012, at 2:16, Thomas Leonard wrote:
>> It's generally useful to support backwards-compatible updates. e.g. a future version of the service might declare:
>>
>> struct User {
>> name :String,
>> email :Email,
>> phone :nullOk[Phone] := null,
>> }
>>
>> If a user registers with extra details that an old version doesn't need then it can just store them in the database anyway. No need to reject the message.
>
> What comes to mind now is that there could be a pattern for extensible records: add a single field for extra data,
> unknowns :Map[String, Data],
> such that the User (version 1) guard coerces (using placeholder syntax!)
> struct [
> name = "Alice",
> email = <mailto:[email protected]>,
> phone = <tel:+5555555>,
> ]
> into the typed struct
> User [
> name = "Alice",
> email = <mailto:[email protected]>,
> unknowns = ["phone" => <tel:+5555555>],
> ]
> . That is, all unknown fields are stuffed into a plain Map (hm, or perhaps an untyped record). This keeps the record semantics simple for applications that don't want extensibility, and makes it easy to process extra fields if wanted. What do you think?
Is the type of a record visible to E?
If not, records are basically just Maps, and the guards just verify the
structure. Not running the guards repeatedly is simply an optimisation.
However, that's a bit odd, because the guards will only be called when
passing record between vats, not within a vat, and this difference will be
visible. It's not necessarily a problem, but a bit un-E-like. Unless record
guards are more limited than regular guards (e.g. pure functions which
verify but do not coerce).
If the type of a record is visible to E (e.g. a User behaves differently to
a NewUser), then sending a record to a remote vat must also send its type
information. Again, that will be tricky with user-specified guards, since
they can't travel in general.
How are you planning to implement them?
--
Dr Thomas Leonard
IT Innovation Centre
Gamma House, Enterprise Road,
Southampton SO16 7NS, UK
tel: +44 23 8059 8866
mailto:tal-v5nx5w6akNyLE8xUarVfuPLx9OUvmyODWmv/[email protected]
http://www.it-innovation.soton.ac.uk/