Here are initial reactions. I like the concept but I do not like the exported function names using '...wrap...'. Although 'wrap' is descriptive of how Maybe is implemented, it is not helpful when it comes to understanding how to use it and reading source code.
> Maybe(R : Type) : Exports == Implementation where
> Exports == with
> failed : () -> %
> ++ failed() returns a value that indicates failure.
> failed? : % -> Boolean
> ++ failed?(x) checks if x is failed().
> wrap : R -> %
> ++ wrap(x) returns x wrapped in type Maybe(R).
> wrap? : % -> Boolean
> ++ wrap?(x) checks if x is of type R.
> unwrap : % -> R
> ++ unwrap(x) returns x as type R, gives an error if x is failed().
> unwrap! : % -> R
> ++ unwrap!(x) returns x as type R without checking, use with caution.
> unwrapOr : (%, R) -> R
> ++ unwrapOr(x, default) returns x as type R if it's not failed(),
> ++ otherwise returns default.
I prefer either something more "FriCASic".
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.
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.
(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
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.
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.
I attach a copy of my test version using a convenient but less
efficient representation.
Bill Page.
On 22 September 2017 at 07:49, oldk1331 <[email protected]> wrote:
> The updated Maybe domain using GENSYM:
>
> https://github.com/oldk1332/fricas/commit/dfea59ff10cec3007486f3ed205a9be1dea1a48b
>
> --
> 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.
--
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.
maybe.spad
Description: Binary data
