racket / typed-racket

Typed Racket
Other
521 stars 104 forks source link

curryr #607

Open schackbrian2012 opened 6 years ago

schackbrian2012 commented 6 years ago

What version of Racket are you using?

6.10.1

What program did you run?

(curryr / 2)

What should have happened?

#<procedure:curried>

If you got an error message, please include it here.

Type Checker: missing type for identifier;
 consider using `require/typed' to import it
  identifier: curryr
  from module: typed/racket in: curryr
bennn commented 6 years ago

You can use curryr if you use require/typed to give it a type annotation

#lang typed/racket

(require/typed racket/function
  (curryr (-> (-> Real Real Real) Real (-> Real Real))))

(curryr / 2)
;; #<procedure:curried>
schackbrian2012 commented 6 years ago

@bennn That's a good workaround, but since curryr is a built-in function, I think that the type annotation should be built-in also. The type annotation for curry is built-in.

AlexKnauth commented 6 years ago

The racket versions of curry and curryr are variadic and and even curry-variadic (if that's a word) in some very weird ways, so it's impossible to give them types in typed racket.

However, if you instead make a simpler function with simpler run-time behavior, and if you sacrifice some flexibility, you might be able to describe it better with a type.

(: partialr : (All (X Y) (-> (-> X * Y) X * (-> X * Y))))
(define ((partialr f . bs) . as)
  (apply f (append as bs)))

But notice how curryr could never be described by this type, because it's behavior decides at run time whether to produce another function or to produce a final result value, based on the procedure-arity.

schackbrian2012 commented 6 years ago

@AlexKnauth Yeah, I can certainly see how it could be impossible to make a type for curryr if the type system is insufficiently expressive. I would say to put it in as best as you can either with a syntactical special case or a simplified type. Bring curryr up to parity with curry. And then keep a list in the documentation of the built-in functions that are less expressive in typed/racket than untyped racket.