large-records-0.1.0.0: Efficient compilation for large records, linear in the size of the record
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Record.QQ.Runtime.MatchHasField

Description

Infrastructure for supporting matching on records

We are be careful not to reintroduce quadratic code size here.

Synopsis

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

matchHasField

Instances

Instances details
(MatchHasField a b, MatchHasField a c) => MatchHasField a (b, c) Source # 
Instance details

Defined in Data.Record.QQ.Runtime.MatchHasField

Methods

matchHasField :: a -> (b, c) 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.