pointfree 1.0.4.8 → 1.1
raw patch · 8 files changed
+77/−17 lines, 8 filesdep ~QuickCheckdep ~base
Dependency ranges changed: QuickCheck, base
Files
- ChangeLog +8/−0
- Main.hs +12/−4
- Plugin/Pl/Common.hs +1/−4
- Plugin/Pl/PrettyPrinter.hs +2/−1
- Pointfree.hs +31/−0
- README +1/−2
- pointfree.cabal +19/−4
- test/Test.hs +3/−2
ChangeLog view
@@ -1,3 +1,11 @@+v1.1:+* Drop support for GHC 7.0 and 7.2 (actually already lost with HSE 1.16)+* Add support for GHC 7.10.1+* Expose the string -> string transformation as a library (thanks Taylor Fausak)+* Add --stdin flag to enable reading from stdin (thanks Martin Zeller)+* Support some Unicode operators+* Dependency update for QuickCheck 2.9+ v1.0.4.8: * Dependency update for HSE 1.16 and transformers 0.5
Main.hs view
@@ -10,10 +10,13 @@ import System.Console.GetOpt data Flag = Verbose + | StdIn deriving Eq options :: [OptDescr Flag]-options = [ Option ['v'] ["verbose"] (NoArg Verbose) "verbose results"]+options = [ Option ['v'] ["verbose"] (NoArg Verbose) "verbose results"+ , Option [] ["stdin"] (NoArg StdIn) "read from stdin"+ ] header :: String header = "Usage: pointfree [OPTION...] query"@@ -24,14 +27,19 @@ (flags, nonOptions, []) -> return (flags, nonOptions) (_, _, errs) -> ioError (userError (concat errs ++ usageInfo header options)) +getQuery :: [Flag] -> [String] -> IO String+getQuery flags nonOptions+ | StdIn `elem` flags = getLine+ | otherwise = return $ unwords nonOptions+ main :: IO () main = do args <- getArgs (flags, nonOptions) <- parseArgs args- if null nonOptions+ query <- getQuery flags nonOptions+ if null query then putStrLn $ usageInfo header options- else let query = concat $ intersperse " " nonOptions- verbose = Verbose `elem` flags+ else let verbose = Verbose `elem` flags in pf query verbose pf :: String -> Bool -> IO ()
Plugin/Pl/Common.hs view
@@ -1,7 +1,7 @@ module Plugin.Pl.Common ( Fixity(..), Expr(..), Pattern(..), Decl(..), TopLevel(..), bt, sizeExpr, mapTopLevel, mapTopLevel', getExpr,- operators, opchars, reservedOps, lookupOp, lookupFix, minPrec, maxPrec,+ operators, reservedOps, lookupOp, lookupFix, minPrec, maxPrec, comp, flip', id', const', scomb, cons, nil, fix', if', readM, makeList, getList, Assoc(..),@@ -121,9 +121,6 @@ [inf name AssocRight 0 | name <- ["$", "$!", "`seq`"]] ] where inf name assoc fx = (name, (assoc, fx))--opchars :: [Char]-opchars = "!@#$%^*./|=-+:?<>&" reservedOps :: [String] reservedOps = ["->", "..", "="]
Plugin/Pl/PrettyPrinter.hs view
@@ -7,6 +7,7 @@ import Plugin.Pl.Common +import Data.Char import Data.List (intercalate) prettyDecl :: Decl -> String@@ -126,7 +127,7 @@ prettyPrecPattern 6 p1 . (':':) . prettyPrecPattern 5 p2 isOperator :: String -> Bool-isOperator = all (`elem` opchars)+isOperator s = s /= "()" && all (\c -> isSymbol c || isPunctuation c) s getInfName :: String -> String getInfName str = if isOperator str then str else "`"++str++"`"
+ Pointfree.hs view
@@ -0,0 +1,31 @@+module Pointfree where++import Plugin.Pl.Common (mapTopLevel, mapTopLevel')+import Plugin.Pl.Optimize (optimize)+import Plugin.Pl.Parser (parsePF)+import Plugin.Pl.PrettyPrinter (prettyTopLevel)+import Plugin.Pl.Transform (transform)++import Data.Maybe (listToMaybe)++{- |+ >>> pointfree "I'm not a valid Haskell expression!"+ []+ >>> pointfree "sum xs = foldr (+) 0 xs"+ ["sum = id (fix (const (foldr (+) 0)))","sum = fix (const (foldr (+) 0))","sum = foldr (+) 0"]+-}+pointfree :: String -> [String]+pointfree+ = either+ (const [])+ (map prettyTopLevel . mapTopLevel' optimize . mapTopLevel transform)+ . parsePF++{- |+ >>> pointfree' "I'm not a valid Haskell expression!"+ Nothing+ >>> pointfree' "sum xs = foldr (+) 0 xs"+ Just "sum = foldr (+) 0"+-}+pointfree' :: String -> Maybe String+pointfree' = listToMaybe . reverse . pointfree
README view
@@ -19,5 +19,4 @@ Future directions ================= -It would be nice to make pointfree a library that operated on ASTs, or at the -very least on strings.+It would be nice to make pointfree a library that operated on ASTs.
pointfree.cabal view
@@ -1,7 +1,7 @@ Cabal-Version: >= 1.8 Name: pointfree-Version: 1.0.4.8+Version: 1.1 Category: Tool Synopsis: Tool for refactoring expressions into pointfree form @@ -17,12 +17,27 @@ Extra-source-files: ChangeLog README test/Test.hs Build-type: Simple-Tested-with: GHC == 7.0.4, GHC == 7.2.2, GHC == 7.4.2, GHC == 7.6.2+Tested-with: GHC == 7.4.2, GHC == 7.6.2, GHC == 7.8.2, GHC == 7.10.1 Source-repository head type: git location: git://github.com/benmachine/pointfree.git +library+ Exposed-modules: Pointfree+ Build-depends: base >= 4.5 && < 4.9,+ array >= 0.3 && < 0.6,+ containers >= 0.4 && < 0.6,+ haskell-src-exts == 1.16.*,+ transformers < 0.5+ Other-modules: Plugin.Pl.Common+ Plugin.Pl.Parser+ Plugin.Pl.PrettyPrinter+ Plugin.Pl.Optimize+ Plugin.Pl.Rules+ Plugin.Pl.Transform+ GHC-options: -Wall+ Executable pointfree Main-is: Main.hs GHC-options: -Wall@@ -31,7 +46,7 @@ ImplicitParams, PatternGuards, ScopedTypeVariables- Build-depends: base >= 4.3 && < 4.8,+ Build-depends: base >= 4.3 && < 4.9, array >= 0.3 && < 0.6, containers >= 0.4 && < 0.6, haskell-src-exts == 1.16.*,@@ -55,7 +70,7 @@ containers >= 0.3 && < 0.6, haskell-src-exts == 1.16.*, HUnit >= 1.1 && < 1.3,- QuickCheck >= 2.1 && < 2.8,+ QuickCheck >= 2.1 && < 2.9, transformers < 0.5 Extensions:
test/Test.hs view
@@ -46,7 +46,7 @@ arbVar :: Gen Expr arbVar = oneof [(Var Pref . return) `fmap` choose ('a','z'), - (Var Inf . return) `fmap` elements (opchars\\"=|@")]+ (Var Inf . return) `fmap` elements "!#$%^*./-+:?<>&"] propRoundTrip :: Expr -> Bool propRoundTrip e = Right (TLE e) == parsePF (prettyExpr e)@@ -184,7 +184,8 @@ unitTest "p x = product [1,2,3,x]" ["p = (6 *)"], unitTest "(concat .) . map" ["(=<<)"], unitTest "let f ((a,b),(c,d)) = a + b + c + d in f ((1,2),(3,4))" ["10"],- unitTest "let x = const 3 y; y = const 4 x in x + y" ["7"] -- yay!+ unitTest "let x = const 3 y; y = const 4 x in x + y" ["7"], -- yay!+ unitTest "(\\n -> (return 0) ± (return $ sqrt n))" ["(return 0 ±) . return . sqrt"] ] main :: IO ()