Copyright | Dennis Gosnell 2017 |
---|---|
License | BSD3 |
Maintainer | Dennis Gosnell (cdep.illabout@gmail.com) |
Stability | experimental |
Portability | unknown |
Safe Haskell | Safe |
Language | Haskell2010 |
This module defines an open product type. This is used in the case-analysis
handler for the open sum type (catchesUnion
).
- data Product (f :: u -> *) (as :: [u]) where
- class ToProduct (tuple :: *) (f :: u -> *) (as :: [u]) | f as -> tuple where
- tupleToProduct :: ToProduct t f as => t -> Product f as
- type OpenProduct = Product Identity
- class ToOpenProduct (tuple :: *) (as :: [*]) | as -> tuple where
- tupleToOpenProduct :: ToOpenProduct t as => t -> OpenProduct as
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.
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
.
toProduct :: tuple -> Product f as Source #
Convert a tuple into a Product
. See tupleToProduct
for examples.
ToProduct u (f a) f ((:) u a ([] u)) Source # | Convert a single value into a |
ToProduct u (f a, f b) f ((:) u a ((:) u b ([] u))) Source # | Convert a tuple into a |
ToProduct u (f a, f b, f c) f ((:) u a ((:) u b ((:) u c ([] u)))) Source # | Convert a 3-tuple into a |
ToProduct u (f a, f b, f c, f d) f ((:) u a ((:) u b ((:) u c ((:) u d ([] u))))) Source # | Convert a 4-tuple into a |
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 #
class ToOpenProduct (tuple :: *) (as :: [*]) | as -> tuple where Source #
ToOpenProduct
gives us a way to convert a tuple to an OpenProduct
.
See tupleToOpenProduct
.
toOpenProduct :: tuple -> OpenProduct as Source #
ToOpenProduct a ((:) * a ([] *)) Source # | Convert a single value into an |
ToOpenProduct (a, b) ((:) * a ((:) * b ([] *))) Source # | Convert a tuple into an |
ToOpenProduct (a, b, c) ((:) * a ((:) * b ((:) * c ([] *)))) Source # | Convert a 3-tuple into an |
ToOpenProduct (a, b, c, d) ((:) * a ((:) * b ((:) * c ((:) * d ([] *))))) Source # | Convert a 4-tuple into an |
tupleToOpenProduct :: ToOpenProduct t as => t -> OpenProduct as Source #
Turn a tuple into an OpenProduct
.
Examples
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