packages feed

reflection 1.5.2 → 1.5.2.1

raw patch · 1 files changed

+4/−45 lines, 1 files

Files

reflection.cabal view
@@ -1,5 +1,5 @@ name:           reflection-version:        1.5.2+version:        1.5.2.1 license:        BSD3 license-file:   LICENSE author:         Edward A. Kmett, Elliott Hird, Oleg Kiselyov and Chung-chieh Shan@@ -20,54 +20,13 @@   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:-  .-  @-    &#123;-# LANGUAGE ScopedTypeVariables, RankNTypes, ConstraintKinds, FlexibleContexts, UndecidableInstances #-&#125;-  .-    import Data.Proxy      (Proxy(Proxy))-    import Data.Reflection (Reifies, reflect, reify)-  @-  .-  and definitions:-  .-  @-    data Modulus s = M &#123; getModulus :: Integer &#125;-    type Modular s = 'Data.Reflection.Reifies' s Integer-  .-    normalize :: forall s. Modular s => Integer -> Modulus s-    normalize n = M (mod n modulus) where-    &#x20;  modulus = 'Data.Reflection.reflect' ('Data.Proxy.Proxy' :: 'Data.Proxy.Proxy' s)-  .-    instance Modular s => Num (Modulus s) where-    &#x20;  M a + M b = normalize (a + b)-    &#x20;  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)-    &#x20;  where-    &#x20;  asProxyOf :: f s -> Proxy s -> f s-    &#x20;  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.+  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.+  approach taken by this library, along with more motivating examples.  extra-source-files:   examples/Monoid.hs