Safe Haskell | None |
---|---|

Language | Haskell98 |

Predefined references for commonly used data structures and reference generators.

When defining lenses one should use the more general types. For instance `Lens`

instead of the more strict `Lens'`

. This way references with different `m1`

and `m2`

monads can be combined if there is a monad `m'`

for `MMorph m1 m'`

and `MMorph m2 m'`

.

- self :: Lens a b a b
- emptyRef :: Simple RefPlus s a
- atArg :: Eq a => a -> Simple Lens (a -> b) b
- just :: Prism (Maybe a) (Maybe b) a b
- right :: Prism (Either a b) (Either a c) b c
- left :: Prism (Either a c) (Either b c) a b
- anyway :: Lens (Either a a) (Either b b) a b
- both :: Traversal (a, a) (b, b) a b
- atHead :: Simple Lens [a] (Maybe a)
- headElem :: Simple Partial [a] a
- _tail :: Simple Partial [a] [a]
- dropped :: Int -> Simple Partial [a] [a]
- view :: Iso [a] [b] (Maybe (a, [a])) (Maybe (b, [b]))
- text :: Simple Iso String Text
- reversed :: Iso [a] [b] [a] [b]
- _numerator :: Integral a => Simple Lens (Ratio a) a
- _denominator :: Integral a => Simple Lens (Ratio a) a
- _realPart :: RealFloat a => Simple Lens (Complex a) a
- _imagPart :: RealFloat a => Simple Lens (Complex a) a
- _polar :: RealFloat a => Simple Lens (Complex a) (a, a)
- data Console = Console
- consoleLine :: Simple IOLens Console String
- fileContent :: Simple IOLens FilePath (Maybe String)
- mvar :: Simple IOLens (MVar a) a
- modifyMVarMasked_ :: (Monad m, Morph IO m, MorphControl IO m) => MVar a -> (a -> m a) -> m ()
- mask_ :: MorphControl IO m => m a -> m a
- onException :: MorphControl IO m => m a -> m b -> m a
- chan :: Simple IOLens (Chan a) a
- ioref :: Simple IOLens (IORef a) a
- state :: forall s m a. Monad m => Simple (StateLens s m) a s
- stRef :: Simple (STLens s) (STRef s a) a
- whereOf :: (RefMonads w r, MonadPlus r) => (i -> Bool) -> IndexedReference i w r MU MU s s a a -> IndexedReference i w r MU MU s s a a

# Trivial references

emptyRef :: Simple RefPlus s a Source

An empty reference that do not traverse anything

emptyRef &+& a = a &+& emptyRef = a

a & emptyRef = emptyRef & a = emptyRef

# References for simple data structures

right :: Prism (Either a b) (Either a c) b c Source

A partial lens to access the right option of an `Either`

left :: Prism (Either a c) (Either b c) a b Source

A partial lens to access the left option of an `Either`

anyway :: Lens (Either a a) (Either b b) a b Source

Access the value that is in the left or right state of an `Either`

text :: Simple Iso String Text Source

An isomorphism between the list and text representation of a string

reversed :: Iso [a] [b] [a] [b] Source

Accesses the reversed version of a list

'turn' reversed == reversed

_realPart :: RealFloat a => Simple Lens (Complex a) a Source

Accesses the real part of a complex number

_imagPart :: RealFloat a => Simple Lens (Complex a) a Source

Accesses the imaginary part of a complex number

_polar :: RealFloat a => Simple Lens (Complex a) (a, a) Source

Accesses the polar representation of a complex number

# Stateful references

consoleLine :: Simple IOLens Console String Source

Interacts with a line of text on the console. Values set are printed, getting is reading from the console.

fileContent :: Simple IOLens FilePath (Maybe String) Source

Reference to the contents of the file. Not thread-safe.

An empty file's content is `Just ""`

while a non-existent file's is `Nothing`

Creates a temporary file to store the result.

mvar :: Simple IOLens (MVar a) a Source

Access a value inside an MVar. Setting is not atomic. If there is two supplier that may set the accessed value, one may block and can corrupt the following updates.

Reads and updates are done in sequence, always using consistent data.

modifyMVarMasked_ :: (Monad m, Morph IO m, MorphControl IO m) => MVar a -> (a -> m a) -> m () Source

Generalized version of `modifyMVarMasked_`

.

mask_ :: MorphControl IO m => m a -> m a Source

Generalized version of `mask_`

.

onException :: MorphControl IO m => m a -> m b -> m a Source

Generalized version of `onException`

.