@@ -131,11 +131,22 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
132 return (CppComment com fn')
132 return (CppComment com fn')
134− declToCpp _ ident (Constructor _ _ (ProperName _) fields) = return $
134+ declToCpp _ ident (Constructor _ _ (ProperName _) []) = return $
135+ CppFunction (identToCpp ident)
136+ [] (Just $ CppAny [])
138+ (CppBlock [CppReturn (CppArrayLiteral [CppStringLiteral (identToCpp ident)])])
140+ declToCpp _ ident (Constructor _ _ (ProperName _) fields) = return . CppNamespace [] $
141+ [ CppFunction ('$' : identToCpp ident) (farg <$> fields')
144+ (CppBlock fullyConstructed)
135− CppFunction (identToCpp ident) (farg <$> f)
145+ , CppFunction (identToCpp ident) (farg <$> f)
136− (Just $ CppAny [])
146+ (Just $ CppAny [])
138− (CppBlock (fieldLambdas fs))
148+ (CppBlock (fieldLambdas fs))
140 name = identToCpp ident
151 name = identToCpp ident
141 fields' = identToCpp <$> fields
152 fields' = identToCpp <$> fields
@@ -147,7 +158,8 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
147 CppLambda [CppCaptureAll] (farg <$> [f'])
158 CppLambda [CppCaptureAll] (farg <$> [f'])
148 (Just $ CppAny [])
159 (Just $ CppAny [])
149 (CppBlock $ fieldLambdas fs')]
160 (CppBlock $ fieldLambdas fs')]
161+ | otherwise = fullyConstructed
150− | otherwise = [CppReturn (CppArrayLiteral (CppStringLiteral name : (CppVar <$> fields')))]
162+ fullyConstructed = [CppReturn (CppArrayLiteral (CppStringLiteral name : (CppVar <$> fields')))]
152 declToCpp _ ident val = do
164 declToCpp _ ident val = do
153 val' <- valueToCpp val
165 val' <- valueToCpp val
@@ -290,6 +302,8 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
290 args' <- mapM valueToCpp args
302 args' <- mapM valueToCpp args
291 case f of
303 case f of
292 Var (_, _, _, Just IsNewtype) _ -> return (head args')
304 Var (_, _, _, Just IsNewtype) _ -> return (head args')
305+ Var (_, _, _, Just (IsConstructor _ fields)) (Qualified qual (Ident name)) | length args == length fields ->
306+ return $ CppApp (qualifiedToCpp id . Qualified qual . Ident $ '$' : name) args'
293 Var (_, _, _, Just IsTypeClassConstructor) (Qualified mn' (Ident classname)) ->
307 Var (_, _, _, Just IsTypeClassConstructor) (Qualified mn' (Ident classname)) ->
294 let Just (_, constraints, fns) = findClass (Qualified mn' (ProperName classname)) in
308 let Just (_, constraints, fns) = findClass (Qualified mn' (ProperName classname)) in
295 return . CppObjectLiteral $ zip ((sort $ superClassDictionaryNames constraints) ++ (fst <$> fns)) args'
309 return . CppObjectLiteral $ zip ((sort $ superClassDictionaryNames constraints) ++ (fst <$> fns)) args'