Safe Haskell | None |
---|---|
Language | Haskell2010 |
GenI values (variables, constants)
- data GeniVal
- gLabel :: GeniVal -> Maybe Text
- gConstraints :: GeniVal -> Maybe (FullList Text)
- mkGConst :: FullList Text -> GeniVal
- mkGConstNone :: Text -> GeniVal
- mkGVar :: Text -> Maybe (FullList Text) -> GeniVal
- mkGVarNone :: Text -> GeniVal
- mkGAnon :: GeniVal
- isAnon :: GeniVal -> Bool
- singletonVal :: GeniVal -> Maybe Text
- newtype SchemaVal = SchemaVal [GeniVal]
- crushOne :: SchemaVal -> Maybe GeniVal
- finaliseVars :: (Collectable a, DescendGeniVal a) => Text -> a -> a
- finaliseVarsById :: (Collectable a, DescendGeniVal a, Idable a) => a -> a
- anonymiseSingletons :: (Collectable a, DescendGeniVal a) => a -> a
- class (MonadPlus m, MonadError String m, Functor m) => MonadUnify m
- unify :: MonadUnify m => [GeniVal] -> [GeniVal] -> m ([GeniVal], Subst)
- data UnificationResult
- type Subst = Map Text GeniVal
- appendSubst :: Subst -> Subst -> Subst
- subsumeOne :: GeniVal -> GeniVal -> UnificationResult
- allSubsume :: MonadUnify m => [GeniVal] -> [GeniVal] -> m ([GeniVal], Subst)
- class DescendGeniVal a where
- class Collectable a where
- class Idable a where
- replace :: DescendGeniVal a => Subst -> a -> a
- replaceList :: DescendGeniVal a => [(Text, GeniVal)] -> a -> a
GeniVal
- constant : no label, just constraints
- variable : label, with or without constraints
- anonymous : no label, no constraints
Eq GeniVal Source # | |
Data GeniVal Source # | |
Ord GeniVal Source # | |
Binary GeniVal Source # | |
NFData GeniVal Source # | |
Pretty GeniVal Source # | |
Pretty SemInput Source # | |
Pretty Sem Source # | |
GeniShow GeniVal Source # | |
GeniShow SemInput Source # | |
GeniShow LitConstr Source # | |
GeniShow Sem Source # | |
DescendGeniVal GeniVal Source # | |
Collectable GeniVal Source # | |
HasConstants GeniVal Source # | |
Pretty (AvPair GeniVal) Source # | |
Pretty (Flist GeniVal) Source # | |
Pretty (Literal GeniVal) Source # | |
Pretty (GNode GeniVal) Source # | The default show for GNode tries to be very compact; it only shows the value for cat attribute and any flags which are marked on that node. This is one the places where the pretty representation of a GenI object is different from its GenI-format one |
GeniShow (Literal GeniVal) Source # | |
HasConstants (Literal GeniVal) Source # | |
gConstraints :: GeniVal -> Maybe (FullList Text) Source #
Optional values/constraints Must have at least one if at all
Though it may seem a bit redudant, this is not quite the same
as having '[Text]' because Nothing
means no constraints;
whereas Just []
(impossible here) would mean bottom.
mkGConstNone :: Text -> GeniVal Source #
Create a singleton constant (no disjunction here)
mkGVarNone :: Text -> GeniVal Source #
Create a variable with no constraints
queries and manipulation
fancy disjunction
A schema value is a disjunction of GenI values. It allows us to express
“fancy” disjunctions in tree schemata, ie. disjunctions over variables
and not just atoms (?X;?Y
).
Our rule is that that when a tree schema is instantiated, any fancy
disjunctions must be “crushed” into a single GeniVal
lest it be
rejected (see crushOne
)
Note that this is still not recursive; we don't have disjunction over
schema values, nor can schema values refer to schema values. It just
allows us to express the idea that in tree schemata, you can have
either variable ?X
or ?Y
.
crushOne :: SchemaVal -> Maybe GeniVal Source #
Convert a fancy disjunction (allowing disjunction over variables) value into a plain old atomic disjunction. The idea is to support a limited notion of fancy disjunction by requiring that there be a single point where this disjunction can be converted into a plain old variable. Note that we currently convert these to constants only.
Unification and subsumption
Finalisation
finaliseVars :: (Collectable a, DescendGeniVal a) => Text -> a -> a Source #
finaliseVars
does the following:
- (if suffix is non-null) appends a suffix to all variable names to ensure global uniqueness
- intersects constraints for for all variables within the same object
finaliseVarsById :: (Collectable a, DescendGeniVal a, Idable a) => a -> a Source #
finaliseVarsById
appends a unique suffix to all variables in
an object. This avoids us having to alpha convert all the time
and relies on the assumption finding that a unique suffix is
possible.
anonymiseSingletons :: (Collectable a, DescendGeniVal a) => a -> a Source #
Anonymise any variable that occurs only once in the object
Unification
class (MonadPlus m, MonadError String m, Functor m) => MonadUnify m Source #
data UnificationResult Source #
Unification can either…
SuccessSans GeniVal | succeed for free (no substitutions), |
SuccessRep Text GeniVal | succeed with a one-way substitution, |
SuccessRep2 Text Text GeniVal | succeed w both vars needing substitution (constraint intersection), |
Failure | or fail |
type Subst = Map Text GeniVal Source #
A variable substitution map. GenI unification works by rewriting variables
appendSubst :: Subst -> Subst -> Subst Source #
Note that the first Subst is assumed to come chronologically
before the second one; so merging { X -> Y }
and { Y -> 3 }
should give us { X -> 3; Y -> 3 }
;
See prependToSubst
for a warning!
subsumption
subsumeOne :: GeniVal -> GeniVal -> UnificationResult Source #
subsumeOne
x y
returns the same result as unifyOne x y
if x
subsumes y
or Failure
otherwise
allSubsume :: MonadUnify m => [GeniVal] -> [GeniVal] -> m ([GeniVal], Subst) Source #
l1
returns the result of allSubsume
l2l1
if
doing a simultaneous traversal of both lists, each item in
unify
l2l1
subsumes the corresponding item in l2
Traversing GeniVal containers
class DescendGeniVal a where Source #
A structure that can be traversed with a GeniVal
-replacing
function (typical use case: substitution after unification)
Approach suggested by Neil Mitchell after I found that Uniplate seemed to hurt GenI performance a bit.
descendGeniVal :: (GeniVal -> GeniVal) -> a -> a Source #
descendGeniVal f x
applies f
to all GeniVal
in x
class Collectable a where Source #
A Collectable
is something which can return its variables as a
map from the variable to the number of times that variable occurs
in it.
Important invariant: if the variable does not occur, then it does not appear in the map (ie. all counts must be >= 1 or the item does not occur at all)
By variables, what I most had in mind was the GVar values in a GeniVal. This notion is probably not very useful outside the context of alpha-conversion task, but it seems general enough that I'll keep it around for a good bit, until either some use for it creeps up, or I find a more general notion that I can transform this into.
collect :: a -> Map CollectedVar Int -> Map CollectedVar Int Source #
collect x m
increments our count for any variables in x
(adds not-yet-seen variables as needed)
Collectable SchemaVal Source # | |
Collectable GeniVal Source # | |
Collectable LexEntry Source # | |
Collectable TagElem Source # | |
Collectable UninflectedDisjunction Source # | |
Collectable a => Collectable [a] Source # | |
Collectable a => Collectable (Maybe a) Source # | |
Collectable a => Collectable (AvPair a) Source # | |
Collectable a => Collectable (Literal a) Source # | |
Collectable gv => Collectable (GNode gv) Source # | |
Collectable a => Collectable (Ttree a) Source # | |
An Idable is something that can be mapped to a unique id. You might consider using this to implement Ord, but I won't. Note that the only use I have for this so far (20 dec 2005) is in alpha-conversion.
replace :: DescendGeniVal a => Subst -> a -> a Source #
Apply variable substitutions
replaceList :: DescendGeniVal a => [(Text, GeniVal)] -> a -> a Source #
Here it is safe to say (X -> Y; Y -> Z) because this would be crushed down into a final value of (X -> Z; Y -> Z)