on master help sign in
Use Data.Type.Bool for type-level bools
commit6cee2a92fad77d0231cd40bea3f1f4cd111c6a38 authorCsongor Kiss <csongor@habito.com> dateTue 1 Aug 2017, 10:46 (9 years ago) parentd04fa38
5 files changed+6−40
generic-lens.cabal−1 src/Data/Generics/Internal/Families.hs−1 src/Data/Generics/Internal/Families/Bool.hs−17 src/Data/Generics/Internal/Families/Has.hs+2−2 src/Data/Generics/Product/Positions.hs+4−19
generic-lens.cabal−1
@@ -32,7 +32,6 @@ library
3232 , Data.Generics.Internal.Lens
3333
3434 other-modules: Data.Generics.Internal.Families
35− , Data.Generics.Internal.Families.Bool
3635 , Data.Generics.Internal.Families.Count
3736 , Data.Generics.Internal.Families.Has
3837 , Data.Generics.Internal.HList
src/Data/Generics/Internal/Families.hs−1
@@ -2,6 +2,5 @@ module Data.Generics.Internal.Families
22 ( module Families
33 ) where
44
5−import Data.Generics.Internal.Families.Bool as Families
65import Data.Generics.Internal.Families.Count as Families
76import Data.Generics.Internal.Families.Has as Families
src/Data/Generics/Internal/Families/Bool.hsdeleted−17
@@ -1,17 +0,0 @@
1−{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE KindSignatures #-}
3−{-# LANGUAGE TypeFamilies #-}
4−{-# LANGUAGE TypeOperators #-}
5−
6−module Data.Generics.Internal.Families.Bool
7− ( type (||)
8− , type (&&)
9− ) where
10−
11−type family (a :: Bool) || (b :: Bool) :: Bool where
12− 'True || _ = 'True
13− _ || b = b
14−
15−type family (a :: Bool) && (b :: Bool) :: Bool where
16− 'True && 'True = 'True
17− _ && _ = 'False
src/Data/Generics/Internal/Families/Has.hs+2−2
@@ -11,11 +11,11 @@ module Data.Generics.Internal.Families.Has
1111 , HasCtorP
1212 ) where
1313
14−import Data.Generics.Internal.Families.Bool
15−
1614import GHC.Generics
1715import GHC.TypeLits
1816
17+import Data.Type.Bool (type (||), type (&&))
18+
1919type family HasTotalFieldP (field :: Symbol) f :: Bool where
2020 HasTotalFieldP field (S1 ('MetaSel ('Just field) _ _ _) (Rec0 t))
2121 = 'True
src/Data/Generics/Product/Positions.hs+4−19
@@ -40,6 +40,8 @@ import Data.Kind
4040import GHC.Generics
4141import GHC.TypeLits
4242
43+import Data.Type.Bool (type (&&), If, Not)
44+
4345-- $example
4446-- @
4547-- module Example where
@@ -154,24 +156,7 @@ type family Size f :: Nat where
154156
155157--------------------------------------------------------------------------------
156158
157−type family Not (b :: Bool) where
158− Not 'True = 'False
159− Not 'False = 'True
160−
161−type family (<?) (x :: Nat) (y :: Nat) :: Bool where
162− x <? y = Not (y <=? x)
163−
159+type x <? y = Not (y <=? x)
164160infixl 4 <?
165161
166−type family If (c :: Bool) (x :: k) (y :: k) :: k where
167− If 'True x _ = x
168− If 'False _ y = y
169−
170−type family Min (a :: Nat) (b :: Nat) :: Nat where
171− Min a b = If (a <? b) a b
172−
173−type family (a :: Bool) && (b :: Bool) :: Bool where
174− 'True && 'True = 'True
175− _ && _ = 'False
176−
177−infix 3 &&
162+type Min a b = If (a <? b) a b