On 10/09/2017 02:39 AM, oldk1331 wrote:
> Let "Partial" stands for the global GENSYM() solution and "Maybe"
> stands for the "Rep := List R" solution.
> Then we still need to pick a default: what should 'subtractIfCan' return?
In fact, I would choose the one that works faster and has minimal memory
usage. But actually, I tend to want a "canSubtract?" function.
As you mentioned earlier "canSubtract?" might in some cases lead to
recomputation whereas "subtractIfCan" might allocate memory that is not
needed if the computation fails. So what would be the best choice here?
Probably, to provide both? I think a test function is anyway a good
idea. There might be situation where it is only necessary to check if
subtraction is possible, but the actual value is not needed. (Of course,
I do not only speak for subtractIfCan, but also for similar cases.)
> We can't have both signatures because that will complicate type inference.
> I propose to use "Maybe" as default and to use "Partial" in performance
> critical code.
I can agree to that.
> Aldor uses "nil pretend %" for the "failed" value, I guess you don't like
> the 'pretend'.
OK, Bill and you got me with the "not so logical choice". But ...
my understanding is that the memory footprint for List and Record is a
bit different.
List(X): NIL or a pointer to a record r
where r holds a value of type X and a NIL pointer
Record(x: X): NIL or a pointer to a value of type X
So the List version stores an unnecessary NIL pointer together with a
heap allocation for a Record(x: X, next: Pointer).
This is the actual reason why Record(x: X) seems better to me. And I
don't care about the "pretend" in this case, because I consider such a
"Partial" domain as a very low-level domain that would have to be
changed with the runtime support of the language.
Ralf
PS: Oh, only now I've seen your new thread "Maybe preview 2".
--
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.