on master help sign in
Docs
commit41477708a45c7630b91b8186a2212d1da04804ad authorCsongor Kiss <kiss.csongor.kiss@gmail.com> dateMon 5 Sep 2016, 21:52 (10 years ago) parent8866da7
3 files changed+27−2
README.md+2 generic-records.cabal+2 src/Records/Generic.hs+23−2
README.md+2
@@ -1,6 +1,8 @@
11# generic-records
22Magic record operations using generics (i.e. both type- and morally safe - no TH)
33
4+Available on [Hackage](https://hackage.haskell.org/package/generic-records)
5+
46This package uses the GHC8 Generic representation of records to derive magic classes (siilar to the OverloadedRecordLabels proposal), and prove structural subtyping relationship between records.
57The latter can be used to upcast the "sub-record" to the more general "interface".
68
generic-records.cabal+2
@@ -18,6 +18,8 @@ synopsis: Magic record operations using generics
1818-- A longer description of the package.
1919description: This package uses the GHC8 Generic representation of records to derive magic classes (a la OverloadedRecordLabels), and prove structural subtyping relationship between records. The latter can be used to upcast the "sub-record" to the more general "interface".
2020
21+homepage: https://github.com/kcsongor/generic-records
22+
2123-- The license under which the package is released.
2224license: BSD3
2325
src/Records/Generic.hs+23−2
@@ -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