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?
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
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
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
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 -
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
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
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
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
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
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
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
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
13 matches
Mail list logo