haskell-packages-0.4: Haskell suite library for package management and integration with Cabal

Safe HaskellNone
LanguageHaskell2010

Distribution.HaskellSuite.Modules

Contents

Synopsis

Module monad

When you need to resolve modules, you work in a ModuleT monad (or another monad that is an instance of MonadModule) and use the getModuleInfo function.

It finds an installed module by its name and reads (and caches) its info from the info file. Then you run a ModuleT monadic action using evalModuleT or runModuleT.

To run a ModuleT action you'll also need to provide the set of packages (represented by their InstalledPackageInfo) in which to search for modules. You can get such a set from either getInstalledPackages or readPackagesInfo, depending on your use case.

data ModuleT i m a Source #

A standard module monad transformer.

i is the type of module info, m is the underlying monad.

Instances

MonadError e m => MonadError e (ModuleT i m) Source # 

Methods

throwError :: e -> ModuleT i m a #

catchError :: ModuleT i m a -> (e -> ModuleT i m a) -> ModuleT i m a #

MonadReader r m => MonadReader r (ModuleT i m) Source # 

Methods

ask :: ModuleT i m r #

local :: (r -> r) -> ModuleT i m a -> ModuleT i m a #

reader :: (r -> a) -> ModuleT i m a #

MonadState s m => MonadState s (ModuleT i m) Source # 

Methods

get :: ModuleT i m s #

put :: s -> ModuleT i m () #

state :: (s -> (a, s)) -> ModuleT i m a #

MonadWriter w m => MonadWriter w (ModuleT i m) Source # 

Methods

writer :: (a, w) -> ModuleT i m a #

tell :: w -> ModuleT i m () #

listen :: ModuleT i m a -> ModuleT i m (a, w) #

pass :: ModuleT i m (a, w -> w) -> ModuleT i m a #

MonadTrans (ModuleT i) Source # 

Methods

lift :: Monad m => m a -> ModuleT i m a #

Monad m => Monad (ModuleT i m) Source # 

Methods

(>>=) :: ModuleT i m a -> (a -> ModuleT i m b) -> ModuleT i m b #

(>>) :: ModuleT i m a -> ModuleT i m b -> ModuleT i m b #

return :: a -> ModuleT i m a #

fail :: String -> ModuleT i m a #

Functor m => Functor (ModuleT i m) Source # 

Methods

fmap :: (a -> b) -> ModuleT i m a -> ModuleT i m b #

(<$) :: a -> ModuleT i m b -> ModuleT i m a #

Monad m => Applicative (ModuleT i m) Source # 

Methods

pure :: a -> ModuleT i m a #

(<*>) :: ModuleT i m (a -> b) -> ModuleT i m a -> ModuleT i m b #

(*>) :: ModuleT i m a -> ModuleT i m b -> ModuleT i m b #

(<*) :: ModuleT i m a -> ModuleT i m b -> ModuleT i m a #

MonadIO m => MonadIO (ModuleT i m) Source # 

Methods

liftIO :: IO a -> ModuleT i m a #

MonadCont m => MonadCont (ModuleT i m) Source # 

Methods

callCC :: ((a -> ModuleT i m b) -> ModuleT i m a) -> ModuleT i m a #

(Functor m, Monad m) => MonadModule (ModuleT i m) Source # 

Associated Types

type ModuleInfo (ModuleT i m :: * -> *) :: * Source #

type ModuleInfo (ModuleT i m) Source # 
type ModuleInfo (ModuleT i m) = i

getModuleInfo :: (MonadModule m, ModName n) => n -> m (Maybe (ModuleInfo m)) Source #

Tries to find the module in the current set of packages, then find the module's info file, and reads and caches its contents.

Returns Nothing if the module could not be found in the current set of packages. If the module is found, but something else goes wrong (e.g. there's no info file for it), an exception is thrown.

evalModuleT Source #

Arguments

:: MonadIO m 
=> ModuleT i m a

the monadic action to run

-> Packages

packages in which to look for modules

-> String

file extension of info files

-> (FilePath -> m i)

how to read information from an info file

-> m a 

Run a ModuleT action.

This is a simplified version of runModuleT.

runModuleT Source #

Arguments

:: MonadIO m 
=> ModuleT i m a

the monadic action to run

-> Packages

packages in which to look for modules

-> String

file extension of info files

-> (FilePath -> m i)

how to read information from an info file

-> Map ModuleName i

initial set of module infos

-> m (a, Map ModuleName i)

return value, plus all cached module infos (that is, the initial set plus all infos that have been read by the action itself)

Run a ModuleT action

class Monad m => MonadModule m where Source #

This class defines the interface that is used by getModuleInfo, so that you can use it in monads other than ModuleT.

You don't typically have to define your own instances of this class, but here are a couple of cases when you might:

  • A pure (non-MonadIO) mockup module monad for testing purposes
  • A transformer over ModuleT
  • You need a more complex way to retrieve the module info

Associated Types

type ModuleInfo m Source #

The type of module info

Methods

lookupInCache :: ModName n => n -> m (Maybe (ModuleInfo m)) Source #

insertInCache :: ModName n => n -> ModuleInfo m -> m () Source #

getPackages :: m Packages Source #

readModuleInfo :: ModName n => [FilePath] -> n -> m (ModuleInfo m) Source #

Read the module info, given a list of search paths and the module name

Instances

(Functor m, Monad m) => MonadModule (ModuleT i m) Source # 

Associated Types

type ModuleInfo (ModuleT i m :: * -> *) :: * Source #

Module names

class ModName n where Source #

Different libraries (Cabal, haskell-src-exts, ...) use different types to represent module names. Hence this class.

Minimal complete definition

modToString

Methods

modToString :: n -> String Source #

convertModuleName :: ModName n => n -> ModuleName Source #

Convert module name from arbitrary representation to Cabal's one