Re: [Haskell-cafe] After `readFile`, why cannot i `writeFile` ?

2010-06-07 Thread Bill Atkins
readFile reads the file lazily so it isn't closed until the entire contents have been consumed. Try System.IO.Strict.readFile, which will read the entire file at once. zaxis writes: > hitSSQ :: String -> [Int] -> IO () > hitSSQ no hitNum = do >let newNum = unwords $ [no] ++ map (\n -> show

Re: [Haskell-cafe] Removing alternate items from a list

2010-06-07 Thread Bill Atkins
alts :: [a] -> [a] alts xs = map fst . filter snd $ zip xs (cycle [False, True]) Prelude> alts [0, 1..5] [1,3, 5] On Sunday Jun 6, 2010, at 10:46 AM, R J wrote: > What's the cleanest definition for a function f :: [a] -> [a] that takes a > list and returns the same list, with alternate items re

Re: [Haskell-cafe] After `readFile`, why cannot i `writeFile` ?

2010-06-07 Thread Bill Atkins
BTW, "\n -> show n" is equivalent to "show" . On Monday Jun 7, 2010, at 8:37 PM, zaxis wrote: >> Yes, and i can use appendFile too. >> >> appendFile "ssqHitNum.txt" $ unwords $ [no] ++ map (\n -> show n) hitNum >> ++ ["\n"] > ___ Haskell-Cafe mailing

Re: [Haskell-cafe] Removing alternate items from a list

2010-06-08 Thread Bill Atkins
f :: [a] -> [a] f = filter snd $ zip a (cycle [True, False]) On Monday, June 7, 2010, Ozgur Akgun wrote: > or, since you don't need to give a name to the second element of the list: > > f :: [a] -> [a] > f (x:_:xs) = x : f xsf x = x > > > > > On 7 June 2010 20:11, Ozgur Akgun wrote: > > i think

Re: [Haskell-cafe] Removing alternate items from a list

2010-06-08 Thread Bill Atkins
you might have forgotten the "map fst $" part. > > Best, > > > On 8 June 2010 14:51, Bill Atkins wrote: > > f :: [a] -> [a] > f = filter snd $ zip a (cycle [True, False]) > > On Monday, June 7, 2010, Ozgur Akgun wrote: >> or, since you don't ne

Re: [Haskell-cafe] Re: Lists and monads

2010-07-26 Thread Bill Atkins
Can you post an example of your code? mapM and map are actually for pretty distinct purposes. If you find yourself wanting to map over a pure list in monadic code, you should really look at applicative style, e.g.: import Control.Applicative data Struct = deriving (Read) readStruc

Re: [Haskell-cafe] Re: Lists and monads

2010-07-26 Thread Bill Atkins
The answer is still applicative. :) On Monday Jul 26, 2010, at 10:06 AM, Kevin Jardine wrote: > On Jul 26, 3:49 pm, Kevin Jardine wrote: >> I find >> myself wishing that f (m [a]) just automatically returned m f([a]) >> without me needing to do anything but I expect that there are reasons >> wh

Re: [Haskell-cafe] Is 'flip' really necessary?

2010-07-26 Thread Bill Atkins
Seconded. On Monday Jul 26, 2010, at 6:24 PM, Edward Z. Yang wrote: > IMO, if you really want a wildcard, just write a lambda... > >\x -> foo 1 x 3 > > Cheers, > Edward > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.hask

Re: [Haskell-cafe] Couple of questions about *let* within *do*

2010-08-10 Thread Bill Atkins
The let's aren't really statements, they're just named expressions and are still subject to lazy evaluation. In: let x = putStrLn "Name" >> getLine putStrLn "Welcome" x The program will print: Welcome Name? and then prompt for input, even though the let comes first. And if you never ran

Re: [Haskell-cafe] Unwrapping long lines in text files

2010-08-13 Thread Bill Atkins
Not sure if I understood what you're trying to do, but development will be easier if you minimize your IO, e.g. : maxLineLength :: Int maxLineLength = 72 wrapLine :: String -> [String] wrapLine "" = [] wrapLine line | length line <= maxLineLength= [line] | otherwise

Re: [Haskell-cafe] Unwrapping long lines in text files

2010-08-14 Thread Bill Atkins
row alight upon my shoulder for a moment, while I was h > oeing in a village garden, and I felt that I was more distinguished by t > hat circumstance that I should have been by any epaulet I could have wor > n. > -Thoreau > === > > > --- On Fri, 8/13/10, B

Re: [Haskell-cafe] Re: philosophy of Haskell

2010-08-14 Thread Bill Atkins
On Saturday Aug 14, 2010, at 12:50 AM, Conal Elliott wrote: > And the IO monad is what Jerzy asked about. I'm pointing out that the state > monad does not capture concurrency, and the "EDSL model" does not capture > FFI. (Really, it depends which "EDSL model". I haven't seen one that can > c

Re: [Haskell-cafe] Unwrapping long lines in text files

2010-08-14 Thread Bill Atkins
Oof, that's what I get for making "just one little change" without testing. You're right. On Saturday Aug 14, 2010, at 9:17 AM, Felipe Lessa wrote: > On Sat, Aug 14, 2010 at 9:59 AM, Bill Atkins wrote: >> | otherwise= l

Re: [Haskell-cafe] Unwrapping long lines in text files

2010-08-14 Thread Bill Atkins
k lines between individual > quotes. THe only thing in the input text that should change are the lines > longer than 72 characters, and they should be reformatted to one or more > lines less than or equal to 72 characters. > > Michael > > --- On Sat, 8/14/10, Felipe Lessa

Re: [Haskell-cafe] Re: String vs ByteString

2010-08-15 Thread Bill Atkins
No, not really. Linked lists are very easy to deal with recursively and Strings automatically work with any already-defined list functions. On Sun, Aug 15, 2010 at 11:17 AM, Brandon S Allbery KF8NH < allb...@ece.cmu.edu> wrote: > More to the point, there's nothing elegant about [Char] --- its so

Re: [Haskell-cafe] Re: philosophy of Haskell

2010-08-15 Thread Bill Atkins
On Sunday, August 15, 2010, Tillmann Rendel wrote: > Bulat Ziganshin wrote: > > But in a world passing interpretation of IO, print is supposed to be a > pure Haskell function. So the value world2 can only depend on the values > of print and world1, but not on the actions of some concurrent thread.

Re: [Haskell-cafe] Code that writes code

2010-08-21 Thread Bill Atkins
Have you looked at creating Template Haskell splices to generate this for you? On Friday Aug 20, 2010, at 2:21 PM, Andrew Coppin wrote: > All I'm actually using it to do is generate a set of fixed-size containers > (each of which has a bazillion class instances). I've got a variable-sized > con

Re: [Haskell-cafe] feasability of implementing an awk interpreter.

2010-08-21 Thread Bill Atkins
I don't think Template Haskell will be essential for this - you will probably need a parser (probably written with Parsec), an eval function, and a state monad to represent imperative changes made by the language you're evaluating. Template Haskell is more for the elimination of boilerplate cod

[Haskell-cafe] macosx-app for wxHaskell

2010-05-05 Thread Bill Atkins
In order to run apps built with wxHaskell on OS X, you're supposed to wrap the binary using a script called macosx-app ( http://www.haskell.org/haskellwiki/WxHaskell/MacOS_X). Unfortunately, after running "cabal install wx" this file is not in "~/.cabal" - it's also not in the wxHaskell source. D

Re: [Haskell-cafe] mixing map and mapM ?

2010-05-06 Thread Bill Atkins
Almost - "liftM modificationTime" has type Status -> IO EpochTime. Like other IO functions (getLine, putStrLn), it returns an IO action but accepts a pure value (the modification time) Also, I like this style: import Control.Applicative ((<$>)) blah = do times <- mapM (PF.modificationTime <$>

Re: [Haskell-cafe] mixing map and mapM ?

2010-05-06 Thread Bill Atkins
Yep, you and Ben are both correct. Mea culpa and sorry for the bad answer. Just curious: why does getModificationTime take an IO FileStatus rather than a FileStatus? On Thu, May 6, 2010 at 7:00 AM, Neil Brown wrote: > Bill Atkins wrote: > > Almost - "liftM modificationTime&qu

[Haskell-cafe] cabal problem on OS X

2010-05-22 Thread Bill Atkins
When I run "cabal update" on my Mac (Snow Leopard, Intel), I get: % cabal update Downloading the latest package list from hackage.haskell.org cabal: Codec.Compression.Zlib: incompatible zlib version Anyone else seeing this? Reinstalling the Haskell Platform hasn't helped. Thanks! __