Iāve been looking forward to each new post in this series eagerly, and I have a couple notes about part 3.
So we just saw that we need HRTB to declare that any type I is a collection (otherwise, we just know it is some type). But (as far as I know) Haskell doesnāt have anything like HRTB [ā¦]
It may not be possible directly, but with ConstraintKinds it is possible with some type-level hackery and with an ok interface. I would render for<T> I<T>: Collection<T> in rust as ForallF Collection i in haskell, using this library.
(Interestingly, GHCI will happily parse forall a. Collection (f a) and even identify it as a constraint, but wonāt let you actually use it anywhere.)
The same problem also confronts collections like HashSet or BTreeSet that require bounds ā that is, even though these are generic types, you canāt actually make a HashSet of just any old type T.
This problem usually shows up in haskell-land as āwhy doesnāt the Set type implement Functor?ā
With constraint kinds, that specific problem can be solved by adding an associated constraint type to the Functor class (for an example see this reddit comment), though itās not clear at all to me if this is a good solution or a scalable one.
However both of these solutions use constraint kinds, which are definitely further down this rabbit hole than HKT alone.