@@ -131,11 +131,22 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
131131 block'
132132 return (CppComment com fn')
133133
134− declToCpp _ ident (Constructor _ _ (ProperName _) fields) = return $
135− CppFunction (identToCpp ident) (farg <$> f)
136− (Just $ CppAny [])
137− []
138− (CppBlock (fieldLambdas fs))
134+ declToCpp _ ident (Constructor _ _ (ProperName _) []) = return $
135+ CppFunction (identToCpp ident)
136+ [] (Just $ CppAny [])
137+ [CppInline]
138+ (CppBlock [CppReturn (CppArrayLiteral [CppStringLiteral (identToCpp ident)])])
139+
140+ declToCpp _ ident (Constructor _ _ (ProperName _) fields) = return . CppNamespace [] $
141+ [ CppFunction ('$' : identToCpp ident) (farg <$> fields')
142+ (Just $ CppAny [])
143+ [CppInline]
144+ (CppBlock fullyConstructed)
145+ , CppFunction (identToCpp ident) (farg <$> f)
146+ (Just $ CppAny [])
147+ []
148+ (CppBlock (fieldLambdas fs))
149+ ]
139150 where
140151 name = identToCpp ident
141152 fields' = identToCpp <$> fields
@@ -147,7 +158,8 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
147158 CppLambda [CppCaptureAll] (farg <$> [f'])
148159 (Just $ CppAny [])
149160 (CppBlock $ fieldLambdas fs')]
150− | otherwise = [CppReturn (CppArrayLiteral (CppStringLiteral name : (CppVar <$> fields')))]
161+ | otherwise = fullyConstructed
162+ fullyConstructed = [CppReturn (CppArrayLiteral (CppStringLiteral name : (CppVar <$> fields')))]
151163
152164 declToCpp _ ident val = do
153165 val' <- valueToCpp val
@@ -290,6 +302,8 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
290302 args' <- mapM valueToCpp args
291303 case f of
292304 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'
293307 Var (_, _, _, Just IsTypeClassConstructor) (Qualified mn' (Ident classname)) ->
294308 let Just (_, constraints, fns) = findClass (Qualified mn' (ProperName classname)) in
295309 return . CppObjectLiteral $ zip ((sort $ superClassDictionaryNames constraints) ++ (fst <$> fns)) args'