reflection 1.4 → 1.5.1
raw patch · 4 files changed
+50/−15 lines, 4 files
Files
- CHANGELOG.markdown +7/−0
- README.markdown +1/−1
- fast/Data/Reflection.hs +28/−10
- reflection.cabal +14/−4
CHANGELOG.markdown view
@@ -1,3 +1,10 @@+# 1.5.1+* We no longer export Show (Q a) for GHC >= 7.4. This was causing random hangs when users tried to somehow run declaration splices from the REPL.+* We no longer depend on tagged for GHC >= 7.8, since `Proxy` is now in `base`.++# 1.5+* Added a flag to disable `template-haskell` support for GHC stage1 platforms.+* Added instances of `Reifies` for `GHC.TypeLits` # 1.4 * Changed the behavior of the $(1) template haskell splices for Exp to use a Proxy rather than value-level numbers. This is more consistent with the role of this libraary and the other could always be generated via sa splice anyways.
README.markdown view
@@ -1,7 +1,7 @@ reflection ========== -[](http://travis-ci.org/ekmett/reflecton)+[](http://travis-ci.org/ekmett/reflection) This package provides an implementation of the ideas presented in [Functional Pearl: Implicit Configurations](http://www.cs.rutgers.edu/~ccshan/prepose/prepose.pdf) by Oleg Kiselyov and Chung-Chieh Shan. However, the API has been implemented in a much more efficient manner.
fast/Data/Reflection.hs view
@@ -1,19 +1,22 @@-{-# LANGUAGE PatternGuards #-} {-# LANGUAGE CPP #-}+{-# LANGUAGE EmptyDataDecls #-} {-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE PatternGuards #-} {-# LANGUAGE Rank2Types #-} {-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE EmptyDataDecls #-}-{-# LANGUAGE TemplateHaskell #-} #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 706 {-# LANGUAGE DataKinds #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE TypeOperators #-} #define USE_TYPE_LITS 1 #endif+#ifdef TEMPLATE_HASKELL+{-# LANGUAGE TemplateHaskell #-}+#endif {-# OPTIONS_GHC -fno-warn-orphans #-} ---------------------------------------------------------------------------- -- |@@ -58,21 +61,25 @@ -- * Given , Given(..) , give+#ifdef TEMPLATE_HASKELL -- * Template Haskell reflection , int, nat+#endif -- * Useful compile time naturals , Z, D, SD, PD ) where -import Control.Monad import Data.Functor import Data.Proxy -#ifdef USE_TYPE_LITS+#if (defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 707) || (TEMPLATE_HASKELL && USE_TYPE_LITS) import GHC.TypeLits #endif +#ifdef TEMPLATE_HASKELL import Language.Haskell.TH hiding (reify)+import Control.Monad+#endif #ifdef __HUGS__ import Hugs.IOExts@@ -80,7 +87,6 @@ import Unsafe.Coerce #endif - ------------------------------------------------------------------------------ -- Reifies ------------------------------------------------------------------------------@@ -97,6 +103,14 @@ reify a k = unsafeCoerce (Magic k :: Magic a r) (const a) Proxy {-# INLINE reify #-} +#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 707+instance KnownNat n => Reifies n Integer where+ reflect = natVal++instance KnownSymbol n => Reifies n String where+ reflect = symbolVal+#endif+ ------------------------------------------------------------------------------ -- Given ------------------------------------------------------------------------------@@ -152,6 +166,7 @@ reflect = (\n -> n + n - 1) <$> retagPD reflect {-# INLINE reflect #-} +#ifdef TEMPLATE_HASKELL -- | This can be used to generate a template haskell splice for a type level version of a given 'int'. -- -- This does not use GHC TypeLits, instead it generates a numeric type by hand similar to the ones used@@ -177,9 +192,11 @@ | n >= 0 = int n | otherwise = error "nat: negative" -#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL < 704-instance Show (Q a)-instance Eq (Q a)+#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ < 704+instance Show (Q a) where+ show _ = "Q"+instance Eq (Q a) where+ _ == _ = False #endif instance Num a => Num (Q a) where (+) = liftM2 (+)@@ -223,7 +240,6 @@ abs = error "Type.abs" signum = error "Type.signum" - onProxyType1 :: (Type -> Type) -> (Exp -> Exp) onProxyType1 f (SigE _ ta@(AppT (ConT proxyName) (VarT _)))@@ -275,4 +291,6 @@ mulProxy _ _ = error "Exp.(*): undefined" subProxy :: Proxy a -> Proxy b -> Proxy c subProxy _ _ = error "Exp.(-): undefined"+#endif+ #endif
reflection.cabal view
@@ -1,5 +1,5 @@ name: reflection-version: 1.4+version: 1.5.1 license: BSD3 license-file: LICENSE author: Edward A. Kmett, Elliott Hird, Oleg Kiselyov and Chung-chieh Shan@@ -44,6 +44,10 @@ default: False manual: False +flag th+ default: True+ manual: True+ source-repository head type: git location: git://github.com/ekmett/reflection.git@@ -55,11 +59,17 @@ default-extensions: Trustworthy build-depends:- base >= 2 && < 5,- tagged >= 0.4.4 && < 1,- template-haskell+ base >= 2 && < 5 + if impl(ghc < 7.8)+ build-depends:+ tagged >= 0.4.4 && < 1+ default-language: Haskell98++ if flag(th) && impl(ghc)+ cpp-options: -DTEMPLATE_HASKELL+ build-depends: template-haskell if !flag(slow) && (impl(ghc) || impl(hugs)) hs-source-dirs: fast