u/AshleyYakeleyin r/haskell • Recommends
On “Lattice and calculation of Least Upper Bounds”
Slightly off-topic, but if you're looking at lattices of types, are you familiar with Stephen Dolan's work adding subtyping to Hindley-Milner? Rough idea: given any two types `a` and `b`, rather than consulting the type hierarchy, we simply say that their meet and join are `a & b` and `a | b`. For example:
select p v d = if p v then v else d
Hindley-Milner would type this as
select :: (a -> Bool) -> a -> a -> a
But Dolan gives a more general type:
select :: (a -> Bool) -> a -> b -> a | b
Note that `|` is not the same as `Either`, rather, it means "an `a` or a `b`, but I'm not telling you which". But if your subtype hierarchy happens to have `a ≤ c` and `b ≤ c`, then you hav…