refined-subtype-0.1.0.0: compute subtypes from refinement types
MaintainerOlaf Klinke
Stabilityexperimental
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.SubType

Description

Functions with codomain x, regardless of their domain, can be encoded in the GADT

data Codomain :: Type -> Type where
    Fun :: (y -> x) -> Codomain x

This module decorates this GADT with constraints on the domain y and generalizes functions to morphisms of arbitrary categories.

Synopsis

Documentation

data SomeSubType :: (Type -> Constraint) -> Type -> Type where Source #

Constrained sub-types. This data type records the embedding function but hides its domain in an existential type. This allows us to compute an embedding at run-time. As an extra parameter, we pass a type class so that only those sub-types are representable that are member of this class.

Constructors

EmptySubType :: SomeSubType con t 
Embed :: con x => (x -> y) -> SomeSubType con y 

Instances

Instances details
Functor (SomeSubType con) Source #

post-compose embeddings with functions. This allows us to nest embeddings.

Instance details

Defined in Data.SubType

Methods

fmap :: (a -> b) -> SomeSubType con a -> SomeSubType con b #

(<$) :: a -> SomeSubType con b -> SomeSubType con a #

idSubType :: con t => SomeSubType con t Source #

embed a type into itself via the identity function.

runEmbedding :: (forall x. con x => rep -> Maybe x) -> SomeSubType con y -> rep -> Maybe y Source #

In order to run an embedding with unknown domain, we need a function that can convert a single universal type rep to any sub-type. Nothing is returned if the rep value does not represent an element of the sub-type, in particular if the sub-type is empty.

subDomain :: SomeSubType Typeable x -> SomeTypeRep Source #

The representation of the type of the domain of the sub-type embedding.

runEmbeddingDynamic :: SomeSubType Typeable x -> Dynamic -> Maybe x Source #

It is guaranteed that for every f :: y -> x with Typeable y,

runEmbeddingDynamic (Embed f) (toDyn y) = Just (f y)

data GSubType :: (k -> k -> Type) -> (k -> Constraint) -> k -> Type where Source #

Poly-kinded version of SomeSubType generalized to arbitrary categories.

Constructors

GEmpty :: GSubType cat con x 
GEmbed :: con y => cat y x -> GSubType cat con x 

idGSubType :: (Category cat, con x) => GSubType cat con x Source #

the identiy morphism

mapGSubType :: Category cat => cat x y -> GSubType cat con x -> GSubType cat con y Source #

GSubType cat con is functorial on cat.

runGEmbedding Source #

Arguments

:: (forall g. con g => cat g f -> Dynamic -> Maybe (g ()))

dynamically convert to the sub-type

-> (forall s. cat s f -> s () -> f ())

run the cat morphism

-> GSubType cat con f

the sub-type embedding

-> Dynamic

dynamic representation of the argument

-> Maybe (f ()) 

generic version of runEmbedding.