LogicGrowsOnTrees-1.1.0.2: a parallel implementation of logic programming using distributed tree exploration

Safe HaskellNone

LogicGrowsOnTrees.Location

Contents

Description

This module contains infrastructure for working with Locations, which indicate a location within a tree but, unlike Path, without the cached values.

Synopsis

Type-classes

class MonadPlus m => MonadLocatable m whereSource

The class MonadLocatable allows you to get your current location within a tree.

Types

data Location Source

A Location identifies a location in a tree; unlike Path it only contains information about the list of branches that have been taken, and not information about the cached values encounted along the way.

Instances

Eq Location 
Ord Location

The Ord instance performs the comparison using the list of branches in the path defined by the location, which is obtained using the function branchingFromLocation.

Show Location 
Monoid Location

The Monoid instance constructs a location that is the result of appending the path in the second argument to the path in the first argument.

data Solution α Source

A Solution is a result tagged with the location of the leaf at which it was found.

Constructors

Solution 

Instances

Eq α => Eq (Solution α) 
Ord α => Ord (Solution α) 
Show α => Show (Solution α) 

newtype LocatableT m α Source

LocatableT is a monad transformer that allows you to take any MonadPlus and add to it the ability to tell where you are in the tree created by the mpluss.

Constructors

LocatableT 

type LocatableTree = LocatableTreeT IdentitySource

A Tree augmented with the ability to get the current location

type LocatableTreeIO = LocatableTreeT IOSource

Like LocatableTree, but running in the IO monad.

Utility functions

applyCheckpointCursorToLocationSource

Arguments

:: CheckpointCursor

a path within the subtree

-> Location

the location of the subtree

-> Location

the location within the full tree obtained by following the path to the subtree and then the path indicated by the checkpoint cursor

Append the path indicated by a checkpoint cursor to the given location's path.

applyContextToLocationSource

Arguments

:: Context m α

the path within the subtree

-> Location

the location of the subtree

-> Location

the location within the full tree obtained by following the path to the subtree and then the path indicated by the context

Append the path indicated by a context to the given location's path.

applyPathToLocationSource

Arguments

:: Path

a path within the subtree

-> Location

the location of the subtree

-> Location

the location within the full tree obtained by following the path to the subtree and then the given path

Append a path to a location's path.

branchingFromLocation :: Location -> [BranchChoice]Source

Converts a location to a list of branch choices.

labelFromBranching :: Foldable t => t BranchChoice -> LocationSource

Converts a list (or other Foldable) of branch choices to a location.

labelFromContext :: Context m α -> LocationSource

Contructs a Location representing the location within the tree indicated by the Context.

labelFromPath :: Path -> LocationSource

Contructs a Location representing the location within the tree indicated by the Path.

leftBranchOf :: Location -> LocationSource

Returns the Location at the left branch of the given location.

locationTransformerForBranchChoice :: BranchChoice -> Location -> LocationSource

Convenience function takes a branch choice and returns a location transformer that appends the branch choice to the given location.

rightBranchOf :: Location -> LocationSource

Returns the Location at the right branch of the given location.

rootLocation :: LocationSource

The location at the root of the tree.

runLocatableT :: LocatableT m α -> m αSource

Runs a LocatableT to obtain the nested monad.

sendTreeDownLocation :: Location -> Tree α -> Tree αSource

Walks down a Tree to the subtree at the given Location. This function is analogous to sendTreeDownPath, and shares the same caveats.

sendTreeTDownLocation :: Monad m => Location -> TreeT m α -> m (TreeT m α)Source

Like sendTreeDownLocation, but for impure trees.

solutionsToMap :: Foldable t => t (Solution α) -> Map Location αSource

Converts a list (or other Foldable) of solutions to a Map from Locations to results.

Exploration functions

exploreLocatableTree :: Monoid α => LocatableTree α -> αSource

Explore all the nodes in a LocatableTree and sum over all the results in the leaves.

exploreLocatableTreeT :: (Monoid α, Monad m) => LocatableTreeT m α -> m αSource

Same as exploreLocatableTree, but for an impure tree.

exploreLocatableTreeTAndIgnoreResults :: Monad m => LocatableTreeT m α -> m ()Source

Same as exploreLocatableTree, but the results are discarded so the tree is only explored for its side-effects.

exploreTreeWithLocations :: Tree α -> [Solution α]Source

Explores all of the nodes of a tree, returning a list of solutions each tagged with the location at which it was found.

exploreTreeTWithLocations :: Monad m => TreeT m α -> m [Solution α]Source

Like exploreTreeWithLocations but for an impure tree.

exploreTreeWithLocationsStartingAt :: Location -> Tree α -> [Solution α]Source

Like exploreTreeWithLocations, but for a subtree whose location is given by the first argument; the solutions are labeled by the absolute location within the full tree (as opposed to their relative location within the subtree).

exploreLocatableTreeUntilFirst :: LocatableTree α -> Maybe αSource

Explores all the nodes in a LocatableTree until a result (i.e., a leaf) has been found; if a result has been found then it is returned wrapped in Just, otherwise Nothing is returned.

exploreTreeUntilFirstWithLocation :: Tree α -> Maybe (Solution α)Source

Explores all the nodes in a tree until a result (i.e., a leaf) has been found; if a result has been found then it is returned tagged with the location at which it was found and wrapped in Just, otherwise Nothing is returned.

exploreTreeUntilFirstWithLocationStartingAt :: Location -> Tree α -> Maybe (Solution α)Source

Like exploreTreeUntilFirstWithLocation, but for a subtree whose location is given by the first argument; the solution (if present) is labeled by the absolute location within the full tree (as opposed to its relative location within the subtree).