[Haskell-beginners] Compiling C into Haskell

Chaddaï Fouché chaddai.fouche at gmail.com
Wed Apr 14 06:20:14 EDT 2010


On Tue, Apr 13, 2010 at 2:39 PM, Hein Hundal <hundalhh at yahoo.com> wrote:
> Thanks Allan!
>
>    I was hoping the C-Haskell mix would work.  I am glad to hear that you have good things to say about it.
>
>    My main reason for thinking about the C-to-Haskell compiler was to address the question "Say you had a C program.  Can you always convert it to Haskell in such a way that the compiled Haskell is not too slow and does not need too much memory?"  Supposing that too slow means slower than 1/4 the speed of C and too much memory means twice the memory of C.
>
>    Do you know the answer to this question?

I would say probably yes, since Haskell can do much of the same thing
C does or simulate it closely... But that's not idiomatic Haskell and
thus very uninteresting and probably unreadable. A C to idiomatic
Haskell compiler would be more interesting but extremely hard to write
and the results would probably be pretty slow (since a good and fast
translation would necessarily imply some change of algorithms and
data-structure and so be too hard even for a smart compiler (needs a
full AI ! ;)).

If the question is : Can we always write a fast Haskell equivalent ?
The response is probably yes (when we can write an Haskell equivalent)
but with some effort and not mechanically.

Of course, when we have a good enough C library, it may be better to
just use the FFI in practice.

-- 
Jedaï


More information about the Beginners mailing list