Transform ModuleString and Expression type synonyms into newtypes

This commit is contained in:
Sergey Vinokurov
2015-06-01 18:10:37 +03:00
parent 6a65701397
commit 7b6eb55b11
10 changed files with 27 additions and 18 deletions

View File

@@ -27,7 +27,7 @@ import Exception (ExceptionMonad, ghandle)
-- If 'detailed' is 'True', their types are also obtained.
-- If 'operators' is 'True', operators are also returned.
browse :: forall m. IOish m
=> ModuleString -- ^ A module name. (e.g. \"Data.List\")
=> String -- ^ A module name. (e.g. \"Data.List\", "base:Prelude")
-> GhcModT m String
browse pkgmdl = do
convert' . sort =<< go

View File

@@ -64,6 +64,10 @@ instance ToString [String] where
toLisp opt = toSexp1 opt
toPlain opt = inter '\n' . map (toPlain opt)
instance ToString [ModuleString] where
toLisp opt = toLisp opt . map getModuleString
toPlain opt = toPlain opt . map getModuleString
-- |
--
-- >>> let inp = [((1,2,3,4),"foo"),((5,6,7,8),"bar")] :: [((Int,Int,Int,Int),String)]

View File

@@ -336,7 +336,7 @@ refine :: IOish m
-> Int -- ^ Column number.
-> Expression -- ^ A Haskell expression.
-> GhcModT m String
refine file lineNo colNo expr =
refine file lineNo colNo (Expression expr) =
ghandle handler $
runGmlT' [Left file] deferErrors $ do
opt <- options

View File

@@ -133,9 +133,10 @@ extractBindings :: (Maybe G.ModuleInfo, G.Module)
-> [(Symbol, ModuleString)]
extractBindings (Nothing, _) = []
extractBindings (Just inf, mdl) =
map (\name -> (getOccString name, moduleNameString $ moduleName mdl)) names
map (\name -> (getOccString name, modStr)) names
where
names = G.modInfoExports inf
names = G.modInfoExports inf
modStr = ModuleString $ moduleNameString $ moduleName mdl
collectModules :: [(Symbol, ModuleString)]
-> [(Symbol, [ModuleString])]

View File

@@ -103,6 +103,8 @@ import Parser
import SrcLoc
import Packages
import Language.Haskell.GhcMod.Types (Expression(..))
----------------------------------------------------------------
----------------------------------------------------------------
--
@@ -325,8 +327,8 @@ filterOutChildren get_thing xs
where
implicits = mkNameSet [getName t | x <- xs, t <- implicitTyThings (get_thing x)]
infoThing :: GhcMonad m => String -> m SDoc
infoThing str = do
infoThing :: GhcMonad m => Expression -> m SDoc
infoThing (Expression str) = do
names <- parseName str
#if __GLASGOW_HASKELL__ >= 708
mb_stuffs <- mapM (getInfo False) names

View File

@@ -154,10 +154,12 @@ showPkgId :: Package -> String
showPkgId (n, v, i) = intercalate "-" [n, v, i]
-- | Haskell expression.
type Expression = String
newtype Expression = Expression { getExpression :: String }
deriving (Show, Eq, Ord)
-- | Module name.
type ModuleString = String
newtype ModuleString = ModuleString { getModuleString :: String }
deriving (Show, Read, Eq, Ord)
data GmLogLevel =
GmSilent