[m-rev.] for review: Announce subtypes and coerce.
Peter Wang
novalazy at gmail.com
Tue Apr 6 11:09:22 AEST 2021
On Sun, 04 Apr 2021 16:36:10 +1000 Julien Fischer <jfischer at opturion.com> wrote:
>
> Hi Peter,
>
> On Thu, 1 Apr 2021, Peter Wang wrote:
>
> > NEWS:
> > As above.
> >
> > doc/reference_manual.texi:
> > Uncomment documentation for coerce.
> >
> > diff --git a/NEWS b/NEWS
> > index 058e00662..ead462b39 100644
> > --- a/NEWS
> > +++ b/NEWS
> > @@ -341,6 +341,9 @@ Changes to the Mercury standard library
> > Changes to the Mercury language
> > -------------------------------
> >
> > +* The type system now supports subtypes, which work in tandem with
> > + type conversion expressions ("coerce").
>
> I thinks this feature warrants a bit more of a description than one
> sentence. In particular, the NEWS file should definitely contain an
> example subtype.
How about:
diff --git a/NEWS b/NEWS
index ead462b39..7bd2a2582 100644
--- a/NEWS
+++ b/NEWS
@@ -342,7 +342,21 @@ Changes to the Mercury language
-------------------------------
* The type system now supports subtypes, which work in tandem with
- type conversion expressions ("coerce").
+ type conversion expressions ("coerce"). For example, the following
+ defines a subtype `real_color` of a discriminated union type `color`:
+
+ :- type color
+ ---> rgb(float, float, float)
+ ; cmyk(float, float, float, float)
+ ; named(string).
+
+ :- type real_color =< color
+ ---> rgb(float, float, float)
+ ; cmyk(float, float, float, float).
+
+ A term of type `real_color` can be converted to a term of type `color`
+ with `coerce(Term)`. A term of type `color` can be converted to a term of
+ type `real_color` if it has an appropriate inst.
* The compiler can implement tabling only when generating C code.
When compiling a predicate that has a `pragma memo` specified for it
Peter
More information about the reviews
mailing list