{-# language DataKinds #-}
{-# language GADTs #-}
{-# language NamedFieldPuns #-}
{-# language StandaloneKindSignatures #-}
{-# language TypeFamilies #-}
module Rel8.Schema.Result
( Col( R, unR ), Result
, relabel
, null, nullifier, unnullifier
, vectorizer, unvectorizer
)
where
import Prelude hiding ( null )
import Rel8.Kind.Necessity ( Necessity( Required ) )
import Rel8.Schema.Context ( Interpretation( Col ) )
import Rel8.Schema.HTable.Identity ( HIdentity(..) )
import Rel8.Schema.Kind ( Context )
import Rel8.Schema.Null ( Nullify, Nullity( Null, NotNull ) )
import Rel8.Schema.Spec ( Spec( Spec ), SSpec(..) )
type Result :: Context
data Result a
instance Interpretation Result where
data Col Result _spec where
R :: {Col Result ('Spec labels necessity a) -> a
unR :: !a} -> Col Result ('Spec labels necessity a)
relabel :: ()
=> HIdentity ('Spec labels necessity a) (Col Result)
-> HIdentity ('Spec relabels necessity a) (Col Result)
relabel :: HIdentity ('Spec labels necessity a) (Col Result)
-> HIdentity ('Spec relabels necessity a) (Col Result)
relabel (HIdentity (R a)) = Col Result ('Spec relabels necessity a)
-> HIdentity ('Spec relabels necessity a) (Col Result)
forall (spec :: Spec) (context :: HContext).
context spec -> HIdentity spec context
HIdentity (a -> Col Result ('Spec relabels necessity a)
forall a (labels :: Labels) (necessity :: Necessity).
a -> Col Result ('Spec labels necessity a)
R a
a)
null :: Col Result ('Spec labels necessity (Maybe a))
null :: Col Result ('Spec labels necessity (Maybe a))
null = Maybe a -> Col Result ('Spec labels necessity (Maybe a))
forall a (labels :: Labels) (necessity :: Necessity).
a -> Col Result ('Spec labels necessity a)
R Maybe a
forall a. Maybe a
Nothing
nullifier :: ()
=> SSpec ('Spec labels necessity a)
-> Col Result ('Spec labels necessity a)
-> Col Result ('Spec labels necessity (Nullify a))
nullifier :: SSpec ('Spec labels necessity a)
-> Col Result ('Spec labels necessity a)
-> Col Result ('Spec labels necessity (Nullify a))
nullifier SSpec {Nullity a
nullity :: forall (labels :: Labels) (necessity :: Necessity) a.
SSpec ('Spec labels necessity a) -> Nullity a
nullity :: Nullity a
nullity} (R a) = Nullify a -> Col Result ('Spec labels necessity (Nullify a))
forall a (labels :: Labels) (necessity :: Necessity).
a -> Col Result ('Spec labels necessity a)
R (Nullify a -> Col Result ('Spec labels necessity (Nullify a)))
-> Nullify a -> Col Result ('Spec labels necessity (Nullify a))
forall a b. (a -> b) -> a -> b
$ case Nullity a
nullity of
Nullity a
Null -> a
Nullify a
a
Nullity a
NotNull -> a -> Maybe a
forall a. a -> Maybe a
Just a
a
unnullifier :: ()
=> SSpec ('Spec labels necessity a)
-> Col Result ('Spec labels necessity (Nullify a))
-> Maybe (Col Result ('Spec labels necessity a))
unnullifier :: SSpec ('Spec labels necessity a)
-> Col Result ('Spec labels necessity (Nullify a))
-> Maybe (Col Result ('Spec labels necessity a))
unnullifier SSpec {Nullity a
nullity :: Nullity a
nullity :: forall (labels :: Labels) (necessity :: Necessity) a.
SSpec ('Spec labels necessity a) -> Nullity a
nullity} (R a) =
case Nullity a
nullity of
Nullity a
Null -> Col Result ('Spec labels necessity a)
-> Maybe (Col Result ('Spec labels necessity a))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Col Result ('Spec labels necessity a)
-> Maybe (Col Result ('Spec labels necessity a)))
-> Col Result ('Spec labels necessity a)
-> Maybe (Col Result ('Spec labels necessity a))
forall a b. (a -> b) -> a -> b
$ a -> Col Result ('Spec labels necessity a)
forall a (labels :: Labels) (necessity :: Necessity).
a -> Col Result ('Spec labels necessity a)
R a
a
Nullity a
NotNull -> a -> Col Result ('Spec labels necessity a)
forall a (labels :: Labels) (necessity :: Necessity).
a -> Col Result ('Spec labels necessity a)
R (a -> Col Result ('Spec labels necessity a))
-> Maybe a -> Maybe (Col Result ('Spec labels necessity a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a
Maybe a
a
vectorizer :: Functor f
=> SSpec ('Spec labels necessity a)
-> f (Col Result ('Spec labels necessity a))
-> Col Result ('Spec labels 'Required (f a))
vectorizer :: SSpec ('Spec labels necessity a)
-> f (Col Result ('Spec labels necessity a))
-> Col Result ('Spec labels 'Required (f a))
vectorizer SSpec ('Spec labels necessity a)
_ = f a -> Col Result ('Spec labels 'Required (f a))
forall a (labels :: Labels) (necessity :: Necessity).
a -> Col Result ('Spec labels necessity a)
R (f a -> Col Result ('Spec labels 'Required (f a)))
-> (f (Col Result ('Spec labels necessity a)) -> f a)
-> f (Col Result ('Spec labels necessity a))
-> Col Result ('Spec labels 'Required (f a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Col Result ('Spec labels necessity a) -> a)
-> f (Col Result ('Spec labels necessity a)) -> f a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Col Result ('Spec labels necessity a) -> a
forall (labels :: Labels) (necessity :: Necessity) a.
Col Result ('Spec labels necessity a) -> a
unR
unvectorizer :: Functor f
=> SSpec ('Spec labels necessity a)
-> Col Result ('Spec labels 'Required (f a))
-> f (Col Result ('Spec labels necessity a))
unvectorizer :: SSpec ('Spec labels necessity a)
-> Col Result ('Spec labels 'Required (f a))
-> f (Col Result ('Spec labels necessity a))
unvectorizer SSpec ('Spec labels necessity a)
_ (R results) = a -> Col Result ('Spec labels necessity a)
forall a (labels :: Labels) (necessity :: Necessity).
a -> Col Result ('Spec labels necessity a)
R (a -> Col Result ('Spec labels necessity a))
-> f a -> f (Col Result ('Spec labels necessity a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a
f a
results