fields-0.1.0: First-class record field combinators with infix record field syntax.

Data.Record.Field.Basic

Contents

Description

The Field class and basic operations.

Synopsis

Record fields.

class Field a whereSource

Instances of this class can be combined with the functions and operators in this package.

Associated Types

type Src a :: *Source

The source type of the field. I.e. the record type.

type Dst a :: *Source

The destination type of the field. I.e. the type of the field in question.

Methods

field :: a -> Src a :-> Dst aSource

Return an fclabels lens corresponding to this field.

Instances

(r ~ Src f, Field f) => Field (:-> r a, f) 
Field (:-> a b) 
Field (:-> r a, :-> r b, :-> r c) 
Field (:-> r a, :-> r b, :-> r c, :-> r d) 
Field (:-> r a, :-> r b, :-> r c, :-> r d, :-> r e) 
Field (:-> r a, :-> r b, :-> r c, :-> r d, :-> r e, :-> r f) 
Field (:-> r a, :-> r b, :-> r c, :-> r d, :-> r e, :-> r f, :-> r g) 
Field (:-> r a, :-> r b, :-> r c, :-> r d, :-> r e, :-> r f, :-> r g, :-> r h) 
Field (:-> r a, :-> r b, :-> r c, :-> r d, :-> r e, :-> r f, :-> r g, :-> r h, :-> r i) 
Field (:-> r a, :-> r b, :-> r c, :-> r d, :-> r e, :-> r f, :-> r g, :-> r h, :-> r i, :-> r j) 

Basic field operators.

(.#) :: Field a => Src a -> a -> Dst aSource

Return the value of the field in the given record.

(=:) :: Field a => a -> Dst a -> Src a :-> Src aSource

Infix assignment lookalike.

 r.#f =: v

returns a modified version of r so that the field corresponding to f are set to v.

(=~) :: Field a => a -> (Dst a -> Dst a) -> Src a :-> Src aSource

Infix modification lookalike.

 r.#f =~ g

returns a modified version of r so that the fields corresponding to f are modified with the function g.

Pattern matching.

match :: Field a => a -> Src a -> Dst aSource

Convenience function for use with the ViewPatterns extension.

 case r of
      (match int -> 5)                   -> "It's 5!"
      (match (int,str#$length) -> (i,l))
            | i == l                     -> "They're equal!"
            | otherwise                  -> "Not equal."
      _                                  -> "Something else."