singleton-bool-0.1.4/0000755000000000000000000000000013254525617012647 5ustar0000000000000000singleton-bool-0.1.4/CHANGELOG.md0000644000000000000000000000050013254525617014453 0ustar0000000000000000- 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.4/LICENSE0000644000000000000000000000276213254525617013663 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.4/Setup.hs0000644000000000000000000000005613254525617014304 0ustar0000000000000000import Distribution.Simple main = defaultMain singleton-bool-0.1.4/singleton-bool.cabal0000644000000000000000000000210513254525617016564 0ustar0000000000000000name: singleton-bool version: 0.1.4 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 cabal-version: >= 1.10 tested-with: GHC==7.6.3, GHC==7.8.4, GHC==7.10.3, GHC==8.0.2, GHC==8.2.2, GHC==8.4.1 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.12 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.4/README.md0000644000000000000000000000063613254525617014133 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.4/src/0000755000000000000000000000000013254525617013436 5ustar0000000000000000singleton-bool-0.1.4/src/Data/0000755000000000000000000000000013254525617014307 5ustar0000000000000000singleton-bool-0.1.4/src/Data/Singletons/0000755000000000000000000000000013254525617016434 5ustar0000000000000000singleton-bool-0.1.4/src/Data/Singletons/Bool.hs0000644000000000000000000000651213254525617017667 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 FlexibleContexts #-} #endif -- | Additions to "Data.Type.Bool". module Data.Singletons.Bool ( SBool(..), SBoolI(..), fromSBool, withSomeSBool, reflectBool, reifyBool, -- * 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.Equality import Unsafe.Coerce (unsafeCoerce) #endif import Data.Proxy (Proxy (..)) 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 ------------------------------------------------------------------------------- -- conversion to and from explicit SBool values ------------------------------------------------------------------------------- -- | Convert an 'SBool' to the corresponding 'Bool'. -- -- @since next 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 next withSomeSBool :: Bool -> (forall b. SBool b -> r) -> r withSomeSBool True f = f STrue withSomeSBool False f = f SFalse ------------------------------------------------------------------------------- -- reify & reflect ------------------------------------------------------------------------------- -- | Reify 'Bool'. -- -- >>> 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) reflectBool :: forall b proxy. SBoolI b => proxy b -> Bool reflectBool _ = case sbool :: SBool b of STrue -> True SFalse -> False ------------------------------------------------------------------------------- -- Witnesses ------------------------------------------------------------------------------- #if MIN_VERSION_base(4,7,0) 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 (a :: k) (b :: k). SBoolI (a == b) => Maybe (a :~: b) sboolEqRefl = case sbool :: SBool (a == b) of STrue -> Just eqToRefl SFalse -> Nothing #endif