HList-0.3.4.1: Heterogeneous lists

Safe HaskellNone

Data.HList.HOccurs

Contents

Description

The HList library

(C) 2004, Oleg Kiselyov, Ralf Laemmel, Keean Schupke

Result-type-driven operations on typeful heterogeneous lists.

Synopsis

Documentation

class HOccurrence e1 l l' | e1 l -> l' whereSource

Methods

hOccurrence :: e1 -> HList l -> HList l'Source

Instances

HOccurrence e1 ([] *) ([] *) 
(HEq * e1 e b, HOccurrence' b e1 (: * e l) l') => HOccurrence e1 (: * e l) l' 

class HOccurrence' b e1 l l' | b e1 l -> l' whereSource

Methods

hOccurrence' :: Proxy b -> e1 -> HList l -> HList l'Source

Instances

HOccurrence e1 l l' => HOccurrence' False e1 (: * e l) l' 
HOccurrence' True e1 (: * e l) (: * e l) 

class HOccursMany e l whereSource

Methods

hOccursMany :: HList l -> [e]Source

Instances

(HOccurrence e l l', HOccursMany' e l') => HOccursMany e l 

class HOccursMany' e l whereSource

Methods

hOccursMany' :: HList l -> [e]Source

Instances

HOccursMany' e ([] *) 
(~ * e e1, HOccursMany e l) => HOccursMany' e (: * e1 l) 

hOccursMany1 :: forall e l l'. (HOccurrence e l (e : l'), HOccursMany e l') => HList l -> (e, [e])Source

hOccursFst :: forall e l l'. HOccurrence e l (e : l') => HList l -> eSource

class HOccurs' e l whereSource

Methods

hOccurs' :: HList l -> eSource

Instances

Fail * (TypeNotFound * e) => HOccurs' e ([] *) 
(~ * e e1, HOccursNot * [*] e l) => HOccurs' e (: * e l) 

hOccursOpt :: forall e l l'. (HOccurrence e l l', HOccursOpt' e l') => HList l -> Maybe eSource

class HOccursOpt' e l whereSource

Methods

hOccursOpt' :: HList l -> Maybe eSource

Instances

HOccursOpt' e ([] *) 
~ * e e1 => HOccursOpt' e (: * e1 l) 

class HOccursNot' b e l Source

Instances

HOccursNot k [*] e l => HOccursNot' k False e l 
Fail * (TypeFound k e) => HOccursNot' k True e l 

Illustration of typical test scenarios

Retrieve the Breed of an animal.

 ghci-or-hugs> hOccurs myAnimal :: Breed
 Cow

Normal hOccurs requires specification of the result type even if the result type is determined by the fact that we are faced with a singleton list.

 ghci-or-hugs> hOccurs (HCons 1 HNil)

 <interactive>:1:
     No instance for (HOccurs e1 (HCons e HNil))

However, hOccurs can be elaborated as improved as follows:

 ghci-or-hugs> hLookup (HCons 1 HNil)
 1