Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data ABT (f :: Type -> Type) v r
- data Term (f :: Type -> Type) v a = Term {}
- data Term' (f :: Type -> Type) v a x = Term' {
- freeVars' :: Set v
- annotation' :: a
- out' :: ABT f v x
- class Ord v => Var v where
- data V v
- data Subst f v a = Subst {}
- fresh :: Var v => Term f v a -> v -> v
- unvar :: V v -> v
- freshenS :: (Var v, MonadState (Set v) m) => v -> m v
- freshInBoth :: forall v (f :: Type -> Type) a. Var v => Term f v a -> Term f v a -> v -> v
- freshenBothWrt :: (Var v, Traversable f) => Term f v a -> Term f v a -> Term f v a -> (Term f v a, Term f v a)
- freshenWrt :: (Var v, Traversable f) => (v -> v) -> Term f v a -> [Term f v a] -> [Term f v a]
- visit :: forall (f :: Type -> Type) g v a. (Traversable f, Applicative g, Ord v) => (Term f v a -> Maybe (g (Term f v a))) -> Term f v a -> g (Term f v a)
- visit' :: (Traversable f, Monad g, Ord v) => (f (Term f v a) -> g (f (Term f v a))) -> Term f v a -> g (Term f v a)
- visit_ :: (Traversable f, Applicative g, Ord v) => (f (Term f v a) -> g ()) -> Term f v a -> g (Term f v a)
- visitPure :: forall (f :: Type -> Type) v a. (Traversable f, Ord v) => (Term f v a -> Maybe (Term f v a)) -> Term f v a -> Term f v a
- changeVars :: (Foldable f, Functor f, Var v) => Map v v -> Term f v a -> Term f v a
- allVars :: forall (f :: Type -> Type) v a. Foldable f => Term f v a -> [v]
- numberedFreeVars :: (Ord v, Foldable f) => Term f v a -> Map v Int
- subterms :: forall v (f :: Type -> Type) a. (Ord v, Traversable f) => Term f v a -> [Term f v a]
- annotateBound :: (Ord v, Foldable f, Functor f) => Term f v a -> Term f v (a, Set v)
- rebuildUp :: (Ord v, Foldable f, Functor f) => (f (Term f v a) -> f (Term f v a)) -> Term f v a -> Term f v a
- rebuildMaybeUp :: (Ord v, Foldable f, Functor f) => (Term f v a -> Maybe (Term f v a)) -> Term f v a -> Maybe (Term f v a)
- rebuildUp' :: (Ord v, Foldable f, Functor f) => (Term f v a -> Term f v a) -> Term f v a -> Term f v a
- reannotateUp :: (Ord v, Foldable f, Functor f, Monoid b) => (Term f v a -> b) -> Term f v a -> Term f v (a, b)
- rewriteDown :: (Traversable f, Ord v) => (Term f v a -> Term f v a) -> Term f v a -> Term f v a
- transform :: (Ord v, Foldable g, Functor g) => (forall a1. f a1 -> g a1) -> Term f v a -> Term g v a
- transformM :: (Ord v, Monad m, Traversable g) => (forall a1. f a1 -> m (g a1)) -> Term f v a -> m (Term g v a)
- foreachSubterm :: forall (f :: Type -> Type) g v a b. (Traversable f, Applicative g) => (Term f v a -> g b) -> Term f v a -> g [b]
- freeVarOccurrences :: (Traversable f, Ord v) => Set v -> Term f v a -> [(v, a)]
- isFreeIn :: Ord v => v -> Term f v a -> Bool
- occurrences :: (Foldable f, Var v) => v -> Term f v a -> Int
- extraMap :: Functor g => (forall k. f k -> g k) -> Term f v a -> Term g v a
- vmap :: forall (f :: Type -> Type) v' v a. (Functor f, Foldable f, Ord v') => (v -> v') -> Term f v a -> Term f v' a
- vmapM :: forall m (f :: Type -> Type) v2 v a. (Applicative m, Traversable f, Foldable f, Ord v2) => (v -> m v2) -> Term f v a -> m (Term f v2 a)
- amap :: (Functor f, Foldable f, Ord v) => (a -> a2) -> Term f v a -> Term f v a2
- rename :: forall (f :: Type -> Type) v a. (Foldable f, Functor f, Var v) => v -> v -> Term f v a -> Term f v a
- renames :: (Foldable f, Functor f, Var v) => Map v v -> Term f v a -> Term f v a
- subst :: (Foldable f, Functor f, Var v) => v -> Term f v a -> Term f v a -> Term f v a
- substs :: (Foldable f, Functor f, Var v) => [(v, Term f v a)] -> Term f v a -> Term f v a
- substInheritAnnotation :: forall (f :: Type -> Type) v b a. (Foldable f, Functor f, Var v) => v -> Term f v b -> Term f v a -> Term f v a
- substsInheritAnnotation :: forall (f :: Type -> Type) v b a. (Foldable f, Functor f, Var v) => [(v, Term f v b)] -> Term f v a -> Term f v a
- find :: (Ord v, Foldable f, Functor f) => (Term f v a -> FindAction x) -> Term f v a -> [x]
- find' :: (Ord v, Foldable f, Functor f) => (Term f v a -> Bool) -> Term f v a -> [Term f v a]
- data FindAction x
- containsExpression :: forall f v a. (Var v, forall a. Eq a => Eq (f a), Traversable f) => Term f v a -> Term f v a -> Bool
- rewriteExpression :: forall f v a. (Var v, Show v, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), Traversable f) => Term f v a -> Term f v a -> Term f v a -> Maybe (Term f v a)
- baseFunctor_ :: Applicative m => (f (Term f v a) -> m (f (Term f v a))) -> Term f v a -> m (Term f v a)
- rewriteDown_ :: (Traversable f, Monad m, Ord v) => (Term f v a -> m (Term f v a)) -> Term f v a -> m (Term f v a)
- annotate :: a -> Term f v a -> Term f v a
- annotatedVar :: a -> v -> Term f v a
- var :: v -> Term f v ()
- tm :: (Foldable f, Ord v) => f (Term f v ()) -> Term f v ()
- tm' :: (Foldable f, Ord v) => a -> f (Term f v a) -> Term f v a
- abs :: Ord v => v -> Term f v () -> Term f v ()
- absChain :: Ord v => [v] -> Term f v () -> Term f v ()
- absChain' :: Ord v => [(a, v)] -> Term f v a -> Term f v a
- abs' :: Ord v => a -> v -> Term f v a -> Term f v a
- absr :: (Functor f, Foldable f, Var v) => v -> Term f (V v) () -> Term f (V v) ()
- unabs :: forall (f :: Type -> Type) v a. Term f v a -> ([v], Term f v a)
- unabsA :: Term f v a -> ([(a, v)], Term f v a)
- dropAbs :: Int -> Term f v a -> Term f v a
- cycle :: Term f v () -> Term f v ()
- cycle' :: a -> Term f v a -> Term f v a
- cycler :: (Functor f, Foldable f, Var v) => [v] -> Term f (V v) () -> Term f (V v) ()
- pattern Abs' :: (Foldable f, Functor f, Var v) => Subst f v a -> Term f v a
- pattern Abs'' :: v -> Term f v a -> Term f v a
- pattern AbsN' :: [v] -> Term f v a -> Term f v a
- pattern AbsNA' :: [(a, v)] -> Term f v a -> Term f v a
- pattern Var' :: v -> Term f v a
- pattern Cycle' :: [v] -> f (Term f v a) -> Term f v a
- pattern Cycle'' :: Term f v a -> Term f v a
- pattern CycleA' :: a -> [(a, v)] -> Term f v a -> Term f v a
- pattern Tm' :: f (Term f v a) -> Term f v a
- components :: Var v => [(v, Term f v a)] -> [[(v, Term f v a)]]
- orderedComponents :: Var v => [(v, Term f v a)] -> [[(v, Term f v a)]]
Types
data ABT (f :: Type -> Type) v r #
Instances
Foldable f => Foldable (ABT f v) | |
Defined in U.Core.ABT fold :: Monoid m => ABT f v m -> m # foldMap :: Monoid m => (a -> m) -> ABT f v a -> m # foldMap' :: Monoid m => (a -> m) -> ABT f v a -> m # foldr :: (a -> b -> b) -> b -> ABT f v a -> b # foldr' :: (a -> b -> b) -> b -> ABT f v a -> b # foldl :: (b -> a -> b) -> b -> ABT f v a -> b # foldl' :: (b -> a -> b) -> b -> ABT f v a -> b # foldr1 :: (a -> a -> a) -> ABT f v a -> a # foldl1 :: (a -> a -> a) -> ABT f v a -> a # elem :: Eq a => a -> ABT f v a -> Bool # maximum :: Ord a => ABT f v a -> a # minimum :: Ord a => ABT f v a -> a # | |
Traversable f => Traversable (ABT f v) | |
Functor f => Functor (ABT f v) | |
Generic (ABT f v r) | |
(Show v, Show r, Show (f r)) => Show (ABT f v r) | |
(Eq v, Eq r, Eq (f r)) => Eq (ABT f v r) | |
type Rep (ABT f v r) | |
Defined in U.Core.ABT type Rep (ABT f v r) = D1 ('MetaData "ABT" "U.Core.ABT" "unison-core-0.0.0-7TTEaGpY3e79hYDTKjX5dL" 'False) ((C1 ('MetaCons "Var" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 v)) :+: C1 ('MetaCons "Cycle" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 r))) :+: (C1 ('MetaCons "Abs" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 v) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 r)) :+: C1 ('MetaCons "Tm" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (f r))))) |
data Term (f :: Type -> Type) v a #
At each level in the tree, we store the set of free variables and
a value of type a
. Variables are of type v
.
Instances
Foldable f => Foldable (Term f v) | |
Defined in U.Core.ABT fold :: Monoid m => Term f v m -> m # foldMap :: Monoid m => (a -> m) -> Term f v a -> m # foldMap' :: Monoid m => (a -> m) -> Term f v a -> m # foldr :: (a -> b -> b) -> b -> Term f v a -> b # foldr' :: (a -> b -> b) -> b -> Term f v a -> b # foldl :: (b -> a -> b) -> b -> Term f v a -> b # foldl' :: (b -> a -> b) -> b -> Term f v a -> b # foldr1 :: (a -> a -> a) -> Term f v a -> a # foldl1 :: (a -> a -> a) -> Term f v a -> a # elem :: Eq a => a -> Term f v a -> Bool # maximum :: Ord a => Term f v a -> a # minimum :: Ord a => Term f v a -> a # | |
Traversable f => Traversable (Term f v) | |
Functor f => Functor (Term f v) | |
Generic (Term f v a) | |
(forall a1. Show a1 => Show (f a1), Show v) => Show (Term f v a) | |
(Foldable f, Functor f, forall a1. Eq a1 => Eq (f a1), Var v) => Eq (Term f v a) | |
(forall a1. Eq a1 => Eq (f a1), Foldable f, Functor f, forall a1. Ord a1 => Ord (f a1), Var v) => Ord (Term f v a) | |
Functor f => Recursive (Term f v a) (Term' f v a) | |
type Rep (Term f v a) | |
Defined in U.Core.ABT type Rep (Term f v a) = D1 ('MetaData "Term" "U.Core.ABT" "unison-core-0.0.0-7TTEaGpY3e79hYDTKjX5dL" 'False) (C1 ('MetaCons "Term" 'PrefixI 'True) (S1 ('MetaSel ('Just "freeVars") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Set v)) :*: (S1 ('MetaSel ('Just "annotation") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Just "out") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (ABT f v (Term f v a)))))) |
A class for avoiding accidental variable capture
Combinators & Traversals
freshenS :: (Var v, MonadState (Set v) m) => v -> m v #
Freshens the given variable wrt. the set of used variables tracked by state. Adds the result to the set of used variables.
freshInBoth :: forall v (f :: Type -> Type) a. Var v => Term f v a -> Term f v a -> v -> v #
Produce a variable which is free in both terms
freshenBothWrt :: (Var v, Traversable f) => Term f v a -> Term f v a -> Term f v a -> (Term f v a, Term f v a) Source #
freshenWrt :: (Var v, Traversable f) => (v -> v) -> Term f v a -> [Term f v a] -> [Term f v a] Source #
visit :: forall (f :: Type -> Type) g v a. (Traversable f, Applicative g, Ord v) => (Term f v a -> Maybe (g (Term f v a))) -> Term f v a -> g (Term f v a) #
`visit f t` applies an effectful function to each subtree of
t
and sequences the results. When f
returns Nothing
, visit
descends into the children of the current subtree. When f
returns
`Just t2`, visit
replaces the current subtree with t2
. Thus:
`visit (const Nothing) t == pure t` and
`visit (const (Just (pure t2))) t == pure t2`
visit' :: (Traversable f, Monad g, Ord v) => (f (Term f v a) -> g (f (Term f v a))) -> Term f v a -> g (Term f v a) #
Apply an effectful function to an ABT tree top down, sequencing the results.
visit_ :: (Traversable f, Applicative g, Ord v) => (f (Term f v a) -> g ()) -> Term f v a -> g (Term f v a) #
Apply an effectful function to an ABT tree top down, sequencing the results.
visitPure :: forall (f :: Type -> Type) v a. (Traversable f, Ord v) => (Term f v a -> Maybe (Term f v a)) -> Term f v a -> Term f v a #
rebuildUp :: (Ord v, Foldable f, Functor f) => (f (Term f v a) -> f (Term f v a)) -> Term f v a -> Term f v a Source #
rebuildMaybeUp :: (Ord v, Foldable f, Functor f) => (Term f v a -> Maybe (Term f v a)) -> Term f v a -> Maybe (Term f v a) Source #
rebuildUp' :: (Ord v, Foldable f, Functor f) => (Term f v a -> Term f v a) -> Term f v a -> Term f v a Source #
reannotateUp :: (Ord v, Foldable f, Functor f, Monoid b) => (Term f v a -> b) -> Term f v a -> Term f v (a, b) Source #
rewriteDown :: (Traversable f, Ord v) => (Term f v a -> Term f v a) -> Term f v a -> Term f v a Source #
transform :: (Ord v, Foldable g, Functor g) => (forall a1. f a1 -> g a1) -> Term f v a -> Term g v a #
transformM :: (Ord v, Monad m, Traversable g) => (forall a1. f a1 -> m (g a1)) -> Term f v a -> m (Term g v a) #
foreachSubterm :: forall (f :: Type -> Type) g v a b. (Traversable f, Applicative g) => (Term f v a -> g b) -> Term f v a -> g [b] #
freeVarOccurrences :: (Traversable f, Ord v) => Set v -> Term f v a -> [(v, a)] Source #
isFreeIn :: Ord v => v -> Term f v a -> Bool Source #
True
if v
is a member of the set of free variables of t
vmap :: forall (f :: Type -> Type) v' v a. (Functor f, Foldable f, Ord v') => (v -> v') -> Term f v a -> Term f v' a #
vmapM :: forall m (f :: Type -> Type) v2 v a. (Applicative m, Traversable f, Foldable f, Ord v2) => (v -> m v2) -> Term f v a -> m (Term f v2 a) #
rename :: forall (f :: Type -> Type) v a. (Foldable f, Functor f, Var v) => v -> v -> Term f v a -> Term f v a #
renames old
to new
in the given term, ignoring subtrees that bind old
subst :: (Foldable f, Functor f, Var v) => v -> Term f v a -> Term f v a -> Term f v a Source #
`subst v e body` substitutes e
for v
in body
, avoiding capture by
renaming abstractions in body
substs :: (Foldable f, Functor f, Var v) => [(v, Term f v a)] -> Term f v a -> Term f v a Source #
`substs [(t1,v1), (t2,v2), ...] body` performs multiple simultaneous substitutions, avoiding capture
substInheritAnnotation :: forall (f :: Type -> Type) v b a. (Foldable f, Functor f, Var v) => v -> Term f v b -> Term f v a -> Term f v a #
substsInheritAnnotation :: forall (f :: Type -> Type) v b a. (Foldable f, Functor f, Var v) => [(v, Term f v b)] -> Term f v a -> Term f v a #
find :: (Ord v, Foldable f, Functor f) => (Term f v a -> FindAction x) -> Term f v a -> [x] Source #
find' :: (Ord v, Foldable f, Functor f) => (Term f v a -> Bool) -> Term f v a -> [Term f v a] Source #
data FindAction x Source #
Instances
Functor FindAction Source # | |
Defined in Unison.ABT fmap :: (a -> b) -> FindAction a -> FindAction b # (<$) :: a -> FindAction b -> FindAction a # | |
Show x => Show (FindAction x) Source # | |
Defined in Unison.ABT showsPrec :: Int -> FindAction x -> ShowS # show :: FindAction x -> String # showList :: [FindAction x] -> ShowS # |
containsExpression :: forall f v a. (Var v, forall a. Eq a => Eq (f a), Traversable f) => Term f v a -> Term f v a -> Bool Source #
rewriteExpression :: forall f v a. (Var v, Show v, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), Traversable f) => Term f v a -> Term f v a -> Term f v a -> Maybe (Term f v a) Source #
Core logic of structured find and replace. Works for any base functor.
Returns Nothing
if no replacements.
Optics
baseFunctor_ :: Applicative m => (f (Term f v a) -> m (f (Term f v a))) -> Term f v a -> m (Term f v a) Source #
rewriteDown_ :: (Traversable f, Monad m, Ord v) => (Term f v a -> m (Term f v a)) -> Term f v a -> m (Term f v a) Source #
Setter' (Term f v a) (Term f v a)
Safe Term constructors & Patterns
annotatedVar :: a -> v -> Term f v a Source #