mirror of
https://github.com/github/semantic.git
synced 2024-12-24 23:42:31 +03:00
Define a typeclass to embed/project elements into/out of a Union.
This commit is contained in:
parent
df3c26f17b
commit
9486b80efc
@ -1,7 +1,16 @@
|
|||||||
{-# LANGUAGE DataKinds, GADTs, KindSignatures, TypeOperators #-}
|
{-# LANGUAGE DataKinds, GADTs, KindSignatures, MultiParamTypeClasses, TypeOperators #-}
|
||||||
module Data.Functor.Union where
|
module Data.Functor.Union where
|
||||||
|
|
||||||
|
import Prologue
|
||||||
|
|
||||||
-- | N-ary union of type constructors.
|
-- | N-ary union of type constructors.
|
||||||
data Union (ts :: [* -> *]) (a :: *) where
|
data Union (ts :: [* -> *]) (a :: *) where
|
||||||
Here :: f a -> Union (f ': ts) a
|
Here :: f a -> Union (f ': ts) a
|
||||||
There :: Union ts a -> Union (f ': ts) a
|
There :: Union ts a -> Union (f ': ts) a
|
||||||
|
|
||||||
|
|
||||||
|
-- Classes
|
||||||
|
|
||||||
|
class InUnion (fs :: [* -> *]) (f :: * -> *) where
|
||||||
|
emb :: f a -> Union fs a
|
||||||
|
proj :: Union fs a -> Maybe (f a)
|
||||||
|
Loading…
Reference in New Issue
Block a user