| License | BSD-3-Clause |
|---|---|
| Maintainer | Jamie Willis, Gigaparsec Maintainers |
| Stability | experimental |
| Safe Haskell | Safe |
| Language | Haskell2010 |
Text.Gigaparsec.Expr.Subtype
Contents
Description
This module defines explicit subtyping, with up- and -downcasting.
Subtyping is used in Text.Gigaparsec.Expr to allow for more specific types within a single layer of a precedence table, as long as they all have a common supertype.
Subtyping
class Subtype sub sup where Source #
Explicit subtyping with up- and down-casting.
sub is a Subtype of sup when there is an upcasting function sub -> sup.
The intuition is that for each value of type sub, there is a (unique) corresponding value in sup
upcast will convert values in sub to their corresponding values in sup.
The downcast function describes all those values in sup which correspond to values in sub;
if v :: sup does not correspond to any value in sub, then .downcast v = Nothing
This is encapsulated by the following property:
downcast . upcast = Just
meaning that upcast should be a right inverse for downcast.
In other words, if you upcast and then downcast some value, you will end up with the same value
(albeit wrapped under a Just).
Methods
Inject the subtype into the supertype.
Cast values in sub into a value of type sup.
This should be a right inverse of downcast.
Module Re-export
This should be removed.
class Subtype sub sup where Source #
Explicit subtyping with up- and down-casting.
sub is a Subtype of sup when there is an upcasting function sub -> sup.
The intuition is that for each value of type sub, there is a (unique) corresponding value in sup
upcast will convert values in sub to their corresponding values in sup.
The downcast function describes all those values in sup which correspond to values in sub;
if v :: sup does not correspond to any value in sub, then .downcast v = Nothing
This is encapsulated by the following property:
downcast . upcast = Just
meaning that upcast should be a right inverse for downcast.
In other words, if you upcast and then downcast some value, you will end up with the same value
(albeit wrapped under a Just).
Methods
Inject the subtype into the supertype.
Cast values in sub into a value of type sup.
This should be a right inverse of downcast.