packages feed

reflection 0.0.0 → 0.1.0

raw patch · 2 files changed

+23/−23 lines, 2 files

Files

Data/Reflection.hs view
@@ -23,18 +23,18 @@ module Data.Reflection      (      -- * Reflect Integrals-      ReflectNum+      ReflectedNum     , reflectNum     , reifyIntegral     -- * Reflect Lists of Integrals-    , ReflectNums+    , ReflectedNums     , reifyIntegrals     -- * Reflect Storables-    , ReflectStorable+    , ReflectedStorable     , reflectStorable     , reifyStorable     -- * Reflect Anything-    , Reflect+    , Reflects     , reflect     , reify     ) where@@ -53,22 +53,22 @@ data Succ s data Pred s -class ReflectNum s where+class ReflectedNum s where     reflectNum :: Num a => s -> a -instance ReflectNum Zero where+instance ReflectedNum Zero where     reflectNum _ = 0 -instance ReflectNum s => ReflectNum (Twice s) where+instance ReflectedNum s => ReflectedNum (Twice s) where     reflectNum _ = reflectNum (undefined :: s) * 2 -instance ReflectNum s => ReflectNum (Succ s) where+instance ReflectedNum s => ReflectedNum (Succ s) where     reflectNum _ = reflectNum (undefined :: s) + 1 -instance ReflectNum s => ReflectNum (Pred s) where+instance ReflectedNum s => ReflectedNum (Pred s) where     reflectNum _ = reflectNum (undefined :: s) - 1 -reifyIntegral :: Integral a => a -> (forall s. ReflectNum s => s -> w) -> w+reifyIntegral :: Integral a => a -> (forall s. ReflectedNum s => s -> w) -> w reifyIntegral i k = case quotRem i 2 of     (0, 0) -> k (undefined :: Zero)     (j, 0) -> reifyIntegral j (\(_ :: s) -> k (undefined :: Twice s))@@ -79,16 +79,16 @@ data Nil data Cons s ss -class ReflectNums ss where+class ReflectedNums ss where     reflectNums :: Num a => ss -> [a] -instance ReflectNums Nil where+instance ReflectedNums Nil where     reflectNums _ = [] -instance (ReflectNum s, ReflectNums ss) => ReflectNums (Cons s ss) where+instance (ReflectedNum s, ReflectedNums ss) => ReflectedNums (Cons s ss) where     reflectNums _ = reflectNum (undefined :: s) : reflectNums (undefined :: ss) -reifyIntegrals :: Integral a => [a] -> (forall ss. ReflectNums ss => ss -> w) -> w+reifyIntegrals :: Integral a => [a] -> (forall ss. ReflectedNums ss => ss -> w) -> w reifyIntegrals [] k = k (undefined :: Nil) reifyIntegrals (i:ii) k =      reifyIntegral i (\(_ :: s) -> @@ -97,10 +97,10 @@  data Store s a  -class ReflectStorable s where+class ReflectedStorable s where     reflectStorable :: Storable a => s a -> a -instance ReflectNums s => ReflectStorable (Store s) where+instance ReflectedNums s => ReflectedStorable (Store s) where     {-# NOINLINE reflectStorable #-}     reflectStorable _ = unsafePerformIO . alloca $ \p -> do              pokeArray (castPtr p) bytes@@ -108,28 +108,28 @@         where              bytes = reflectNums (undefined :: s) :: [CChar] -reifyStorable :: Storable a => a -> (forall s. ReflectStorable s => s a -> w) -> w+reifyStorable :: Storable a => a -> (forall s. ReflectedStorable s => s a -> w) -> w reifyStorable a k = reifyIntegrals (bytes :: [CChar]) (\(_ :: s) -> k (undefined :: Store s a))   where     bytes = unsafePerformIO $ with a (peekArray (sizeOf a) . castPtr)  {-# NOINLINE reifyStorable #-} -class Reflect s a | s -> a where +class Reflects s a | s -> a where      reflect :: s -> a  data Stable (s :: * -> *) a  {--instance ReflectStorable s => Reflect (Stable s a) a where+instance ReflectedStorable s => Reflects (Stable s a) a where     reflect = unsafePerformIO . fmap const . deRefStablePtr $ reflectStorable (undefined :: s p)  -reify :: a -> (forall s. Reflect s a => s -> w) -> w+reify :: a -> (forall s. Reflects s a => s -> w) -> w reify (a :: a) k = unsafePerformIO $ do         p <- newStablePtr a         reifyStorable p (\(_ :: s (StablePtr a)) -> return (k (undefined :: Stable s a))) -} -instance ReflectStorable s => Reflect (Stable s a) a where+instance ReflectedStorable s => Reflects (Stable s a) a where     reflect = unsafePerformIO $ do             a <- deRefStablePtr p             freeStablePtr p@@ -138,7 +138,7 @@             p = reflectStorable (undefined :: s p)     {-# NOINLINE reflect #-} -reify :: a -> (forall s. Reflect s a => s -> w) -> w+reify :: a -> (forall s. (s `Reflects` a) => s -> w) -> w reify (a :: a) k = unsafePerformIO $ do         p <- newStablePtr a         reifyStorable p (\(_ :: s (StablePtr a)) -> 
reflection.cabal view
@@ -1,5 +1,5 @@ name:		    reflection-version:	    0.0.0+version:	    0.1.0 license:	    BSD3 license-file:   LICENSE author:		    Oleg Kiselyov and Chung-chieh Shan