> You seem to want to use '>>' to convert functions from
> T to Union(T, "failed") into functions from
> Union(T, "failed") to Union(T, "failed").

No, it doesn't create new functions, just "combine" them.

Say we want to apply a series of functions, first f, then g:

x:INT, f:INT->INT, g:INT->INT
The result of f(x) can go directly into g:  g(f(x))

x:List INT (or Maybe INT), f:INT->INT, g:INT->INT
We can use map:      map(g, (map(f, x))

x:Maybe INT, f:INT->Maybe INT, g:INT->Maybe INT
Now we can't use map, or we have to manually check
for failure at every call, or we can use >>:
x >> f >> g

> Actually Spad compiler need some explicit or
> implicit import to use a type.  Interpeter has a bunch
> of hardcoded rules, go beyond them and it can not
> fand Spad compiler knows that coercion in third line is legit,
because we excluded the other possibility in line 2.ind type.  So
there is good chance that you will have
> to explicitely import your packages/domains for all
> involved T-s.

I just checked, for the same type (A->Maybe A), there's
no problem.  But for more than 2 types: (A->Maybe B, B->Maybe C),
you have to explicitly import from MonadPackage in Spad,
and explicitly construct typed anonymous function wrapper
in interpreter.

> and Spad compiler knows that coercion in third line is legit,
> because we excluded the other possibility in line 2.
> ....  but then you loose static checking:

This is the advantage of Maybe: in your example, there's
no point doing such things, just return the Maybe type:

    ru := retractIfCan(x)@Maybe(T)

The following code that deals with ru should handle Maybe(T).
Say the following lines that handle ru is function "g" (the continuation).

In your example, it is:
    ru := retractIfCan(x)@Union(T, "failed")
    ru case "failed" => "failed"
    r := ru::T
    g : T->T2
    g(r)

In my example,
    ru := retractIfCan(x)@Maybe(T)
    g : T->T2
    map(g, ru)

If there's still a failure in g:
    ru := retractIfCan(x)@Maybe(T)
    g : T->Maybe T2
    ru >> g

-- 
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.

Reply via email to