On Mon, Sep 18, 2017 at 1:24 PM, Ralf Hemmecke <r...@hemmecke.org> wrote: > On 09/18/2017 01:16 AM, oldk1331 wrote: >> In Maybe, we can have >> if R is NNI then >> Rep := Integer >> and use -1 to denote failure. And we can specialize for more types. > > Aha! Yes, that's probably a good compromise. In fact every domain that > uses a pointer to some data structure on the heap could use NIL to > represent failure. So there are only a few domains like Integer where > the Maybe domain would have to use an extra bit of storage. > > Ralf
Since data in Lisp is already tagged, we can always prevent unnecessary memory allocation, for Integer, we can use NIL to indicate failure, for List, we can use 0 to indicate failure. This way, we also solve the 'subtractIfCan' problem, no more computation twice, no more unwanted alloc. -- 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.