Re: [Haskell-cafe] Software Tools in Haskell

2008-01-06 Thread gwern0
On 2007.12.12 12:51:58 -0600, Tommy M McGuire [EMAIL PROTECTED] scribbled 2.7K characters: Gwern Branwen wrote: Some of those really look like they could be simpler, like 'copy' - couldn't that simply be 'main = interact (id)'? Have you seen http://haskell.org/haskellwiki/Simple_Unix_tools?

Re: [Haskell-cafe] Software Tools in Haskell

2007-12-14 Thread Henning Thielemann
On Wed, 12 Dec 2007, Don Stewart wrote: ndmitchell: A much simpler version: main = print . length . words = getContents Beautiful, specification orientated, composed of abstract components. My thoughts too when reading the initial post was that it was all very low level

Re: [Haskell-cafe] Software Tools in Haskell

2007-12-14 Thread Benja Fallenstein
On Dec 14, 2007 9:29 AM, Henning Thielemann [EMAIL PROTECTED] wrote: I remember there was a discussion about how to implement full 'wc' in an elegant but maximally lazy form, that is counting bytes, words and lines in one go. Did someone have a nice idea of how to compose the three counters

Re: [Haskell-cafe] Software Tools in Haskell

2007-12-12 Thread Neil Mitchell
Hi main = do (print . showln . length) = getContents where showln a = show a ++ \n This can be written better. print puts a newline at the end and does a show, so lets remove that bit: main = do (print . length) = getContents Now we aren't using do notation, despite having a do block, and

Re: [Haskell-cafe] Software Tools in Haskell

2007-12-12 Thread Conal Elliott
Here's a version with cleaner separation between pure IO: main = interact $ show . length . words - Conal On Dec 12, 2007 11:12 AM, Neil Mitchell [EMAIL PROTECTED] wrote: Hi Having got to the word counting example on the website: wordcount :: IO () wordcount = do wc -

Re: [Haskell-cafe] Software Tools in Haskell

2007-12-12 Thread Neil Mitchell
Hi Having got to the word counting example on the website: wordcount :: IO () wordcount = do wc - wordcount' False 0 putStrLn (show wc) where wordcount' inword wc = do ch - getc case ch of

Re: [Haskell-cafe] Software Tools in Haskell

2007-12-12 Thread Tommy M McGuire
Don Stewart wrote: My thoughts too when reading the initial post was that it was all very low level imperative programming. Not of the Haskell flavour. -- Don Oh, heck yeah. As I was thinking when I was translating it, I can't even say I'm writing Pascal code using Haskell; I wouldn't

Re: [Haskell-cafe] Software Tools in Haskell

2007-12-12 Thread Tillmann Rendel
Hi Tommy, detab is one of the programs I do not like. I kept the direct translation approach up through that, but I think it really hides the simplicity there; detab copies its input to its output replacing tabs with 1-8 spaces, based on where the tab occurs in a line. The only interesting

Re: [Haskell-cafe] Software Tools in Haskell

2007-12-12 Thread Benja Fallenstein
Another version of detab: main = interact $ perLine $ concat . snd. mapAccumL f 0 where f tab '\t' = (0, replicate (4-tab) ' ') f tab char = ((tab+1) `mod` 4, [char]) - Benja ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] Software Tools in Haskell

2007-12-12 Thread Benja Fallenstein
On Dec 13, 2007 2:20 AM, Benja Fallenstein [EMAIL PROTECTED] wrote: Another version of detab: main = interact $ perLine $ concat . snd. mapAccumL f 0 where f tab '\t' = (0, replicate (4-tab) ' ') f tab char = ((tab+1) `mod` 4, [char]) Although on reflection, I think I might like the

Re: [Haskell-cafe] Software Tools in Haskell

2007-12-12 Thread Benja Fallenstein
On Dec 13, 2007 2:28 AM, Benja Fallenstein [EMAIL PROTECTED] wrote: Although on reflection, I think I might like the following compromise with Tillmann's version best: main = interact $ perLine $ detab 0 where detab tab ('\t':cs) = replicate (4-tab) ' ' ++ detab 0 cs

[Haskell-cafe] Software Tools in Haskell

2007-12-11 Thread Gwern Branwen
On 2007.12.10 13:52:41 -0600, Tommy McGuire [EMAIL PROTECTED] scribbled 1.7K characters: In the if anyone is interested,... department For reasons that remain unclear, early this fall I started translating Brian W. Kernighan and P.J. Plaugher's classic _Software Tools in Pascal_ into

[Haskell-cafe] Software Tools in Haskell

2007-12-10 Thread Tommy McGuire
In the if anyone is interested,... department For reasons that remain unclear, early this fall I started translating Brian W. Kernighan and P.J. Plaugher's classic _Software Tools in Pascal_ into Haskell. I have completed most of it, up to the second part of chapter 8 which presents a