[racket] Puzzled about type inference
Alexander, hello.
On 2014 Aug 5, at 14:11, "Alexander D. Knauth" <alexander at knauth.org> wrote:
> Well ann can’t add any detail, it can only make types less specific.
Aha: I was thinking of this the wrong way round.
If I type, say, #(1 2) into TR, it determines its type as
> #(1 2)
- : (Vector Integer Integer)
'#(1 2)
Compared to that,
> (ann #(1 2) (Vectorof Positive-Integer))
- : (Vectorof Positive-Integer)
'#(1 2)
...is more specific. But your explanation makes me realise that the most specific possible type is (Vector 1 2) (of limited utility), and that (Vector (U 1 2) (U 1 2), (Vector Integer Integer) and (Vectorof Positive-Integer) are just samples of the many possible less specific ones, and it happens that the less-specific one that TR guesses I want is not the one I actually want. Which is why I have to use `ann`.
Simple, really -- cor, it's wall-to-wall epiphanies today....
All the best,
Norman
--
Norman Gray : http://nxg.me.uk
SUPA School of Physics and Astronomy, University of Glasgow, UK