Skip to content

Instantly share code, notes, and snippets.

@dcoutts
Created February 7, 2017 20:18
Show Gist options
  • Save dcoutts/fc343ef68c9177423824bdb187a67415 to your computer and use it in GitHub Desktop.
Save dcoutts/fc343ef68c9177423824bdb187a67415 to your computer and use it in GitHub Desktop.
ghc-pkg read/write GADT
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.
@bgamari
Copy link

bgamari commented Feb 8, 2017

No love for DataKinds here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment