Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use hygenic name for Control.Newtype.Newtype

  • Loading branch information...
commit fceebf7f8623ec29ae6b3e9b7c8325af17f95c6b 1 parent 75f2445
Eyal Lotem authored
Showing with 5 additions and 3 deletions.
  1. +5 −3 Control/Newtype/TH.hs
View
8 Control/Newtype/TH.hs
@@ -26,6 +26,8 @@ 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)
@@ -33,15 +35,15 @@ mkNewTypes = fmap concat . mapM (fmap mkInst . reify)
[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)) []]
]
Please sign in to comment.
Something went wrong with that request. Please try again.