@@ -106,23 +106,54 @@ delist fullList (Var.Listing partial open)
107 _ -> go list xs partial
107 _ -> go list xs partial
109−filterExports :: Module.Types -> [Var.Value] -> Module.Types
109+filterExports :: Module.CanonicalBody -> [Var.Value] -> Module.CanonicalBody
110−filterExports types values =
110+filterExports body exportedValues =
113+ Map.fromList (concatMap getTypes exportedValues)
115+ Map.fromList (concatMap getAliases exportedValues)
116+ , Module.datatypes =
111− Map.fromList (concatMap getValue values)
117+ Map.fromList (concatMap getAdts exportedValues)
113− getValue :: Var.Value -> [(String, Type.CanonicalType)]
120+ get :: Map.Map String a -> String -> [(String, a)]
116− Var.Value x -> get x
117− Var.Alias x -> get x
118− Var.ADT _ (Var.Listing ctors _) -> concatMap get ctors
120− get :: String -> [(String, Type.CanonicalType)]
121− get x =
121+ get dict x =
122− case Map.lookup x types of
122+ case Map.lookup x dict of
123 Just t -> [(x,t)]
123 Just t -> [(x,t)]
124 Nothing -> []
124 Nothing -> []
126+ getTypes :: Var.Value -> [(String, Type.CanonicalType)]
129+ Var.Value x -> getType x
131+ Var.ADT _ (Var.Listing ctors _) -> concatMap getType ctors
133+ getType :: String -> [(String, Type.CanonicalType)]
134+ getType = get (Module.types body)
136+ getAliases :: Var.Value -> [(String, ([String], Type.CanonicalType))]
140+ Var.Alias name -> get (Module.aliases body) name
143+ getAdts :: Var.Value -> [(String, Module.AdtInfo String)]
148+ Var.ADT name (Var.Listing exportedCtors _) ->
149+ case Map.lookup name (Module.datatypes body) of
151+ Just (tvars, ctors) ->
152+ [(name, (tvars, filter isExported ctors))]
154+ isExported (ctor, _) = ctor `elem` exportedCtors
126declToValue :: D.ValidDecl -> [Var.Value]
157declToValue :: D.ValidDecl -> [Var.Value]
127declToValue decl =
158declToValue decl =
128 case decl of
159 case decl of
@@ -132,8 +163,11 @@ declToValue decl =
132 D.Datatype name _tvs ctors ->
163 D.Datatype name _tvs ctors ->
133 [ Var.ADT name (Var.Listing (map fst ctors) False) ]
164 [ Var.ADT name (Var.Listing (map fst ctors) False) ]
135− D.TypeAlias name _ (Type.Record _ _) ->
166+ D.TypeAlias name _ tipe ->
169+ [ Var.Alias name, Var.Value name ]
136− [ Var.Alias name ]
170+ _ -> [ Var.Alias name ]