1
1
mirror of https://github.com/github/semantic.git synced 2024-12-24 15:35:14 +03:00

Define a typeclass to embed/project elements into/out of a Union.

This commit is contained in:
Rob Rix 2017-03-26 12:06:57 -04:00
parent df3c26f17b
commit 9486b80efc

View File

@ -1,7 +1,16 @@
{-# LANGUAGE DataKinds, GADTs, KindSignatures, TypeOperators #-}
{-# LANGUAGE DataKinds, GADTs, KindSignatures, MultiParamTypeClasses, TypeOperators #-}
module Data.Functor.Union where
import Prologue
-- | N-ary union of type constructors.
data Union (ts :: [* -> *]) (a :: *) where
Here :: f 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)