Skip to content

Commit

Permalink
Provide better capitalized functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mgsloan committed Jul 19, 2012
1 parent b1334bc commit baed867
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
25 changes: 19 additions & 6 deletions Control/Newtype/TH.hs
Expand Up @@ -23,7 +23,9 @@
--
-----------------------------------------------------------------------------

module Control.Newtype.TH ( mkNewType, mkNewTypes ) where
module Control.Newtype.TH
( mkNewtype, mkNewtypes
, mkNewType, mkNewTypes ) where

import Control.Newtype ( Newtype(pack, unpack) )

Expand All @@ -41,13 +43,13 @@ import Language.Haskell.TH
import Language.Haskell.Meta.Utils (conName, conTypes)

-- | Derive a single instance of @Newtype@.
mkNewType :: Name -> Q [Dec]
mkNewType = mkNewTypes . (:[])
mkNewtype :: Name -> Q [Dec]
mkNewtype = mkNewTypes . (:[])

-- | Derive instances of @Newtype@, specified as a list of references
-- to newtypes.
mkNewTypes :: [Name] -> Q [Dec]
mkNewTypes = mapM (\n -> rewriteFamilies =<< mkInst <$> reify n)
mkNewtypes :: [Name] -> Q [Dec]
mkNewtypes = mapM (\n -> rewriteFamilies =<< mkInst <$> reify n)
where
mkInst (TyConI (NewtypeD a b c d _)) = mkInstFor a b c d
mkInst (TyConI (DataD a b c [d] _)) = mkInstFor a b c d
Expand Down Expand Up @@ -135,4 +137,15 @@ rewriteFamilies (InstanceD preds ity ds) = do
generic :: Data a => a -> [(Name, Type)]
generic = concat . gmapQ (const [] `extQ` handleType)

rewriteFamilies d = return d
rewriteFamilies d = return d


{-# DEPRECATED Use mkNewtype instead. #-}
-- | Compatibility with an old, ill-capitalized name.
mkNewType :: Name -> Q [Dec]
mkNewType = mkNewtype

{-# DEPRECATED Use mkNewtypes instead. #-}
-- | Compatibility with an old, ill-capitalized name.
mkNewTypes :: [Name] -> Q [Dec]
mkNewTypes = mkNewtypes
4 changes: 2 additions & 2 deletions newtype-th.cabal
@@ -1,5 +1,5 @@
Name: newtype-th
Version: 0.3.2
Version: 0.3.3
Synopsis: A template haskell deriver to create Control.Newtype instances.
Description: Provides a template haskell based mechanism for
deriving instances of djahandarie's Control.Newtype class.
Expand All @@ -9,7 +9,7 @@ Author: Michael Sloan
Maintainer: Michael Sloan <mgsloan at gmail>
Homepage: http://github.com/mgsloan/newtype-th
Copyright: Michael Sloan 2011
Category: Control
Category: Control, Template Haskell
Build-type: Simple
Extra-source-files: Tests.hs
Data-files: README
Expand Down

0 comments on commit baed867

Please sign in to comment.