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

Language | Haskell2010 |

Record types in Haskell can be made lazy through lazy pattern
matching. This module offers functions for making them lazy
*generically*.

- class Lazifiable a where
- genericLazify :: (Generic a, GLazifiable (Rep a)) => a -> a
- ($~) :: forall rep a (b :: TYPE rep). Lazifiable a => (a -> b) -> a -> b

# Documentation

class Lazifiable a where Source #

A class for types that can be lazified. A generic
default is provided for convenience. To lazify a type using
its generic representation, use `genericLazify`

.

Lazily rewrap a record. Applying `lazify`

to a record and then
pattern matching on it strictly is equivalent to pattern matching
on it lazily.

strictFirst :: (a -> a') -> (a, b) -> (a', b) strictFirst f (a, b) = (f a, b) lazyFirst :: (a -> a') -> (a, b) -> (a', b) lazyFirst f = strictFirst f . lazify -- Equivalently lazyFirst f ~(a, b) = (f a, b)

lazify :: (Generic a, GLazifiable (Rep a)) => a -> a Source #

Lazily rewrap a record. Applying `lazify`

to a record and then
pattern matching on it strictly is equivalent to pattern matching
on it lazily.

strictFirst :: (a -> a') -> (a, b) -> (a', b) strictFirst f (a, b) = (f a, b) lazyFirst :: (a -> a') -> (a, b) -> (a', b) lazyFirst f = strictFirst f . lazify -- Equivalently lazyFirst f ~(a, b) = (f a, b)

genericLazify :: (Generic a, GLazifiable (Rep a)) => a -> a Source #

Lazify a record using its generic representation.

Note that newtypes are treated specially: a newtype is lazified
by lazifying its *underlying* type using its `Lazifiable`

instance.

($~) :: forall rep a (b :: TYPE rep). Lazifiable a => (a -> b) -> a -> b Source #

Apply a function to a lazified value.