pointfree 1.1.1.5 → 1.1.1.6
raw patch · 5 files changed
+17/−9 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- ChangeLog +4/−0
- Main.hs +2/−1
- Plugin/Pl/Transform.hs +8/−6
- pointfree.cabal +1/−1
- test/Test.hs +2/−1
ChangeLog view
@@ -1,3 +1,7 @@+v1.1.1.6:+* Fix a bug in alpha-renaming (thanks Bertram Felgenhauer)+* Exit nonzero on parse failures (thanks meck)+ v1.1.1.5: * Metadata fixes and dependency update for base 4.12, containers 0.6, QuickCheck 2.12 (thanks Bryan Gardiner)
Main.hs view
@@ -7,6 +7,7 @@ import Plugin.Pl.Transform import System.Environment (getArgs)+import System.Exit (die) import System.Console.GetOpt data Flag = Verbose @@ -52,5 +53,5 @@ putStrLn "Optimized expression:" mapM_ (putStrLn . prettyTopLevel) $ mapTopLevel' optimize d' else putStrLn . prettyTopLevel . last . mapTopLevel' optimize $ mapTopLevel transform d- Left err -> putStrLn err+ Left err -> die err
Plugin/Pl/Transform.hs view
@@ -60,15 +60,17 @@ unLet (Lambda v e) = Lambda v (unLet e) unLet (Var f x) = Var f x -type Env = M.Map String String+type Env = (M.Map String String, Int)+-- note: The second component is the environment size, counting duplicate+-- variables. -- It's a pity we still need that for the pointless transformation. -- Otherwise a newly created id/const/... could be bound by a lambda -- e.g. transform' (\id x -> x) ==> transform' (\id -> id) ==> id alphaRename :: Expr -> Expr-alphaRename e = alpha e `evalState` M.empty where+alphaRename e = alpha e `evalState` (M.empty, 0) where alpha :: Expr -> State Env Expr- alpha (Var f v) = do fm <- get; return $ Var f $ maybe v id (M.lookup v fm)+ alpha (Var f v) = do (fm, _) <- get; return $ Var f $ maybe v id (M.lookup v fm) alpha (App e1 e2) = liftM2 App (alpha e1) (alpha e2) alpha (Let _ _) = assert False bt alpha (Lambda v e') = inEnv $ liftM2 Lambda (alphaPat v) (alpha e')@@ -78,9 +80,9 @@ inEnv f = gets $ evalState f alphaPat (PVar v) = do- fm <- get- let v' = "$" ++ show (M.size fm)- put $ M.insert v v' fm+ (fm, i) <- get+ let v' = "$" ++ show i+ put (M.insert v v' fm, i+1) return $ PVar v' alphaPat (PTuple p1 p2) = liftM2 PTuple (alphaPat p1) (alphaPat p2) alphaPat (PCons p1 p2) = liftM2 PCons (alphaPat p1) (alphaPat p2)
pointfree.cabal view
@@ -1,7 +1,7 @@ Cabal-Version: >= 1.8 Name: pointfree-Version: 1.1.1.5+Version: 1.1.1.6 Category: Tool Synopsis: Tool for refactoring expressions into pointfree form
test/Test.hs view
@@ -188,7 +188,8 @@ unitTest "\\b -> (\\c -> ((Control.Monad.>>=) c) (\\g -> Control.Applicative.pure (b g)))" ["flip (Control.Monad.>>=) . (Control.Applicative.pure .)"], unitTest "\\(x, y) -> z" ["const z"],- unitTest "\\(x, y) -> a" ["const a"]+ unitTest "\\(x, y) -> a" ["const a"],+ unitTest "\\x -> \\x y -> x" ["const const"] ] main :: IO ()