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

Safe HaskellNone

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) 
MonadReader r m => MonadReader r (ModuleT i m) 
MonadState s m => MonadState s (ModuleT i m) 
MonadWriter w m => MonadWriter w (ModuleT i m) 
MonadTrans (ModuleT i) 
Monad m => Monad (ModuleT i m) 
Functor m => Functor (ModuleT i m) 
(Monad m, Functor m) => Applicative (ModuleT i m) 
MonadIO m => MonadIO (ModuleT i m) 
MonadCont m => MonadCont (ModuleT i m) 
(Functor m, Monad m) => MonadModule (ModuleT i m) 

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.

evalModuleTSource

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.

runModuleTSource

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 whereSource

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 PackagesSource

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) 

Module names

class ModName n whereSource

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

Methods

modToString :: n -> StringSource

convertModuleName :: ModName n => n -> ModuleNameSource

Convert module name from arbitrary representation to Cabal's one