[plt-scheme] Typed scheme: Cannot apply expression of type Procedure, since it is not a function type
You're getting up even earlier than me on a Saturday :-;
>
> type Fun = Plus Number Number -> Number | Minus Number Number ->
> Number | String-Append String String -> String | ...
I just wonder how I get at the "procedure code" (scheme function) in this case? Wouldn't I still have the problem of extracting the code and making it look as something "applicable"/"executable" to TR?
In fact I have already something for arithmetic and boolean Operators, where I use a helper function for this:
(define-datatype Arith-Op
(Plus #:constant _+)
(Min #:constant _-)
(Tim #:constant _*)
(Div #:constant _/))
(define-predicate Arith-Op? Arith-Op)
(: get-arith-function (Arith-Op -> (Value Value -> Value)))
(define get-arith-function
(lambda (op)
(cond ((eq? op _+) add)
((eq? op _-) sub)
((eq? op _*) mul)
((eq? op _/) div)
(else (error "get-arith-function: Operator not known: " op)))))
(define-type Operator (U Arith-Op Bool-Op))
(: get-op-function (Operator -> (U (Value Value -> Value)(Value Value -> Boolean))))
(define get-op-function
(lambda (op)
(cond ((Arith-Op? op) (get-arith-function op))
((Bool-Op? op) (get-comp-function op)))))
I guess I could do it for functions in the same way, too... unless there's a more elegant way?
Thanks for your help,
Sigrid
>
> I've MLish syntax here as it is a bit more compact. This is basically
> how you get dynamic checks into a statically typed language.
>
> HTH,
> N.
>
> On Fri, May 28, 2010 at 8:44 PM, keydana at gmx.de <keydana at gmx.de> wrote:
>> I'm just looking for a way to represent functions - so I have this 'Fun'
>> type storing the function's name, return type and arguments (up till now I
>> have a number type and a string type only, represented by symbols N and S),
>> and the action it's supposed to execute, which would be the scheme function
>> if an appropriate one exists or a lambda expression otherwise.
>> Then I really just want to extract the code from this representation and
>> apply it to some given object... just like in the made-up example I posted.
>> And this should work for every kind of function, so yes it should be
>> variable arity, but also variable return types - just some general
>> possibility to apply "anything at all" to anything - like if I had
>>
>> (define-struct: Fun ((name : Symbol) (proc : Procedure) (args : (Listof
>> Symbol)) (ret : Symbol)))
>>
>> (define f1 (make-Fun 'plus + '(N N) 'N))
>> ((Fun-proc f1) 1 2)
>>
>> (define f2 (make-Fun 'substr substring '(S N N) 'S))
>> ((Fun-proc f2) "astring" 2 4)
>>
>> and it worked...
>> I don't know if this sounds silly, but I wouldn't know how I could represent
>> functions in another way.
>> Ciao,
>> Sigrid
>>
>> _________________________________________________
>> For list-related administrative tasks:
>> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>>
>>