contact
2018-7-1 16:21:02

@contact has joined the channel


gfb
2018-7-1 19:26:08

In the Racket 6.12 Typed Racket Guide section 4.8.2 Polymorphic Functions, the example is of type (All (A) (-> (Listof A) Integer))). In this case, and essentially any case with a single occurrence of the type variable, I can’t see any benefit over Any. Am I missing something (I realize the docs don’t claim it’s actually worthwhile in this case).


shu--hung
2018-7-1 20:03:29

That’s interesting, I would like to know the answer too


shu--hung
2018-7-1 20:08:16

If we were considering a different type system, the type (All (A) (-> (Listof A) Integer))) would tell us that this function can never inspect the elements in the list it received but only look at the length. But Typed Racket is different..


greg
2018-7-2 00:08:40

I’m only a dabbler in Typed Racket (and “strong” static typing generally), but: The previous two examples are lists where the elements are all the same type — (Listof Number) and (Listof String). So I might expect that (All (A) (-> (Listof A) Integer))) means it takes a list where every element is the same type (as opposed to a heterogeneous list). Such as (list 1 2 3) — but not (list 1 'two "three"). And yet, when I try the example list-length function with say (list-length (list 1 'two "three")), it happily type-checks and says 3.


lexi.lambda
2018-7-2 00:11:49

The thing is, Typed Racket has subtyping, and all types have a common supertype, Any, so the caller can always pick Any for A.


lexi.lambda
2018-7-2 00:12:20

I think what @gfb says is correct, but I can’t be sure. @samth or @pnwamk would probably know for certain.


samth
2018-7-2 00:20:07

What @gfb says is right