I spent over a year trying to improve my proposal how to easyly implement Existential types into the Haskell.
And I have a brilliant idea!
In Haskel forall quantifier is stands for … input type!
So we add exists quantifer for … output type! That means thatwe new the exact type in dynamic runtime only.
ForallType during Typecheck is checked and become Monomorhic by substitutional law.
But ExistentialType during Typecheck is checked but remains Polymorphic. And … during runtime it could be substituted to Monomorphic type.
Dynamic Existentials do NOT cover all Existentials, but it covers 4 main cases
- Quasi Existentials
qex :: exists a.a qex = therefore @String in "Some small text" - Extractable Existentials
data E = forall a. MkE [a] unE :: E -> exists a. [a] unE (MkE @e xs) = therefore @e in xs - Branched Existentials
data T a where MkInt :: T Int MkBool :: T Bool serialize :: forall a. T a -> String serialize MkInt = "int" serialize MkBool = "bool" deserialize :: String -> exists a. T a deserialize "int" = therefore @Int in MkInt deserialize "bool" = therefore @Bool in MkBool - Transit Existentials
someT :: exists a. T a someT = id $ deserialize "bool"
Here we see that we guarantee that during Runtime construction therefore @ty in expr allows to supstitute existential variable to monomorhic one.
We also change how to find a type from case expression: if any sub-type of type application is NOT the same, but still have same kind, then we replace this column type to existential variable.
And the last change: substitutional hierarchy to
Int < exists a. a < forall b. b
The full proposal you could find here Proposal: DynamicExistentials
You could react, like or comment there or here.
But here I have a question: what did I wrote WRONG?
Any suggestion are welcomed!