| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Data.Record.QQ.Runtime.MatchHasField
Description
Infrastructure for supporting matching on records
We are be careful not to reintroduce quadratic code size here.
Synopsis
- class MatchHasField a b | b -> a
- matchHasField :: MatchHasField a b => a -> b
- fieldNamed :: GetField x r a -> a
- viewAtType :: a -> a -> a
Documentation
class MatchHasField a b | b -> a Source #
Pattern match on HasField
This is intended to be used together with matchHasField. Example usage:
data Foo a
instance HasField "fooX" (Foo a) Int where ..
instance HasField "fooY" (Foo a) [a] where ..
_example :: Foo Char -> (Int, [Char])
_example (matchHasField -> ( fieldNamed @"fooX" -> x
, fieldNamed @"fooY" -> y
) ) = (x, y)Minimal complete definition
Instances
| (MatchHasField a b, MatchHasField a c) => MatchHasField a (b, c) Source # | |
Defined in Data.Record.QQ.Runtime.MatchHasField Methods matchHasField :: a -> (b, c) Source # | |
matchHasField :: MatchHasField a b => a -> b Source #
fieldNamed :: GetField x r a -> a Source #
To be used in conjunction with MatchHasField.
See MatchHasField for details.
viewAtType :: a -> a -> a Source #
Can be used alongside matchHasField to fix the type of the argument
This avoids inferring types in terms of HasField ..; see example below.