sec-0.0.1: Semantic Editor Combinators.

Data.SemanticEditors

Synopsis

Documentation

result :: (b -> b') -> (a -> b) -> a -> b'Source

Semantic Editor Combinator on the result of an unary function

first :: Arrow a => forall b c d. a b c -> a (b, d) (c, d)

Send the first component of the input through the argument arrow, and copy the rest unchanged to the output.

second :: Arrow a => forall b c d. a b c -> a (d, b) (d, c)

A mirror image of first.

The default definition may be overridden with a more efficient version if desired.

each :: (a -> b) -> [a] -> [b]Source

Semantic Editor Combinator on each value of a list

editIf :: (a -> Bool) -> (a -> a) -> a -> aSource

Semantic Editor Combinator applying the given function only when the given predicate yields true for an input value.

set :: a -> b -> aSource

Using set one can set instead of modify a value using Semantic Editor Combinators for example '(first.set) 1' will set the first value of a tuple to 1

argument :: (a' -> a) -> (a -> b) -> a' -> bSource

Semantic Editor Combinator on argument of an unary function

left :: ArrowChoice a => forall b c d. a b c -> a (Either b d) (Either c d)

Feed marked inputs through the argument arrow, passing the rest through unchanged to the output.

right :: ArrowChoice a => forall b c d. a b c -> a (Either d b) (Either d c)

A mirror image of left.

The default definition may be overridden with a more efficient version if desired.

ioref :: (a -> a) -> IORef a -> IO ()Source

maybe :: b -> (a -> b) -> Maybe a -> b

The maybe function takes a default value, a function, and a Maybe value. If the Maybe value is Nothing, the function returns the default value. Otherwise, it applies the function to the value inside the Just and returns the result.

just :: (a -> b) -> Maybe a -> Maybe bSource

Semantic Editor Combinator for Maybe

monad :: Monad m => (a -> b) -> m a -> m bSource

Semantic Editor Combinator for monads

bind :: Monad m => (a -> m b) -> m a -> m bSource

Semantic Editor Combinator for monadicaly transforming a monadic value

applicative :: Applicative f => (a -> b) -> f a -> f bSource

Semantic Editor Combinator for applicatives

mkEditors :: [Name] -> Q [Dec]Source

mkEditors creates Semantic Editor Combinators for each data type given. More information see mkEditor

mkEditor :: Name -> Q [Dec]Source

mkEditor creates Semantic Editor Combinators for each named field in a given data type by appending the fields name (first letter is converted to uppercase) to the name "edit". If a fields name starts with an underscore '_' no editor will be generated

for example:

  data Person = Person { age :: Integer, name :: String, _sex :: String }

will generate the lifters editAge and editName:

    editAge  f p = p { age = f (age p) }
    editName f p = p { name = f (name p) }

mkConstrTests :: [Name] -> Q [Dec]Source

Template Haskell function for automatically creating predicates testing the constructors of a given data type. for example:

   data Color = Red | Green | Blue
  $(mkConstrTests [''Color])

will generate the following functions:

   isRed Red     = True
   isRed _       = False
   isGreen Green = True
   isGreen _     = False
   isBlue Blue   = True
   isBlue _      = False