On Sun, Sep 24, 2017 at 9:50 AM, Bill Page <[email protected]> wrote:
> The meaning of 'empty' is more neutral than 'failed'. It is possible
> to use Maybe in situations where an empty value does not imply
> failure.
As the docstring said (which I copied from Haskell's documentation):
++ Using Maybe is a good way to deal with errors or exceptional cases without
++ resorting to drastic measures such as error.
So I think "failed" is better than "empty".
"empty" is also exported by aggregates, it might cause confusion in
x : Maybe List Integer := empty()
> Instead of wrap/unwrap 'Maybe' should satisfy the exports of
> RetractableTo(R). Then 'Maybe' can export retractIfCan to convert to
> the old representation (at least until 'RetractableTo' is modified to
> use 'Maybe'). 'coerce' and 'retract' play nicely with the interpreter,
> e.g.
I support to use Maybe explicitly than implicitly. I think Ralf will agree.
I chooes the name "unwrap" from Rust. I like the duality of "wrap" and
"UNwrap".
> (1) -> x:Maybe INT := 2
>
> (1) 2
> Type: Maybe(Integer)
> (2) -> y:Maybe INT := 3
>
> (2) 3
> Type: Maybe(Integer)
> (3) -> x+y
>
> (3) 5
> Type: PositiveInteger
In my case, it will be
x := wrap 2
y := wrap 3
map(+, x, y)
Your "x+y" can't handle when x or y is "failed".
> I don't think it is a good idea to export a function like 'unwrap!',
> plus the naming convention is non-standard, but it is probably OK as a
> local function.
I export that function for performance reason. I think the "!"
can give people attention. An example in codebase is
elt and qelt, but I don't think "qunwrap" is better than "unwrap!".
> Why not implement the 'maybe' operator?
>
> maybe : (R -> R, %, R) -> R
> ++ maybe(f,x,default) returns f(unwrap x) or default if failed?(x)
>
> then 'unwrapOr' could be just the two argument form of this function.
Why is your signature useful? I add 'unwrapOr' because Aldor
has that signature.
> I attach a copy of my test version using a convenient but less
> efficient representation.
>
> Bill Page.
--
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.