singleton-bool-0.1.8/0000755000000000000000000000000007346545000012644 5ustar0000000000000000singleton-bool-0.1.8/CHANGELOG.md0000644000000000000000000000120707346545000014455 0ustar0000000000000000- 0.1.8 - Support GHC-8.6.5...9.10.1 - 0.1.7 - Add EqP and OrdP instances - 0.1.6 - Add `boring` instances - Add `some` (`GEq` etc) instances - Add `deepseq` instances - Require GHC-7.8+ - 0.1.5 - Add `discreteBool :: Dec (a :~: b)` (GHC-7.8+) - Add `Show`, `Eq`, `Ord` `SBool b` instances. - 0.1.4 - Add `fromSBool` and `withSomeSBool`. - 0.1.3.0 - Add `reifyBool` and `reflectBool`. - Drop GHC-7.4 support (broken `PolyKinds`) - 0.1.2.0 - Enable `PolyKinds` on GHC >= 7.6 - Add `sboolEqRefl :: SBoolI (a == b) => Maybe (a :~: b)` - 0.1.1.0 - Add `eqToRefl`, `eqCast`, `trivialRefl` singleton-bool-0.1.8/LICENSE0000644000000000000000000000276207346545000013660 0ustar0000000000000000Copyright (c) 2016, Oleg Grenrus All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Oleg Grenrus nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. singleton-bool-0.1.8/Setup.hs0000644000000000000000000000005607346545000014301 0ustar0000000000000000import Distribution.Simple main = defaultMain singleton-bool-0.1.8/singleton-bool.cabal0000644000000000000000000000226707346545000016572 0ustar0000000000000000cabal-version: 2.2 name: singleton-bool version: 0.1.8 synopsis: Type level booleans description: Type level booleans. . @singletons@ package provides similar functionality, but it has tight dependency constraints. category: Dependent Types homepage: https://github.com/phadej/singleton-bool#readme bug-reports: https://github.com/phadej/singleton-bool/issues author: Oleg Grenrus maintainer: Oleg Grenrus license: BSD-3-Clause license-file: LICENSE build-type: Simple extra-source-files: CHANGELOG.md tested-with: GHC ==8.6.5 || ==8.8.4 || ==8.10.7 || ==9.0.2 || ==9.2.8 || ==9.4.8 || ==9.6.5 || ==9.8.2 || ==9.10.1 source-repository head type: git location: https://github.com/phadej/singleton-bool library hs-source-dirs: src ghc-options: -Wall build-depends: , base >=4.12.0.0 && <4.21 , deepseq >=1.4.4.0 && <1.6 build-depends: , boring ^>=0.2.2 , dec ^>=0.0.6 , some ^>=1.0.6 exposed-modules: Data.Singletons.Bool default-language: Haskell2010 singleton-bool-0.1.8/src/Data/Singletons/0000755000000000000000000000000007346545000016431 5ustar0000000000000000singleton-bool-0.1.8/src/Data/Singletons/Bool.hs0000644000000000000000000001516507346545000017670 0ustar0000000000000000{-# LANGUAGE DataKinds #-} {-# LANGUAGE EmptyCase #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeOperators #-} {-# OPTIONS_GHC -Wno-redundant-constraints #-} -- | Additions to "Data.Type.Bool". module Data.Singletons.Bool ( SBool(..), SBoolI(..), fromSBool, withSomeSBool, reflectBool, reifyBool, -- * Data.Type.Dec -- | 'discreteBool' is available with @base >= 4.7@ (GHC-7.8) discreteBool, -- * Data.Type.Bool and .Equality -- | These are only defined with @base >= 4.7@ sboolAnd, sboolOr, sboolNot, eqToRefl, eqCast, sboolEqRefl, trivialRefl, ) where import Control.DeepSeq (NFData (..)) import Data.Boring (Boring (..)) import Data.GADT.Compare (GCompare (..), GEq (..), GOrdering (..)) import Data.GADT.DeepSeq (GNFData (..)) import Data.GADT.Show (GRead (..), GShow (..)) import Data.Proxy (Proxy (..)) import Data.Type.Bool import Data.Type.Dec (Dec (..)) import Data.Type.Equality import Unsafe.Coerce (unsafeCoerce) import Data.EqP (EqP (..)) import Data.OrdP (OrdP (..)) import qualified Data.Some.Church as Church -- $setup -- >>> :set -XDataKinds -XTypeOperators -- >>> import Data.Proxy (Proxy (..)) -- >>> import Data.Type.Dec -- >>> import Data.Some -- >>> import Data.GADT.Compare -- >>> import Data.GADT.Show -- >>> import Data.Type.Equality data SBool (b :: Bool) where STrue :: SBool 'True SFalse :: SBool 'False class SBoolI (b :: Bool) where sbool :: SBool b instance SBoolI 'True where sbool = STrue instance SBoolI 'False where sbool = SFalse -- | @since 0.1.5 instance Show (SBool b) where showsPrec _ STrue = showString "STrue" showsPrec _ SFalse = showString "SFalse" -- | @since 0.1.5 instance Eq (SBool b) where _ == _ = True -- | @since 0.1.5 instance Ord (SBool b) where compare _ _ = EQ -- | @since 0.1.6 instance NFData (SBool b) where rnf STrue = () rnf SFalse = () ------------------------------------------------------------------------------- -- conversion to and from explicit SBool values ------------------------------------------------------------------------------- -- | Convert an 'SBool' to the corresponding 'Bool'. -- -- @since 0.1.4 fromSBool :: SBool b -> Bool fromSBool STrue = True fromSBool SFalse = False -- | Convert a normal 'Bool' to an 'SBool', passing it into a continuation. -- -- >>> withSomeSBool True fromSBool -- True -- -- @since 0.1.4 withSomeSBool :: Bool -> (forall b. SBool b -> r) -> r withSomeSBool True f = f STrue withSomeSBool False f = f SFalse ------------------------------------------------------------------------------- -- reify & reflect ------------------------------------------------------------------------------- -- | Reify 'Bool' to type-level. -- -- >>> reifyBool True reflectBool -- True -- reifyBool :: forall r. Bool -> (forall b. SBoolI b => Proxy b -> r) -> r reifyBool True f = f (Proxy :: Proxy 'True) reifyBool False f = f (Proxy :: Proxy 'False) -- | Reflect to term-level. -- -- >>> reflectBool (Proxy :: Proxy 'True) -- True reflectBool :: forall b proxy. SBoolI b => proxy b -> Bool reflectBool _ = fromSBool (sbool :: SBool b) ------------------------------------------------------------------------------- -- Boring ------------------------------------------------------------------------------- -- | @since 0.1.6 instance SBoolI b => Boring (SBool b) where boring = sbool ------------------------------------------------------------------------------- -- Data.GADT (some) ------------------------------------------------------------------------------- -- | -- -- >>> geq STrue STrue -- Just Refl -- -- >>> geq STrue SFalse -- Nothing -- -- @since 0.1.6 instance GEq SBool where geq STrue STrue = Just Refl geq SFalse SFalse = Just Refl geq _ _ = Nothing -- | -- -- @since 0.1.6 instance GCompare SBool where gcompare SFalse SFalse = GEQ gcompare SFalse STrue = GLT gcompare STrue SFalse = GGT gcompare STrue STrue = GEQ -- | @since 0.1.6 instance GNFData SBool where grnf STrue = () grnf SFalse = () -- | -- -- >>> showsPrec 0 STrue "" -- "STrue" -- -- @since 0.1.6 instance GShow SBool where gshowsPrec = showsPrec -- | -- -- >>> readsPrec 0 "Some STrue" :: [(Some SBool, String)] -- [(Some STrue,"")] -- -- >>> readsPrec 0 "Some SFalse" :: [(Some SBool, String)] -- [(Some SFalse,"")] -- -- >>> readsPrec 0 "Some Else" :: [(Some SBool, String)] -- [] -- -- @since 0.1.6 instance GRead SBool where greadsPrec _ s = [ (Church.mkSome STrue, t) | ("STrue", t) <- lex s ] ++ [ (Church.mkSome SFalse, t) | ("SFalse", t) <- lex s ] -- | @since 0.1.7 instance EqP SBool where eqp STrue STrue = True eqp SFalse SFalse = True eqp _ _ = False -- | @since 0.1.7 instance OrdP SBool where comparep STrue STrue = EQ comparep SFalse SFalse = EQ comparep STrue SFalse = GT comparep SFalse STrue = LT ------------------------------------------------------------------------------- -- Discrete ------------------------------------------------------------------------------- -- | Decidable equality. -- -- >>> decShow (discreteBool :: Dec ('True :~: 'True)) -- "Yes Refl" -- -- @since 0.1.5 discreteBool :: forall a b. (SBoolI a, SBoolI b) => Dec (a :~: b) discreteBool = case (sbool :: SBool a, sbool :: SBool b) of (STrue, STrue) -> Yes Refl (STrue, SFalse) -> No $ \p -> case p of {} (SFalse, STrue) -> No $ \p -> case p of {} (SFalse, SFalse) -> Yes Refl ------------------------------------------------------------------------------- -- Witnesses ------------------------------------------------------------------------------- -- | >>> sboolAnd STrue SFalse -- SFalse sboolAnd :: SBool a -> SBool b -> SBool (a && b) sboolAnd SFalse _ = SFalse sboolAnd STrue b = b sboolOr :: SBool a -> SBool b -> SBool (a || b) sboolOr STrue _ = STrue sboolOr SFalse b = b sboolNot :: SBool a -> SBool (Not a) sboolNot STrue = SFalse sboolNot SFalse = STrue -- | @since 0.1.1.0 eqToRefl :: (a == b) ~ 'True => a :~: b eqToRefl = unsafeCoerce trivialRefl -- | @since 0.1.1.0 eqCast :: (a == b) ~ 'True => a -> b eqCast = unsafeCoerce -- | @since 0.1.1.0 trivialRefl :: () :~: () trivialRefl = Refl -- | Useful combination of 'sbool' and 'eqToRefl' -- -- @since 0.1.2.0 sboolEqRefl :: forall k (a :: k) (b :: k). SBoolI (a == b) => Maybe (a :~: b) sboolEqRefl = case sbool :: SBool (a == b) of STrue -> Just eqToRefl SFalse -> Nothing