unison-parser-typechecker-0.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Unison.UnisonFile

Synopsis

UnisonFile

data UnisonFile v a Source #

Instances

Instances details
Generic (UnisonFile v a) Source # 
Instance details

Defined in Unison.UnisonFile.Type

Associated Types

type Rep (UnisonFile v a) :: Type -> Type #

Methods

from :: UnisonFile v a -> Rep (UnisonFile v a) x #

to :: Rep (UnisonFile v a) x -> UnisonFile v a #

(Show a, Show v) => Show (UnisonFile v a) Source # 
Instance details

Defined in Unison.UnisonFile.Type

Methods

showsPrec :: Int -> UnisonFile v a -> ShowS #

show :: UnisonFile v a -> String #

showList :: [UnisonFile v a] -> ShowS #

type Rep (UnisonFile v a) Source # 
Instance details

Defined in Unison.UnisonFile.Type

type Rep (UnisonFile v a) = D1 ('MetaData "UnisonFile" "Unison.UnisonFile.Type" "unison-parser-typechecker-0.0.0-KNkVGbTXlis2lnVjsRIJUx" 'False) (C1 ('MetaCons "UnisonFileId" 'PrefixI 'True) ((S1 ('MetaSel ('Just "dataDeclarationsId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Map v (TypeReferenceId, DataDeclaration v a))) :*: S1 ('MetaSel ('Just "effectDeclarationsId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Map v (TypeReferenceId, EffectDeclaration v a)))) :*: (S1 ('MetaSel ('Just "terms") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Map v (a, Term v a))) :*: S1 ('MetaSel ('Just "watches") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (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 Source #

emptyUnisonFile :: UnisonFile v a Source #

An empty Unison file.

allWatches :: UnisonFile v a -> [(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.

Instances

Instances details
Ord v => Functor (TypecheckedUnisonFile v) Source # 
Instance details

Defined in Unison.UnisonFile.Type

Generic (TypecheckedUnisonFile v a) Source # 
Instance details

Defined in Unison.UnisonFile.Type

Associated Types

type Rep (TypecheckedUnisonFile v a) :: Type -> Type #

(Show a, Show v) => Show (TypecheckedUnisonFile v a) Source # 
Instance details

Defined in Unison.UnisonFile.Type

type Rep (TypecheckedUnisonFile v a) Source # 
Instance details

Defined in Unison.UnisonFile.Type

type Rep (TypecheckedUnisonFile v a) = D1 ('MetaData "TypecheckedUnisonFile" "Unison.UnisonFile.Type" "unison-parser-typechecker-0.0.0-KNkVGbTXlis2lnVjsRIJUx" 'False) (C1 ('MetaCons "TypecheckedUnisonFileId" 'PrefixI 'True) ((S1 ('MetaSel ('Just "dataDeclarationsId'") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Map v (TypeReferenceId, DataDeclaration v a))) :*: S1 ('MetaSel ('Just "effectDeclarationsId'") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Map v (TypeReferenceId, EffectDeclaration v a)))) :*: (S1 ('MetaSel ('Just "topLevelComponents'") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [[(v, a, Term v a, Type v a)]]) :*: (S1 ('MetaSel ('Just "watchComponents") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [(WatchKind, [(v, a, Term v a, Type v a)])]) :*: S1 ('MetaSel ('Just "hashTermsId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Map v (a, TermReferenceId, Maybe WatchKind, Term v a, Type v a)))))))

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.

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.

topLevelComponents :: TypecheckedUnisonFile v a -> [[(v, a, Term v a, Type v a)]] Source #

the top level components (no watches) plus test watches.

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.