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 ScopedTypeVariables #-}
14{-# language StandaloneKindSignatures #-}
15{-# language TypeFamilies #-}
16{-# language UndecidableInstances #-}
18module Rel8.Schema.HTable.Nullify
19 ( HNullify( HNullify )
21 , hnulls, hnullify, hunnullify
26import Prelude hiding ( null )
29import Rel8.Schema.HTable ( HTable, hfield, htabulate, htabulateA, hspecs )
30import qualified Rel8.Schema.Kind as K
31import Rel8.Schema.Null ( Nullity( Null, NotNull ) )
32import qualified Rel8.Schema.Null as Type ( Nullify )
33import Rel8.Schema.Spec ( Spec( Spec ), SSpec(..) )
36import Data.Functor.Apply ( Apply )
37import Rel8.Schema.HTable.MapTable
39import GHC.Generics (Generic)
42type HNullify :: K.HTable -> K.HTable
43newtype HNullify table context = HNullify (HMapTable Nullify table context)
44 deriving stock Generic
45 deriving anyclass HTable
49-- | Transform a 'Spec' by allowing it to be @null@.
50data Nullify :: Spec -> Exp Spec
53type instance Eval (Nullify ('Spec labels necessity a)) =
54 'Spec labels necessity (Type.Nullify a)
57instance MapSpec Nullify where
59 SSpec{labels, necessity, info, nullity} -> SSpec
63 , nullity = case nullity of
70 => (forall labels necessity a. ()
71 => SSpec ('Spec labels necessity a)
72 -> context ('Spec labels necessity (Type.Nullify a)))
74hnulls null = HNullify $ htabulate $ \(HMapTableField field) -> case hfield hspecs field of
75 spec@SSpec {} -> null spec
76{-# INLINABLE hnulls #-}
80 => (forall labels necessity a. ()
81 => SSpec ('Spec labels necessity a)
82 -> context ('Spec labels necessity a)
83 -> context ('Spec labels necessity (Type.Nullify a)))
86hnullify nullifier a = HNullify $ htabulate $ \(HMapTableField field) ->
87 case hfield hspecs field of
88 spec@SSpec {} -> nullifier spec (hfield a field)
89{-# INLINABLE hnullify #-}
92hunnullify :: (HTable t, Apply m)
93 => (forall labels necessity a. ()
94 => SSpec ('Spec labels necessity a)
95 -> context ('Spec labels necessity (Type.Nullify a))
96 -> m (context ('Spec labels necessity a)))
99hunnullify unnullifier (HNullify as) =
100 htabulateA $ \field -> case hfield hspecs field of
101 spec@SSpec {} -> case hfield as (HMapTableField field) of
102 a -> unnullifier spec a
103{-# 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