Strafunski-StrategyLib-5.0.0.5: Library for strategic programming

MaintainerRalf Laemmel, Joost Visser
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell98

Data.Generics.Strafunski.StrategyLib.KeyholeTheme

Contents

Description

This module is part of StrategyLib, a library of functional strategy combinators, including combinators for generic traversal. This module defines a number combinators for keyhole operations, i.e. for operations that have ordinary parametric or adhoc polymorhpic types, but employ strategies inside.

Synopsis

Focus

selectFocus Source

Arguments

:: (Term f, Term t) 
=> (f -> Maybe f)

Identify focus

-> t

Input term

-> Maybe f

Focused term

Select the identified focus. Fails if no subterm can be selected.

replaceFocus :: (Term t, Term t') => (t -> Maybe t) -> t' -> Maybe t' Source

Replace the identified focus. Fails if no subterm can be replaced.

deleteFocus Source

Arguments

:: (Term f, Term [f], Term t) 
=> (f -> Maybe f)

Identify focus

-> t

Input term

-> Maybe t

Output term without focused entity

Delete the focus assuming it is an element in a list. Fails if no deletion can be performed.

selectHost Source

Arguments

:: (Term f, Term h, Term t) 
=> (f -> Maybe f)

Get focus

-> (h -> Maybe h)

Get host

-> t

Input term

-> Maybe h

Located host

Find the host of the focused entity, i.e. a superterm of the focussed subterm.

markHost Source

Arguments

:: (Term f, Term h, Term t) 
=> (f -> Bool)

Test focus

-> (h -> h)

Wrap host

-> t

Input term

-> Maybe t

Output term

Listification

listify :: (Term x, Term y) => x -> [y] Source

Put all nodes of a certain type into a list.

strings :: Term x => x -> [String] Source

Put all nodes of type String into a list. This is a type-specialization of listify.

Keyhole versions of basic strategy combinators.

inj :: (MonadPlus m, Term x, Term c) => (c -> m c) -> x -> m x Source

Apply the argument function to the unique subterm of the input term. Fail if the input term has more subterms or if the subterm is not of the appropriate type. This is a keyhole version of the traversal combinator injTP