Emulating OCaml modules with typeclasses

The problem is that Stack is kind-polymorphic, so the type of empty is:

ghci> :t empty
empty :: forall k (m :: k). Stack m => Container m (Elem m)

So you need to invoke it like this: empty @_ @(ListStack Int)

Alternatively, you can make Stack and SizedStack not kind-polymorphic by replacing k with Type. I don’t see any reason not to do that.

2 Likes