Skip to content

Commit 5986b61

Browse files
committed
Merge pull request #65 from phischu/v0.5.3
V0.5.3
2 parents f44eba9 + 494a30c commit 5986b61

File tree

6 files changed

+41
-12
lines changed

6 files changed

+41
-12
lines changed

haskell-names.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Name: haskell-names
2-
Version: 0.5.2
2+
Version: 0.5.3
33
License: BSD3
44
Author: Philipp Schuster, Roman Cheplyaka, Lennart Augustsson
55
Maintainer: Philipp Schuster

hs-gen-iface/hs-gen-iface.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Name: hs-gen-iface
2-
Version: 0.5.2
2+
Version: 0.5.3
33
License: MIT
44
License-file: LICENSE
55
Author: Roman Cheplyaka

src/Language/Haskell/Names/ModuleSymbols.hs

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,10 @@ getTopDeclSymbols impTbl modulename d = (case d of
5656
TypeFamDecl _ dh _ -> [declHeadSymbol TypeFam dh]
5757

5858
DataDecl _ dataOrNew _ dh qualConDecls _ -> declHeadSymbol (dataOrNewCon dataOrNew) dh : infos where
59-
cons :: [(Name l,[Name l])]
60-
cons = do -- list monad
61-
QualConDecl _ _ _ conDecl <- qualConDecls
62-
case conDecl of
63-
ConDecl _ n _ -> return (n, [])
64-
InfixConDecl _ _ n _ -> return (n, [])
65-
RecDecl _ n fields ->
66-
return (n , [f | FieldDecl _ fNames _ <- fields, f <- fNames])
6759

6860
dq = getDeclHeadName dh
6961

70-
infos = constructorsToInfos modulename dq cons
62+
infos = constructorsToInfos modulename dq (qualConDeclNames qualConDecls)
7163

7264
GDataDecl _ dataOrNew _ dh _ gadtDecls _ -> declHeadSymbol (dataOrNewCon dataOrNew) dh : infos where
7365
-- FIXME: We shouldn't create selectors for fields with existential type variables!
@@ -99,6 +91,15 @@ getTopDeclSymbols impTbl modulename d = (case d of
9991

10092
ForImp _ _ _ _ fn _ -> [ Value (sModuleName modulename) (sName fn)]
10193

94+
DataInsDecl _ _ typ qualConDecls _ -> constructorsToInfos modulename (typeOuterName typ) (qualConDeclNames qualConDecls)
95+
96+
GDataInsDecl _ _ typ _ gadtDecls _ -> constructorsToInfos modulename (typeOuterName typ) cons where
97+
-- FIXME: We shouldn't create selectors for fields with existential type variables!
98+
cons :: [(Name l,[Name l])]
99+
cons = do -- list monad
100+
GadtDecl _ cn (fromMaybe [] -> fields) _ty <- gadtDecls
101+
return (cn , [f | FieldDecl _ fNames _ <- fields, f <- fNames])
102+
102103
_ -> [])
103104
where
104105
declHeadSymbol c dh = c (sModuleName modulename) (sName (getDeclHeadName dh))
@@ -122,5 +123,26 @@ constructorsToInfos modulename typename constructors = conInfos ++ selInfos wher
122123
constructornames <- maybeToList (Map.lookup (nameToString selectorname) selectorsMap)
123124
return (Selector (sModuleName modulename) (sName selectorname) (sName typename) (map sName constructornames))
124125

126+
typeOuterName :: Type l -> Name l
127+
typeOuterName t = case t of
128+
TyForall _ _ _ typ -> typeOuterName typ
129+
TyApp _ typ _ -> typeOuterName typ
130+
TyCon _ qname -> qNameToName qname
131+
TyParen _ typ -> typeOuterName typ
132+
TyInfix _ _ qname _ -> qNameToName qname
133+
TyKind _ typ _ -> typeOuterName typ
134+
TyBang _ _ typ -> typeOuterName typ
135+
_ -> error "illegal data family in data instance"
136+
137+
qualConDeclNames :: [QualConDecl l] -> [(Name l,[Name l])]
138+
qualConDeclNames qualConDecls = do
139+
QualConDecl _ _ _ conDecl <- qualConDecls
140+
case conDecl of
141+
ConDecl _ n _ -> return (n, [])
142+
InfixConDecl _ _ n _ -> return (n, [])
143+
RecDecl _ n fields ->
144+
return (n , [f | FieldDecl _ fNames _ <- fields, f <- fNames])
145+
146+
125147
dataOrNewCon :: Syntax.DataOrNew l -> UnAnn.ModuleName -> UnAnn.Name -> Symbol
126148
dataOrNewCon dataOrNew = case dataOrNew of DataType {} -> Data; Syntax.NewType {} -> NewType

tests/exports/DataFamilies.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ data family Vector a
66
class ListLike a where
77
type I a
88
h :: a -> I a
9+
10+
newtype instance Vector () = U_Vector ()

tests/exports/DataFamilies.hs.golden

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@
1515
, symbolName = Ident "h"
1616
, className = Ident "ListLike"
1717
}
18+
, Constructor
19+
{ symbolModule = ModuleName "DataFamilies"
20+
, symbolName = Ident "U_Vector"
21+
, typeName = Ident "Vector"
22+
}
1823
]

tests/run.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-- vim:fdm=marker:foldtext=foldtext()
22
{-# LANGUAGE FlexibleInstances, OverlappingInstances, ImplicitParams,
3-
MultiParamTypeClasses, FlexibleContexts #-}
3+
MultiParamTypeClasses, FlexibleContexts, GADTs #-}
44
-- GHC 7.8 fails with the default context stack size of 20
55
{-# OPTIONS_GHC -fcontext-stack=50 #-}
66
-- Imports {{{

0 commit comments

Comments
 (0)