Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data UnisonFile v a = UnisonFileId {
- dataDeclarationsId :: Map v (TypeReferenceId, DataDeclaration v a)
- effectDeclarationsId :: Map v (TypeReferenceId, EffectDeclaration v a)
- terms :: Map v (a, Term v a)
- watches :: Map WatchKind [(v, a, Term v a)]
- pattern UnisonFile :: Map v (TypeReference, DataDeclaration v a) -> Map v (TypeReference, EffectDeclaration v a) -> Map v (a, Term v a) -> Map WatchKind [(v, a, Term v a)] -> UnisonFile v a
- emptyUnisonFile :: UnisonFile v a
- allWatches :: UnisonFile v a -> [(v, a, Term v a)]
- dataDeclarations :: UnisonFile v a -> Map v (Reference, DataDeclaration v a)
- declsToTypeLookup :: Var v => UnisonFile v a -> TypeLookup v a
- dependencies :: (Monoid a, Var v) => UnisonFile v a -> DefnsF Set TermReference TypeReference
- effectDeclarations :: UnisonFile v a -> Map v (Reference, EffectDeclaration v a)
- typecheckingTerm :: (Var v, Monoid a) => UnisonFile v a -> Term v a
- watchesOfKind :: WatchKind -> UnisonFile v a -> [(v, a, Term v a)]
- definitionLocation :: Var v => v -> UnisonFile v a -> Maybe a
- termBindings :: UnisonFile v a -> [(v, a, Term v a)]
- leftBiasedMerge :: forall v a. Ord v => UnisonFile v a -> UnisonFile v a -> UnisonFile v a
- data TypecheckedUnisonFile v a = TypecheckedUnisonFileId {
- dataDeclarationsId' :: Map v (TypeReferenceId, DataDeclaration v a)
- effectDeclarationsId' :: Map v (TypeReferenceId, EffectDeclaration v a)
- topLevelComponents' :: [[(v, a, Term v a, Type v a)]]
- watchComponents :: [(WatchKind, [(v, a, Term v a, Type v a)])]
- hashTermsId :: Map v (a, TermReferenceId, Maybe WatchKind, Term v a, Type v a)
- allTerms :: Ord v => TypecheckedUnisonFile v a -> Map v (Term v a)
- dataDeclarations' :: TypecheckedUnisonFile v a -> Map v (Reference, DataDeclaration v a)
- discardTypes :: Ord v => TypecheckedUnisonFile v a -> UnisonFile v a
- effectDeclarations' :: TypecheckedUnisonFile v a -> Map v (Reference, EffectDeclaration v a)
- hashConstructors :: forall v a. Ord v => TypecheckedUnisonFile v a -> Map v Id
- constructorsForDecls :: Ord v => Set v -> TypecheckedUnisonFile v a -> Set v
- hashTerms :: TypecheckedUnisonFile v a -> Map v (a, Reference, Maybe WatchKind, Term v a, Type v a)
- indexByReference :: TypecheckedUnisonFile v a -> (Map Id (a, Term v a, Type v a), Map Id (Decl v a))
- lookupDecl :: Ord v => v -> TypecheckedUnisonFile v a -> Maybe (Id, Decl v a)
- nonEmpty :: TypecheckedUnisonFile v a -> Bool
- termSignatureExternalLabeledDependencies :: Ord v => TypecheckedUnisonFile v a -> Set LabeledDependency
- topLevelComponents :: TypecheckedUnisonFile v a -> [[(v, a, Term v a, Type v a)]]
- typecheckedToTypeLookup :: TypecheckedUnisonFile v a -> TypeLookup v a
- typecheckedUnisonFile :: forall v a. Var v => Map v (Id, DataDeclaration v a) -> Map v (Id, EffectDeclaration v a) -> [[(v, a, Term v a, Type v a)]] -> [(WatchKind, [(v, a, Term v a, Type v a)])] -> TypecheckedUnisonFile v a
- rewrite :: (Var v, Eq a) => Set v -> (Term v a -> Maybe (Term v a)) -> UnisonFile v a -> ([v], UnisonFile v a)
- prepareRewrite :: (Monoid a, Var v) => UnisonFile v a -> ([v] -> Term v a -> Term v a, UnisonFile v a, UnisonFile v a -> UnisonFile v a)
- termNamespaceBindings :: Ord v => TypecheckedUnisonFile v a -> Set v
- typeNamespaceBindings :: Ord v => TypecheckedUnisonFile v a -> Set v
UnisonFile
data UnisonFile v a Source #
UnisonFileId | |
|
Instances
pattern UnisonFile :: Map v (TypeReference, DataDeclaration v a) -> Map v (TypeReference, EffectDeclaration v a) -> Map v (a, Term v a) -> Map WatchKind [(v, a, Term v a)] -> UnisonFile v a Source #
emptyUnisonFile :: UnisonFile v a Source #
An empty Unison file.
allWatches :: UnisonFile v a -> [(v, a, Term v a)] Source #
dataDeclarations :: UnisonFile v a -> Map v (Reference, DataDeclaration v a) Source #
declsToTypeLookup :: Var v => UnisonFile v a -> TypeLookup v a Source #
dependencies :: (Monoid a, Var v) => UnisonFile v a -> DefnsF Set TermReference TypeReference Source #
effectDeclarations :: UnisonFile v a -> Map v (Reference, EffectDeclaration v a) Source #
typecheckingTerm :: (Var v, Monoid a) => UnisonFile v a -> Term v a Source #
watchesOfKind :: WatchKind -> UnisonFile v a -> [(v, a, Term v a)] Source #
definitionLocation :: Var v => v -> UnisonFile v a -> Maybe a Source #
Get the location of a given definition in the file.
termBindings :: UnisonFile v a -> [(v, a, Term v a)] Source #
leftBiasedMerge :: forall v a. Ord v => UnisonFile v a -> UnisonFile v a -> UnisonFile v a Source #
TypecheckedUnisonFile
data TypecheckedUnisonFile v a Source #
A UnisonFile after typechecking. Terms are split into groups by cycle and the type of each term is known.
TypecheckedUnisonFileId | |
|
Instances
allTerms :: Ord v => TypecheckedUnisonFile v a -> Map v (Term v a) Source #
A mapping of all terms in the file by their var name. The returned terms refer to other definitions in the file by their var, not by reference. Includes test watches.
dataDeclarations' :: TypecheckedUnisonFile v a -> Map v (Reference, DataDeclaration v a) Source #
discardTypes :: Ord v => TypecheckedUnisonFile v a -> UnisonFile v a Source #
effectDeclarations' :: TypecheckedUnisonFile v a -> Map v (Reference, EffectDeclaration v a) Source #
hashConstructors :: forall v a. Ord v => TypecheckedUnisonFile v a -> Map v Id Source #
constructorsForDecls :: Ord v => Set v -> TypecheckedUnisonFile v a -> Set v Source #
Returns the set of constructor names for decls whose names in the given Set.
hashTerms :: TypecheckedUnisonFile v a -> Map v (a, Reference, Maybe WatchKind, Term v a, Type v a) Source #
indexByReference :: TypecheckedUnisonFile v a -> (Map Id (a, Term v a, Type v a), Map Id (Decl v a)) Source #
lookupDecl :: Ord v => v -> TypecheckedUnisonFile v a -> Maybe (Id, Decl v a) Source #
nonEmpty :: TypecheckedUnisonFile v a -> Bool Source #
termSignatureExternalLabeledDependencies :: Ord v => TypecheckedUnisonFile v a -> Set LabeledDependency Source #
topLevelComponents :: TypecheckedUnisonFile v a -> [[(v, a, Term v a, Type v a)]] Source #
the top level components (no watches) plus test watches.
typecheckedToTypeLookup :: TypecheckedUnisonFile v a -> TypeLookup v a Source #
typecheckedUnisonFile :: forall v a. Var v => Map v (Id, DataDeclaration v a) -> Map v (Id, EffectDeclaration v a) -> [[(v, a, Term v a, Type v a)]] -> [(WatchKind, [(v, a, Term v a, Type v a)])] -> TypecheckedUnisonFile v a Source #
rewrite :: (Var v, Eq a) => Set v -> (Term v a -> Maybe (Term v a)) -> UnisonFile v a -> ([v], UnisonFile v a) Source #
prepareRewrite :: (Monoid a, Var v) => UnisonFile v a -> ([v] -> Term v a -> Term v a, UnisonFile v a, UnisonFile v a -> UnisonFile v a) Source #
This function should be called in preparation for a call to UnisonFile.rewrite. It prevents the possibility of accidental variable capture while still allowing the rules to capture variables where that's the intent. For example:
f x = x + 42 ex = List.map (x -> Nat.increment x) [1,2,3]
rule1 f = rewrite term (x -> f x) ==> f
rule2 =
rewrite term (x -> f x) ==> f
Here, rule1
introduces a variable f
, which can stand for
any definition. Whereas rule2
refers to the top-level f
function in the file.
This function returns a tuple of: (prepareRule, preparedFile, finish)
prepareRule
should be called on any `@rewrite` block to do
prevent accidental capture. It receives the [v] of
variables bound locally by the rule (rule1
above binds f
).
preparedFile
should be passed to rewrite
finish
should be called on the result of rewrite
Internally, the function works by replacing all free variables in the file with a unique reference, performing the rewrite using the ABT machinery, then converting back to a "regular" UnisonFile with free variables in the terms.
termNamespaceBindings :: Ord v => TypecheckedUnisonFile v a -> Set v Source #
All bindings in the term namespace: terms, test watches (since those are the only watches that are actually stored in the codebase), data constructors, and effect constructors.
typeNamespaceBindings :: Ord v => TypecheckedUnisonFile v a -> Set v Source #
All bindings in the term namespace: data declarations and effect declarations.