Re: [Haskell-cafe] IO (Either a Error) question
On Sat, May 8, 2010 at 1:16 AM, Ivan Lazar Miljenovic ivan.miljeno...@gmail.com wrote: David Menendez d...@zednenem.com writes: On Sat, May 8, 2010 at 12:15 AM, Ivan Lazar Miljenovic Well, any time you have a do-block like this you're using failable patterns: maybeAdd :: Maybe Int - Maybe Int - Maybe Int maybeAdd mx my = do x - mx y - my return $ x + y This is true in the sense that the translation for the do syntax in the Haskell report uses fail. do { p - e; stmts } = let ok p = do { stmts } ok _ = fail ... in e = ok However, it's also true that the fails introduced by the translation of maybeAdd will never be invoked, since the two patterns are irrefutable. Huh? What about maybeAdd (Just 2) Nothing ? That does not invoke fail. Let's take a simpler example: do { x - Nothing; stmt }. This translates to let ok x = do { stmt } ok _ = fail ... in Nothing = ok By the definition of (=) for Maybe, 'ok' is never called. That is, maybeAdd would work exactly the same if the do syntax translation were changed to read: do { p - e; stmts } = e = \p - do { stmts } Wait, are you using irrefutable as it will still work if we make do blocks work the way I want? I am using irrefutable to refer to patterns which always match. From the Haskell Report, section 3.17.2: It is sometimes helpful to distinguish two kinds of patterns. Matching an irrefutable pattern is non-strict: the pattern matches even if the value to be matched is _|_. Matching a refutable pattern is strict: if the value to be matched is _|_ the match diverges. The irrefutable patterns are as follows: a variable, a wildcard, N apat where N is a constructor defined by newtype and apat is irrefutable (see Section 4.2.3), v...@apat where apat is irrefutable, or of the form ~apat (whether or not apat is irrefutable). All other patterns are refutable. -- Dave Menendez d...@zednenem.com http://www.eyrie.org/~zednenem/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] IO (Either a Error) question
David Menendez d...@zednenem.com writes: That does not invoke fail. Let's take a simpler example: do { x - Nothing; stmt }. This translates to let ok x = do { stmt } ok _ = fail ... in Nothing = ok By the definition of (=) for Maybe, 'ok' is never called. As I said in another email: does not the x - Nothing itself call fail as it expects x to be an actual value wrapped in Just? -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] IO (Either a Error) question
On May 8, 2010, at 02:16 , Ivan Lazar Miljenovic wrote: David Menendez d...@zednenem.com writes: That does not invoke fail. Let's take a simpler example: do { x - Nothing; stmt }. This translates to let ok x = do { stmt } ok _ = fail ... in Nothing = ok By the definition of (=) for Maybe, 'ok' is never called. As I said in another email: does not the x - Nothing itself call fail as it expects x to be an actual value wrapped in Just? It's not a call, it's a definition as shown above. The simpler translation is: x - y becomes y = \x - (note incomplete expression; the next line must complete it) and the refutable pattern match takes place in the lambda binding. But because of the whole fail thing, instead of letting pattern match failure be caught by the lambda binding it gets handled specially beforehand, which is especially silly when in most cases fail is defined to do the same thing as the lambda binding would. I'm suggesting (as is David, I think) that a saner definition would let the lambda binding randle refutable patterns, and for something like Maybe (=) can decide how to deal with it in the usual way. Otherwise you're either using a default fail that duplicates the lambda binding, or if you want custom handling (as with Maybe and Either that propagate Nothing/Left _ respectively) you end up reimplementing part of (=) as fail, which is just dumb. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon universityKF8NH PGP.sig Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] installing haskell platform on 64-bit ubuntu 10.04 (Lucid)
On 08/05/10 04:20, Andy Lee wrote: Has anyone had problems getting Haskell Platform installed on Ubuntu 10.04? I've got GHC 6.12.1 installed via apt-get, and I've downloaded/untarred haskell-platform-2010.1.0.0.tar.gz. But when I run ./configure, it fails fairly quickly, with an error 'cause it can't build the hello world test program, complaining: command line: unknown package: haskell98 Anyone else seen this? Am I missing something obvious? What does 'ghc-pkg list|grep haskell' show? /M -- Magnus Therning(OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus@therning.org http://therning.org/magnus identi.ca|twitter: magthe signature.asc Description: OpenPGP digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Shorthand method of enumerating a list a gotcha ... or is it just me?
Hugs [3,7..22] [3,7,11,15,19] - OK Hugs map (* 1.0) [3,7..22] - same spec as first but !!! when mapped to with a (*1.0) to coerce them to reals: [3.0,7.0,11.0,15.0,19.0,23.0] - went one outside of range spec. This is because the Enum instance for floating point numbers is screwy and shouldn't be used in general I think the original poster is probably being confused by the fact that the first mention of [3,7..22] looks identical to the second mention, but they are given different types by Haskell. The literal '3', although it looks like an integer, is being given the type Double in the second list enumeration, because of the context of needing to multiply it by 1.0. The comment mentions coercion, as if the list is generated at type Integer, and then converted to Double, but that is not the case. It is generated at type Double, and no coercion happens. Regards, Malcolm ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: test-framework 0.3.0
On 8 May 2010 02:31, Gregory Collins g...@gregorycollins.net wrote: I don't see this one, although the junit option is there: Argh! I made the release from the wrong branch. I've uploaded v0.3.1 and double-checked that it contains the right functionality. Thanks for the heads-up! Max ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Shorthand method of enumerating a list a gotcha ... or is it just me?
An easier way of demonstrating this issue: Prelude [3,7..22]::[Int] [3,7,11,15,19] Prelude [3,7..22]::[Double] [3.0,7.0,11.0,15.0,19.0,23.0] /Jonas On 8 May 2010 09:47, Malcolm Wallace malcolm.wall...@cs.york.ac.uk wrote: Hugs [3,7..22] [3,7,11,15,19] - OK Hugs map (* 1.0) [3,7..22] - same spec as first but !!! when mapped to with a (*1.0) to coerce them to reals: [3.0,7.0,11.0,15.0,19.0,23.0] - went one outside of range spec. This is because the Enum instance for floating point numbers is screwy and shouldn't be used in general I think the original poster is probably being confused by the fact that the first mention of [3,7..22] looks identical to the second mention, but they are given different types by Haskell. The literal '3', although it looks like an integer, is being given the type Double in the second list enumeration, because of the context of needing to multiply it by 1.0. The comment mentions coercion, as if the list is generated at type Integer, and then converted to Double, but that is not the case. It is generated at type Double, and no coercion happens. Regards, Malcolm ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] IO (Either a Error) question
On Sat, May 8, 2010 at 3:26 AM, John Meacham j...@repetae.net wrote: What counts as unfailable? (x,y) probably, but what about data Foo = Foo x y If we don't allow it, we add 'magic' to tuples, which is a bad thing, if we do allow it, there are some odd consequences. adding another constructor to Foo will suddenly change the type of do notations involving it non locally. said constructor may not even be exported from the module defining Foo, its existence being an implementation detail. All in all, it is very hacky one way or another. Much more so than having 'fail' in Monad. This is an interesting point, but I still disagree. A data type having constructors added or changed *is* going to break code in clients using it, or at least make GHC spit out a bunch of non-exhaustive warnings. It's then a good idea, I think, that people are forced to re-examine their use sites which don't obviously handle the new failing case. Presumably if they were really really sure then just a few well-placed ~s would make the problem go away. (i.e. to answer your question, pattern matching against any single-constructor data type should be unfailable in my opinion). On Sat, May 8, 2010 at 7:16 AM, Ivan Lazar Miljenovic ivan.miljeno...@gmail.com wrote: As I said in another email: does not the x - Nothing itself call fail as it expects x to be an actual value wrapped in Just? No, the propagation of Nothings is done solely by the definition of = for Monad, and doesn't need fail at all. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Ideas for better network IO in Combinatorrent?
Hi, Cafe! (This post got rather long, and in writing it, I probably answered some of my own questions. I'll still post it because it might be interesting to read for somebody). This post concerns the currently central problem in Combinatorrent. But the problem is interesting from another angle. If you want fast servers in Haskell, I am pretty sure you will need to crack this nut as well. Status is that my Erlang-client, which handles all IO by hand in Erlang uses much less CPU resources than the Combinatorrent client in Haskell. Especially under load. Productivity is usually around 70-75% so we spend some considerable time in the GC still. It is up from some 30%, so we are faring much better than earlier. Still, we use about 4 times as many CPU seconds per downloaded megabyte compared to Erlang. And it is not like the Erlang code is optimized: The parser loop is Erlang and not using the C drivers packeting facility. (Aside: For non-Erlangers -- In erlang you can set options on a TCP socket about how you want data to be delivered. There are several (C-hand-optimized protocol parsers for ASN.1, FastCGI, or even HTTP), but one of them designates that the TCP stream will receive data in the format of a 4 byte big endian integer header, the length, followed by the payload of that length. By setting the option {packet, 4} on the TCP link, you can outsource this packeting to the Erlang VM kernel in C and receive a message (in a process channel) whenever such a message arrives.) In Erlang I don't use it because it gives too erratic speed measurements. I need to know how fast I am communicating because it is used in the BitTorrent protocol to gauge which peers it is interesting to talk to. Rather, I run a handrolled parser loop, doing exactly the thing from above. Essentially the loop collects data from the socket in what is equivalent to a Lazy ByteString. When the LBS is full, it is converted to a Strict ByteString and handed on to the parser. While doing this measurements are done on the size of incoming data from the operating system. The parser is fairly naive, but it uses the Erlang-bit-syntax pattern matches to essentially decode the binary chunk with a pointer walking over it. Note that The largest packet type is 16 kilobytes + a_small_constant. Rather than reallocate the binary, the Erlang system just stores a Slice-triple (u, o, l), of the underlying byte array, u, the offset into that array, o and the length from the offset, l. When the slice disappears, the garbage collector can evict the binary. Binaries are ref-counted since they can not contain pointers and they are stored outside the process heap. This has to do with the Erlang VMs garbage collection strategy: Each Erlang process has its own GC and all message passing happens by copying. Since copying around large chunks of binary data is expensive, they are stored immutably and shared by all processes. It is fairly efficient. There is only one major copy going on when assembling the LBS into a Strict BS and that copy knows the exact size of the target allocation area, so it can just allocate the right size and then copy data into that area. Enough Erlang, what does Combinatorrent do? Combinatorrents receiver processes (There are one for each Peer we are communicating with) currently takes 46% of all allocation on their own. Why? Here is why. Our main loop in the receiver process looks like this (explanation below the source code, read it first): bs - liftIO $ recv s 2048 when (B.length bs == 0) stopP loop s c (A.parse getMsg bs) where loop s c (A.Done r msg) = do liftIO . atomically $ writeTChan c (FromPeer (msg, fromIntegral $ msgSize msg)) loop s c (A.parse getMsg r) loop s c (prt@(A.Partial _)) = do bs - liftIO $ recv s 4096 when (B.length bs == 0) stopP loop s c (A.feed prt bs) loop _ _ (A.Fail _ ctx err) = do warningP $ Incorrect parse in receiver, context: ++ show ctx ++ , ++ show err stopP [full code at: http://github.com/jlouis/combinatorrent/blob/master/src/Process/Peer/Receiver.hs#L36 ] The 'A' module you see is Bryan O'Sullivan's attoparsec package. This parser is incremental. Either it returns A.Done r msg, where msg is a decoded message and r is the rest of the input not parsed yet. Or, it returns a Partial parse where it demands more input to successfully parse. If you feed that continuation with more data, it happily continues on. The 'recv' you see is from Johan Tibell's network-bytestring package. It will block on the Socket s until data arrives. Then it will fill up to 4096 bytes into the strict bytestring bs. We use this to feed more data to attoparsec. One problem is that usually, we are so fast that the packet is only some 1448 bytes which make sense: the MTU of the ethernet wire is 1500 bytes and sizeable chunks are taken by TCP/IP and also
Re: [Haskell-cafe] GHC 6.12 on OS X 10.5
Building from source alone didn't help, but building from source together with the following extra lines to .cabal/config worked: extra-lib-dirs: /usr/lib extra-lib-dirs: /opt/local/lib This is not an ideal solution because this means that any OS X library will shadow the corresponding Macports library. This could lead to problems if you use a Macports library that has several dependencies one of which is shadowed. HTH On 7 May 2010 22:42, Jason Dagit da...@codersbase.com wrote: On Mon, Dec 28, 2009 at 9:03 AM, Aaron Tomb at...@galois.com wrote: On Dec 22, 2009, at 9:36 PM, wren ng thornton wrote: Aaron Tomb wrote: I've come across the issue with iconv, as well. The problem seems to be that some versions of iconv define iconv_open and some related functions as macros (that then call libiconv_open, etc.), and some versions of iconv have exported functions for everything. In particular, the iconv bundled with OS X (1.11) defines iconv_open, but the iconv installed with MacPorts (1.13) does not. The binary package for GHC 6.12.1 seems to have been compiled on a system without MacPorts, and therefore references iconv_open (etc.) from the Apple-distributed version of the library. If you set up an installation of GHC 6.12 on OS X (I've only tried 10.5) with no references to /opt/local/lib, everything works fine. If you include /opt/local/lib in the extra-lib-dirs field of your .cabal/config file, it tries to link with the MacPorts version and fails with undefined references. Is this a problem with *versions* of iconv, or with branches/forks? If it's versions, then it seems like migrating to =1.13 would be good for everyone. If it's just branches, do you know whether this afflicts Fink users as well as MacPorts users, or should I be the guinea pig to test that? It's a problem with versions. I checked that the official iconv repository does indeed make the change between 1.11 and 1.13 that causes the problem. The issue is that OS X includes an old version. So migrating to =1.13 means convincing Apple to upgrade what they include with the system. If we can accomplish that, I'd be thrilled. But it hasn't happened yet as of 10.6. Fink comes with 1.12. I'm not sure whether 1.12 is more like 1.11 or 1.13. Resurrecting an old thread. I would like to find out: 1. Has there been any update on how to workaround this? 2. Does building 6.12 from macports (or from source on a macports enabled system) fix the problem? It seems like more than just GHC is affected by this, but I'm having trouble digging up solid information on the web about how to workaround it. Many sources (such as stackoverflow) point to this thread so posting a solution here would be a win. Thanks, Jason ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Push the envelope. Watch it bend. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] tweak vacuum-* output
Hi all, I am using vacuum-opengl and vacuum-ubigraph to visualise and analyse some of my data structures. They are quite helpful most of the time, however sometimes I feel the need to tweak the generated output -- such as removing the auto-generted identifiers from constrcutor names, pack some things together, or similar. Is there a way to configure their output? And for the vacuum-ubigraph option, I like it's output generally, however while creating the expression tree, is doesn't respect my structures. If there is a flag or so to fix this issue, I'd appreciate it. The Problem is like the following: data Expr = Sum Expr Expr | Mult Expr Expr | Single Int e = Sum (Single 2) (Mult (Single 3) (Single 4)) And it orients the tree in such a way that Mult looks like the root node, instead of Sum, as I would expect. Thanks, Ozgur Akgun ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANNOUNCE: hamlet 0.2.0
Hi all, I'm happy to announce the second major release of Hamlet[1]. Hamlet is a HTML templating library which works via quasi-quoting, giving you compile-time assurances, type safety and very efficient HTML generation. I wrote a blog post[2] describing the changes in this version of Hamlet. The two most major are reversing of identifier order in references and dropping the template argument. Combined, these changes make a Hamlet template fit in better with Haskell code. All the other changes are noted in that same blog post. The Hamlet documentation[3] has been updated to reflect all changes. Please let me know if the documentation needs clarification on any points. Cheers, Michael [1] http://hackage.haskell.org/package/hamlet-0.2.0 [2] http://www.snoyman.com/blog/entry/hamlet-version-0-2/ [3] http://docs.yesodweb.com/hamlet/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] installing haskell platform on 64-bit ubuntu 10.04 (Lucid)
On 05/08/2010 03:38 AM, Magnus Therning wrote: On 08/05/10 04:20, Andy Lee wrote: Has anyone had problems getting Haskell Platform installed on Ubuntu 10.04? I've got GHC 6.12.1 installed via apt-get, and I've downloaded/untarred haskell-platform-2010.1.0.0.tar.gz. But when I run ./configure, it fails fairly quickly, with an error 'cause it can't build the hello world test program, complaining: command line: unknown package: haskell98 Anyone else seen this? Am I missing something obvious? What does 'ghc-pkg list|grep haskell' show? /M $ ghc-pkg list|grep haskell haskell98-1.0.1.1 template-haskell-2.4.0.0 haskell-src-1.0.1.3 haskell98-1.0.1.1 template-haskell-2.4.0.1 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] installing haskell platform on 64-bit ubuntu 10.04 (Lucid)
On 05/08/2010 08:27 PM, Andy Lee wrote: On 05/08/2010 03:38 AM, Magnus Therning wrote: On 08/05/10 04:20, Andy Lee wrote: Has anyone had problems getting Haskell Platform installed on Ubuntu 10.04? I've got GHC 6.12.1 installed via apt-get, and I've downloaded/untarred haskell-platform-2010.1.0.0.tar.gz. But when I run ./configure, it fails fairly quickly, with an error 'cause it can't build the hello world test program, complaining: command line: unknown package: haskell98 Anyone else seen this? Am I missing something obvious? What does 'ghc-pkg list|grep haskell' show? /M $ ghc-pkg list|grep haskell haskell98-1.0.1.1 template-haskell-2.4.0.0 haskell-src-1.0.1.3 haskell98-1.0.1.1 template-haskell-2.4.0.1 So, after seeing the above, I figured out that I had a ~/.ghc directory, apparently left from a previous attempt at installing haskell-platform. After deleting it, I was able to get past the ./configure step. I then just had to figure out I needed to install libghc6-monadcatchio-mtl-{dev,prof} and everything went swimmingly. Thanks for the clue! --Andy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] How efficient is read?
I have a lot of structured data in a program written in a different language, which I would like to read in and analyze with Haskell. And I'm free to format this data in any shape or form from the other language. Could I define a Haskell type for this data that derives the default Read, then simply print out Haskell code from the program and 'read' it in? Would this be horribly inefficient? It would save me some time of writing a parser. -Tom ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How efficient is read?
tomahawkins: I have a lot of structured data in a program written in a different language, which I would like to read in and analyze with Haskell. And I'm free to format this data in any shape or form from the other language. Could I define a Haskell type for this data that derives the default Read, then simply print out Haskell code from the program and 'read' it in? Would this be horribly inefficient? It would save me some time of writing a parser. It would be easy but inefficient for more than say, 100k of data. deriving Binary will be faster and almost as easy (the derive script is in the binary/scripts dir). ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How efficient is read?
In fact, the time you'd spend writing read instances would not compare to the half hour required to learn parsec. And your parser will be efficient (at least, according to the guys from the parser team ;-) Cheers, PE El 08/05/2010, a las 23:32, Tom Hawkins escribió: I have a lot of structured data in a program written in a different language, which I would like to read in and analyze with Haskell. And I'm free to format this data in any shape or form from the other language. Could I define a Haskell type for this data that derives the default Read, then simply print out Haskell code from the program and 'read' it in? Would this be horribly inefficient? It would save me some time of writing a parser. -Tom ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How efficient is read?
On May 9, 2010, at 12:32 AM, Tom Hawkins wrote: I have a lot of structured data in a program written in a different language, which I would like to read in and analyze with Haskell. And I'm free to format this data in any shape or form from the other language. Could I define a Haskell type for this data that derives the default Read, then simply print out Haskell code from the program and 'read' it in? Would this be horribly inefficient? It would save me some time of writing a parser. -Tom If your types contain infix constructors, the derived Read instances may be almost unusable; see http://hackage.haskell.org/trac/ghc/ticket/1544 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe