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: ghci reports "The last statement in a 'do' construct must be an expression" error (Nico Rolle) 2. Re: xml parsing (Antoine Latter) 3. Modifications inside a Reader? (Brian Troutwine) 4. Re: xml parsing (Yitzchak Gale) 5. Re: map increases length of list (Jack Kennedy) 6. Re: map increases length of list (Daniel Fischer) ---------------------------------------------------------------------- Message: 1 Date: Wed, 17 Jun 2009 18:13:03 +0200 From: Nico Rolle <nico.ro...@googlemail.com> Subject: Re: [Haskell-beginners] ghci reports "The last statement in a 'do' construct must be an expression" error To: Daniel Fischer <daniel.is.fisc...@web.de> Cc: beginners@haskell.org Message-ID: <45fccde20906170913t1fe143c3q26f8008cd37b1...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" it really was an indentation error i configured my editor to expand tabs into spaces but somehow he did a real tab on line 9 and 10 thank you 2009/6/16 Daniel Fischer <daniel.is.fisc...@web.de> > Am Dienstag 16 Juni 2009 22:35:17 schrieb Nico Rolle: > > Hi > > > > Heres my code snippet. > > It reports that my error is in line 9 right after the main definition. > > All functions that i call work under normal circumstances. > > Thanks > > Must be the indentation, probably the xs is indented further than the > following line > (though that's not the case for the code copy-pasted from the mail to an > editor). > > But note that this will most likely print out 0 twice. > The let pnp = ... bindings don't cause any computation to occur. > To measure the time the computations take, you must force them to occur > between the two > calls to getCurrentTime. > > > > > > > module Benchmark > > where > > > > import ReadCSV > > import Operators > > import Data.Time.Clock (diffUTCTime, getCurrentTime) > > > > main = do > > xs <- readCSV "dataconvert/lineitem.tbl" '|' > > start <- getCurrentTime > > let pnp = projection [5] xs > > let snp = selection (\x -> (x!!0) > (Int 17000)) pnp > > end <- getCurrentTime > > putStrLn $ show (end `diffUTCTime` start) > > start2 <- getCurrentTime > > let pp = pProjection [5] xs > > let sp = pSelection (\x -> (x!!0) > (Int 17000)) pp > > end2 <- getCurrentTime > > putStrLn $ show (end2 `diffUTCTime` start2) > > return xs > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090617/c37de581/attachment-0001.html ------------------------------ Message: 2 Date: Wed, 17 Jun 2009 22:32:50 -0500 From: Antoine Latter <aslat...@gmail.com> Subject: Re: [Haskell-beginners] xml parsing To: Benedikt Ahrens <benedikt.ahr...@gmx.net> Cc: beginners@haskell.org Message-ID: <694519c50906172032r23e7b0b2xe6439e9e2de46...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 On Wed, Jun 17, 2009 at 1:05 PM, Benedikt Ahrens<benedikt.ahr...@gmx.net> wrote: > Hello, > > I want to write a program which among other should read some xml file. > The xml tags will mostly be custom ones defined by a dtd. > > My question is: which parsing library to use? > > On > http://en.wikibooks.org/wiki/Haskell/XML > three libraries are mentioned, but a comparison and recommendation of > which one to choose is missing. > > As you might imagine, I would like to use a library which is actively > maintained? Has any of these libraries developed into a "standard" > library? > > Thanks in advance for your help. > ben One option I've used before which isn't on the list is on hackage here: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/xml I have a parser for these XML files: http://cgit.freedesktop.org/xcb/proto/tree/src in this Haskell package on hackage: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/xcb-types I'm no Haskell guru, and the code may not be the best example - but the library is pretty easy to get started with. Antoine ------------------------------ Message: 3 Date: Wed, 17 Jun 2009 20:32:53 -0700 From: Brian Troutwine <goofyheadedp...@gmail.com> Subject: [Haskell-beginners] Modifications inside a Reader? To: beginners@haskell.org Message-ID: <971980cc0906172032v5b9a9ad2l5ea0ea4fc878b...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Hello all. I'm writing a UDP echo server, full source given below. The current implementation echoes back the "payload" of every incoming message but I would prefer that only unique payloads be echoed back. To that end I've started in with Data.BloomFilter but am not sure how to update it accordingly. I imagine that Reader is probably the wrong monad to be using though I'm unsure how I might modify my program to use State. Could someone lead me along a bit? Also, any general comments on the style of my program? Thanks, Brian -- import Prelude hiding (putStrLn, catch) import Network.Socket hiding (send, sendTo, recv, recvFrom) import Network.Socket.ByteString import Data.ByteString.Char8 hiding (head) import Control.Monad.Reader import Control.Monad (forever) import Control.Exception (bracket) import Data.BloomFilter import Data.BloomFilter.Easy import Data.BloomFilter.Hash (cheapHashes) data Globals = Globals { socketG :: Socket , bloomF :: Bloom ByteString } type Echo = ReaderT Globals IO run :: Echo () run = forever $ do s <- asks socketG (msg, addr) <- liftIO $ recvFrom s 1024 let [_, _, _, payload] = split ':' msg liftIO $ sendTo s payload addr main :: IO () main = bracket build disconnect loop where disconnect = sClose . socketG loop st = runReaderT run st build :: IO Globals build = do addrinfos <- getAddrInfo (Just (defaultHints {addrFlags = [AI_PASSIVE]})) Nothing (Just "1514") let serveraddr = head addrinfos sock <- socket (addrFamily serveraddr) Datagram defaultProtocol bindSocket sock (addrAddress serveraddr) return $ Globals sock $ emptyB (cheapHashes 3) 1024 ------------------------------ Message: 4 Date: Thu, 18 Jun 2009 12:26:58 +0300 From: Yitzchak Gale <g...@sefer.org> Subject: Re: [Haskell-beginners] xml parsing To: Antoine Latter <aslat...@gmail.com> Cc: Benedikt Ahrens <benedikt.ahr...@gmx.net>, beginners@haskell.org Message-ID: <2608b8a80906180226j5a9382f1ke6fa26738d9e4...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Benedikt Ahrens wrote: >> I want to write a program which among other should read some xml file. >> The xml tags will mostly be custom ones defined by a dtd. >> My question is: which parsing library to use? Antoine Latter wrote: > One option I've used before which isn't on the list is on hackage here: > http://hackage.haskell.org/cgi-bin/hackage-scripts/package/xml Yes, that is a great library for quick-and-dirty xml work. It's very easy to use. And it's very well maintained, because it was written at Galois and is actively used there. But if you need to do more serious XML work, including support and verified compliance for the alphabet soup of XML specs, you need to use one of the other libraries. For example, the xml library will work fine with custom tags. But if you want to verify against the DTD, you'll have to look elsewhere. It is easy to search an XML tree by hand with the xml library, but I don't think it will do an XPath search for you. Etc. By the way, perhaps the xml library should be added to that wikibook page. Hope this helps, Yitz ------------------------------ Message: 5 Date: Thu, 18 Jun 2009 08:24:20 -0500 From: Jack Kennedy <j...@realmode.com> Subject: Re: [Haskell-beginners] map increases length of list To: Alan Mock <docm...@gmail.com> Cc: beginners@haskell.org Message-ID: <1008bfc90906180624s3c6757a9kb2bdcac14c2cb...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" I think I understand the reason why, but still I find it disturbing that in this first expression, x has 6 elements: Prelude> let x = [0,60..359]; y = [0,60..359] in (x, y, map degreesToRadians y) ([0,60,120,180,240,300],[0.0,60.0,120.0,180.0,240.0,300.0,360.0],[0.0,1.0471975333333332,2.094395066 6666664,3.1415926,4.188790133333333,5.235987666666667,6.2831852]) But if I add a comparison to y, x now has 7 elements: Prelude> let x = [0,60..359]; y = [0,60..359] in (x, y, map degreesToRadians y, *x==y*) ([0.0,60.0,120.0,180.0,240.0,300.0,360.0],[0.0,60.0,120.0,180.0,240.0,300.0,360.0],[0.0,1.0471975333 333332,2.0943950666666664,3.1415926,4.188790133333333,5.235987666666667,6.2831852],True) I. J. Kennedy On Wed, Jun 17, 2009 at 4:55 PM, Alan Mock <docm...@gmail.com> wrote: > That's because [0,60,..359] is not the same as [0,60..359] :: [Double]. So > what you're passing to degreesToRadians is > [0.0,60.0,120.0,180.0,240.0,300.0,360.0] and not [0,60,120,180,240,300]. I > don't know why the Double version adds another number, though. > > > On Jun 17, 2009, at 4:35 PM, Aaron MacDonald wrote: > > For some reason, the map function returns a list that has one more element >> than my input list. >> >> My input list is a range defined by [0, 60..359] (should translate into >> [0,60,120,180,240,300]). >> >> The function I'm giving to map is defined this way: >> ----- >> degreesToRadians :: Double -> Double >> degreesToRadians degrees = degrees * (pi / 180) >> ----- >> >> This is how I'm calling map overall: >> ----- >> > map degreesToRadians [0,60..359] >> >> [0.0,1.0471975511965976,2.0943951023931953,3.141592653589793,4.1887902047863905,5.235987755982989,6.283185307179586] >> ----- >> >> As you can hopefully see, there are seven elements instead of six. Getting >> the length confirms this: >> ----- >> > length [0,60..359] >> 6 >> > length $ map degreesToRadians [0,60..359] >> 7 >> ----- >> >> I do not seem to get this behaviour with the length if I either substitute >> the degreesToRadians function or substitute the [0,60..359] range. >> >> P.S. Is there a built-in function to convert degrees to radians and >> vice-versa? >> _______________________________________________ >> Beginners mailing list >> Beginners@haskell.org >> http://www.haskell.org/mailman/listinfo/beginners >> > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090618/32f60c05/attachment-0001.html ------------------------------ Message: 6 Date: Thu, 18 Jun 2009 15:49:02 +0200 From: Daniel Fischer <daniel.is.fisc...@web.de> Subject: Re: [Haskell-beginners] map increases length of list To: beginners@haskell.org Message-ID: <200906181549.02790.daniel.is.fisc...@web.de> Content-Type: text/plain; charset="iso-8859-15" Am Donnerstag 18 Juni 2009 15:24:20 schrieb Jack Kennedy: > I think I understand the reason why, but still I find it disturbing that in > this first expression, x has 6 elements: > > Prelude> let x = [0,60..359]; y = [0,60..359] in (x, y, map > degreesToRadians y) You give no type for x, so the default is chosen, that is Integer. The expression map degreesToRadians y forces y to have type [Double] (you could give y a more general type if you specified a type signature). > ([0,60,120,180,240,300],[0.0,60.0,120.0,180.0,240.0,300.0,360.0],[0.0,1.047 >1975333333332,2.094395066 > 6666664,3.1415926,4.188790133333333,5.235987666666667,6.2831852]) > > But if I add a comparison to y, x now has 7 elements: > > Prelude> let x = [0,60..359]; y = [0,60..359] in (x, y, map > degreesToRadians y, *x==y*) > ([0.0,60.0,120.0,180.0,240.0,300.0,360.0],[0.0,60.0,120.0,180.0,240.0,300.0 >,360.0],[0.0,1.0471975333 > 333332,2.0943950666666664,3.1415926,4.188790133333333,5.235987666666667,6.2 >831852],True) Now, the expression x==y forces x to have the same type as y, which still is [Double]. But, lo and behold: Prelude> let degreesToRadians :: Double -> Double; degreesToRadians d = d*pi/180 Prelude> let x :: (Num a, Enum a) => [a]; x = [0, 60 .. 359]; y :: (Num a, Enum a) => [a]; y = [0, 60 .. 359] Prelude> (x,y,map degreesToRadians y, x == y) ([0,60,120,180,240,300],[0,60,120,180,240,300], [0.0,1.0471975511965976,2.0943951023931953,3.141592653589793,4.1887902047863905,5.235987755982989,6.283185307179586],True) > > I. J. Kennedy > ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 12, Issue 8 ****************************************