@@ -10,8 +10,28 @@
1010{-# LANGUAGE TypeApplications #-}
1111{-# LANGUAGE TypeOperators #-}
1212
13+-----------------------------------------------------------------------------
14+-- |
15+-- Module : Records.Generic
16+-- Copyright : (C) 2016 Csongor Kiss
17+-- License : BSD3
18+-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
19+-- Stability : experimental
20+-- Portability : non-portable
21+--
22+-- Magic record operations using Generics
23+--
24+-- These classes need not be instantiated manually, as GHC can automatically
25+-- prove valid instances via Generics. Only the `Generic` class needs to
26+-- be derived (see examples).
27+--
28+-----------------------------------------------------------------------------
1329module Records.Generic
14− ( HasField (..)
30+ (
31+ -- * Magic getter
32+ HasField (..)
33+
34+ -- * Subtype relationship
1535 , Subtype (..)
1636 ) where
1737
@@ -100,13 +120,14 @@ instance {-# OVERLAPS #-} Convert rep f => Convert rep (M1 i c f) where
100120
101121-- Exported stuff
102122
103−-- Structural subtype relationship
123+-- |Structural subtype relationship
104124class Subtype a b where
105125 upcast :: a -> b
106126
107127instance (Convert (Rep a) (Rep b), Generic a, Generic b) => Subtype a b where
108128 upcast = to . convert . from
109129
130+-- |Records that have a field with a given name
110131class Generic rec => HasField rec (field :: Symbol) a where
111132 getField :: rec -> Proxy field -> a
112133