reflection-1.5.1.1: reflection.cabal
name: reflection
version: 1.5.1.1
license: BSD3
license-file: LICENSE
author: Edward A. Kmett, Elliott Hird, Oleg Kiselyov and Chung-chieh Shan
maintainer: Edward A. Kmett <ekmett@gmail.com>
stability: experimental
homepage: http://github.com/ekmett/reflection
bug-reports: http://github.com/ekmett/reflection/issues
category: Data, Reflection, Dependent Types
synopsis: Reifies arbitrary terms into types that can be reflected back into terms
copyright: 2009-2013 Edward A. Kmett,
2012 Elliott Hird,
2004 Oleg Kiselyov and Chung-chieh Shan
build-type: Simple
cabal-version: >= 1.10
description:
This package addresses the /configuration problem/ which is
propogating configurations that are available at run-time, allowing
multible configurations to coexist without resorting to mutable
global variables or 'System.IO.Unsafe.unsafePerformIO'.
.
An example is modular arithmetic where the modulus itself can be
supplied at run-time:
.
@
foo :: Modular s => Modulus s
foo = 1000 * 1000 * 5 + 2000
@
>>> withModulus 1280 foo
1040
.
given the following setup:
.
@
{-# LANGUAGE ScopedTypeVariables, RankNTypes, ConstraintKinds, FlexibleContexts, UndecidableInstances #-}
.
import Data.Proxy (Proxy(Proxy))
import Data.Reflection (Reifies, reflect, reify)
@
.
and definitions:
.
@
data Modulus s = M { getModulus :: Integer }
type Modular s = 'Data.Reflection.Reifies' s Integer
.
normalize :: forall s. Modular s => Integer -> Modulus s
normalize n = M (mod n modulus) where
  modulus = 'Data.Reflection.reflect' ('Data.Proxy.Proxy' :: 'Data.Proxy.Proxy' s)
.
instance Modular s => Num (Modulus s) where
  M a + M b = normalize (a + b)
  M a * M b = normalize (a * b)
.
withModulus :: Integer -> (forall s. Modular s => Modulus s) -> Integer
withModulus m v = 'Data.Reflection.reify' m (getModulus . asProxyOf v)
  where
  asProxyOf :: f s -> Proxy s -> f s
  asProxyOf = const
@
.
That package is an implementation of the ideas presented in the
paper \"Functional Pearl: Implicit Configurations\" by Oleg Kiselyov
and Chung-chieh Shan (<http://okmij.org/ftp/Haskell/tr-15-04.pdf original paper>). However, the API has been streamlined to improve
performance.
.
Austin Seipp's tutorial <https://www.fpcomplete.com/user/thoughtpolice/using-reflection Reflecting values to types and back> provides a summary of the
approach taken by this library, along with more motivating
examples.
extra-source-files:
examples/Monoid.hs
examples/Constraints.hs
examples/Benchmark.hs
CHANGELOG.markdown
README.markdown
slow/Data/Reflection.hs
fast/Data/Reflection.hs
.travis.yml
-- If you enable this flag, we use a more portable much much slower implementation.
-- Moreover, the 'Given' API is broken, so this is currently an unsupported configuration.
--
-- If you feel the need to turn on this flag for any reason, please email the maintainer!
flag slow
default: False
manual: False
flag th
default: True
manual: True
source-repository head
type: git
location: git://github.com/ekmett/reflection.git
library
ghc-options: -Wall
if impl(ghc >= 7.2)
default-extensions: Trustworthy
build-depends:
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
else
other-extensions: ScopedTypeVariables, FlexibleInstances
hs-source-dirs: slow
other-extensions:
MultiParamTypeClasses,
FunctionalDependencies,
Rank2Types,
CPP
exposed-modules: Data.Reflection