Ralf Hemmecke wrote:
> 
> I don't like Union(SomeDomain, "failed") very much.
> 
> 1) Since Union actually requires domains as arguments, there must be 
> some special compiler code dealing with that.

Yes, there is special case code, but it is probably more general
than you think: each string is regarded as being a type having
itself as unique value.  If context requires String as a type,
then this unique type is silently coerced to String.  Consider:

(2) -> "ralf"::"ralf"

   (2)  ralf
                                                                   Type: ralf
(5) -> List("ralf")

   (5)  List(ralf)
                                                                   Type: Type
(8) -> "ralf" has Type

   (8)  true
                                                                Type: Boolean
(9) -> "ralf" has SetCategory
 
   >> System error:
   The index 4 is too large.

The last result shows that this "string as a type" mechanism is not
fully implemented.

ATM I am not sure what to do about this.  On one hand it allows nicer
syntax (without a lot of boilerplate to declare trivial types).
On the other hand it introduces irregularity into types system
and it is not clear how much effort is needed for complete implementation.

> In the long run, I would 
> like to either have a special domain Failed, which only has one element 
> called failed and which can be used as Union(D, Failed) or to have a 
> domain like Partial (see below).
> 
> 2) I've tried to write a Partial domain, but with some problems.
> 
> ---rhxBEGIN partial.spad
> )abbrev domain PARTIAL Partial
> Partial(V: Type): with
>      if V has CoercibleTo OutputForm then CoercibleTo OutputForm
>      inject: V -> %
>      retract: % -> V
>      failed: () -> %
>      failed?: % -> Boolean
>   == add
>      Rep := Record(val: V)
>      if V has CoercibleTo OutputForm then
>          coerce(x: %): OutputForm ==
>              failed? x => "failed"::Symbol::OutputForm
>           x.val :: OutputForm
>      inject(v: V): % == construct v
>      retract(x: %): V == x.val
>      failed: % == NIL$Lisp
>      failed?(x: %): Boolean == EQ(x, failed)$Lisp
> ---rhxEND partial.spad
> 
> (1) -> Integer has CoercibleTo OutputForm
> 
>     (1)  true
>                                                  Type: Boolean
> 
> (2) -> Partial Integer has CoercibleTo OutputForm
> 
>     (2)  false
>                                                  Type: Boolean
> 
> Any idea why I don't get true for (2)?
> 

As I wrote in proivate mail you currently need Type as part of
category expression.

> 3) I actually would like something like in Aldor, i.e. that I can specify
> 
>    failed: %
> 
> in the categorial part. But that doesn't work. Any chance that it can 
> work in some near future?
>

But what the above do.  Consider the following implementation:

     Rep := Integer

     n := 0

     failed == (n := n + 1; n)

Is it allowed by Aldor?  Related to this is question if runtime
interface is functional (this is each time you use 'failed' getter
function is called to fetch its value).

-- 
                              Waldek Hebisch
[email protected] 

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/fricas-devel?hl=en.

Reply via email to