ap-reflect 0.2 → 0.3
raw patch · 4 files changed
+17/−21 lines, 4 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
- Debug.Reflect: instance Functor ((~>) a)
- Debug.Reflect: instance Show (a ~> b)
- Debug.Reflect: instance Show a => Show (Ap a)
+ Debug.Reflect: infix 6 -$-
+ Debug.Reflect: infixl 5 -*-
+ Debug.Reflect: instance GHC.Base.Functor ((Debug.Reflect.~>) a)
+ Debug.Reflect: instance GHC.Show.Show (a Debug.Reflect.~> b)
+ Debug.Reflect: instance GHC.Show.Show a => GHC.Show.Show (Debug.Reflect.Ap a)
Files
- CHANGELOG.md +4/−1
- README.md +1/−0
- ap-reflect.cabal +2/−2
- examples/examples.hs +10/−18
CHANGELOG.md view
@@ -1,4 +1,7 @@+0.3+---+* switched to new `base` (>= 4.8 && < 5)+ 0.2 --- * switched to new `base` (>= 4.7 && < 5)-
README.md view
@@ -1,5 +1,6 @@ # ap-reflect +[](http://hackage.haskell.org/package/ap-reflect) [](https://travis-ci.org/cmc-msu-ai/ap-reflect) Partial evaluation reflection a la simple-reflect.
ap-reflect.cabal view
@@ -1,5 +1,5 @@ name: ap-reflect -version: 0.2 +version: 0.3 synopsis: Partial evaluation reflection a la simple-reflect. description: The library provides a simple reflection technique, substituting functions like @fmap@ and @\<*\>@ with reflection-aware analogues. @@ -25,7 +25,7 @@ ghc-options: -Wall exposed-modules: Debug.Reflect -- other-modules: - build-depends: base >= 4.7 && < 5 + build-depends: base >= 4.8 && < 5 Source-Repository head Type: git
examples/examples.hs view
@@ -1,7 +1,7 @@ {-# LANGUAGE TypeOperators #-} import Control.Applicative -import Control.Monad.Identity +import Data.Functor.Identity import Debug.SimpleReflect import Debug.Reflect @@ -32,23 +32,16 @@ (.:) :: (Show a) => a ~> [a] ~> [a] (.:) = makeBinOp ":" (:) -sequenceA :: (Show a, Show (f a), Show (f [a]), Show (f ([a] ~> [a])), Applicative f) => [f a] -> Ap (f [a]) -sequenceA [] = pure'' [] -sequenceA (x:xs) = Val ap' :$ ((.:) -$- x) :$ sequenceA xs +sequenceA' :: (Show a, Show (f a), Show (f [a]), Show (f ([a] ~> [a])), Applicative f) => [f a] -> Ap (f [a]) +sequenceA' [] = pure'' [] +sequenceA' (x:xs) = Val ap' :$ ((.:) -$- x) :$ sequenceA' xs -traverse :: (Show a, Show b, Show (f b), Show (f [b]), Show (f ([b] ~> [b])), Applicative f) => (a -> f b) -> [a] -> Ap (f [b]) -traverse _ [] = pure'' [] -traverse f (x:xs) = Val ap' :$ (Val fmap' :$ Val (.:) :$ fx) :$ traverse f xs +traverse' :: (Show a, Show b, Show (f b), Show (f [b]), Show (f ([b] ~> [b])), Applicative f) => (a -> f b) -> [a] -> Ap (f [b]) +traverse' _ [] = pure'' [] +traverse' f (x:xs) = Val ap' :$ (Val fmap' :$ Val (.:) :$ fx) :$ traverse' f xs where fx = Val (Fn "f" f) :$ Val x -instance Show m => Show (Const m a) where - show (Const x) = "Const " ++ addParens (show x) - where addParens s = if ' ' `elem` s then parens s else s -instance Show a => Show (Identity a) where - show (Identity x) = "Identity " ++ addParens (show x) - where addParens s@(x:_) = if x /= '(' && ' ' `elem` s then parens s else s - main :: IO () main = do @@ -92,11 +85,11 @@ line let f x = if even (length x) then Just (head x) else Nothing - mapM_ print . reductions $ traverse f ["ab","cdef","gh"] + mapM_ print . reductions $ traverse' f ["ab","cdef","gh"] line - mapM_ print . reductions $ sequenceA [Just a, Just b, Just c] + mapM_ print . reductions $ sequenceA' [Just a, Just b, Just c] line - mapM_ print . reductions $ sequenceA [Just a, Nothing, Just c] + mapM_ print . reductions $ sequenceA' [Just a, Nothing, Just c] line mapM_ print . reductions $ makeBinOp "f" (+) -$- [x, y] line @@ -135,4 +128,3 @@ line mapM_ print . reductions $ (.+) -$- Left a -*- Right b line -