On Mon, Mar 31, 2025 at 09:44:34PM +0200, 'Ralf Hemmecke' via FriCAS - computer 
algebra system wrote:
> Dear Waldek,
> 
> suppose I write a domain as follows:
> ========================
> Foo(R: Ring): Exports == Implementation where
>   Exports ==> Join(SetCategory, CoercibleFrom R) with
>     _*: (Integer, %) -> %
>     _*: (R, %) -> %
>   Implementation ==> add
>     ((z: Integer) * (x: %)): % == (z::R) * x
>     ((r: R) * (x: %)): % == ... -- actual implementation --
> ========================
> 
> I wonder whether I should actually do this.
> Does the compiler really produce proper code for Foo(Integer)?
> I fear that the compiler might think that implementing
> 
>   ((z: Integer) * (x: %)): %
> 
> it, it just needs to call coerce(z)@Integer and then generate code
> for (coerce(z)@Integer)*x) basically leading to an infinite loop.
> 
> Can the compiler handle that case or must I be more careful with that
> definition?

AFAICS your code should compile as intended.  There are similar                 
situations which may be problematic, but they involve Rep.                      
Namely, automatic coercions between % and Rep may sometimes give                
problems.  But normally Spad compiler will not introduce 'coerce' on            
its own.  Users may define 'autoCoerce', and if it is defined then              
compiler may automatically use it, but currently 'autoCoerce' is                
only defined for unions.

-- 
                              Waldek Hebisch

-- 
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 view this discussion visit 
https://groups.google.com/d/msgid/fricas-devel/Z-splYT4WKkbcrDW%40fricas.org.

Reply via email to