cmdargs-0.7: Command line argument processingSource codeContentsIndex
System.Console.CmdArgs.Annotate
Contents
Capture framework
Impure
Pure
Description

This module captures annotations on a value, and builds a Capture value. This module has two ways of writing annotations:

Impure: The impure method of writing annotations is susceptible to over-optimisation by GHC - sometimes {-# OPTIONS_GHC -fno-cse #-} will be required.

Pure: The pure method is more verbose, and lacks some type safety.

As an example of the two styles:

 data Foo = Foo {foo :: Int, bar :: Int}
 impure = capture $ Foo {foo = 12, bar = many [1 &= "inner", 2]} &= "top"
 pure = capture_ $ record Foo{} [foo := 12, bar :=+ [atom 1 += "inner", atom 2]] += "top"

Both evaluate to:

 Capture (Ann "top") (Ctor (Foo 12 1) [Value 12, Many [Ann "inner" (Value 1), Value 2]]
Synopsis
data Capture ann
= Many [Capture ann]
| Ann ann (Capture ann)
| Value Any
| Missing Any
| Ctor Any [Capture ann]
data Any = forall a . Data a => Any a
fromCapture :: Capture ann -> Any
defaultMissing :: Capture ann -> Capture ann
capture :: (Data val, Data ann) => val -> Capture ann
many :: Data val => [val] -> val
(&=) :: (Data val, Data ann) => val -> ann -> val
capture_ :: Show a => Annotate a -> Capture a
many_ :: [Annotate a] -> Annotate a
(+=) :: Annotate ann -> ann -> Annotate ann
atom :: Data val => val -> Annotate ann
record :: Data a => a -> [Annotate b] -> Annotate b
data Annotate ann
= forall c f . (Data c, Data f) => (c -> f) := f
| forall c f . (Data c, Data f) => (c -> f) :=+ [Annotate ann]
Capture framework
data Capture ann Source
The result of capturing some annotations.
Constructors
Many [Capture ann]Many values collapsed (many or many_)
Ann ann (Capture ann)An annotation attached to a value (&= or +=)
Value AnyA value (just a value, or atom)
Missing AnyA missing field (a RecConError exception, or missing from record)
Ctor Any [Capture ann]A constructor (a constructor, or record)
show/hide Instances
data Any Source
Any value, with a Data dictionary.
Constructors
forall a . Data a => Any a
show/hide Instances
fromCapture :: Capture ann -> AnySource
Return the value inside a capture.
defaultMissing :: Capture ann -> Capture annSource
Remove all Missing values by using any previous instances as default values
Impure
capture :: (Data val, Data ann) => val -> Capture annSource

Capture a value. Note that if the value is evaluated more than once the result may be different, i.e.

 capture x /= capture x
many :: Data val => [val] -> valSource
Collapse multiple values in to one.
(&=) :: (Data val, Data ann) => val -> ann -> valSource

Add an annotation to a value.

It is recommended that anyone making use of this function redefine it with a more restrictive type signature to control the type of the annotation (the second argument). Any redefinitions of this function should add an INLINE pragma, to reduce the chance of incorrect optimisations.

Pure
capture_ :: Show a => Annotate a -> Capture aSource
Capture the annotations from an annotated value.
many_ :: [Annotate a] -> Annotate aSource
Collapse many annotated values in to one.
(+=) :: Annotate ann -> ann -> Annotate annSource
Add an annotation to a value.
atom :: Data val => val -> Annotate annSource
Lift a pure value to an annotation.
record :: Data a => a -> [Annotate b] -> Annotate bSource

Create a constructor/record. The first argument should be the type of field, the second should be a list of fields constructed originally defined by := or :=+.

This operation is not type safe, and may raise an exception at runtime if any field has the wrong type or label.

data Annotate ann Source
This type represents an annotated value. The type of the underlying value is not specified.
Constructors
forall c f . (Data c, Data f) => (c -> f) := fConstruct a field, fieldname := value.
forall c f . (Data c, Data f) => (c -> f) :=+ [Annotate ann]Add annotations to a field.
Produced by Haddock version 2.6.1