world-peace-1.0.1.0: Open Union and Open Product Types

CopyrightDennis Gosnell 2017
LicenseBSD3
MaintainerDennis Gosnell (cdep.illabout@gmail.com)
Stabilityexperimental
Portabilityunknown
Safe HaskellSafe
LanguageHaskell2010

Data.WorldPeace.Product

Description

This module defines an open product type. This is used in the case-analysis handler for the open sum type (catchesUnion).

Synopsis

Documentation

>>> -- :set -XDataKinds

data Product (f :: u -> *) (as :: [u]) where Source #

An extensible product type. This is similar to Union, except a product type instead of a sum type.

Constructors

Nil :: Product f '[] 
Cons :: !(f a) -> Product f as -> Product f (a ': as) 
Instances
(Show (f a2), Show (Product f as)) => Show (Product f (a2 ': as)) Source #

Show Cons values.

Instance details

Defined in Data.WorldPeace.Product

Methods

showsPrec :: Int -> Product f (a2 ': as) -> ShowS #

show :: Product f (a2 ': as) -> String #

showList :: [Product f (a2 ': as)] -> ShowS #

Show (Product f ([] :: [u])) Source #

Show Nil values.

Instance details

Defined in Data.WorldPeace.Product

Methods

showsPrec :: Int -> Product f [] -> ShowS #

show :: Product f [] -> String #

showList :: [Product f []] -> ShowS #

class ToProduct (tuple :: *) (f :: u -> *) (as :: [u]) | f as -> tuple where Source #

This type class provides a way to turn a tuple into a Product.

Methods

toProduct :: tuple -> Product f as Source #

Convert a tuple into a Product. See tupleToProduct for examples.

Instances
ToProduct (f a) (f :: u -> Type) (a ': ([] :: [u]) :: [u]) Source #

Convert a single value into a Product.

Instance details

Defined in Data.WorldPeace.Product

Methods

toProduct :: f a -> Product f (a ': []) Source #

ToProduct (f a, f b) (f :: u -> Type) (a ': (b ': ([] :: [u])) :: [u]) Source #

Convert a tuple into a Product.

Instance details

Defined in Data.WorldPeace.Product

Methods

toProduct :: (f a, f b) -> Product f (a ': (b ': [])) Source #

ToProduct (f a, f b, f c) (f :: u -> Type) (a ': (b ': (c ': ([] :: [u]))) :: [u]) Source #

Convert a 3-tuple into a Product.

Instance details

Defined in Data.WorldPeace.Product

Methods

toProduct :: (f a, f b, f c) -> Product f (a ': (b ': (c ': []))) Source #

ToProduct (f a, f b, f c, f d) (f :: u -> Type) (a ': (b ': (c ': (d ': ([] :: [u])))) :: [u]) Source #

Convert a 4-tuple into a Product.

Instance details

Defined in Data.WorldPeace.Product

Methods

toProduct :: (f a, f b, f c, f d) -> Product f (a ': (b ': (c ': (d ': [])))) Source #

tupleToProduct :: ToProduct t f as => t -> Product f as Source #

Turn a tuple into a Product.

>>> tupleToProduct (Identity 1, Identity 2.0) :: Product Identity '[Int, Double]
Cons (Identity 1) (Cons (Identity 2.0) Nil)

type OpenProduct = Product Identity Source #

Product Identity is used as a standard open product type.

class ToOpenProduct (tuple :: *) (as :: [*]) | as -> tuple where Source #

ToOpenProduct gives us a way to convert a tuple to an OpenProduct. See tupleToOpenProduct.

Methods

toOpenProduct :: tuple -> OpenProduct as Source #

Instances
ToOpenProduct a (a ': ([] :: [Type])) Source #

Convert a single value into an OpenProduct.

Instance details

Defined in Data.WorldPeace.Product

Methods

toOpenProduct :: a -> OpenProduct (a ': []) Source #

ToOpenProduct (a, b) (a ': (b ': ([] :: [Type]))) Source #

Convert a tuple into an OpenProduct.

Instance details

Defined in Data.WorldPeace.Product

Methods

toOpenProduct :: (a, b) -> OpenProduct (a ': (b ': [])) Source #

ToOpenProduct (a, b, c) (a ': (b ': (c ': ([] :: [Type])))) Source #

Convert a 3-tuple into an OpenProduct.

Instance details

Defined in Data.WorldPeace.Product

Methods

toOpenProduct :: (a, b, c) -> OpenProduct (a ': (b ': (c ': []))) Source #

ToOpenProduct (a, b, c, d) (a ': (b ': (c ': (d ': ([] :: [Type]))))) Source #

Convert a 4-tuple into an OpenProduct.

Instance details

Defined in Data.WorldPeace.Product

Methods

toOpenProduct :: (a, b, c, d) -> OpenProduct (a ': (b ': (c ': (d ': [])))) Source #

tupleToOpenProduct :: ToOpenProduct t as => t -> OpenProduct as Source #

Turn a tuple into an OpenProduct.

Examples

Expand

Turn a triple into an OpenProduct:

>>> tupleToOpenProduct (1, 2.0, "hello") :: OpenProduct '[Int, Double, String]
Cons (Identity 1) (Cons (Identity 2.0) (Cons (Identity "hello") Nil))

Turn a single value into an OpenProduct:

>>> tupleToOpenProduct 'c' :: OpenProduct '[Char]
Cons (Identity 'c') Nil