jiazhaoconga wrote:
> 
> > Hmmm... Acutally I really wouldn't expect this to work in the
> > interpreter given what I know about it's design, but it seems OK in
> > when using the compiler:
> >
> > (3) -> h := plus2(double2,double2)$PLSPKG(FLOAT,FLOAT)
> >
> >    (3)  theMap(PLSPKG;plus2;3M;1!0,655)
> >                                                        Type: (Float -> 
> > Float)
> > (4) -> h 3.5
> >
> >    (4)  14.0
> >                                                                   Type: 
> > Float
> > (5) ->
> 
> Yeah, but I don't want to specify the '$PLSPKG(FLOAT,FLOAT)' by hand, I want
> Fricas to do type inference for me, to be exact, I want 'h :=
> plus2(double2,double2)'
> to act like as if the following Spad code have been added into the system:
> 
> AnonymousPackage(A:AbelianSemiGroup) : Exports == Impl where
>   Exports == with
>     h : A->A
>   Impl == add
>     h x == double2 x+ double2 x
> 
> So that I can do 'h := plus2(double2,double2);h 4; h 3.5' without
> specify any type.

h := plus2(double2,double2);h 4; h 3.5

in current FriCAS has typing problem: assignment produces value of
definite type.  So the only way to satify this is to have
some type which can be both applied to integer argumements and
to float arguments.  This is doable, but different from what
you think.  Basically you need some "universal" type U.  Then
you need to define 

elt : (U, U) -> U
elt : (U, U, U) -> U

and so on up to some maximal arity.  Additinally you need
coercions from concrete types (like integer) to the universal
type.

The way to do this is to have type schemes with free parameters
(equivalently have "forall" types).  Interpreter currently
supports limited form of type schemes called "modes".  But
a mode can have only one free parameter and modes can not
be used in some contexts, which unfortunately excludes
use of modes in higher order functions.  This is not
fundamental restriction, but requires better typechecker
than what we have now.

Concerning use of generic functions defined in Spad
files: in Spad you need to specify types in terms of
parameters.  Interpreter sometimes can infer parameters,
but in general you need to give them explicitely.


-- 
                              Waldek Hebisch
[email protected] 

-- 
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