Copyright | (c) 2019 disco team (see LICENSE) |
---|---|
License | BSD-3-Clause |
Maintainer | byorgey@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
The ModuleInfo
record representing a disco module, and functions
to resolve the location of a module on disk.
Synopsis
- data LoadingMode
- = REPL
- | Standalone
- data Defn = Defn (Name ATerm) [Type] Type [Clause]
- type Clause = Bind [APattern] ATerm
- eraseClause :: Clause -> Bind [Pattern] Term
- data ModuleInfo = ModuleInfo {}
- miTys :: Lens' ModuleInfo TyCtx
- miTydefs :: Lens' ModuleInfo TyDefCtx
- miTerms :: Lens' ModuleInfo [(ATerm, PolyType)]
- miTermdefs :: Lens' ModuleInfo (Ctx ATerm Defn)
- miProps :: Lens' ModuleInfo (Ctx ATerm [AProperty])
- miName :: Lens' ModuleInfo ModuleName
- miImports :: Lens' ModuleInfo (Map ModuleName ModuleInfo)
- miExts :: Lens' ModuleInfo ExtSet
- miDocs :: Lens' ModuleInfo (Ctx Term Docs)
- withImports :: Monoid a => Getting a ModuleInfo a -> ModuleInfo -> a
- allTys :: ModuleInfo -> TyCtx
- allTydefs :: ModuleInfo -> TyDefCtx
- emptyModuleInfo :: ModuleInfo
- combineModuleInfo :: Member (Error TCError) r => [ModuleInfo] -> Sem r ModuleInfo
- data Resolver
- withStdlib :: Resolver -> Resolver
- resolveModule :: Member (Embed IO) r => Resolver -> String -> Sem r (Maybe (FilePath, ModuleProvenance))
Documentation
data LoadingMode Source #
When loading a module, we could be loading it from code entered at the REPL, or from a standalone file. The two modes have slightly different behavior.
A definition consists of a name being defined, the types of any pattern arguments (each clause must have the same number of patterns), the type of the body of each clause, and a list of clauses. For example,
f x (0,z) = 3*x + z > 5 f x (y,z) = z == 9
might look like Defn f [Z, Z*Z] B [clause 1 ..., clause 2 ...]
Instances
type Clause = Bind [APattern] ATerm Source #
A clause in a definition consists of a list of patterns (the LHS
of the =) and a term (the RHS). For example, given the concrete
syntax f n (x,y) = n*x + y
, the corresponding Clause
would be
something like [n, (x,y)] (n*x + y)
.
data ModuleInfo Source #
Type checking a module yields a value of type ModuleInfo which contains mapping from terms to their relavent documenation, a mapping from terms to properties, and a mapping from terms to their types.
Instances
Show ModuleInfo Source # | |
Defined in Disco.Module showsPrec :: Int -> ModuleInfo -> ShowS # show :: ModuleInfo -> String # showList :: [ModuleInfo] -> ShowS # |
miTermdefs :: Lens' ModuleInfo (Ctx ATerm Defn) Source #
withImports :: Monoid a => Getting a ModuleInfo a -> ModuleInfo -> a Source #
Get something from a module and its direct imports.
allTys :: ModuleInfo -> TyCtx Source #
Get the types of all names bound in a module and its direct imports.
allTydefs :: ModuleInfo -> TyDefCtx Source #
Get all type definitions from a module and its direct imports.
emptyModuleInfo :: ModuleInfo Source #
The empty module info record.
combineModuleInfo :: Member (Error TCError) r => [ModuleInfo] -> Sem r ModuleInfo Source #
Merges a list of ModuleInfos into one ModuleInfo. Two ModuleInfos are merged by joining their doc, type, type definition, and term contexts. The property context of the new module is the one obtained from the second module. The name of the new module is taken from the first. Definitions from later modules override earlier ones. Note that this function should really only be used for the special top-level REPL module.
A data type indicating where we should look for Disco modules to be loaded.
FromStdlib | Load only from the stdlib (standard lib modules) |
FromDir FilePath | Load only from a specific directory (:load) |
FromCwdOrStdlib | Load from current working dir or stdlib (import at REPL) |
FromDirOrStdlib FilePath | Load from specific dir or stdlib (import in file) |
withStdlib :: Resolver -> Resolver Source #
Add the possibility of loading imports from the stdlib. For example, this is what we want to do after a user loads a specific file using `:load` (for which we will NOT look in the stdlib), but then we need to recursively load modules which it imports (which may either be in the stdlib, or the same directory as the `:load`ed module).
resolveModule :: Member (Embed IO) r => Resolver -> String -> Sem r (Maybe (FilePath, ModuleProvenance)) Source #
Given a module resolution mode and a raw module name, relavent directories are searched for the file containing the provided module name. Returns Nothing if no module with the given name could be found.