On 04/02/2011 02:50 PM, Yrogirg wrote:
And what's wrong with this one:

)abbrev package MYEXP MyExp

MyExp(F: Ring): with
     myexp: (F, PositiveInteger) ->  F
  == add
     myexp(x, n) ==
         a : PositiveInteger ->  F
         a i == x
         a n

All types are given explicitly, the resulted function should be
myexp(x, n) = x for all n

Well, I am not 100% sure what happens here, but I guess the spad compiler isn't able to bring your declaration a : PositiveInteger -> F together with the following definition a i == x. And, actually, why should it?

You have not given a type for i, so maybe you mean a function

  a(i: String): F == x

Why should the compiler assume that in your definition a i == x the i stands for a PositiveInteger?

You probably know that Spad allows you to define something like (*), see below.

To make your code work, you would have to give the type of the argument.
But you can do without the signature declaration by giving explicit types to the argument and the result type.

---rhxBEGIN myexp.spad
)abbrev package MYEXP MyExp
MyExp(F: Ring): with
    myexp: (F, PositiveInteger) -> F
 == add
    myexp(x, n) ==
        a(i: PositiveInteger): F == x
        a n
---rhxEND myexp.spad

I seem to remember

http://groups.google.com/group/fricas-devel/msg/c6b9ac05fad9e74c?hl=en

that there was a problem with local function anyway.
According to Waldek, they should work in the compiler (and Waldek probably knows best), but you might want think of it if you run into troubles.

Ralf

(*)
=============================================================
)abbrev package MY My
My(F: Ring): with
    a: String -> F
    a: Integer -> F
 == add
    a(i: Integer):F == -i::F
    a(i: String): F == 1
=============================================================

(1) -> F := Fraction Integer

   (1)  Fraction(Integer)

Type: Type
(2) -> H := My F

   (2)  My(Fraction(Integer))

Type: Type
(3) -> a 3

   (3)  - 3
                                    Type: Integer
(4) -> a "x"

   (4)  1
                                    Type: PositiveInteger

BTW, don't get confused about the return types. The function a actually returns something of type Fraction(Integer), but the interpreter tries to turn this into a simpler type.

--
You received this message because you are subscribed to the Google Groups "FriCAS - 
computer algebra system" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/fricas-devel?hl=en.

Reply via email to