[Haskell-cafe] Where are rank-3 types necessary in practice for maintaining abstraction?
ekmett at gmail.com
Wed Apr 4 05:38:24 UTC 2018
The proper type for callCC would be rank-3. The current form is an
under-approximation that only allows you to choose to use the continuation
at one type.
Going higher rank (usefully) is still pretty straight-forward. There is the
Mendler-style encoding of functors that gets used every once in a while in
recursion-schemes work. It adds a rank to get rid of a Functor constraint.
This is basically replacing a functor f with (forall b. (a -> b) -> f b),
which is the same as the Yoneda f a newtype.
For more information, see some of the lovely examples in
update :: (forall c’. (forall y’. (y’ -> c’) -> (y’ -> Mu f) -> f y’ -> c’)
-> y -> c’) -> (Mu f -> c) -> (forall c’. (forall y’. (y’ -> c) -> (y’ ->
c’) -> f y’ -> c’) -> y -> c’)
On Mon, Apr 2, 2018 at 11:36 PM, Timotej Tomandl <timotomandl at gmail.com>
> So we need rank-2 type in runST :: (forall s. ST
> s a) -> a, to prevent s from appearing in a.
> I have been thinking about this for a bit, but I failed to come up with a
> practical situation, where rank-3 types are necessary for safety of some
> The rank-3 example in here and any other I found, look very synthetic,
> i.e. limiting computation to id:
> and compared to the runST example of limiting a scope of a type variable
> for purposes of safety looks unnatural.
> Could anyone please point me to a practical example of rank-3
> polymorphism, where it is necessary for safety of an abstraction, if it
> I suspect there is a situation, where rank-3 is necessary for maintaining
> abstration exists, but I can't think of any.
> Any ideas about such situations and even better situations where this is
> used on hackage?
> Timotej Tomandl
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe