Hacker News new | ask | show | jobs
by ambrosebs 4618 days ago
The dotted type-variable on the right hand side of ... is what ensures both sets of dots get instantiated with the same sequence of types.

Both sides of b ... b are actually completely different. The left is a type (called a "pre-type") and the right is a dotted type variable currently in scope.

The trick is that the dotted type-variable is also scoped as a normal free variable in the pre-type.

It might help thinking of "b ... b" as expanding to "b1 b2 b3 b4 b5", where each is a fresh type variable.

Then, consider "(NonEmptySeqable b) ... b" as expanding to "(NonEmptySeqable b1) (NonEmptySeqable b2) (NonEmptySeqable b3) (NonEmptySeqable b4) (NonEmptySeqable b5)".

The b's "match up" pairwise, but they're quite different than what you might expect.

1 comments

Yup, makes sense (well, paragraph three onward -- I don't know enough yet to understand stuff like "dotted type-variable", but I think the general way this is working is clear :).

So would this definition be equivalent and work?

  (ann clojure.core/map
    (All [c b ...]
      (Fn [[b ... b -> c] 
           (NonEmptySeqable b) ... b 
           -> (NonEmptyLazySeq c)]
          [[b ... b -> c] 
           (U nil (Seqable b)) ... b
           -> (LazySeq c)])))
| The b's "match up" pairwise, but they're quite different than what you might expect.

Makes sense, but slightly confusing at first, 'cuz the b before the ... is a different thing than the b after.

Thanks for the response, and typed clojure. I think this is going to be the thing that finally gets me to start playing with clojure. :)

Clojure's map takes at least 2 arguments, so that's why we have an extra "a".

I also commented on the blog post explaining the terms I used.

Ah, that makes sense.