]> gitweb @ CieloNegro.org - Lucu.git/blobdiff - Data/Collections/Newtype/TH.hs
docs
[Lucu.git] / Data / Collections / Newtype / TH.hs
index c60ea2b9b823311c05a1b9fa6faf4e5b365055a5..0301fd37562222cc896bc9246dc20c0c423d1bba 100644 (file)
@@ -2,7 +2,9 @@
     TemplateHaskell
   , UnicodeSyntax
   #-}
--- |FIXME: doc
+-- |Doesn't anyone know why these instances can't be derived using
+-- GeneralizedNewtypeDeriving? I think its limitation isn't reasonable
+-- at all...
 module Data.Collections.Newtype.TH
     ( derive
     )
@@ -27,7 +29,42 @@ import Prelude.Unicode
 
 type Deriver = Q Cxt → Q Type → Q Exp → Q Exp → Q Dec
 
--- |FIXME: doc
+-- |Automatic newtype instance deriver for type classes defined by the
+-- collections-api package.
+--
+-- @
+--   {-\# LANGUAGE TemplateHaskell \#-}
+--   module Foo (T) where
+--   import "Data.Collections"
+--   import "Data.Collections.BaseInstances" ()
+--   import qualified Data.Collections.Newtype.TH as C
+--   import qualified "Data.Map" as M
+--
+--   newtype T = T (M.Map 'Int' 'Bool')
+--
+--   C.derive [d| instance 'Unfoldable' T ('Int', 'Bool')
+--                instance 'Foldable'   T ('Int', 'Bool')
+--                instance 'Indexed'    T  'Int'  'Bool'
+--                ...
+--              |]
+-- @
+--
+-- This function can derive the following instances:
+--
+--   * 'Unfoldable'
+--
+--   * 'Foldable'
+--
+--   * 'Collection'
+--
+--   * 'Indexed'
+--
+--   * 'Map'
+--
+--   * 'Set'
+--
+--   * 'SortingCollection'
+--
 derive ∷ Q [Dec] → Q [Dec]
 derive = (concat <$>) ∘ (mapM go =≪)
     where