singleton-bool-0.1.5/0000755000000000000000000000000007346545000012641 5ustar0000000000000000singleton-bool-0.1.5/CHANGELOG.md0000755000000000000000000000066107346545000014460 0ustar0000000000000000- 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.5/LICENSE0000644000000000000000000000276207346545000013655 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.5/README.md0000755000000000000000000000063607346545000014130 0ustar0000000000000000# singleton-bool [![Build Status](https://travis-ci.org/phadej/singleton-bool.svg?branch=master)](https://travis-ci.org/phadej/singleton-bool) [![Hackage](https://img.shields.io/hackage/v/singleton-bool.svg)](http://hackage.haskell.org/package/singleton-bool) [![Stackage Nightly](http://stackage.org/package/singleton-bool/badge/nightly)](http://stackage.org/nightly/package/singleton-bool) Type level booleans singleton-bool-0.1.5/Setup.hs0000644000000000000000000000005607346545000014276 0ustar0000000000000000import Distribution.Simple main = defaultMain singleton-bool-0.1.5/singleton-bool.cabal0000644000000000000000000000223107346545000016556 0ustar0000000000000000cabal-version: >=1.10 name: singleton-bool version: 0.1.5 synopsis: Type level booleans description: Type level booleans. . @singletons@ package provides similar functionality, but it has tight dependency constraints. category: Web homepage: https://github.com/phadej/singleton-bool#readme bug-reports: https://github.com/phadej/singleton-bool/issues author: Oleg Grenrus maintainer: Oleg Grenrus license: BSD3 license-file: LICENSE build-type: Simple tested-with: GHC ==8.8.1 || ==8.6.5 || ==8.4.4 || ==8.2.2 || ==8.0.2 || ==7.10.3 || ==7.8.4 || ==7.6.3 extra-source-files: CHANGELOG.md README.md source-repository head type: git location: https://github.com/phadej/singleton-bool library hs-source-dirs: src ghc-options: -Wall build-depends: base >=4.6 && <4.13 if impl(ghc >= 7.8) build-depends: dec >=0.0.3 && <0.1 exposed-modules: Data.Singletons.Bool default-language: Haskell2010 if !impl(ghc >=7.8) build-depends: tagged >=0.8.5 && <0.9 singleton-bool-0.1.5/src/Data/Singletons/0000755000000000000000000000000007346545000016426 5ustar0000000000000000singleton-bool-0.1.5/src/Data/Singletons/Bool.hs0000644000000000000000000001216107346545000017656 0ustar0000000000000000{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeOperators #-} #if __GLASGOW_HASKELL__ >= 800 {-# OPTIONS_GHC -Wno-redundant-constraints #-} #endif #if MIN_VERSION_base(4,7,0) {-# LANGUAGE EmptyCase #-} {-# LANGUAGE FlexibleContexts #-} #endif -- | Additions to "Data.Type.Bool". module Data.Singletons.Bool ( SBool(..), SBoolI(..), fromSBool, withSomeSBool, reflectBool, reifyBool, -- * Data.Type.Dec #if MIN_VERSION_base(4,7,0) -- | 'discreteBool' is available with @base >= 4.7@ (GHC-7.8) discreteBool, #endif -- * Data.Type.Bool and .Equality -- | These are only defined with @base >= 4.7@ #if MIN_VERSION_base(4,7,0) sboolAnd, sboolOr, sboolNot, eqToRefl, eqCast, sboolEqRefl, trivialRefl, #endif ) where #if MIN_VERSION_base(4,7,0) import Data.Type.Bool import Data.Type.Dec (Dec (..)) import Data.Type.Equality import Unsafe.Coerce (unsafeCoerce) #endif import Data.Proxy (Proxy (..)) -- $setup -- >>> :set -XDataKinds -XTypeOperators -- >>> import Data.Type.Dec (decShow) 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 ------------------------------------------------------------------------------- -- 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) ------------------------------------------------------------------------------- -- Discrete ------------------------------------------------------------------------------- #if MIN_VERSION_base(4,7,0) -- | 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 #endif ------------------------------------------------------------------------------- -- Witnesses ------------------------------------------------------------------------------- #if MIN_VERSION_base(4,7,0) -- | >>> 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 -- GHC 8.10+ requires that all kind variables be explicitly quantified after -- a `forall`. Technically, GHC has had the ability to do this since GHC 8.0, -- but GHC 8.0-8.4 require enabling TypeInType to do. To avoid having to faff -- around with CPP to enable TypeInType on certain GHC versions, we only -- explicitly quantify kind variables on GHC 8.6 or later, since those versions -- do not require TypeInType, only PolyKinds. # if __GLASGOW_HASKELL__ >= 806 # define KVS(kvs) kvs # else # define KVS(kvs) # endif -- | Useful combination of 'sbool' and 'eqToRefl' -- -- @since 0.1.2.0 sboolEqRefl :: forall KVS(k) (a :: k) (b :: k). SBoolI (a == b) => Maybe (a :~: b) sboolEqRefl = case sbool :: SBool (a == b) of STrue -> Just eqToRefl SFalse -> Nothing #endif