Quick explanation of why the "control inversion" trick in this explanation of existential types on StackOverflow is actually currying:
- the type of the original for-loop body was
(∃B:VirtualMachine<B>) -> IO void
- (where
IO void
represents thatvm.run()
had side-effects and avoid
return type)
- (where
- the type of
VMHandler.handle()
is∀B:(VirtualMachine<B> -> IO void)
If you interpret an existential type as describing a pair of a type and a value, and interpret a universal type as describing a function from a type to a value (see footnote), then those can be interpreted as:
- the original for-loop body:
(B, VirtualMachine<B>) -> IO void
VMHandler.handle()
:B -> VirtualMachine<b> -> IO void