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 )
22 , hnulls, hnullify, hunnullify
27import Prelude hiding ( null )
30import Rel8.Schema.HTable ( HTable, hfield, htabulate, htabulateA, hspecs )
31import qualified Rel8.Schema.Kind as K
32import Rel8.Schema.Null ( Nullity( Null, NotNull ) )
33import qualified Rel8.Schema.Null as Type ( Nullify )
34import Rel8.Schema.Spec ( Spec( Spec ), SSpec(..) )
37import Data.Functor.Apply ( Apply )
38import Rel8.Schema.HTable.MapTable
40import GHC.Generics (Generic)
43type HNullify :: K.HTable -> K.HTable
44newtype HNullify table context = HNullify (HMapTable Nullify table context)
45 deriving stock Generic
46 deriving anyclass HTable
50-- | Transform a 'Spec' by allowing it to be @null@.
51data Nullify :: Spec -> Exp Spec
54type instance Eval (Nullify ('Spec a)) =
55 'Spec (Type.Nullify a)
58instance MapSpec Nullify where
60 SSpec {nullity, ..} -> SSpec
61 { nullity = case nullity of
71 -> context ('Spec (Type.Nullify a)))
73hnulls null = HNullify $ htabulate $ \(HMapTableField field) -> case hfield hspecs field of
74 spec@SSpec {} -> null spec
75{-# INLINABLE hnulls #-}
82 -> context ('Spec (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)
94 -> context ('Spec (Type.Nullify a))
95 -> m (context ('Spec 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