3 ms·
All you need is a GADT which carries around the type class constraint. data Object cls a where Object :: cls a => a -> Object cls a Now, the class `
by tathougies 9y ago
All you need is a GADT which carries around the type class constraint.
data Object cls a where
Object :: cls a => a -> Object cls a
Now, the class `cls a` is carried around with the value `a`. You can even go one step further and reify the vtable by itself.
data Dict c where
Dict :: c => Dict
which you can't really do in standard C++.