On Sat, 7 Aug 2021 at 17:06, Ralf Hemmecke <r...@hemmecke.org> wrote:
> Think about it. Suppose you want to write a function
>
>   coerce: Polynomial R -> Polynomial S
>
> In order for this coerce to work nicely, it should either live in
> Polynomial(R) or Polynomial(S). OK, that means it should live in the
> code of the Polynomial constructor. But wait, the definition goes
>
>   Polynomial(R: Ring): with ... == add ...
>
> Ooops. How would you specify the second type? You could do it this way:
>
>   Polynomial(R: Ring): with
>     ...
>     coerce: (S: Ring) -> % -> Polynomial S
>     ...
>  == add
>     ...
>     coerce(S: Ring): % -> Polynomial S == (x: %): Polynomial S +->
>         -- here you program the conversion into Polynomial S
>
> But look closer at that definition. You are about to define the domain
> "Polynomial". Inside of it you use the constructor "Polynomial(S)".
> That's a recursive definition. And the above coerce has a dependent
> type, i.e., its result type depends on the input. Pretty involve, hey?

Hmmm, this is all very interesting. A couple of questions:

1. On what level are recursive definitions a problem? I know, for
example, that in the C programming language it is possible to define a
struct with fields that contain pointers to the struct type itself.
Most other programming languages likewise support features like this.
Fricas itself has a linked list type: List. I should really look at
how List is implemented in the library when I get the chance.

2. This seems to tie in with my previous recent question about the
possibility of polymorphic functions. How hard would it be to
implement those? Superficially it seems like they could be implemented
as simple syntax sugar over parametric packages (each function
parameterized over type T gets its own (anonymous?) package with T as
constructor parameter).

3. I noticed that there's a category called CoercibleFrom (and one
called CoercibleTo, too). Could one of those categories be used to
solve this issue, maybe?
So it would go something like this (I don't know the appropriate
syntax, I'm just asking if this could be possible):
For any types A and B that Polynomial can be parameterized with, if
type A is in CoercibleFrom(B), define a function like so:

coerce: Polynomial(B) -> Polynomial(A)

coerce(b: Polynomial(B)): Polynomial(A) ==
        map(c +-> coerce(c)@A, b)$PolynomialFunctions2(B, A)


Thanks,
Neven

-- 
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 on the web visit 
https://groups.google.com/d/msgid/fricas-devel/CAL%2BbK4ORaXa9CT0VHrkM9GqNxC-rjy0zmamVFntvzPQ32rOOeQ%40mail.gmail.com.

Reply via email to