typed-racket icon indicating copy to clipboard operation
typed-racket copied to clipboard

Inferred type of (compose number->string add1) is (-> Zero String)

Open LiberalArtist opened this issue 3 years ago • 1 comments

What version of Racket are you using?

7.9 CS

What program did you run?

Welcome to DrRacket, version 7.9 [cs].
Language: typed/racket, with debugging; memory limit: 512 MB.
> (compose number->string add1)
- : (-> Zero String)
#<procedure:composed>

What should have happened?

I would have expected the inferred type to be (-> Number String).

LiberalArtist avatar Dec 10 '20 17:12 LiberalArtist

This may or may not help, but (ann (compose number->string add1) (-> Number String)) works.

As for why inference picks this in the absence of other constraints, it's a somewhat tricky problem but we could probably do better here.

The bigger issue is that ((compose number->string add1) 5) doesn't add any other constraints to make it work, but that requires a much more comprehensive re-do of how inference and type checking work to change.

samth avatar Dec 10 '20 17:12 samth