Permalink
Browse files

support newtypes in makeFields

  • Loading branch information...
1 parent e95fe9a commit e517b4810d3d212fd7f659328bbb238f7a5cde09 @mikeplus64 mikeplus64 committed Jan 28, 2013
Showing with 12 additions and 2 deletions.
  1. +12 −2 src/Control/Lens/TH.hs
@@ -807,7 +807,12 @@ camelCaseFields = FieldRules prefix rawLens niceLens classNaming
verboseLenses :: FieldRules -> Name -> Q [Dec]
verboseLenses c src = do
- TyConI (DataD _ _ _ [RecC _ rs] _) <- reify src
+ rs <- do
+ TyConI dec <- reify src
+ case dec of
+ DataD _ _ _ [RecC _ rs] _ -> return rs
+ NewtypeD _ _ _ (RecC _ rs) _ -> return rs
+ _ -> error "verboseLenses: invalid type."
flip makeLensesFor src
$ mkFields c rs
& map (\(Field n _ l _ _) -> (show n, show l))
@@ -832,7 +837,12 @@ hasClassAndInstance :: FieldRules -> Name -> Q [Dec]
hasClassAndInstance cfg src = do
c <- newName "c"
e <- newName "e"
- TyConI (DataD _ _ vs [RecC _ rs] _) <- reify src
+ (vs,rs) <- do
+ TyConI dec <- reify src
+ case dec of
+ DataD _ _ vs [RecC _ rs] _ -> return (vs,rs)
+ NewtypeD _ _ vs (RecC _ rs) _ -> return (vs,rs)
+ _ -> error "hasClassAndInstance: invalid type."
fmap concat . forM (mkFields cfg rs) $ \(Field field _ fullLensName className lensName) -> do
classHas <- classD
(return [])

0 comments on commit e517b48

Please sign in to comment.