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 a)) =
54 'Spec labels (Type.Nullify a)
57instance MapSpec Nullify where
59 SSpec{labels, info, nullity} -> SSpec
62 , nullity = case nullity of
69 => (forall labels a. ()
70 => SSpec ('Spec labels a)
71 -> context ('Spec labels (Type.Nullify a)))
73hnulls null = HNullify $ htabulate $ \(HMapTableField field) -> case hfield hspecs field of
74 spec@SSpec {} -> null spec
75{-# INLINABLE hnulls #-}
79 => (forall labels a. ()
80 => SSpec ('Spec labels a)
81 -> context ('Spec labels a)
82 -> context ('Spec labels (Type.Nullify a)))
85hnullify nullifier a = HNullify $ htabulate $ \(HMapTableField field) ->
86 case hfield hspecs field of
87 spec@SSpec {} -> nullifier spec (hfield a field)
88{-# INLINABLE hnullify #-}
91hunnullify :: (HTable t, Apply m)
92 => (forall labels a. ()
93 => SSpec ('Spec labels a)
94 -> context ('Spec labels (Type.Nullify a))
95 -> m (context ('Spec labels a)))
98hunnullify unnullifier (HNullify as) =
99 htabulateA $ \field -> case hfield hspecs field of
100 spec@SSpec {} -> case hfield as (HMapTableField field) of
101 a -> unnullifier spec a
102{-# 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