Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

attempt at memoization on file system

  • Loading branch information...
commit 68c8c98f07311eed3a51aeed099211011e162ba3 1 parent a6a8756
phischu authored
Showing with 26 additions and 3 deletions.
  1. +26 −3 MasterPipe.hs
29 MasterPipe.hs
View
@@ -24,9 +24,7 @@ import qualified Data.Version as V (Version(Version))
masterpipe :: IO ()
masterpipe = runSafeIO $ runProxy $ runEitherK $
packages >->
- tryK configurations >->
- tryK modules >->
- tryK asts
+ tryK (loadConfigurations >-> leftD configurations >-> mapD (either id id) >-> saveConfigurations)
data Package = Package Name Version FilePath deriving (Show,Read,Eq)
type Name = String
@@ -38,6 +36,31 @@ packages = readFileS "packages.list" >-> mapD read
data Configuration = Configuration (Either NoModulesReason ([Module],CPPOptions)) deriving (Show,Read)
data NoModulesReason = ConfigureFailure | NoLibrary deriving (Show,Read)
+loadConfigurations :: (Proxy p,CheckP p) => () -> Pipe p Package (Either Package (Package,Configuration)) IO ()
+loadConfigurations () = runIdentityP $ forever $ do
+ package <- request ()
+ let path = configurationpath package
+ exists <- lift (doesFileExist path)
+ if exists
+ then do
+ configuration <- fmap read (lift (readFile path))
+ respond (Right (package,configuration))
+ else respond (Left package)
+
+configurationpath :: Package -> FilePath
+configurationpath (Package name version _) = "Configurations/" ++ name ++ "-" ++ version ++ ".configuration"
+
+saveConfigurations :: (Proxy p,CheckP p) => () -> Pipe p (Package,Configuration) (Package,Configuration) IO ()
+saveConfigurations () = runIdentityP $ forever $ do
+ (package,configuration) <- request ()
+ let path = configurationpath package
+ exists <- lift (doesFileExist path)
+ if exists
+ then respond (package,configuration)
+ else do
+ lift (writeFile path (show configuration))
+ respond (package,configuration)
+
configurations :: (Proxy p,CheckP p) => () -> Pipe p Package (Package,Configuration) IO ()
configurations () = runIdentityP $ forever $ do
package <- request ()
Please sign in to comment.
Something went wrong with that request. Please try again.