Thomas Leonard | 6 Oct 2011 12:35
Picon
Favicon
Gravatar

Interfaces / data types in E

We've got quite a few methods that take or return maps. e.g.

to purchase(customerDetails :Map[String,any]) {
   ... customerDetails["name"] ...
   ...
   if (problem) {
     notify(customerDetails["email"])
   }
   ...
}

The problem is that it's not obvious from the method signature what keys 
need to be present. Often someone fails to include a mapping, and the 
system only fails later in some case where it needed that value.

What I think I'd like to do is something like:

def CustomerDetails := makeNamedTuple([
	"name" => String,
	"email" => String,
])

...

to purchase(customerDetails :CustomerDetails]) {
   ... customerDetails["name"] ...
}

So that:

(Continue reading)

Kevin Reid | 6 Oct 2011 12:50
Favicon
Gravatar

Re: Interfaces / data types in E

On Oct 6, 2011, at 6:35, Thomas Leonard wrote:

> We've got quite a few methods that take or return maps. e.g.
> 
> to purchase(customerDetails :Map[String,any]) {
>   ... customerDetails["name"] ...
>   ...
>   if (problem) {
>     notify(customerDetails["email"])
>   }
>   ...
> }

When you say "We" do you mean the E project or one of yours?

> The problem is that it's not obvious from the method signature what keys 
> need to be present. Often someone fails to include a mapping, and the 
> system only fails later in some case where it needed that value.
> 
> What I think I'd like to do is something like:
> 
> def CustomerDetails := makeNamedTuple([
> 	"name" => String,
> 	"email" => String,
> ])
> 
> ...
> 
> to purchase(customerDetails :CustomerDetails]) {
>   ... customerDetails["name"] ...
(Continue reading)

Thomas Leonard | 6 Oct 2011 17:27
Picon
Favicon
Gravatar

Re: Interfaces / data types in E

On 2011-10-06 11:50, Kevin Reid wrote:
> On Oct 6, 2011, at 6:35, Thomas Leonard wrote:
>
>> We've got quite a few methods that take or return maps. e.g.
>>
>> to purchase(customerDetails :Map[String,any]) { ...
>> customerDetails["name"] ... ... if (problem) {
>> notify(customerDetails["email"]) } ... }
>
> When you say "We" do you mean the E project or one of yours?

One of mine.

>> The problem is that it's not obvious from the method signature what
>> keys need to be present. Often someone fails to include a mapping,
>> and the system only fails later in some case where it needed that
>> value.
>>
>> What I think I'd like to do is something like:
>>
>> def CustomerDetails := makeNamedTuple([ "name" =>  String, "email"
>> =>  String, ])
>>
>> ...
>>
>> to purchase(customerDetails :CustomerDetails]) { ...
>> customerDetails["name"] ... }
>
> I think this is a fine guard to have. For consistency with other
> parameterized guards, it should be written NamedTuple[[...]].
(Continue reading)


Gmane