On 10/08/2017 07:40 PM, Bill Page wrote: > On 8 October 2017 at 03:47, Ralf Hemmecke <[email protected]> wrote: >> On 10/08/2017 05:55 AM, Bill Page wrote: >>> "Union(R,"failed")" on the other hand does seem to take about 80% >>> longer to unwrap a value. >> >> I'm not a compiler expert (and I don't actually like Union(X,"failed") >> so much, but we can have Monad in FriCAS without changing the language. > > Can you explain how we can define Monad in FriCAS without changing the > language?
Arrhhh. Sorry. I intended to write I'm not a compiler expert (and I don't actually like Union(X,"failed") so much), but we *cannot* have Monad in FriCAS without changing the language. >> We can have Maybe with a global failed(). > > But then Maybe would not be a Monad (at least in the since used in Haskell). Exactly. And that is why for this case I would be rather against the name "Maybe". I'd rather opt for "Partial" as in Aldor even though AldorLib implements Partial via Record and is thus more similar to Union(X,"failed") or "Maybe with GENSYM()" (in terms of behaviour). https://github.com/pippijn/aldor/blob/master/aldor/lib/aldor/src/base/sal_partial.as#L92 >> We can have Maybe with GENSYM(). > > Do you mean Maybe with a local instance GENSYM? Right. An implementation of Maybe where the failed@Maybe(Maybe(X)) is not (lisp) equal to failed@Maybe(X). Waldek suggested distinguishable failed values. So it is more like the Maybe as a type functor FX=1+X. That equation would not hold for "Maybe with global failed()". > I have just run a benchmark with oldk's optimizations that shows that > the performance of Union(X,"failed") is identical to Union(val:X, > failed:"failed") while the "Rep := List R" representation of Maybe(R) > where "failed" is represented by empty list (NIL) and non "failed" > values as a singleton list (cons), has performance the same or > slightly better (in the case of failed values) than Maybe with global > fGENSYM (at the cost of using about the same extra storage as the > Union representation, compared to no extra storage for Maybe with the > global or local GENSYM. A more logical representation (which does not rely on the underlying Lisp) would be similar to what Partial in Aldor has, see link above. Rep == Record(val:T); It doesn't suggest that there is ever more than one value. Therefore, I suggested Rep == Reference(X) in an earlier mail. Relying on lisp as the target language is not a good idea. I'd rather like to be independent of such implementation details. Ralf -- 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.
