[Haskell-cafe] Re: Useful: putCharLn {inspire by the Int->[Char] thread

John Meacham john at repetae.net
Mon Aug 21 19:45:23 EDT 2006


On Mon, Aug 21, 2006 at 04:31:42PM -0700, Gene A wrote:
> hi,
> Now, is there a speed or "cleaness of code" advantage to using the
> function composition method using (.) :
>   putStrLn . return . head $ "This and that"
> over the application method...using ($):
>   putStrLn $ return $ head "this and that"
> 
> some thoughts on that ... they both work.. but any advantage or disadvantage
> to one over the other.. I find a lot of these kind of things in
> Haskell, and it is purely wonderful.. but always go away wondering if
> I am really using the most efficient, or most acceptable method..
> gene

There is no difference with any good compiler. (.) is always inlined and
the types are fixed by the 'putStrLn' so all the overloaded will be
gotten rid of.

You can pretty much write code in whatever style you want in haskell and
count on the compiler to optimize it to be as efficient as possible. The
things the compiler can't optimize are usually general inefficient
algorithms, not matters of style. There is no need to second guess the
compiler for the most part. And certainly not until after you have done
profiling or looked at the core and actually seen there is an issue.


        John

-- 
John Meacham - ⑆repetae.net⑆john⑈


More information about the Haskell-Cafe mailing list