gigaparsec-0.3.0.0: Refreshed parsec-style library for compatibility with Scala parsley
LicenseBSD-3-Clause
MaintainerJamie Willis, Gigaparsec Maintainers
Stabilityexperimental
Safe HaskellSafe
LanguageHaskell2010

Text.Gigaparsec.Expr.Subtype

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.

Synopsis

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

upcast :: sub -> sup Source #

Inject the subtype into the supertype.

Cast values in sub into a value of type sup. This should be a right inverse of downcast.

downcast :: sup -> Maybe sub Source #

Describes which elements of sup correspond with those in sub.

That is, downcast v = Just w precisely when upcast w = v.

If v :: sup corresponds with some element w :: sub, then,

downcast v = Just w

Otherwise, if v :: sup is not the upcast of any element of sub, then,

downcast v = Nothing

Instances

Instances details
Subtype a a Source # 
Instance details

Defined in Text.Gigaparsec.Expr.Subtype

Methods

upcast :: a -> a Source #

downcast :: a -> Maybe a Source #

type (<) sub sup = Subtype sub sup Source #

An infix alias of Subtype.

Module Re-export

This should be removed.

type (<) sub sup = Subtype sub sup Source #

An infix alias of Subtype.

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

upcast :: sub -> sup Source #

Inject the subtype into the supertype.

Cast values in sub into a value of type sup. This should be a right inverse of downcast.

downcast :: sup -> Maybe sub Source #

Describes which elements of sup correspond with those in sub.

That is, downcast v = Just w precisely when upcast w = v.

If v :: sup corresponds with some element w :: sub, then,

downcast v = Just w

Otherwise, if v :: sup is not the upcast of any element of sub, then,

downcast v = Nothing

Instances

Instances details
Subtype a a Source # 
Instance details

Defined in Text.Gigaparsec.Expr.Subtype

Methods

upcast :: a -> a Source #

downcast :: a -> Maybe a Source #