Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Compiling C into Haskell (Chadda? Fouch?)
   2.  Re: Compiling C into Haskell (Heinrich Apfelmus)
   3. Re:  Compiling C into Haskell (Hein Hundal)


----------------------------------------------------------------------

Message: 1
Date: Wed, 14 Apr 2010 12:20:14 +0200
From: Chadda? Fouch? <[email protected]>
Subject: Re: [Haskell-beginners] Compiling C into Haskell
To: Hein Hundal <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=UTF-8

On Tue, Apr 13, 2010 at 2:39 PM, Hein Hundal <[email protected]> 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ï


------------------------------

Message: 2
Date: Wed, 14 Apr 2010 12:21:45 +0200
From: Heinrich Apfelmus <[email protected]>
Subject: [Haskell-beginners] Re: Compiling C into Haskell
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

Brent Yorgey wrote:
> Hein Hundal wrote:
>> 
>> 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?
> 
> My guess is that the answer is technically "no".  If I recall 
> correctly, there are some imperative data structures where the best 
> known time complexity for a functional version is worse than the 
> imperative version by a factor of (log n), so in that case you 
> wouldn't be able to stay within a constant factor of C.

Well, you can always fall back to arrays in the ST monad...

> However, I think in practice the answer is usually "yes"; but it
> might be hard to do it via a mechanical compilation. Idiomatic (and
> fast) Haskell is often organized very differently than corresponding
> C code.

If you already have a C program, then it's probably easiest to link it
in with the Foreign Function Interface.


Regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com



------------------------------

Message: 3
Date: Wed, 14 Apr 2010 04:34:32 -0700 (PDT)
From: Hein Hundal <[email protected]>
Subject: Re: [Haskell-beginners] Compiling C into Haskell
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

Thank you to everyone who responded.

My main question was "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.


Let me summarize some of your responses:

1) The general consensus seems to be the answer is probably yes.  
The exceptions, if there are any, are C programs with complex 
data structures.

2) One of the simpler ways to get the speed and memory 
efficiency of C is using the ST monad.

3) The "Foreign Function Interface" (FFI) is sometimes used by 
Haskell programmers to improve the speed or memory efficiency
of a slow or memory intensive subroutine.

4) For my particular project, I should look into "hmatrix" 
which binds to LAPACK, a linear algebra package that I have 
used before.

5) The conversion process from the C program to the speedy 
Haskell program is probably not simple.  


These responses were great!  

Cheers,
Hein 










      


------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 22, Issue 21
*****************************************

Reply via email to