1{-# language ConstraintKinds #-}
2{-# language DataKinds #-}
3{-# language DeriveAnyClass #-}
4{-# language DerivingStrategies #-}
5{-# language DeriveGeneric #-}
6{-# language FlexibleInstances #-}
8{-# language LambdaCase #-}
9{-# language MultiParamTypeClasses #-}
10{-# language NamedFieldPuns #-}
11{-# language QuantifiedConstraints #-}
12{-# language RankNTypes #-}
13{-# language RecordWildCards #-}
14{-# language ScopedTypeVariables #-}
15{-# language StandaloneKindSignatures #-}
16{-# language TypeFamilies #-}
17{-# language UndecidableInstances #-}
19module Rel8.Schema.HTable.Nullify
20 ( HNullify( HNullify )
30import Data.Kind ( Type )
31import GHC.Generics ( Generic )
32import Prelude hiding ( null )
35import Rel8.FCF ( Eval, Exp )
36import Rel8.Schema.HTable ( HTable, hfield, htabulate, htabulateA, hspecs )
37import Rel8.Schema.HTable.MapTable
38 ( HMapTable, HMapTableField( HMapTableField )
41import qualified Rel8.Schema.Kind as K
42import Rel8.Schema.Null ( Nullity( Null, NotNull ) )
43import qualified Rel8.Schema.Null as Type ( Nullify )
44import Rel8.Schema.Spec ( Spec(..) )
47import Data.Functor.Apply ( Apply )
50type HNullify :: K.HTable -> K.HTable
51newtype HNullify table context = HNullify (HMapTable Nullify table context)
52 deriving stock Generic
53 deriving anyclass HTable
56-- | Transform a 'Type' by allowing it to be @null@.
57data Nullify :: Type -> Exp Type
58type instance Eval (Nullify a) = Type.Nullify a
61instance MapSpec Nullify where
63 Spec {nullity, ..} -> Spec
64 { nullity = case nullity of
72 => (forall a. context (Maybe a) -> context (Maybe a))
73 -> HNullify t context -> HNullify t context
74hguard guarder (HNullify as) = HNullify $ htabulate $ \(HMapTableField field) ->
75 case hfield hspecs field of
76 Spec {nullity} -> case hfield as (HMapTableField field) of
83 => (forall a. Spec a -> context (Type.Nullify a))
85hnulls null = HNullify $ htabulate $ \(HMapTableField field) ->
86 case hfield hspecs field of
87 spec@Spec {} -> null spec
88{-# INLINABLE hnulls #-}
92 => (forall a. Spec a -> context a -> context (Type.Nullify a))
95hnullify nullifier a = HNullify $ htabulate $ \(HMapTableField field) ->
96 case hfield hspecs field of
97 spec@Spec {} -> nullifier spec (hfield a field)
98{-# INLINABLE hnullify #-}
101hunnullify :: (HTable t, Apply m)
102 => (forall a. Spec a -> context (Type.Nullify a) -> m (context a))
103 -> HNullify t context
105hunnullify unnullifier (HNullify as) =
106 htabulateA $ \field -> case hfield hspecs field of
107 spec@Spec {} -> case hfield as (HMapTableField field) of
108 a -> unnullifier spec a
109{-# INLINABLE hunnullify #-}
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list