On Fri, Jun 29, 2018 at 10:10 AM, Riccardo GUIDA
<[email protected]> wrote:
>
> Thanks for your clarifications Bill.
>

Thank you for asking the question.

>
> Just to say that my original question to Ralf was a much more low
> level quest for clarifications in the user guide:
>

OK. I think I understand your motivation and Ralf's concerns about clarity.

Let me try to annotate the quoted section with my interpretation:

> 1) A user reads:
>
> section 5.3 pag 149
> "An if-then-else expression always returns a value.

I think this is clear.

> If the else clause is missing then the entire expression
> returns the unique value of Void.

I agree that this sentence is either confusing or wrong. I would
suggest the following:

If the else clause is missing but the if condition is false then the
value of the if-then expression is the unique value of Void.

> If both clauses are present, the type of the value returned by if is obtained
> by resolving the types of the values of the two clauses. See Section 2.10
> on page 109 for more information." (Check also the boxed text above this
> statement.)
>

I suppose that the key issue is what might be meant by "resolving the
types". My interpretation is that that although both an if-then-else
expression and an if-then expression "always return a value", the
actual type is indeterminate and depends on knowing the types of both
clauses, i.e. the type of the then-part and the type of the (possibly
missing) else-part. But in the appropriate context the compiler (and
in principle the interpreter) are able to determine an appropriate for
the result.

> 2) The user does not really understand the statement and, if he is
> motivated, tries to experiment:
>
> (1) -> if 1>2 then 1   -- here he expects Void
>                                                                    Type:
> Void

OK.

> (2) -> if 2>1 then 1  -- here he expects Void but gets PositiveInteger
>
>    (2)  1
>                                         Type: PositiveInteger


I can see that a naive interpretation of the statement in the guide
might lead to this expectation. But given a clear understanding of the
Void domain, it should be obvious that such a result could not be
useful.

> (3) -> if 2>1 then 1 else [1,2,3] -- here he expects common supertype, but
> which one?
>
>    (3)  1
>                                         Type: PositiveInteger


So, to this user "resolving the type" seems to imply the existence of
a supertype. In fact such a supertype does exist in FriCAS (Union) and
given that the statement in the guide is not so clear this is
certainly a reasonable expectation but I do not think that it is
actually implied.

> (4) -> if 1>2 then 1 else [1,2,3] --  here he expects common supertype,
> which  one?
>
>    (4)  [1, 2, 3]
>                                                   Type:
> List(PositiveInteger)
>

If we provide a bit more type information then the users expectations
can be met.

(1) -> A:Union(PositiveInteger, List PositiveInteger) := if 2>1 then 1
else [1,2,3]

   (1)  1
                                             Type: Union(PositiveInteger,...)
(2) -> A:Union(PositiveInteger, List PositiveInteger) := if 1>2 then 1
else [1,2,3]

   (2)  [1, 2, 3]
                                       Type: Union(List(PositiveInteger),...)


> 3) The user is puzzled because
>
> * in (2) below he gets Type: Positive Integer not Type: Void
> * in (3) and (4) below he sees 2 different types and not a "common
> supertype"
>

Yes I see how this is possible.

>
> From your explanations now I understand that there are a lot of
> hidden coercion in the game and that what is said in the user
> guide does not contradict the experiments. But I feel it would be
> helpful to have some clarifying information in the user guide not
> after page 149. Writing "the unique value of Void" is not of help
> because what is not evident is the fact that "every value can be
> coerced to Void". I realize now that this is said at pag 763,
> sec 9.87 (in my version of FricasUG), but at least a footnote in
> page 149 would have helped.
>

I think an important though somewhat less technical addition to the
user guide concerning the meaning and use of the Void and Exit domains
would indeed be quite useful.

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to