@@ -124,10 +124,13 @@ typeInstanceDictionaryDeclaration name mn deps className tys decls = do
124124 m <- get
125125
126126 -- Lookup the type arguments and member types for the type class
127− (TypeClassDeclaration _ args implies tyDecls) <- lift $ maybe (Left $ mkErrorStack ("Type class " ++ show className ++ " is undefined") Nothing) Right
128− $ M.lookup (qualify mn className) m
127+ (TypeClassDeclaration _ args implies tyDecls) <- lift $
128+ maybe (Left $ mkErrorStack ("Type class " ++ show className ++ " is undefined") Nothing) Right $
129+ M.lookup (qualify mn className) m
129130 let instanceTys = map memberToNameAndType tyDecls
130131
132+ let superclasses = TypedValue False (ArrayLiteral [ TypeClassDictionary (superclass, tyArgs) [] | (superclass, tyArgs) <- implies ]) (TypeApp tyArray unit)
133+
131134 -- Replace the type arguments with the appropriate types in the member types
132135 let memberTypes = map (second (replaceAllTypeVars (zip args tys))) instanceTys
133136 -- Create values for the type instance members
@@ -137,9 +140,10 @@ typeInstanceDictionaryDeclaration name mn deps className tys decls = do
137140 -- The dictionary itself is an object literal, but for reasons related to recursion, the dictionary
138141 -- must be guarded by at least one function abstraction. For that reason, if the dictionary has no
139142 -- dependencies, we introduce an unnamed function parameter.
140− let dictTy = TypeApp tyObject (rowFromList (map (first identToProperty) memberTypes, REmpty))
143+ let dictTy = TypeApp tyObject (rowFromList (map (first identToProperty) memberTypes, RCons "__superclasses" (TypeApp tyArray unit) REmpty))
141144 constrainedTy = quantify (if null deps then function unit dictTy else ConstrainedType deps dictTy)
142− dict = if null deps then Abs (Left (Ident "_")) (ObjectLiteral memberNames) else ObjectLiteral memberNames
145+ memberNames' = ("__superclasses", superclasses) : memberNames
146+ dict = if null deps then Abs (Left (Ident "_")) (ObjectLiteral memberNames') else ObjectLiteral memberNames'
143147 return $ ValueDeclaration name TypeInstanceDictionaryValue [] Nothing (TypedValue True dict constrainedTy)
144148 where
145149 unit :: Type