@@ -23,12 +23,14 @@
2323-- You can automatically derive generic instances. for example:
2424--
2525-- @
26−-- -- LANGUAGE DeriveGeneric, TypeOperators
26+-- -- LANGUAGE <https://ocharles.org.uk/blog/posts/2014-12-16-derive-generic.html DeriveGeneric>, TypeOperators, TypeFamilies #-}
27+-- import Data.MemoTrie
28+-- import GHC.Generics (Generic)
2729--
2830-- data Color
2931-- = RGB Int Int Int
3032-- | Color String
31−-- deriving (Generic)
33+-- deriving ('Generic')
3234--
3335-- instance HasTrie Color where
3436-- newtype (Color :->: b) = ColorTrie { unColorTrie :: 'Reg' Color :->: b }
@@ -37,6 +39,12 @@
3739-- enumerate = 'enumerateGeneric' unColorTrie
3840-- @
3941--
42+-- see @examples/Generic.hs@, which can be run with:
43+--
44+-- @
45+-- $ cabal configure -fexamples && cabal run generic
46+-- @
47+--
4048--
4149----------------------------------------------------------------------
4250
@@ -62,8 +70,8 @@ import Data.Monoid
6270import Data.Function (on)
6371import GHC.Generics
6472
65−import Data.Void
66−
73+import Data.Void (Void)
74+
6775-- import Prelude hiding (id,(.))
6876-- import Control.Category
6977-- import Control.Arrow
@@ -173,7 +181,7 @@ instance HasTrie Void where
173181 -- As suggested by Audun Skaugen
174182 data Void :->: a = VoidTrie
175183 trie _ = VoidTrie
176− untrie VoidTrie = absurd
184+ untrie VoidTrie = \case
177185 enumerate VoidTrie = []
178186
179187instance HasTrie () where
@@ -595,7 +603,8 @@ instance (HasTrie (f x)) => HasTrie (M1 i t f x) where
595603 untrie (M1Trie t) = \(M1 a) -> (untrie t) a
596604 enumerate (M1Trie t) = enum' M1 t
597605
598−-- | "unlifted" generic representation. (i.e. is a unary type constructor).
606+-- | the data type in a __reg__ular form.
607+-- "unlifted" generic representation. (i.e. is a unary type constructor).
599608type Reg a = Rep a ()
600609
601610trieGeneric
@@ -640,19 +649,3 @@ liftSum :: Either (f a) (g a) -> (f :+: g) a
640649liftSum = either L1 R1
641650{-# INLINEABLE liftSum #-}
642651
643−{- example:
644−
645−{-# LANGUAGE DeriveGeneric, TypeOperators #-}
646−
647−data Color
648− = RGB Int Int Int
649− | Color String
650− deriving (Generic)
651−
652−instance HasTrie Color where
653− newtype (Color :->: b) = ColorTrie { unColorTrie :: Reg Color :->: b }
654− trie = trieGeneric ColorTrie
655− untrie = untrieGeneric unColorTrie
656− enumerate = enumerateGeneric unColorTrie
657−
658−-}