git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Provide more information in `exportedDctors`

Currently, `exportedDctors` returns only a [ProperName] with the names of the data constructors. This is no good if you want to know about the arguments of each constructor. This commit fixes the issue by changing the return type to [(ProperName, [Type])]. On a related note, I wonder if the documentation for `isExported` and `isDctorExported` should encourage you to use `exportedDecls` and `exportedDctors`, as these are 'higher level' versions of what is really the same function, which won't require you to pattern match (and therefore hopefully be safer and less likely to break because of updates).

commit52c8b688ee20307fea03f7bef93592a1366247f4 authorHarry Garrood <harry@garrood.me> dateThu 19 Mar 2015, 06:57 (12 years ago) parent005eed5
2 files changed+4−4
psci/Completion.hs+1−1 src/Language/PureScript/AST/Declarations.hs+3−3
psci/Completion.hs+1−1
@@ -218,7 +218,7 @@ dctorNames m = nubOnFst $ concatMap dctors dnames
218218 onlyDataDecls = (filter P.isDataDecl (P.exportedDeclarations m))
219219
220220 dctors :: (N.ProperName, P.Declaration) -> [(N.ProperName, P.Declaration)]
221− dctors (name, decl) = map (\n -> (n, decl)) (P.exportedDctors m name)
221+ dctors (name, decl) = map (\n -> (n, decl)) (map fst (P.exportedDctors m name))
222222
223223moduleNames :: [P.Module] -> [String]
224224moduleNames ms = nub [show moduleName | P.Module _ moduleName _ _ <- ms]
src/Language/PureScript/AST/Declarations.hs+3−3
@@ -78,12 +78,12 @@ isDctorExported ident (Just exps) ctor = test `any` exps
7878-- |
7979-- Return the exported data constructors for a given type.
8080--
81−exportedDctors :: Module -> ProperName -> [ProperName]
81+exportedDctors :: Module -> ProperName -> [(ProperName, [Type])]
8282exportedDctors (Module _ _ decls exps) ident =
83− filter (isDctorExported ident exps) dctors
83+ filter (isDctorExported ident exps . fst) dctors
8484 where
8585 dctors = concatMap getDctors (flattenDecls decls)
86− getDctors (DataDeclaration _ _ _ ctors) = map fst ctors
86+ getDctors (DataDeclaration _ _ _ ctors) = ctors
8787 getDctors (PositionedDeclaration _ _ d) = getDctors d
8888 getDctors _ = []
8989