| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Language.Rzk.Foil.Names
Description
Surface names, binders and modalities.
These are what the checker shows the user, and they are independent of how a
term represents its variables: a VarIdent is a surface identifier (with the
position of its defining occurrence), and a Binder records the names a binder
introduces — including a pair pattern, which still binds exactly one variable
whose components are projections of it.
Synopsis
- markUnresolved :: VarIdent -> VarIdent
- unmarkUnresolved :: VarIdent -> Maybe VarIdent
- type Display = (VarIdent, Binder)
- data TypeInfo term = TypeInfo {}
- data RzkPosition = RzkPosition {}
- ppRzkPosition :: RzkPosition -> String
- newtype VarIdent = VarIdent {}
- ppVarIdentWithLocation :: VarIdent -> String
- varIdent :: VarIdent -> VarIdent
- varIdentAt :: Maybe FilePath -> VarIdent -> VarIdent
- fromVarIdent :: VarIdent -> VarIdent
- holeName :: Text -> Maybe VarIdent
- holeIdentToken :: Maybe VarIdent -> Text
- data Binder
- binderName :: Binder -> Maybe VarIdent
- data TModality
- toModality :: Modality -> TModality
- fromMod :: TModality -> Modality
- desugarTuple :: BNFC'Position -> [Pattern] -> Pattern -> Pattern -> Pattern
- toBinder :: Pattern -> Binder
- patternToTerm :: Pattern -> Term
- modalColonModality :: ModalColon -> Modality
- modalColonToTModality :: ModalColon -> TModality
- fromTModalityToModalColon :: TModality -> ModalColon
- flattenBinderApp :: Term -> [Term]
- unsafeTermToPattern :: Term -> Pattern
- sigmaParamToTypeSigma :: BNFC'Position -> SigmaParam -> Term -> Term
- data Proj
- binderToPattern :: Binder -> Pattern
- binderDisplayName :: Binder -> VarIdent
- binderPaths :: Binder -> [([Proj], VarIdent)]
- binderLeaves :: Binder -> [VarIdent]
- binderIsCompound :: Binder -> Bool
- freshenBinderLeaves :: [VarIdent] -> Binder -> Binder
- defaultVarIdents :: [VarIdent]
- refreshVar :: [VarIdent] -> VarIdent -> VarIdent
- refreshVarIn :: Set VarIdent -> VarIdent -> VarIdent
- freshenBinderLeavesIn :: Set VarIdent -> Binder -> Binder
- incVarIdentIndex :: VarIdent -> VarIdent
- incIndex :: Text -> Text
Documentation
markUnresolved :: VarIdent -> VarIdent Source #
An identifier that is not in scope becomes a hole under a marked name.
A free-foil term refers to a variable by name, and an unresolved identifier has none — so the term cannot represent it. Elaboration marks it instead, and the checker reports it when it reaches it, which is what keeps the error where the identifier was used (inside the binders and topes it was written under) rather than at the top of the declaration.
The marker cannot be mistaken for a hole the user wrote: the grammar forbids #
in an identifier.
type Display = (VarIdent, Binder) Source #
What a bound name is shown as: the display name standing for the variable itself, and the (freshened) binder, which gives the pattern to print and the component names to fold projections back to.
The annotation on every node of a typed term: its type, plus its memoised weak head and normal forms.
Instances
| Functor TypeInfo Source # | |
| Foldable TypeInfo Source # | |
Defined in Language.Rzk.Foil.Names Methods fold :: Monoid m => TypeInfo m -> m # foldMap :: Monoid m => (a -> m) -> TypeInfo a -> m # foldMap' :: Monoid m => (a -> m) -> TypeInfo a -> m # foldr :: (a -> b -> b) -> b -> TypeInfo a -> b # foldr' :: (a -> b -> b) -> b -> TypeInfo a -> b # foldl :: (b -> a -> b) -> b -> TypeInfo a -> b # foldl' :: (b -> a -> b) -> b -> TypeInfo a -> b # foldr1 :: (a -> a -> a) -> TypeInfo a -> a # foldl1 :: (a -> a -> a) -> TypeInfo a -> a # elem :: Eq a => a -> TypeInfo a -> Bool # maximum :: Ord a => TypeInfo a -> a # minimum :: Ord a => TypeInfo a -> a # | |
| Traversable TypeInfo Source # | |
| ZipMatchK TypeInfo Source # | The annotation is ignored in matching, so two terms differing only in their
types are α-equivalent. The |
data RzkPosition Source #
Constructors
| RzkPosition | |
Fields | |
ppRzkPosition :: RzkPosition -> String Source #
Constructors
| VarIdent | |
Fields | |
Instances
| IsString VarIdent Source # | |
Defined in Language.Rzk.Foil.Names Methods fromString :: String -> VarIdent # | |
| Show VarIdent Source # | |
| Eq VarIdent Source # | Identifiers are equal when they are spelled the same, whatever their source positions. Written out rather than |
| Ord VarIdent Source # | Identifiers are ordered by name, ignoring the source position, so that the
order agrees with |
Defined in Language.Rzk.Foil.Names | |
| ZipMatchK VarIdent Source # | |
| ZipMatchK (Maybe VarIdent) Source # | A hole's name is a whole field ( |
fromVarIdent :: VarIdent -> VarIdent Source #
holeName :: Text -> Maybe VarIdent Source #
The display name of a hole from its surface token text. The token includes
the leading ?; an anonymous hole (bare ?) has no name.
holeIdentToken :: Maybe VarIdent -> Text Source #
The surface token text (including the leading ?) for a hole name.
The name(s) a binder introduces. A binder may name a single (possibly
anonymous) variable, or destructure a pair/tuple via a pattern. The pattern
structure is kept around purely so that goals, holes and error messages can
show the user's original names (e.g. t and s for \ (t , s) -> …)
instead of projections of a fresh variable (e.g. π₁ x₄ and π₂ x₄).
Operationally a pair pattern still binds a single variable; the components
are projections of it (see toScopePattern). Binder only records the names
so they can be restored when rendering.
Constructors
| BinderVar (Maybe VarIdent) | a single variable ( |
| BinderPair Binder Binder | a pair pattern |
| BinderUnit | the unit pattern |
binderName :: Binder -> Maybe VarIdent Source #
The single name of a binder, if it binds exactly one named variable.
A pair/unit pattern has no single name, so this is Nothing for them.
Used wherever the old Maybe VarIdent binder name is still sufficient.
Instances
| Show TModality Source # | |
| Eq TModality Source # | |
| ModeTheory TModality Source # | |
| ZipMatchK TModality Source # | Matching the non-recursive fields of the signature. A modality and a hole's name are part of the term: they must agree. A |
toModality :: Modality -> TModality Source #
desugarTuple :: BNFC'Position -> [Pattern] -> Pattern -> Pattern -> Pattern Source #
A tuple pattern is sugar for nested pairs.
patternToTerm :: Pattern -> Term Source #
flattenBinderApp :: Term -> [Term] Source #
Split a binder term into the individual variables it names. A multi-variable
binder like (x y : A) is parsed as the application spine x y; this returns
[x, y] so each can become its own nested binder. A single binder term (a
variable, a pair pattern, …) is returned unchanged as a singleton.
unsafeTermToPattern :: Term -> Pattern Source #
sigmaParamToTypeSigma :: BNFC'Position -> SigmaParam -> Term -> Term Source #
A projection step: first (π₁) or second (π₂) component.
binderToPattern :: Binder -> Pattern Source #
Render a Binder as a surface pattern (used to display the binder itself,
e.g. (t , s)). Anonymous variables become _.
binderDisplayName :: Binder -> VarIdent Source #
A VarIdent that prints as the binder's surface pattern, e.g. (t , s).
Used to display a pattern binder in a hole's local context as the pattern
itself rather than as the underlying single variable.
binderPaths :: Binder -> [([Proj], VarIdent)] Source #
The named leaves of a binder, each paired with the projection path that
reaches it from the bound variable. For example (t , (a , b)) yields
[([PFst], t), ([PSnd, PFst], a), ([PSnd, PSnd], b)].
binderLeaves :: Binder -> [VarIdent] Source #
The names appearing in a binder.
binderIsCompound :: Binder -> Bool Source #
Does this binder destructure a pair/tuple (as opposed to naming a single
variable or _)?
freshenBinderLeaves :: [VarIdent] -> Binder -> Binder Source #
Refresh the named leaves of a binder so they avoid the given names (and one another). Anonymous leaves and the unit pattern are left unchanged.
defaultVarIdents :: [VarIdent] Source #
Decompose a chain of projections applied to a variable into the projection
path from the variable outwards, matching binderPaths. The outermost
projection is applied last, so it goes at the end of the path: e.g.
π₂ (π₁ x) (select π₁ first, then π₂) becomes Just ([PFst, PSnd], x).
>>>:set -XOverloadedStrings>>>import qualified Data.Text as T>>>import qualified Data.Set as Set
refreshVar :: [VarIdent] -> VarIdent -> VarIdent Source #
Given a list of used variable names in the current context, generate a unique fresh name based on a given one.
>>>print $ refreshVar ["x", "y", "x₁", "z"] "x"x₂
refreshVarIn :: Set VarIdent -> VarIdent -> VarIdent Source #
Refresh a name against a set of taken ones.
The list version above is O(taken) per call, and naming a whole context calls it once per entry, which made reading the naming off a context with every top-level definition of a project in it quadratic.
>>>print $ refreshVarIn (Set.fromList ["x", "y", "x₁", "z"]) "x"x₂
freshenBinderLeavesIn :: Set VarIdent -> Binder -> Binder Source #
freshenBinderLeaves against a set of taken names, for the same
reason refreshVarIn exists beside refreshVar.
incVarIdentIndex :: VarIdent -> VarIdent Source #