reflection: Reifies arbitrary terms into types that can be reflected back into terms

[ bsd3, data, dependent-types, library, reflection ] [ Propose Tags ]
Versions 0.0.0, 0.1.0, 0.1.1, 0.2.0, 0.3.0, 0.3.1, 0.3.2, 0.3.3, 0.3.5, 0.4.0,,, 0.4.1,, 0.5,, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.1.5,, 1.1.6, 1.1.7,, 1.3, 1.3.1, 1.3.2, 1.4, 1.5.1,,, 1.5.2,, 2, 2.1, 2.1.1,, 2.1.2, 2.1.3
Change log CHANGELOG.markdown
Dependencies base (>=2 && <5), tagged (>=0.4.4 && <1), template‑haskell [details]
License BSD-3-Clause
Copyright 2009-2013 Edward A. Kmett, 2012 Elliott Hird, 2004 Oleg Kiselyov and Chung-chieh Shan
Author Edward A. Kmett, Elliott Hird, Oleg Kiselyov and Chung-chieh Shan
Maintainer Edward A. Kmett <>
Category Data, Reflection, Dependent Types
Home page
Bug tracker
Source repo head: git clone git://
Uploaded by EdwardKmett at Sun Mar 8 09:08:45 UTC 2015
Distributions Arch:2.1.3, Debian:, Fedora:2.1.2, FreeBSD:2, LTSHaskell:2.1.3, NixOS:2.1.3, Stackage:2.1.3, openSUSE:2.1.3
Downloads 151974 total (388 in the last 30 days)
Rating 2.25 (votes: 2) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2015-03-08 [all 1 reports]
Hackage Matrix CI

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

given the following setup:


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)
   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 (original paper). However, the API has been streamlined to improve performance.

Austin Seipp's tutorial Reflecting values to types and back provides a summary of the approach taken by this library, along with more motivating examples.

[Skip to Readme]





Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info


Maintainer's Corner

For package maintainers and hackage trustees

Readme for reflection-

[back to package description]


Build Status

This package provides an implementation of the ideas presented in Functional Pearl: Implicit Configurations by Oleg Kiselyov and Chung-Chieh Shan. However, the API has been implemented in a much more efficient manner.

Contact Information

Contributions and bug reports are welcome!

Please feel free to contact me through github or on the #haskell IRC channel on

-Edward Kmett