I've uploaded my CMonad package to Hackage. It allows you to write Haskell code in a C style. Unfortunately, GHC lacks certain optimizations to make efficient code when using CMonad, so instead of C speed you get low speed. Example: Computing some Fibonacci numbers: fib = do { a <- arrayU[40]; i <- auto 0; a[0] =: 1; a[1] =: 1; for (i =: 2, (i :: EIO Int) < 40, i += 1) $ do { a[i] =: a[i-1] + a[i-2]; }; retrn (a[39]); } Example: Copying stdin to stdout: cat = do { c <- auto 0; while ((c =: getchar()) >= 0) $ do { putchar(c); }; return (); } -- Lennart
Well, yes and no. GHC actually does a decent job when given very imperative code with references and mutable arrays. Now the type I use to wrap the references to get type safe l-values and r-values makes it tricker, and ghc lacks a crucial optimization for specialization of constructor returns. With that in place I think the code could be quite performant. -- Lennart On Sun, Mar 29, 2009 at 3:13 PM, Jason Dusek <jason.dusek@gmail.com> wrote:
2009/03/29 Lennart Augustsson <lennart@augustsson.net>:
...GHC lacks certain optimizations to make efficient code when using CMonad, so instead of C speed you get low speed.
Is this surprising to anyone?
-- Jason Dusek
Nested constructed product returns? Or constructed sums? lennart:
Well, yes and no. GHC actually does a decent job when given very imperative code with references and mutable arrays. Now the type I use to wrap the references to get type safe l-values and r-values makes it tricker, and ghc lacks a crucial optimization for specialization of constructor returns. With that in place I think the code could be quite performant.
On Sun, Mar 29, 2009 at 11:16 AM, Lennart Augustsson <lennart@augustsson.net> wrote:
I've uploaded my CMonad package to Hackage. It allows you to write Haskell code in a C style.
Nice! A nice addition would be to output a C AST from language-c: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/language-c regards, Bas
participants (4)
-
Bas van Dijk -
Don Stewart -
Jason Dusek -
Lennart Augustsson