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
- class GLazifiable f where
- class GIsNewtype f 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)
class GLazifiable f where Source #
A Generic
representation that can be lazified.
GLazifiable k (U1 k) Source # | |
(GLazifiable k f, GLazifiable k g) => GLazifiable k ((:*:) k f g) Source # | |
GLazifiable k (K1 k i c) Source # | |
GLazifiable k f => GLazifiable k (S1 k c f) Source # | |
GLazifiable k f => GLazifiable k (C1 k c f) Source # | |
GLazifiable k f => GLazifiable k (D1 k (MetaData x y z False) f) Source # | |
GIsNewtype k f => GLazifiable k (D1 k (MetaData x y z True) f) Source # | |
class GIsNewtype f where Source #
A Generic
representation that should be lazified newtype
-style.
That is, its contents should be lazified.
glazifyNewtype :: f a -> f a Source #
Find the newtype
payload and lazify it.
Lazifiable a => GIsNewtype k (K1 k i a) Source # | |
GIsNewtype k f => GIsNewtype k (M1 k i c f) Source # | |
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.