On 11/04/2015 11:05 AM, Martin Baker wrote:
> In some ways it would be good to go beyond this and implement 'multiple
> dispatch' AKA 'polymorphic method invocation'. Or is that what you meant?

FriCAS has this since long. The compiler chooses a function by looking
not only at it's name but also at the input types and additionally at
the output type.

The problem here is the speciality of NonNegativeInteger vs. Integer.

Look here:
https://github.com/hemmecke/fricas/blob/master-hemmecke/src/algebra//integer.spad#L227

We basically have

  NonNegativeInteger: ... == SubDomain(Integer, #1 >= 0) add ...

and to my understanding this (and probably some compiler internals)
create the problem. I bet in general the overloading works as expected.

> That is: function calls are not bound, at compile time, based on the
> static types of arguments but are bound depending on the actual type
> argument that is passed at runtime.

Wrong. The function selection is neither done at compile time nor at
runtime. (Well it's "instatiation time", which is actually runtime.)

When I want to call a function foo(1/3) then this is probably taken from
Foo(Fraction Integer) while foo(5) will most probably be taken from
Foo(Integer). As you can see, there are two different domains/packages
Foo(Fraction Integer) vs. Foo(Integer) involved. The selection of the
function is done when the respective domain/package is instantiated.
Statically, it is always clear what the type (input/output) of a
function is in a certain context. There is actually no choice except
when you use Foo in the middle of another package Bar so that you'd have

Bar(R: Ring): ... == add

   x: ... == foo(r)$Foo(R)

At compile time, it's unclear what R is, but whenever Bar is used
explicitly, R must be an explicit domain, so Foo(R) can be resolved,
which in turn tells exactly what kind of foo is actually meant.

> This allows a more Haskell-like style of programming.

This says what in this context?

If in FriCAS you want an identity function that works for all types you
write

ID(T: Type): with
    id: T -> T
  == add
    id(t: T): T == t

Probably a bit longer than in Haskell, but doable.

Ralf

-- 
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 http://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to