@@ -106,23 +106,54 @@ delist fullList (Var.Listing partial open)
106106
107107 _ -> go list xs partial
108108
109−filterExports :: Module.Types -> [Var.Value] -> Module.Types
110−filterExports types values =
111− Map.fromList (concatMap getValue values)
109+filterExports :: Module.CanonicalBody -> [Var.Value] -> Module.CanonicalBody
110+filterExports body exportedValues =
111+ body
112+ { Module.types =
113+ Map.fromList (concatMap getTypes exportedValues)
114+ , Module.aliases =
115+ Map.fromList (concatMap getAliases exportedValues)
116+ , Module.datatypes =
117+ Map.fromList (concatMap getAdts exportedValues)
118+ }
112119 where
113− getValue :: Var.Value -> [(String, Type.CanonicalType)]
114− getValue value =
115− case value of
116− Var.Value x -> get x
117− Var.Alias x -> get x
118− Var.ADT _ (Var.Listing ctors _) -> concatMap get ctors
119−
120− get :: String -> [(String, Type.CanonicalType)]
121− get x =
122− case Map.lookup x types of
120+ get :: Map.Map String a -> String -> [(String, a)]
121+ get dict x =
122+ case Map.lookup x dict of
123123 Just t -> [(x,t)]
124124 Nothing -> []
125125
126+ getTypes :: Var.Value -> [(String, Type.CanonicalType)]
127+ getTypes value =
128+ case value of
129+ Var.Value x -> getType x
130+ Var.Alias _ -> []
131+ Var.ADT _ (Var.Listing ctors _) -> concatMap getType ctors
132+
133+ getType :: String -> [(String, Type.CanonicalType)]
134+ getType = get (Module.types body)
135+
136+ getAliases :: Var.Value -> [(String, ([String], Type.CanonicalType))]
137+ getAliases value =
138+ case value of
139+ Var.Value _ -> []
140+ Var.Alias name -> get (Module.aliases body) name
141+ Var.ADT _ _ -> []
142+
143+ getAdts :: Var.Value -> [(String, Module.AdtInfo String)]
144+ getAdts value =
145+ case value of
146+ Var.Value _ -> []
147+ Var.Alias _ -> []
148+ Var.ADT name (Var.Listing exportedCtors _) ->
149+ case Map.lookup name (Module.datatypes body) of
150+ Nothing -> []
151+ Just (tvars, ctors) ->
152+ [(name, (tvars, filter isExported ctors))]
153+ where
154+ isExported (ctor, _) = ctor `elem` exportedCtors
155+
156+
126157declToValue :: D.ValidDecl -> [Var.Value]
127158declToValue decl =
128159 case decl of
@@ -132,8 +163,11 @@ declToValue decl =
132163 D.Datatype name _tvs ctors ->
133164 [ Var.ADT name (Var.Listing (map fst ctors) False) ]
134165
135− D.TypeAlias name _ (Type.Record _ _) ->
136− [ Var.Alias name ]
166+ D.TypeAlias name _ tipe ->
167+ case tipe of
168+ Type.Record _ _ ->
169+ [ Var.Alias name, Var.Value name ]
170+ _ -> [ Var.Alias name ]
137171
138172 _ -> []
139173