Permalink
Browse files

Use hygenic name for Control.Newtype.Newtype

  • Loading branch information...
1 parent 75f2445 commit fceebf7f8623ec29ae6b3e9b7c8325af17f95c6b Eyal Lotem committed Oct 20, 2011
Showing with 5 additions and 3 deletions.
  1. +5 −3 Control/Newtype/TH.hs
@@ -26,22 +26,24 @@ module Control.Newtype.TH (mkNewTypes) where
import Language.Haskell.TH
import Language.Haskell.Meta.Utils (conName, conTypes)
+import Control.Newtype (Newtype(pack, unpack))
+
-- | Derive instances of Newtype, specified as a list of references to newtypes.
mkNewTypes :: [Name] -> Q [Dec]
mkNewTypes = fmap concat . mapM (fmap mkInst . reify)
where mkInst (TyConI (NewtypeD context name vs con _)) =
[InstanceD context
-- Construct the class declaration
-- "class Newtype (<newtype> a ...) (<field type> a ...) where"
- (AppT (AppT (ConT $ mkName "Control.Newtype.Newtype")
+ (AppT (AppT (ConT ''Newtype)
$ bndrsToType (ConT name) vs)
. head $ conTypes con)
(defs (mkName "x") (conName con))]
mkInst _ = []
defs xnam cnam =
- [ FunD (mkName "unpack")
+ [ FunD 'unpack
[Clause [ConP cnam [VarP xnam]] (NormalB $ VarE xnam) []]
- , FunD (mkName "pack")
+ , FunD 'pack
[Clause [] (NormalB $ (ConE cnam)) []]
]

0 comments on commit fceebf7

Please sign in to comment.