Created
February 7, 2017 20:18
-
-
Save dcoutts/fc343ef68c9177423824bdb187a67415 to your computer and use it in GitHub Desktop.
ghc-pkg read/write GADT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data ReadMode -- just type level tags | |
data ReadWriteMode | |
-- | Like Bool but statically determined by the mode type. | |
data OpenMode mode where | |
OpenReadMode :: OpenMode ReadMode | |
OpenReadWriteMode :: OpenMode ReadWriteMode | |
-- | Like Maybe but the case is statically determined by the mode type. | |
data InReadWriteMode mode a where | |
InReadMode :: InReadWriteMode ReadMode a | |
InReadWriteMode :: a -> InReadWriteMode ReadWriteMode a | |
deriving instance Show a => Show (InReadWriteMode mode a) | |
getPkgDatabases :: Verbosity | |
-> OpenMode mode -- we are modifying, not reading | |
-> Bool -- use the user db | |
-> Bool -- read caches, if available | |
-> Bool -- expand vars, like ${pkgroot} and $topdir | |
-> [Flag] | |
-> IO (PackageDBStack, | |
-- the real package DB stack: [global,user] ++ | |
-- DBs specified on the command line with -f. | |
InReadWriteMode mode FilePath, | |
-- which one to modify, if any | |
PackageDBStack) | |
-- then uses look like: | |
(db_stack, InReadWriteMode to_modify, _flag_dbs) <- | |
getPkgDatabases verbosity OpenReadWriteMode True{-use user-} | |
True{-use cache-} False{-expand vars-} my_flags | |
-- but still need some more changes so that changeDB takes this to_modify output, | |
-- rather than what it takes now. That might avoid us having to add a Maybe Handle | |
-- into the PackageDb type. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No love for
DataKinds
here?