singleton-bool 0.1.2.0 → 0.1.3
raw patch · 3 files changed
+41/−10 lines, 3 filesdep +taggeddep ~base
Dependencies added: tagged
Dependency ranges changed: base
Files
- CHANGELOG.md +4/−0
- singleton-bool.cabal +12/−7
- src/Data/Singletons/Bool.hs +25/−3
CHANGELOG.md view
@@ -1,3 +1,7 @@+- 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)`
singleton-bool.cabal view
@@ -1,9 +1,5 @@--- This file has been generated from package.yaml by hpack version 0.14.1.------ see: https://github.com/sol/hpack- name: singleton-bool-version: 0.1.2.0+version: 0.1.3 synopsis: Type level booleans description: Type level booleans. .@@ -16,9 +12,15 @@ maintainer: Oleg Grenrus <oleg.grenrus@iki.fi> license: BSD3 license-file: LICENSE-tested-with: GHC==7.4.2, GHC==7.6.3, GHC==7.8.4, GHC==7.10.3, GHC==8.0.1 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@@ -33,7 +35,10 @@ src ghc-options: -Wall build-depends:- base >=4.5 && <4.10+ base >=4.6 && <4.11 exposed-modules: Data.Singletons.Bool default-language: Haskell2010++ if !impl(ghc >= 7.8)+ build-depends: tagged >= 0.8.5 && <0.9
src/Data/Singletons/Bool.hs view
@@ -2,20 +2,22 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE KindSignatures #-}+{-# LANGUAGE PolyKinds #-}+{-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeOperators #-}-#if __GLASGOW_HASKELL__ >= 706-{-# LANGUAGE PolyKinds #-}-#endif #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(..),+ reflectBool,+ reifyBool, -- * Data.Type.Bool and .Equality -- | These are only defined with @base >= 4.7@ #if MIN_VERSION_base(4,7,0)@@ -31,6 +33,8 @@ import Unsafe.Coerce (unsafeCoerce) #endif +import Data.Proxy (Proxy (..))+ data SBool (b :: Bool) where STrue :: SBool 'True SFalse :: SBool 'False@@ -38,6 +42,24 @@ class SBoolI (b :: Bool) where sbool :: SBool b instance SBoolI 'True where sbool = STrue instance SBoolI 'False where sbool = 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