Re: [fricas-devel] [PATCH] Void is the unit type, fix doc and cleanup (use 0 as representation)

2018-06-28 Thread Bill Page
On Wed, Jun 13, 2018 at 9:22 PM, oldk1331  wrote:
>> However I am uncertain about your proposed changes to Void. Why do you
>> prefer a value of 0 instead of the symbol "()"?  Note of course that
>> this is a Lisp symbol and not Lisp NIL. Although the value can be
>> anything, as the empty tuple, I think () is more intuitive than 0.  A
>> value of 0 might be a bit confusing since the unit *type* is usually
>> denoted by 1, not 0. I see no harm in letting the Rep for Void be
>> String. In fact why not just define
>>
>>   void() == "()"
>
> The underlying value of Void is not important, because the type Void
> can only have one possible value.  I don't want to use string because of
> possible memory waste.
>

Does storing 0 take less space than a pointer to a string?

>> Is the Lisp function call voidValue really important for some reason
>> like in-line optimization?
>
> 'voidValue' is used a few places in the compiler.
>

OK. Maybe a global constant would be better?

>> Also, why did you make the following changes in Exit?
>>
>> -coerce(n:%) == error "Cannot use an Exit value."
>> -n1 = n2 == error "Cannot use an Exit value."
>
> Because Exit is the bottom type, no variable can have an Exit value,
> therefore, it can't be printed or compared. When encountering Exit
> type, the function aborts.
>

OK. A domain with no value is a categorical necessity (e.g. initial
object). You are right of course that the coding is non-functional
though perhaps it serves as a kind of documentation.

>> From a formal point of view I am not certain at all about None. Since
>> FriCAS is a statically typed language I think it would be nice if None
>> could be eliminated from the library. FriCAS already has the type Any
>> which implements a type-correct version of "duck typing" and plays the
>> role of a universal type.
>
> None as the top type is very necessary.  The difference between Any and None
> is that Any contains the value and type, None just contains the value.

You should not think of FriCAS domains as "containers". A variable may
"contain" or a function may "return" something of a given type but as
types domains do not contain values.

> None is widely used and can't be replaced.  Although I think "None" is a 
> terrible name.
>

I disagree. None is both unnecessary and harmful, leading to many
potentially unsafe uses of 'pretend'

It is true that 'None' is currently used in the following 22 spad
files in FriCAS:

  algfunc any combfunc exposed expr files fortout fspace jet kl
laplace liouv mkfunc omcat omdev op opalg openmath rdeefx rec table
xhash

with 'op' and domains that use properties being the worst offenders.

As an experiment I re-coded None as Any in the case of properties in
the following branch

  https://github.com/billpage/fricas/tree/NotNone

There are 118 fewer uses of 'pretend'.

Now only the following uses of None remain:

  any files fortout mkfunc omcat omdev openmath tablexhash

These cases can also be easily eliminated. As a result of this
re-coding the compiler was able to detect two cases of unsafe but
benign type errors (fixed in separate commits).

Timing of 'src/input/make' shows that no significant performance
penalty is incurred for safer coding.

-- 
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 fricas-devel+unsubscr...@googlegroups.com.
To post to this group, send email to fricas-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [fricas-devel] [PATCH] Void is the unit type, fix doc and cleanup (use 0 as representation)

2018-06-13 Thread oldk1331
> However I am uncertain about your proposed changes to Void. Why do you
> prefer a value of 0 instead of the symbol "()"?  Note of course that
> this is a Lisp symbol and not Lisp NIL. Although the value can be
> anything, as the empty tuple, I think () is more intuitive than 0.  A
> value of 0 might be a bit confusing since the unit *type* is usually
> denoted by 1, not 0. I see no harm in letting the Rep for Void be
> String. In fact why not just define
>
>   void() == "()"

The underlying value of Void is not important, because the type Void
can only have one possible value.  I don't want to use string because of
possible memory waste.

> Is the Lisp function call voidValue really important for some reason
> like in-line optimization?

'voidValue' is used a few places in the compiler.

> Also, why did you make the following changes in Exit?
>
> -coerce(n:%) == error "Cannot use an Exit value."
> -n1 = n2 == error "Cannot use an Exit value."

Because Exit is the bottom type, no variable can have an Exit value,
therefore, it can't be printed or compared. When encountering Exit
type, the function aborts.

> From a formal point of view I am not certain at all about None. Since
> FriCAS is a statically typed language I think it would be nice if None
> could be eliminated from the library. FriCAS already has the type Any
> which implements a type-correct version of "duck typing" and plays the
> role of a universal type.

None as the top type is very necessary.  The difference between Any and None
is that Any contains the value and type, None just contains the value. None is
widely used and can't be replaced.  Although I think "None" is a terrible name.

-- 
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 fricas-devel+unsubscr...@googlegroups.com.
To post to this group, send email to fricas-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [fricas-devel] [PATCH] Void is the unit type, fix doc and cleanup (use 0 as representation)

2018-06-13 Thread Bill Page
On Tue, Jun 12, 2018 at 9:37 AM, oldk1331  wrote:
> Clearly domain "Void" is the unit type:
> https://en.wikipedia.org/wiki/Unit_type
>
> So I'm clearing this up.
>

I think that fixes and better documentation of the Void, Exit, and
None domains are quite welcome but still warrant some discussion. From
a formal linguistic or categorical point of view Void (terminal
object) and Exit (initial object) are more important than they look.
As a category, FriCAS domains should form at least a Cartesian
category (although I think an even better model might be a topos).

However I am uncertain about your proposed changes to Void. Why do you
prefer a value of 0 instead of the symbol "()"?  Note of course that
this is a Lisp symbol and not Lisp NIL. Although the value can be
anything, as the empty tuple, I think () is more intuitive than 0.  A
value of 0 might be a bit confusing since the unit *type* is usually
denoted by 1, not 0. I see no harm in letting the Rep for Void be
String. In fact why not just define

  void() == "()"

Is the Lisp function call voidValue really important for some reason
like in-line optimization?

Also, why did you make the following changes in Exit?

-coerce(n:%) == error "Cannot use an Exit value."
-n1 = n2 == error "Cannot use an Exit value."

>From a formal point of view I am not certain at all about None. Since
FriCAS is a statically typed language I think it would be nice if None
could be eliminated from the library. FriCAS already has the type Any
which implements a type-correct version of "duck typing" and plays the
role of a universal type.

-- 
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 fricas-devel+unsubscr...@googlegroups.com.
To post to this group, send email to fricas-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.