Magnus Therning wrote:
I'll certainly try to look into all of that. However, I suspect your
suggestion doesn't scale very well. On my original code it's easy, it
was less than 10 lines, but how do I know where to start looking if it's
a program of 100 lines, or 1000 lines? The problem could
On Sun, 2007-10-21 at 17:15 -0400, Albert Y. C. Lai wrote:
Magnus Therning wrote:
I'll certainly try to look into all of that. However, I suspect your
suggestion doesn't scale very well. On my original code it's easy, it
was less than 10 lines, but how do I know where to start looking if
On Fri, Oct 19, 2007 at 02:09:01 +1000, Matthew Brecknell wrote:
Magnus Therning:
Just out of curiosity, how would I go about finding this myself?
(Ideally it'd be an answer other than read the source for the libraries
you are using. :-)
Well, I can at least try to expand a little on read the
I agree with Matthew's comments in the post immediately before this. It
takes him two decent paragraphs to explain what is going on, including a
description of WHNF, a suggestion to use pen paper, a suggestion to
read up on the semantics of unsafeInterleaveIO and more.
What I find
Magnus Therning:
hasEmpty s = let
_first_empty = s !! 0 == '\n'
_last_empty = (reverse s) !! 1 == '\n'
in _first_empty || _last_empty
loadAndCheck fp = liftM hasEmpty $ readFile fp
main = getArgs = filterM loadAndCheck = mapM_ putStrLn
The one
Is there some (easy) way to avoid this while still using readFile?
readFile' f = do s - readFile f
return (length s `seq` s)
(and curse the fact that the default readFile is unsafelazy).
Jules
___
Haskell-Cafe mailing list
On Thu, Oct 18, 2007 at 12:05:40 +0100, Jules Bean wrote:
Is there some (easy) way to avoid this while still using readFile?
readFile' f = do s - readFile f
return (length s `seq` s)
(and curse the fact that the default readFile is unsafelazy).
:( Doesn't work. I'm starting to
On Thu, Oct 18, 2007 at 20:58:45 +1000, Matthew Brecknell wrote:
Magnus Therning:
hasEmpty s = let
_first_empty = s !! 0 == '\n'
_last_empty = (reverse s) !! 1 == '\n'
in _first_empty || _last_empty
loadAndCheck fp = liftM hasEmpty $ readFile fp
Magnus Therning:
Still no cigar :(
Yes, this is a little more subtle than I first thought. Look at liftM
and filterM:
liftM f m1 = do { x1 - m1; return (f x1) }
filterM :: (Monad m) = (a - m Bool) - [a] - m [a]
filterM _ [] = return []
filterM p (x:xs) = do
flg - p x
ys - filterM p xs
Magnus Therning wrote:
On Thu, Oct 18, 2007 at 12:05:40 +0100, Jules Bean wrote:
Is there some (easy) way to avoid this while still using readFile?
readFile' f = do s - readFile f
return (length s `seq` s)
(and curse the fact that the default readFile is unsafelazy).
:(
On Thu, Oct 18, 2007 at 01:16:37PM +0100, Magnus Therning wrote:
On Thu, Oct 18, 2007 at 20:58:45 +1000, Matthew Brecknell wrote:
For a less hackish solution, you need to do a bit more work. Again, this
is untested.
loadAndCheck fn = bracket (openFile fn ReadMode) hClose checkContents
On Thu, Oct 18, 2007 at 09:25:32 -0400, David Roundy wrote:
On Thu, Oct 18, 2007 at 01:16:37PM +0100, Magnus Therning wrote:
On Thu, Oct 18, 2007 at 20:58:45 +1000, Matthew Brecknell wrote:
For a less hackish solution, you need to do a bit more work. Again, this
is untested.
loadAndCheck fn
On Thu, Oct 18, 2007 at 22:58:48 +1000, Matthew Brecknell wrote:
Magnus Therning:
Still no cigar :(
Yes, this is a little more subtle than I first thought. Look at liftM
and filterM:
liftM f m1 = do { x1 - m1; return (f x1) }
filterM :: (Monad m) = (a - m Bool) - [a] - m [a]
filterM _ [] =
On Thu, Oct 18, 2007 at 22:58:48 +1000, Matthew Brecknell wrote:
Magnus Therning:
Still no cigar :(
Yes, this is a little more subtle than I first thought. Look at liftM
and filterM:
liftM f m1 = do { x1 - m1; return (f x1) }
filterM :: (Monad m) = (a - m Bool) - [a] - m [a]
filterM _ [] =
Magnus Therning:
Just out of curiosity, how would I go about finding this myself?
(Ideally it'd be an answer other than read the source for the libraries
you are using. :-)
Well, I can at least try to expand a little on read the source. :-)
You'll first need a solid understanding of lazy
magnus:
On Thu, Oct 18, 2007 at 12:05:40 +0100, Jules Bean wrote:
Is there some (easy) way to avoid this while still using readFile?
readFile' f = do s - readFile f
return (length s `seq` s)
(and curse the fact that the default readFile is unsafelazy).
:( Doesn't work.
16 matches
Mail list logo