fredag 3. mars 2017 19.42.52 UTC+1 skrev Rupert Smith følgende:
>
> Or could be mapped to something that can be described with a json-schema
> enum for each 'tag' in the union type:
>
> { _type: "Walk" }
>
> { _type: "Ride"
> , fields : [ {numberOfDoors: 1} ]
> }
>
> { _type: "Fly"
> , fields: [ { maxSpeed: 100 } ]
> }
>
On Friday, March 3, 2017 at 8:38:07 PM UTC, Eirik Sletteberg wrote:
> That looks a bit clumsy to use from JS land though... if you want to read
> numberOfDoors you'll have to loop through all the fields to find the
> correct one? The format has to be both correct and easy to work with.
>
The array contains the constructor arguments for each tag in the union
type. So to read numberOfDoors, you get the first item from the array, then
get the numberOfDoors field from the json record. Its not a very good
example, since you cannot really see that I am not listing the fields of
the record type out in the array, but the arguments of the tag constructors.
If 'someRide' contains an instance of the Ride tag, then to get
'numberOfDoors' the expression would be:
someRide.fields[0].numberOfDoors
=======
>From the point of view of being able to describe the structure with
json-schema, the current encoding that Peter Damoc has referred to would
actually be better:
{ "ctor": "Tag", "_0": "first value", "_1":"second value", ... }
The reason being that in my encoding the list of constructor args contains
args of different types. So all I can really say in json-schema is that it
is an array, not what type the elements of the array are.
In the current encoding, I could have a json-schema that describes exactly
what the structure or _0 is and _1 and so on.
=======
So yeah, what is really to prevent this current encoding being pushed
through ports?
--
You received this message because you are subscribed to the Google Groups "Elm
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.