Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Re: Help : foldl skipping one value in list (David Place) 2. problem with lazy IO (Dennis Raddle) 3. Re: Search for docs on operator '<+>'. (Ertugrul Soeylemez) 4. Re: Search for docs on operator '<+>'. (Brent Yorgey) 5. Re: problem with lazy IO (Yitzchak Gale) 6. Re: Help : foldl skipping one value in list (Alexander V Vershilov) 7. Re: problem with lazy IO (Dennis Raddle) 8. Re: problem with lazy IO (Daniel Fischer) ---------------------------------------------------------------------- Message: 1 Date: Wed, 9 Nov 2011 11:17:10 -0500 From: David Place <d...@vidplace.com> Subject: Re: [Haskell-beginners] Help : foldl skipping one value in list To: Lev Broido <lev.bro...@gmail.com> Cc: beginners@haskell.org Message-ID: <5a9c16ca-60f5-46d2-9bb4-c2a49d1c7...@vidplace.com> Content-Type: text/plain; charset=us-ascii On Nov 9, 2011, at 12:18 AM, Lev Broido wrote: > Hi > I am implementing toy loop search algorithm in graph . > I encountered strange problem -- it seems , that fold doesn't run on the > whole list . > Code is at http://hpaste.org/53776 > Section in question is updVis function > Problem occurs when _newStateMap_2 is being calculated > Please advise. Your code is quite complex for the task. Your analysis that the problem lies with foldl' not consuming the whole list is extremely unlikely. Probably, the problem is elsewhere. Try building your solution more from the bottom up and unit testing the components. ------------------------------ Message: 2 Date: Wed, 9 Nov 2011 09:12:20 -0800 From: Dennis Raddle <dennis.rad...@gmail.com> Subject: [Haskell-beginners] problem with lazy IO To: Haskell Beginners <beginners@haskell.org> Message-ID: <cakxlvoqar0fdya-aaxz328zq6hfwcucs+ggpoen4_66cu10...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" I have the following code, which reads several thousand text files and creates some Map data. On Windows XP, it crapped out with the error "resource exhausted: too many open files." So I'm sure I need to make it stricter. I've never tried to do that before, so I'm not sure where the strictness is necessary. Maybe all I need is to switch to strict ByteStrings? -- Read a bunch of text files. The files are organized in pairs, where the file names in each pair are -- "a<number>.txt" and "f<fnumber>.txt". Example: "a00001.txt" and "f00001.txt". -- Each file is a list of float values specified in a certain text format (which happens to be -- an output format of the audio-related program Csound) -- -- Input: -- [(String,String)] : a list of pairs of file names -- String : directory in which the files exist readPvsFiles :: [(String,String)] -> String -> IO (Map Int (Map Float Float)) readPvsFiles filenames dir = do -- contents :: [(Int,Map Float Float)] -- where Int is the number in the file name. -- and Map Float Float is a map of numbers in the -- in the first file mapped to numbers in the second file contents <- mapM (oneFilePair dir) filenames return $ M.fromList contents -- Read one file pair. -- -- Input: -- String : directory of the files -- (String,String) : the two file names in the pair -- (Int,Map Float Float) : -- Int is the number in the file name. -- and Map Float Float is a map of numbers in the -- in the first file mapped to numbers in the second file oneFilePair :: String -> (String,String) -> IO (Int,Map Float Float) oneFilePair dir (ffile,afile) = do -- Read the float values from each file (which is a list of floats in -- a text format. fvalues <- readTableValues (dir ++ "/" ++ ffile) avalues <- readTableValues (dir ++ "/" ++ afile) -- t is the number in the filename. let t = read . take 6 . drop 1 $ ffile return (t, M.fromList $ zip fvalues avalues) -- Open the file via readFile, and parse all the text values in it. readTableValues :: String -> IO [Float] readTableValues s = do b <- readFile s let bs = lines b lenLine = head . drop 1 $ bs n = read (drop 6 lenLine) :: Int -- valueLines :: [String]. This is a list of the lines -- in the file that have the float values. One float -- value in text format per line. valueLines = take n . drop 25 $ bs return $ map read valueLines -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20111109/b0e09ab0/attachment-0001.htm> ------------------------------ Message: 3 Date: Wed, 9 Nov 2011 19:15:18 +0100 From: Ertugrul Soeylemez <e...@ertes.de> Subject: Re: [Haskell-beginners] Search for docs on operator '<+>'. To: beginners@haskell.org Message-ID: <20111109191518.09002...@angst.streitmacht.eu> Content-Type: text/plain; charset=US-ASCII "Allen S. Rout" <a...@ufl.edu> wrote: > Google seems to barf on '<+>'. I've found a haskell "list of > operators", and it's not mentioned. > > Could some kind soul point me at documentation for this thing? This is the combination operator from the ArrowPlus type class for arrows, which can be combined in a monoidic fashion. It corresponds to (<|>) from the Alternative type class and in fact you can give a trivial Alternative instance for every arrow that is both ArrowPlus and ArrowZero. Reasonable laws would be: zeroArrow <+> a = a <+> zeroArrow = a But I don't think that's official. Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/ ------------------------------ Message: 4 Date: Wed, 9 Nov 2011 13:24:54 -0500 From: Brent Yorgey <byor...@seas.upenn.edu> Subject: Re: [Haskell-beginners] Search for docs on operator '<+>'. To: beginners@haskell.org Message-ID: <20111109182454.ga...@seas.upenn.edu> Content-Type: text/plain; charset=us-ascii On Wed, Nov 09, 2011 at 07:15:18PM +0100, Ertugrul Soeylemez wrote: > "Allen S. Rout" <a...@ufl.edu> wrote: > > > Google seems to barf on '<+>'. I've found a haskell "list of > > operators", and it's not mentioned. > > > > Could some kind soul point me at documentation for this thing? > > This is the combination operator from the ArrowPlus type class for > arrows, which can be combined in a monoidic fashion. It corresponds to > (<|>) from the Alternative type class and in fact you can give a trivial > Alternative instance for every arrow that is both ArrowPlus and > ArrowZero. Reasonable laws would be: > > zeroArrow <+> a = a <+> zeroArrow = a > > But I don't think that's official. Let me point out again, just so the OP is not confused: it completely depends where you saw the <+>. There is no "standard" meaning, although the ArrowPlus one that Ertugrul mentions is common. But you could have seen it in some module where the author defines <+> to mean something completely different. Until you tell us where you saw this <+> we cannot really help. In fact, Allen, I now recall seeing you on the xmonad mailing list -- perhaps you saw <+> in an xmonad config? In that case, indeed, it is NOT the ArrowPlus operator, but something defined by xmonad. In the context of xmonad, <+> is used for combining ManageHooks (actually, it can be used to combine any two things which have a type that is an instance of the 'Monoid' type class, but is most commonly used for ManageHooks). -Brent ------------------------------ Message: 5 Date: Wed, 9 Nov 2011 20:40:32 +0200 From: Yitzchak Gale <g...@sefer.org> Subject: Re: [Haskell-beginners] problem with lazy IO To: Dennis Raddle <dennis.rad...@gmail.com> Cc: Haskell Beginners <beginners@haskell.org> Message-ID: <CAOrUaLad1aC60M=BMe=xaqtgn8z4eafms0rbyumuscyptdp...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Dennis Raddle wrote: > I have the following code, which reads several thousand text files and > creates some Map data. On Windows XP, it crapped out with the error > "resource exhausted: too many open files." So I'm sure I need to make it > stricter. Yes. > I've never tried to do that before, so I'm not sure where the > strictness is necessary. When you use readFile, each file remains open until the entire file has been read. When reading is delayed due to laziness, the open file handles begin to pile up. > Maybe all I need is to switch to strict ByteStrings? That should solve your problem in this case, yes. You might consider using Text instead of ByteString, though; you are interpreting those values as text. Text has built-in functions for parsing floating point numbers. With ByteString, you'd have to change each line to a String. I almost always prefer using Text or ByteString over String nowadays anyway. To solve the problem when using readFile from the Prelude, you would need to make sure that each file is read all the way to the end as you go along. One trick sometimes used for that is to use the evaluate function from Control.Exception to force evaluation of the length of each file: b <- readFile s evaluate $ length b ... That would cause the entire contents of the file to be read into memory immediately and the file to be closed, like the behavior of readFile for strict ByteString and strict Text. -Yitz ------------------------------ Message: 6 Date: Thu, 10 Nov 2011 04:39:21 +0000 From: Alexander V Vershilov <alexander.vershi...@gmail.com> Subject: Re: [Haskell-beginners] Help : foldl skipping one value in list To: beginners@haskell.org Message-ID: <20111110043921.gc25...@qnikst.gtn.ru> Content-Type: text/plain; charset="utf-8" Hello. Wed, Nov 09, 2011 at 07:18:14AM +0200, Lev Broido wrote > Hi > I am implementing toy loop search algorithm in graph . > I encountered strange problem -- it seems , that fold doesn't run on the > whole list . > Code is at http://hpaste.org/53776 > Section in question is updVis function > Problem occurs when _newStateMap_2 is being calculated > Please advise. > > Thanks, > Lev > I have not checked all pasted code but for your problem you can try next solution (using Either to specify is it odd or even argument): > f = foldl (\x y -> inner x y) (Left []) > where > inner (Left xs) _ = Right xs > inner (Right xs) y = Left (yourfunction y:xs) -- Alexander V Vershilov -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 490 bytes Desc: Digital signature URL: <http://www.haskell.org/pipermail/beginners/attachments/20111110/b0e1dd6d/attachment-0001.pgp> ------------------------------ Message: 7 Date: Wed, 9 Nov 2011 15:48:20 -0800 From: Dennis Raddle <dennis.rad...@gmail.com> Subject: Re: [Haskell-beginners] problem with lazy IO To: g...@sefer.org Cc: Haskell Beginners <beginners@haskell.org> Message-ID: <cakxlvoryk3drydfjcpo74ba385ru0brcwvkxyhcy-rzydkg...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" Hi Yitz, I tried "evaluate" before posting my question, and for some reason it didn't change the behavior. But strict bytestrings worked. I haven't tried Text yet. It was a pain putting "map (chr . fromIntegral)" in front of everything to get regular strings. On Wed, Nov 9, 2011 at 10:40 AM, Yitzchak Gale <g...@sefer.org> wrote: > > To solve the problem when using readFile from the > Prelude, you would need to make sure that each > file is read all the way to the end as you go along. > One trick sometimes used for that is to use the > evaluate function from Control.Exception to force > evaluation of the length of each file: > > b <- readFile s > evaluate $ length b > ... > > That would cause the entire contents of the file > to be read into memory immediately and the > file to be closed, like the behavior of readFile > for strict ByteString and strict Text. > > -Yitz > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20111109/102b54c4/attachment-0001.htm> ------------------------------ Message: 8 Date: Thu, 10 Nov 2011 00:57:07 +0100 From: Daniel Fischer <daniel.is.fisc...@googlemail.com> Subject: Re: [Haskell-beginners] problem with lazy IO To: beginners@haskell.org Message-ID: <201111100057.07359.daniel.is.fisc...@googlemail.com> Content-Type: Text/Plain; charset="utf-8" On Thursday 10 November 2011, 00:48:20, Dennis Raddle wrote: > It was a pain putting "map (chr . fromIntegral)" in front of everything > to get regular strings. import qualified Data.ByteString.Char8 as C foo <- C.unpack `fmap` C.readFile whichever You don't need to put it *everywhere* ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 41, Issue 14 *****************************************