The reflection package

[Tags: bsd3, library]

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.


Properties

Versions0.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.0.1, 0.4.0.2, 0.4.1, 0.4.1.1, 0.5, 0.5.0.1, 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.5.1, 1.1.6, 1.1.7, 1.2.0.1, 1.3, 1.3.1, 1.3.2, 1.4, 1.5.1, 1.5.1.1, 1.5.1.2
Dependenciesbase (>=2 && <5), tagged (>=0.4.4 && <1), template-haskell
LicenseBSD3
Copyright2009-2013 Edward A. Kmett, 2012 Elliott Hird, 2004 Oleg Kiselyov and Chung-chieh Shan
AuthorEdward A. Kmett, Elliott Hird, Oleg Kiselyov and Chung-chieh Shan
MaintainerEdward A. Kmett <ekmett@gmail.com>
Stabilityexperimental
CategoryData, Reflection, Dependent Types
Home pagehttp://github.com/ekmett/reflection
Bug trackerhttp://github.com/ekmett/reflection/issues
Source repositoryhead: git clone git://github.com/ekmett/reflection.git
UploadedSun Mar 8 09:08:45 UTC 2015 by EdwardKmett
DistributionsDebian:1.2.0.1, Fedora:1.5.1, FreeBSD:1.5.1, LTSHaskell:1.5.1.2, NixOS:1.5.1.2, Stackage:1.5.1.2
Downloads86140 total (1031 in last 30 days)
StatusDocs available [build log]
Last success reported on 2015-03-08 [all 1 reports]

Modules

[Index]

Flags

NameDescriptionDefault
slowDisabled
thEnabled

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

Downloads

Maintainers' corner

For package maintainers and hackage trustees