[plt-scheme] Typed scheme: Cannot apply expression of type Procedure, since it is not a function type

From: keydana at gmx.de (keydana at gmx.de)
Date: Sun May 30 02:51:46 EDT 2010

It's me again, I found the way to put this in typed scheme now:


(define-datatype F
  (Substr ((p : (case-lambda (String Integer -> String) (String Integer Integer -> String)))))
  (StrApp ((p : (String * -> String)))))

(define substr (make-Substr substring))
(define strapp (make-StrApp string-append))

((StrApp-p strapp) "helo" "w")
((Substr-p substr) "helo" 1 2)


This really is nicer than the workaround with the getter functions I have for the arithmetic operators...

Thanks again for the hint,
Sigrid





Am 29.05.2010 um 07:35 schrieb Noel Welsh:

> I don't know that Typed err... Racket can express what you want. Sam
> can give a definitive answer.
> 
> One way to solve this problem is to enumerate all the functions you'll
> ever use, which a type defn like:
> 
> type Fun = Plus Number Number -> Number | Minus Number Number ->
> Number | String-Append String String -> String | ...
> 
> 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
>> 
>> 



Posted on the users mailing list.