I think this is an interpreter bug, that it automatically coerces a Union
type Union(xx, "yy") to its subtype "yy". (Interpreter can handle types like
Union(Integer,String) )

You can use the following workaround:

    remove(x+->x case "failed", l)

But the result type is still List(Union(IntegerMod(10),"failed")).

Another way is to use filter when creating the list:

    T ==> IntegerMod 10
    [y::T for i in 0..9 | (y := recip(i::T)) case T]

BTW, I think the "Maybe" approach doesn't have this problem.

It can enable functional ways to solve this problem, for example
in Haskell, it only uses ">>= maybeToList":

Prelude> import Data.Maybe
Prelude Data.Maybe> let l = [Nothing, Just 1, Nothing, Just 7]
l :: Num a => [Maybe a]
Prelude Data.Maybe> l >>= maybeToList
[1,7]
it :: Num b => [b]


On Sat, May 26, 2018 at 7:42 PM, Prof. Dr. Johannes Grabmeier privat
<[email protected]> wrote:
> What is going wrong here:
>
> (1) -> li := [2,4,3,2,5,2,7,2,2,7]
>
>    (1)  [2, 4, 3, 2, 5, 2, 7, 2, 2, 7]
>
> Type: List(PositiveInteger)
> (2) -> remove(2,li)
>
>    (2)  [4, 3, 5, 7, 7]
>
> Type: List(PositiveInteger)
> (3) -> li10 := [recip(i::IntegerMod 10) for i in 0..9]
>
>    (3)  ["failed", 1, "failed", 7, "failed", "failed", "failed", 3,
> "failed", 9]
>                                                           Type:
> List(Union(IntegerMod(10),"failed"))
> (4) -> f : Union(IntegerMod(10),"failed") := "failed"
>
>    (4)  "failed"
>
> Type: Union("failed",...)
> (5) -> remove(f, li10)
>    There are 3 exposed and 1 unexposed library operations named remove
> having 2 argument(s)
>       but none was determined to be applicable. Use HyperDoc Browse, or
> issue
>                                          )display op remove
>       to learn more about the available operations. Perhaps
> package-calling the operation or
>       using coercions on the arguments will allow you to apply the
> operation.
>
>    Cannot find a definition or applicable library operation named remove
> with argument type(s)
>
>                                                failed
>                                 List(Union(IntegerMod(10),"failed"))
>
>       Perhaps you should use "@" to indicate the required return type,
> or "$" to specify which
>       version of the function you need
>
> --
> Mit freundlichen Grüßen
>
> Johannes Grabmeier
>
> Prof. Dr. Johannes Grabmeier
> Köckstraße 1, D-94469 Deggendorf
> Tel. +49-(0)-991-2979584, Tel. +49-(0)-151-681-70756
> Tel. +49-(0)-991-3615-141 (d),  Fax: +49-(0)-32224-192688
>
> --
> 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.

Reply via email to