From: Peter R. <pet...@mi...> - 2001-01-25 09:07:40
|
Just one question, do we want to make the distinction between Mercury unions and enumerations and structures? An enumeration is a union where none of it functors have arguments, and a structure is a union with only one functor. Maybe it is easier to use the union data structure for all types except the builtin types. This would have the effect of making the representation longer, but possibly easier to parse as you would have to recognize less cases. Is having a short as representation as possible a design goal? If so then maybe we should complicate the representations. Also I am not sure if we should treat lists as a special case or not. BTW the following type doesn't represent an undiscriminated union, but a type with two functors (float and int, could easily be red and green) which have no arguments. :- type myunion ---> float ; int. Pete On Thu, Jan 25, 2001 at 03:23:01PM +1100, Ina Cheng wrote: > Hi Tyson, > > Can you please take a look whether the schemas look ok or not? > Thanks. > > Ina > <in...@st...> > > ========================================================================== > > Mercury builtin types > --------------------- > Eg: int, float, char, string > > data: > <stocknum>1</stocknum> > > schema: > <element name="stocknum" type="mercury:int"/> > <element name="comment" type="mercury:string"/> > </element> > > Mercury enumeration > ------------------- > Eg: > :- type fruit > ---> apple > ; orange > ; banana > ; pear. > > data: > <fruit>apple</fruit> > <fruit>banana</fruit> > > schema: > <element name="fruit" type="tns:fruit"/> % (global declarations) > > <simpleType name="fruit" base="mercury:string"> > <enumeration value="apple"/> > <enumeration value="orange"/> > <enumeration value="banana"/> > <enumeration value="pear"/> > </simpleType> > > or > > <element name="fruit" type="tns:fruit"/> > > <simpleType name="fruit"> > <restriction base="mercury:string"> > <enumeration value="apple"/> > <enumeration value="orange"/> > <enumeration value="banana"/> > <enumeration value="pear"/> > </restriction> > </simpleType> > > > Mercury structure > ----------------- > Eg: > :- type book > ---> book( > title :: string, > author :: author, > intro :: string > ). > > :- type author > ---> author( > surname :: string, > firstname :: string > ). > > data: > <book> > <title>Hello World</title> > <author> > <surname>Foo</surname> > <firstname>Bar</firstname> > </author> > <intro>Introduction</intro> > </book> > > schema: > <element name="book" type="tns:book"/> > <element name="author" base="tns:author"/> > > <complexType name="book"> > <sequence> > <element name="title" type="mercury:string"/> > <element name="author" type="tns:author"/> > <element name="intro" type="mercury:string"/> > </sequence> > </complexType> > > <complexType name="author"> > <sequence> > <element name"surname" type="mercury:string"/> > <element name"firstname" type="mercury:string"/> > </sequence> > </complexType> > > > > Mercury union (members are simple types) > ---------------------------------------- > Eg. > :- type myUnion > ---> int > ; float. > > data: > <myUnion>1<myUnion> > <myUnion>0.4<myUnion> > > schema: > <simpleType name="myUnion"> % without 'type=' means > <union memberTypes="int float"/> % anonymous type definitions > </simpleType> > > > Mercury union (members are complex types) > ----------------------------------------- > Eg: > :- type book_info > ---> author > ; publisher. > > data: > <book_info> > <author> > <surname>Foo</surname> > <firstname>Bar</firstname> > </author> > </book_info> > > <book_info> > <publisher> > <name>Oxford</name> > <date>120100</date> > </publisher> > </book_info> > > schema: > <element name="book_info" type="tns:book_info"/> > <element name="author" type="tns:author"/> > <element name="publisher" type="tns:publisher"/> > > <complexType name="book_info"> > <sequence> > <choice> > <element name="author" type="tns:author"/> > <element name="publisher" type="tns:publisher"/> > </choice> > </sequence> > </complexType> > > <complexType name="author"> > <sequence> > <element name"surname" type="mercury:string"/> > <element name"firstname" type="mercury:string"/> > </sequence> > </complexType> > > <complexType name="publisher"> > <sequence> > <element name"name" type="mercury:string"/> > <element name"date" type="mercury:int"/> > </sequence> > </complexType> > > > Mercury list > ------------ > > :- type list(T) > ---> [] > ; [T|list(T)]. > > schema: > <element name="list" type="tns:list"/> > <element name="nil" type="tns:nil"/> > <element name="cons" type="tns:cons"/> > > <complexType name="list"> > <sequence> > <choice> > <element name="nil" type="tns:nil"/> > <element name="cons" type="tns:cons"/> > </choice> > </sequence> > </complexType> > > <complexType name="nil> > <complexContent> > <restriction base="xsd:anyType"> > </restriction> > </complexContent> > </complexType> > > or <complexType name="nil"> shorthand for complex content > </complexType> that restricts anyType > > <complexType name="cons"> > <sequence> > <element name="head" type="xsd:anyType"> > <element name="tail" type="tns:list"/> > </sequence> > </complexType> > > data: > <list> > <nil/> > </list> > > <list> > <cons> > <head xsi:type="mercury:int">1</head> > <tail> > <list> > <cons> > <head xsi:type="mercury:int">2</head> > <nil/> > </cons> > </list> > </tail> > </cons> > <list> > > <nil/> Such an element has no content at all; its content model is > empty -> define a type that allows only elements in its content, > but we do not actually declare any elements and so the type's > content model is empty. > > > > > _______________________________________________ > Quicksilver-developers mailing list > Qui...@li... > http://lists.sourceforge.net/lists/listinfo/quicksilver-developers |