monad-ox-0.2.0: Monad for observation extraction

Safe HaskellNone

Control.Monad.Ox

Contents

Description

The Ox monad facilitates writing functional expressions over the input sentence with arbitrary type of sentence token.

Synopsis

Types

type Ox t w a = WriterT [(Id, w)] (State Id) aSource

The Ox is a monad stack with observation type identifier handled by the state monad and the resulting observation values paired with identifiers printed using the writer monad.

type Id = [Int]Source

Observation type identifier. It consists of a list of integers, each integer representing a state of the Ox monad on the particular level.

Functions

atWith :: Vector t -> (t -> a) -> Int -> Maybe aSource

Value of the 't -> a' function with respect to the given sentence and sentence position. Return Nothing if the position is out of bounds.

atsWith :: Vector t -> (t -> [a]) -> Int -> [a]Source

Value of the 't -> [a]' function with respect to the given sentence and sentence position. Return empty list if the position is out of bounds.

save :: Maybe w -> Ox t w ()Source

Save the observation value.

saves :: [w] -> Ox t w ()Source

Save observation values in the writer monad of the Ox stack.

when :: Bool -> Ox t w a -> Ox t w (Maybe a)Source

Perform the Ox action only when the cond is True. It works like the standard when function but also changes the current identifier value.

whenJT :: Maybe Bool -> Ox t w a -> Ox t w (Maybe a)Source

Perform the action only when the given condition is equal to Just True.

group :: Ox t w a -> Ox t w aSource

Make all embedded observations to be indistinguishable with respect to their top-most identifier components. TODO: Perhaps should set only the current level, not the deeper ones.

Ox monad execution

execOx :: Ox t w a -> [(Id, w)]Source

Execute the Ox monad and retrieve the saved (with the save and saves functions) results.