|
From: Tyson D. <ty...@ty...> - 2001-01-29 23:56:32
|
On 25-Jan-2001, Ina Cheng <in...@st...> 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>
I don't think you need the trailing </element>
What is "mercury:int" and "mercury:string"? These would be some sort of
equivalences to the primitive types in XML Schemas? You should define
the equivalences in Schema too.
Where do the names stocknum and comment come from in Mercury?
My guess is either they are the names of the parameters to a web method,
or they are fields name of some more complicated type.
Since parameters to Mercury predicates don't really have names,
you might want to call them:
<element name="arg1" type="mercury:int"/>
<element name="arg2" type="mercury:string"/>
if they are top level parameters.
Also, fields of Mercury terms don't necessarily have field names (and
I'm not sure that the Mercury runtime type information system can tell
you what the field names are anyway). So you might have to always
number them for the moment.
> 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>
This looks OK, although I suspect the tns: namespace will need to be
changed.
> 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>
Yep. This is good.
>
>
>
> 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>
This is called an undiscriminated union. Mercury doesn't support this.
:- type myUnion
---> int
^^^
; float.
^^^^^
What you are actually defining here is the constructors int and float.
As Pete said in his email, you could just as easily have written `red'
and `green' rather than `int' and `float'.
We only support discriminated unions, so you can have
:- type myUnion
---> i(int)
^ ***
; f(float).
^ *****
The ^^^ marks the constructors, the *** marks the types of the arguments.
You could use `int' and `float' instead of `i' and `f', it doesn't make
any difference (but it looks a bit confusing here).
> Mercury union (members are complex types)
> -----------------------------------------
> Eg:
> :- type book_info
> ---> author
> ; publisher.
The place where you have written `author' and `publisher' is where the
constructor goes -- so this is just an enumeration again.
It should be
:- type book_info
---> book_info(author, publisher).
^^^^^^^^^ ****** *********
or
:- type book_info
---> author_info(author)
^^^^^^^^^^^ ******
; publisher_info(publisher).
^^^^^^^^^^^^^^ *********
Which you choose depends on the program you are writing, and what the
data is supposed to represent (a book? some piece of information about
a book?).
>
> Mercury list
> ------------
>
> :- type list(T)
> ---> []
> ; [T|list(T)].
This is right. You will see that `[]' and `[ ... | ... ]' are the
constructors (pronounced `nil/0' and `cons/2'). The fields of cons
are allowed to have any type in them (e.g. T or 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.
This sounds right.
--
Tyson Dowd #
# Surreal humour isn't everyone's cup of fur.
tr...@cs... #
http://www.cs.mu.oz.au/~trd #
|