"failed" has Ring gives error

14 views
Skip to first unread message

Qian Yun

unread,
Apr 23, 2026, 9:26:02 AMApr 23
to fricas-devel
(1) -> "failed" has Type

(1) true
Type: Boolean
(2) -> "failed" has Ring

>> System error:
The value
#\e
is not of type
LIST

(2) -> 1 has Ring

1 is not a valid type.


As shown above, the singleton types can't do some
"has" operation.

- Qian

Ralf Hemmecke

unread,
Apr 23, 2026, 10:09:35 AMApr 23
to fricas...@googlegroups.com
Honestly, I don't like a type with the name "failed".
I would be happier, if we do it as in Aldor, i.e. create a type, like
Partial, with the respective exports.

https://github.com/aldorlang/aldor/blob/master/aldor/lib/aldor/src/base/sal_partial.as#L46

At least introducing Partial, could help to slowly fade out
Union(X,"failed") and eventually replace it by Partial(X).

That this will not happen soon, is clear, but "failed" as a Type looks
really bad to me, since it is too easily confused with a string.

Opinions?

Ralf

Qian Yun

unread,
Apr 25, 2026, 6:12:07 PMApr 25
to fricas...@googlegroups.com
+1 for this.

We had a very long discussion about this a few years ago.

One of the results from that discussion, about the advantage
of current Union("failed", xx) is that, there's compiler
support for "failed", so for the other branch, type coercion
is automated, (no need to manually coerce value to type xx).

But I think this is only a small advantage.

- Qian

On 4/23/26 10:09 PM, 'Ralf Hemmecke' via FriCAS - computer algebra

Waldek Hebisch

unread,
Apr 25, 2026, 7:43:43 PMApr 25
to fricas...@googlegroups.com
On Sun, Apr 26, 2026 at 06:12:03AM +0800, Qian Yun wrote:
> +1 for this.
>
> We had a very long discussion about this a few years ago.
>
> One of the results from that discussion, about the advantage
> of current Union("failed", xx) is that, there's compiler
> support for "failed", so for the other branch, type coercion
> is automated, (no need to manually coerce value to type xx).
>
> But I think this is only a small advantage.
>
> - Qian
>
> On 4/23/26 10:09 PM, 'Ralf Hemmecke' via FriCAS - computer algebra
> system wrote:
> > Honestly, I don't like a type with the name "failed".
> > I would be happier, if we do it as in Aldor, i.e. create a type, like
> > Partial, with the respective exports.
> >
> > https://github.com/aldorlang/aldor/blob/master/aldor/lib/aldor/src/base/
> > sal_partial.as#L46
> >
> > At least introducing Partial, could help to slowly fade out
> > Union(X,"failed") and eventually replace it by Partial(X).
> >
> > That this will not happen soon, is clear, but "failed" as a Type looks
> > really bad to me, since it is too easily confused with a string.

We have two general purpose machanisms, that is Union and
singleton types. Those two cover several situations. In
modular code I use something like:

Union(T, "reject", "failed")

where failed means bad reduction, which in turns means that
computation must be retried, "reject" means that no re-try
will succeed. Singleton types are used in situations where
we need argument, but its value does not matter, like

elt(a, "rest")

IMO, replacemnet of general purpose things by special cases
shuld happen only when there is significant gain from the
special case.

Concerning confusion, we have overloading and that IMO is
more confusing than "failed". Yet people cope quite well
with that.

--
Waldek Hebisch

Qian Yun

unread,
Apr 26, 2026, 12:26:56 AMApr 26
to fricas...@googlegroups.com
On 4/26/26 7:43 AM, Waldek Hebisch wrote:
>
> IMO, replacemnet of general purpose things by special cases
> shuld happen only when there is significant gain from the
> special case.

Not a significant gain, but Haskell's Maybe is a higher
abstraction, allows map and composition (>>=).

I don't have much experience with it, so I can't say
more about the advantages.

- Qian

Ralf Hemmecke

unread,
Apr 26, 2026, 3:40:43 PMApr 26
to fricas...@googlegroups.com
On 4/26/26 06:26, Qian Yun wrote:
> On 4/26/26 7:43 AM, Waldek Hebisch wrote:
>>
>> IMO, replacemnet of general purpose things by special cases
>> shuld happen only when there is significant gain from the
>> special case.

I like your conservativeness. I was not asking to remove
Union(X,"failed") immediately. Just asking to also have Partial.

> Not a significant gain, but Haskell's Maybe is a higher
> abstraction, allows map and composition (>>=).

I actually don't care about composition. That would only be a
nice-to-have. In fact, I not even like autocoercion in the compiler for
the Union(X,"failed") type. Would that coercion also work reliably for
"reject" instead of "failed", or ist "failed" as builtin SPAD type?

Why is this "failed" as a type not called Failed, with its only element
"failed", or rather failed (without the quotes)?

Concerning X2==Union(X, "failed", "reject")... Admittedly, introducing
Partial would not help with modelling a type that is a union of 3 types.
On the other hand, X2 can also be modelled by a union of X with a
two-element type.

I will not fight here for anything. It's not very high priority for me.

>> Concerning confusion, we have overloading and that IMO is
>> more confusing than "failed". Yet people cope quite well
>> with that.

Not quite my point. It is just that "failed" (as a type name) does not
fit the convention that types start with a capital letter. And it rather
looks like a string. (It is actually a similar thing like writing

"+": (%, %) -> %

instead of just

+: (%, %) -> %

Things that aren't strings should not be denoted like strings.
It's more aboutl aesthetics than not being able to interpret that stuff.

Ralf
Reply all
Reply to author
Forward
0 new messages