From bf3 at telenet.be Tue Jan 1 05:59:05 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Tue Jan 1 05:53:20 2008 Subject: [Haskell-cafe] Compiler backend question Message-ID: <477A1CF9.90001@telenet.be> If I understand it correctly, the GHC compiler either directly generates machinecode, or it uses C as an intermediate language. I also read somewhere that C is not the most efficient intermediate representation for functional languages, and that one gets better performance when generating native machine code. However, from the discussions in this list, I could conclude that the low level machine code optimizer of GHC is far from state-of-the-art compared to industry standard C/C++ compilers. I was wondering, why doesn't GHC use the GCC (or any other standard compiler) backend intermediate code? The backend of GCC generates highly optimized code no? Or is the intermediate code format of GCC (or other compilers) not suitable for Haskell? Another question regarding the backend: a cool feature of the Microsoft Visual C++ (MVC) compiler is its ability to perform "LTCG" (link-time-code-generation), performing whole program optimization. It something like this possible with Haskell / (or the GCC backend?). Would it be possible to feed all the generated C code of the GHC compiler into the MVC compiler, to generate one big MVC / LTCG generated executable? It would be interesting to see how much the whole program optimization approach (which can do analysis on the program as if it was a single module) would improve performance... Cheers, Peter -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080101/4f032697/attachment.htm From ndmitchell at gmail.com Tue Jan 1 08:37:23 2008 From: ndmitchell at gmail.com (Neil Mitchell) Date: Tue Jan 1 08:31:25 2008 Subject: [Haskell-cafe] Compiler backend question In-Reply-To: <477A1CF9.90001@telenet.be> References: <477A1CF9.90001@telenet.be> Message-ID: <404396ef0801010537o41f292fmd1833ade9b3f73ea@mail.gmail.com> Hi > If I understand it correctly, the GHC compiler either directly generates > machinecode, or it uses C as an intermediate language. > > I also read somewhere that C is not the most efficient intermediate > representation for functional languages, and that one gets better > performance when generating native machine code. > > However, from the discussions in this list, I could conclude that the low > level machine code optimizer of GHC is far from state-of-the-art compared to > industry standard C/C++ compilers. These all seem fair comments, based on my understanding. One other thing to remember is that the GHC people know this, and much work has been done, and will continue to be done until the back end is up to the standard of the front end. > I was wondering, why doesn't GHC use the GCC (or any other standard > compiler) backend intermediate code? The backend of GCC generates highly > optimized code no? Or is the intermediate code format of GCC (or other > compilers) not suitable for Haskell? GCC is optimised for dealing with code that comes from C, and the back end language is much like C. GCC is also not really set up to be used by bolting different front ends on to different back ends - part of this is a license issue - if the front and back ends were well split and available separately you could write a commerical backend onto a GPL front end. > Another question regarding the backend: a cool feature of the Microsoft > Visual C++ (MVC) compiler is its ability to perform "LTCG" > (link-time-code-generation), performing whole program optimization. It > something like this possible with Haskell / (or the GCC backend?). Would it > be possible to feed all the generated C code of the GHC compiler into the > MVC compiler, to generate one big MVC / LTCG generated executable? It would > be interesting to see how much the whole program optimization approach > (which can do analysis on the program as if it was a single module) would > improve performance... You would get much better improvements on whole program at the Haskell level. By the time you get to the generated C you have obfustcated all the structure of the program, and are unlikely to benefit that much. Thanks Neil From benja.fallenstein at gmail.com Tue Jan 1 09:52:56 2008 From: benja.fallenstein at gmail.com (Benja Fallenstein) Date: Tue Jan 1 09:46:58 2008 Subject: [Haskell-cafe] Basic question concerning data constructors In-Reply-To: <20071231011748.sq6ryegp6o8cg4c0@webmail.spamcop.net> References: <49a77b7a0712301219y6959db9y967a9cb75427443d@mail.gmail.com> <20071231011748.sq6ryegp6o8cg4c0@webmail.spamcop.net> Message-ID: On Dec 31, 2007 7:17 AM, wrote: > This declaration states that there's a bijection between the elements of > Foo and the elements of 2^Foo, which by Cantor's diagonal theorem cannot > be true for any set. That's because we only allow computable functions, Nit the nit: Or (more commonly, I think) all continuous functions. > and Foo -> Bool is actually an exponential object in the category Hask. - Benja From gale at sefer.org Tue Jan 1 10:33:14 2008 From: gale at sefer.org (Yitzchak Gale) Date: Tue Jan 1 10:27:20 2008 Subject: [Haskell-cafe] Basic question concerning data constructors In-Reply-To: <20071231011748.sq6ryegp6o8cg4c0@webmail.spamcop.net> References: <49a77b7a0712301219y6959db9y967a9cb75427443d@mail.gmail.com> <20071231011748.sq6ryegp6o8cg4c0@webmail.spamcop.net> Message-ID: <2608b8a80801010733q3f5f4a6ewfba794151757578a@mail.gmail.com> Andrew Bromage wrote: > [*] Theoretical nit: It's not technically a "set". > > Consider the data type: > > data Foo = Foo (Foo -> Bool) > > This declaration states that there's a bijection between the elements of > Foo and the elements of 2^Foo, which by Cantor's diagonal theorem cannot > be true for any set. That's because we only allow computable functions, > and Foo -> Bool is actually an exponential object in the category Hask. Data types consist only of computable elements. Since there are only countably many computable functions, every data type has at most countably many elements. In particular, it is a set. The least fixed point under these restrictions is not a bijection between Foo and 2^Foo. It is only a bijection between Foo and the subset of computable 2^Foo. -Yitz From gale at sefer.org Tue Jan 1 10:43:18 2008 From: gale at sefer.org (Yitzchak Gale) Date: Tue Jan 1 10:37:19 2008 Subject: [Haskell-cafe] Basic question concerning data constructors In-Reply-To: <2608b8a80801010733q3f5f4a6ewfba794151757578a@mail.gmail.com> References: <49a77b7a0712301219y6959db9y967a9cb75427443d@mail.gmail.com> <20071231011748.sq6ryegp6o8cg4c0@webmail.spamcop.net> <2608b8a80801010733q3f5f4a6ewfba794151757578a@mail.gmail.com> Message-ID: <2608b8a80801010743m33409e52w97ba1ad8da9518d9@mail.gmail.com> Andrew Bromage wrote: >> [*] Theoretical nit: It's not technically a "set". >> >> Consider the data type: >> >> data Foo = Foo (Foo -> Bool) >> >> This declaration states that there's a bijection between the elements of >> Foo and the elements of 2^Foo, which by Cantor's diagonal theorem cannot >> be true for any set. That's because we only allow computable functions, >> and Foo -> Bool is actually an exponential object in the category Hask. I wrote: > Data types consist only of computable elements. Since there > are only countably many computable functions, What I meant by that is that there are only countably many lambdas, and we can define a "computable value" as a lambda. The classical definition of "general recursive function" refers to functions in Integer -> Integer to begin with, so there can only be countably many values by construction. > every data type > has at most countably many elements. In particular, it is a set. > > The least fixed point under these restrictions is not a bijection > between Foo and 2^Foo. It is only a bijection between Foo and > the subset of computable 2^Foo. -Yitz From barsoap at web.de Tue Jan 1 12:44:46 2008 From: barsoap at web.de (Achim Schneider) Date: Tue Jan 1 12:39:11 2008 Subject: [Haskell-cafe] Re: Compiler backend question References: <477A1CF9.90001@telenet.be> Message-ID: <20080101184446.7500417a@solaris.tower> Peter Verswyvelen wrote: > Another question regarding the backend: a cool feature of the > Microsoft Visual C++ (MVC) compiler is its ability to perform "LTCG" > (link-time-code-generation), performing whole program optimization. > It something like this possible with Haskell / (or the GCC backend?). > Would it be possible to feed all the generated C code of the GHC > compiler into the MVC compiler, to generate one big MVC / LTCG > generated executable? It would be interesting to see how much the > whole program optimization approach (which can do analysis on the > program as if it was a single module) would improve performance... > jhc does that. Or rather, it doesn't compile Haskell modules separately but throws them together (presumably) in the first pass. Regarding C, it's actually only a high-level assembly language, with compiler optimisations only optimising heavily if you use those idioms... say inlining, loop-unrolling. If your compiler backend outputs something that is already close to some generalisation of different assembly languages, containing no superfluous code and compile-time evaluable expressions and looking generally like a mess of mov's and jmp's, nothing much more than optimisating register allocation and pipeline usage optimisation can be done, which are both highly processor-specific bastards, and likely to be hard to write better than . I figure it's being lazy in the right way(TM) -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From r.kelsall at millstream.com Tue Jan 1 14:43:30 2008 From: r.kelsall at millstream.com (Richard Kelsall) Date: Tue Jan 1 14:37:35 2008 Subject: [Haskell-cafe] Compiler backend question In-Reply-To: <477A1CF9.90001@telenet.be> References: <477A1CF9.90001@telenet.be> Message-ID: <477A97E2.70803@millstream.com> Peter Verswyvelen wrote: ... > I was wondering, why doesn't GHC use the GCC (or any other standard > compiler) backend intermediate code? The backend of GCC generates highly > optimized code no? Or is the intermediate code format of GCC (or other > compilers) not suitable for Haskell? ... My guess is that there is scope for producing assembly code that out-performs GCC. I speak as someone who has no actual knowledge of how GCC works :) I have a theory that the back-end of most compilers, including GCC, are an accretion of many hand-coded hard-coded functions to perform very specific optimisations for particular instructions for particular processors. These have been developed over the years by relatively ad-hoc timings of the precise assembly code the individual who wrote the function wanted to improve. So what's wrong with this approach? When a new processor is introduced it needs a different set of optimisations, which take time to develop, which means the compiler is sub-optimal for a while for new processors. Also, the number of processors we would like the compiler optimised for is large if we're really trying to get the last few percent from every processor. Modern processors aren't simple things like the old 6502 or Z80 which had definite, easily predictable, timings. Think different cache sizes, multiple pipelines, branch prediction etc. "The microarchitecture of Intel and AMD CPU?s: An optimization guide for assembly programmers and compiler makers" here http://www.agner.org/optimize/ It seems unlikely therefore that the code generation for every modern processor variant will be hand-optimised to account for all the small details. Even in GCC, which no doubt has a huge amount of continuous effort applied to it by many clever people, they are never going to hand-code every complexity of every processor. Take a small example : integer multiplication. Looking at the table in the conclusion of the microarchitecture PDF we see that different x86 processors have different relative speed of adding and multiplying. Something like this Execution latencies, typical AMD64 P4E PM Core2 integer addition 1 1 1 1 integer multiplication 3 10 4 3 We can compute 4 * 371 faster on P4E by doing 371 + 371 + 371 + 371 but on Core2 and AMD64 we should do 4 * 371 and on PM it might depend on other factors, I don't know. Now supposing we allow powers of two by shifting as well as integer addition, can we immediately say the best way of multiplying two integers on all these processors? Maybe roughly, but do we always get the absolute fastest code? For example it will depend on the values of the integers. If we know one of them in advance as I've assumed above, or if we know they frequently have particular values we might handle them first etc. This is just one small optimisation out of many. And the optimisations might interact. So the inevitable conclusion is that the precise assembly code optimisations must not be hand-coded directly into the back-end of the compiler, as I expect they are currently in most compilers, but that they need to be expressed at a higher level "repeated addition is equivalent to multiplication" and adapted down to particular processors and situations based on extensive, genetic algorithm guided, timing runs. Anyway, that's my wild idea thrown in the pot. Might be a nice research paper in there for someone :) Richard. From bf3 at telenet.be Tue Jan 1 15:18:21 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Tue Jan 1 15:12:51 2008 Subject: [Haskell-cafe] Compiler backend question In-Reply-To: <404396ef0801010537o41f292fmd1833ade9b3f73ea@mail.gmail.com> References: <477A1CF9.90001@telenet.be> <404396ef0801010537o41f292fmd1833ade9b3f73ea@mail.gmail.com> Message-ID: <000c01c84cb3$74651e20$5d2f5a60$@be> Neil Mitchell wrote: > GCC is optimised for dealing with code that comes from C, and the back > end language is much like C. GCC is also not really set up to be used > by bolting different front ends on to different back ends - part of > this is a license issue - if the front and back ends were well split > and available separately you could write a commerical backend onto a > GPL front end. Well, I don't know about the licensing, but according to http://en.wikipedia.org/wiki/GNU_Compiler_Collection#Front_ends, a new cleaner intermediate language was created in 2005 for GCC, which might be more "general"? > You would get much better improvements on whole program at the Haskell > level. By the time you get to the generated C you have obfustcated all > the structure of the program, and are unlikely to benefit that much. Yes that would be great! Or even at JIT time ;-) But, given the time GHC takes to optimize a single module, I guess it would not really be practical to let those optimization take place on the full program? It would take ages no? I just wanted to see if it is *possible* to feed just all the C code from GHC into a C compiler, and then generate a single executable from that C code (including the GHC runtime). For example, for the XBOX DEVKIT, Microsoft shipped LTCG versions for all the core libraries, which gave a nice performance improvement for free (if I'm not mistaking, this gives 10% to 15% faster code). Actually this LTCG thingy was first supported by the Intel compiler I believe. Thanks, Peter From bos at serpentine.com Tue Jan 1 15:44:23 2008 From: bos at serpentine.com (Bryan O'Sullivan) Date: Tue Jan 1 15:38:24 2008 Subject: [Haskell-cafe] Compiler backend question In-Reply-To: <000c01c84cb3$74651e20$5d2f5a60$@be> References: <477A1CF9.90001@telenet.be> <404396ef0801010537o41f292fmd1833ade9b3f73ea@mail.gmail.com> <000c01c84cb3$74651e20$5d2f5a60$@be> Message-ID: <477AA627.5000008@serpentine.com> Peter Verswyvelen wrote: > Well, I don't know about the licensing, but according to > http://en.wikipedia.org/wiki/GNU_Compiler_Collection#Front_ends, a new > cleaner intermediate language was created in 2005 for GCC, which might be > more "general"? It's still very difficult to work with GCC from the perspective of an external tool. Its current IR is still targeted towards the languages it currently supports and the needs of its back end, so it omits a fair bit of information that third-party tools would find useful. > I just wanted to see if it is *possible* to feed just all the C code from > GHC into a C compiler, and then generate a single executable from that C > code (including the GHC runtime). It would be a fair bit of work. My recollection is that GHC "knows" that it is talking to GCC when you go through -fvia-c, so it uses some gcc extensions to handle things like register reservation. A few compilers support some of those gcc extensions, so you might have some level of success with those. The Intel and PathScale compilers do, for example, and LLVM's clang front end has some level of gcc compatibility already. In the case of the PathScale compiler (which I used to work on), when invoked in whole-program mode it emits files that look like regular .o files, but are in fact just the serialised IR for a compilation unit. It's also open source, so it would be easier to tinker with than the Intel compiler. > Actually this LTCG thingy was first supported by the > Intel compiler I believe. No, that kind of whole-program optimisation long predates its inclusion in the Intel compiler. The earliest I saw it in deployment was in MIPS compilers circa 1992, and I don't recall it being a new idea at the time. Anyway, the point about GCC being an unsuitable vehicle for this sort of thing remains. You'd do better looking at LLVM, for which I've lately been working on nice Haskell bindings: darcs get http://darcs.serpentine.com/llvm References: <4774E022.8070201@btinternet.com> <117f2cc80712280655w70bdcdfet6e11dcb4e2a66bb2@mail.gmail.com> <6BD267D89E66B9499514F119920E583C0203DBCC@usctmx1110.merck.com> Message-ID: <8dde104f0801011429t123450cfjc19c3842bab4ba2@mail.gmail.com> On Dec 28, 2007 11:40 PM, Mitar wrote: > Would not it be interesting and useful (but not really efficient) to > have patterns something like: > > foo :: Eq a => a -> ... > foo (_{4}'b') = ... > > which would match a list with four elements ending with an element 'b'. Or: > > foo (_+';'_+';'_) = ... > > which would match a list with embedded two ';' elements. (Last _ > matched the remaining of the list.) > I suggest you take at look at HaRP, Haskell Regular Patterns: http://www.cs.chalmers.se/~d00nibro/harp/ It hasn't been updated for a while but it should still be useable. Cheers, Josef From lrpalmer at gmail.com Tue Jan 1 18:57:20 2008 From: lrpalmer at gmail.com (Luke Palmer) Date: Tue Jan 1 18:51:20 2008 Subject: [Haskell-cafe] Basic question concerning data constructors In-Reply-To: <2608b8a80801010743m33409e52w97ba1ad8da9518d9@mail.gmail.com> References: <49a77b7a0712301219y6959db9y967a9cb75427443d@mail.gmail.com> <20071231011748.sq6ryegp6o8cg4c0@webmail.spamcop.net> <2608b8a80801010733q3f5f4a6ewfba794151757578a@mail.gmail.com> <2608b8a80801010743m33409e52w97ba1ad8da9518d9@mail.gmail.com> Message-ID: <7ca3f0160801011557x8fc901bv795da1d81662dacb@mail.gmail.com> On Jan 1, 2008 3:43 PM, Yitzchak Gale wrote: > The classical definition of "general recursive function" > refers to functions in Integer -> Integer to begin > with, so there can only be countably many values by > construction. Except that there are uncountably many (2^Aleph_0) functions in Integer -> Integer. That doesn't change the fact that there are countably many computable functions, as you guys have been saying. But I think you need to refer to the LC or Turing machine definition to get countability. Luke From sulzmann at comp.nus.edu.sg Tue Jan 1 21:49:53 2008 From: sulzmann at comp.nus.edu.sg (Martin Sulzmann) Date: Tue Jan 1 21:43:59 2008 Subject: [Haskell-cafe] Missing join and split In-Reply-To: <8dde104f0801011429t123450cfjc19c3842bab4ba2@mail.gmail.com> References: <4774E022.8070201@btinternet.com> <117f2cc80712280655w70bdcdfet6e11dcb4e2a66bb2@mail.gmail.com> <6BD267D89E66B9499514F119920E583C0203DBCC@usctmx1110.merck.com> <8dde104f0801011429t123450cfjc19c3842bab4ba2@mail.gmail.com> Message-ID: <18298.64465.426876.674664@suna0.comp.nus.edu.sg> Josef Svenningsson writes: > On Dec 28, 2007 11:40 PM, Mitar wrote: > > Would not it be interesting and useful (but not really efficient) to > > have patterns something like: > > > > foo :: Eq a => a -> ... > > foo (_{4}'b') = ... > > > > which would match a list with four elements ending with an element 'b'. Or: > > > > foo (_+';'_+';'_) = ... > > > > which would match a list with embedded two ';' elements. (Last _ > > matched the remaining of the list.) > > > I suggest you take at look at HaRP, Haskell Regular Patterns: > http://www.cs.chalmers.se/~d00nibro/harp/ > > It hasn't been updated for a while but it should still be useable. > Also of interest might be XHaskell http://taichi.ddns.comp.nus.edu.sg/taichiwiki/XhaskellHomePage which adds XDuce style regular expression pattern matching to Haskell. Martin From gale at sefer.org Wed Jan 2 04:34:02 2008 From: gale at sefer.org (Yitzchak Gale) Date: Wed Jan 2 04:28:10 2008 Subject: [Haskell-cafe] Basic question concerning data constructors In-Reply-To: <7ca3f0160801011557x8fc901bv795da1d81662dacb@mail.gmail.com> References: <49a77b7a0712301219y6959db9y967a9cb75427443d@mail.gmail.com> <20071231011748.sq6ryegp6o8cg4c0@webmail.spamcop.net> <2608b8a80801010733q3f5f4a6ewfba794151757578a@mail.gmail.com> <2608b8a80801010743m33409e52w97ba1ad8da9518d9@mail.gmail.com> <7ca3f0160801011557x8fc901bv795da1d81662dacb@mail.gmail.com> Message-ID: <2608b8a80801020134y584f52f2t612554f44364365a@mail.gmail.com> I wrote: >> The classical definition of "general recursive function" >> refers to functions in Integer -> Integer to begin >> with, so there can only be countably many values by >> construction. Luke Palmer wrote: > Except that there are uncountably many (2^Aleph_0) functions in > Integer -> Integer. No, only countably many. By the type expression Integer -> Integer we mean all Haskell functions mapping Integers to Integers. There are only countably many of those. Of course, you can sometimes use Haskell-like notation for discussing other mathematical concepts. In that context, you might mean to include uncomputable functions in your types. (Hey, there's a fun idea - how would you write the infinite injury algorithm in Haskell?) But that was not the context in this thread. The category Hask that we often mention in discussions about Haskell the programming language is most certainly a small category. -Yitz From emmanuel.delaborde at citycampus.com Wed Jan 2 05:13:29 2008 From: emmanuel.delaborde at citycampus.com (manu) Date: Wed Jan 2 05:07:31 2008 Subject: [Haskell-cafe] Problem building hdbc-sqlite3 with ghc 6.8.2 Message-ID: <49E913CA-C853-451A-9E6C-FA460EFC6B39@citycampus.com> hello, has anybody managed to build hdbc-sqlite3 with ghc 6.8.2 ? I get the following error : Macintosh:HDBC-sqlite3-1.1.3.0 manu$ runhaskell Setup.lhs build Preprocessing library HDBC-sqlite3-1.1.3.0... ghc-6.8.2: unrecognised flags: -F/Users/manu/Library/Frameworks Usage: For basic information, try the `--help' option. compiling dist/build/Database/HDBC/Sqlite3/Statement_hsc_make.c failed command was: /usr/local/bin/ghc -c -package base-3.0.1.0 -package mtl-1.1.0.0 -package HDBC-1.1.3 -I. -F/Users/manu/Library/Frameworks dist/build/Database/HDBC/Sqlite3/Statement_hsc_make.c -o dist/build/ Database/HDBC/Sqlite3/Statement_hsc_make.o if somebody has an idea... Thanks E.D From ajb at spamcop.net Wed Jan 2 06:15:02 2008 From: ajb at spamcop.net (ajb@spamcop.net) Date: Wed Jan 2 06:09:01 2008 Subject: [Haskell-cafe] Basic question concerning data constructors In-Reply-To: <2608b8a80801010733q3f5f4a6ewfba794151757578a@mail.gmail.com> References: <49a77b7a0712301219y6959db9y967a9cb75427443d@mail.gmail.com> <20071231011748.sq6ryegp6o8cg4c0@webmail.spamcop.net> <2608b8a80801010733q3f5f4a6ewfba794151757578a@mail.gmail.com> Message-ID: <20080102061502.otgf2n7m040owcow@webmail.spamcop.net> G'day all. Quoting Yitzchak Gale : > Data types consist only of computable elements. Since there > are only countably many computable functions, every data type > has at most countably many elements. In particular, it is a set. I still say it "isn't a set" in the same way that a group "isn't a set". Haskell data types have structure that is respected by Haskell homomorphisms. Sets don't. Cheers, Andrew Bromage From bf3 at telenet.be Wed Jan 2 06:50:46 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Wed Jan 2 06:44:45 2008 Subject: [Haskell-cafe] Consensus about databases / serialization Message-ID: <000a01c84d35$b64d3de0$22e7b9a0$@be> As I'm a selfmade man, I never really studied relational databases in detail. My intuition told me that the "relational" part was not really suitable for the 3D data, 2D images, animation curves, state machines, and other data I encountered in the videogame and animation business. I could always get away with files, and for the applications I needed to deploy, plugging in a couple of extra gigabytes of RAM and serializing the "object" state to disk was more practical, cheaper and faster. However, a couple of years ago I started studying computer science (I seem to do the theory after the practice, weird behavior ;-) at the Open University, and one of the exams I did was about databases. Initially this course convinced me that databases are actually very nice, but the course ended with a topic on object oriented databases, which were designed to make storing data like "3D models, graphs, networks, and complex datastructures" more practical. Duh. Since then, I did deploy a few commercial applications for customers using databases, which worked fine for the typical "simple/flat" database data. I hated embedding a dynamic untyped language like SQL, as much as I hated embedding code in HTML or XML. IMHO it feels UGLY and unsafe. Regarding the other popular data storage format - XML - I did use that a lot, but it seems like going back to the stone ages, when hierarchical stores/databases got invented (and ditched?) Now, initially after an introduction to Microsoft's LINQ, and recently having read a very brief overview of HAppS, it seems I'm not the only one with those "feelings". Ouch, this introduction got way to long, sorry about that ;-) Finally some practical questions: . regarding Haskell and databases, the page http://haskell.org/haskellwiki/Libraries_and_tools/Database_interfaces describes a few, but which are the ones that are stable and practical? Any user experiences? . HApps is not listed in the page above, because it does not use databases? Is HApps reliable or experimental, and does it scale well? Any success stories? . regarding Haskell and serialization, I don't think that implementing Read/Show is a good way for real serialization, so what other options exist? I could find some libraries at http://hackage.haskell.org/packages/archive/pkg-list.html#cat:Data, but again which are the most practical and stable? When programming in C++/MFC and C#/.NET, I tended to develop my own serialization frameworks because I used that for many things, like logging commands to disk, performing undo/redo, intra and inter process cut/copy/paste, save/load, etc. . Regarding serialization, I'm kinda curious how ADTs and even GADTs are stored and retrieved in a relational database? I guess it could be done using BLOBs and serialization to ByteStrings, so bypassing a lot of the database table structures? . If I would want to experiment with say HAppS, the way I understand it, I first would first have to study "Scratch your boilerplate" and Template Haskell, and maybe some other language features? I'm still new to Haskell, and the road to understanding all language elements and extensions is very long, so sequentially learning it would be insane I guess. I have no practical experience with TH, but I spent a long time trying to do "aspect oriented programming" in C# without success, so TH looks uber to me. Thanks a lot and best wishes for 2008? Peter -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080102/46a08795/attachment.htm From kirby81 at gmail.com Wed Jan 2 07:20:26 2008 From: kirby81 at gmail.com (Salvatore Insalaco) Date: Wed Jan 2 07:14:27 2008 Subject: [Haskell-cafe] Consensus about databases / serialization In-Reply-To: <000a01c84d35$b64d3de0$22e7b9a0$@be> References: <000a01c84d35$b64d3de0$22e7b9a0$@be> Message-ID: <5a376f550801020420m715a5b29q2ec880889b01f865@mail.gmail.com> > ? regarding Haskell and databases, the page > http://haskell.org/haskellwiki/Libraries_and_tools/Database_interfaces > describes a few, but which are the ones that are stable and practical? Any > user experiences? During my experiments I found Takusen (http://darcs.haskell.org/takusen/) and HDBC (http://software.complete.org/hdbc) very useful, even if I liked Takusen interface more. > ? regarding Haskell and serialization, I don't think that > implementing Read/Show is a good way for real serialization, so what other > options exist? I could suggest Data.Binary (http://code.haskell.org/binary/), that is very well performing and supported. There are ways to generate instances of Binary automatically. I like the "Derive" approach most (http://www.cs.york.ac.uk/fp/darcs/derive/derive.htm), as it uses Template Haskell and does not require separate pre-processing. From jlw501 at cs.york.ac.uk Wed Jan 2 07:32:00 2008 From: jlw501 at cs.york.ac.uk (jlw501) Date: Wed Jan 2 07:26:02 2008 Subject: [Haskell-cafe] Knowledge In-Reply-To: <404396ef0712191341p59cde996s1014e68c6eb59ea5@mail.gmail.com> References: <14423007.post@talk.nabble.com> <7ca3f0160712191328s700a1655l14a900fd177d8c07@mail.gmail.com> <404396ef0712191341p59cde996s1014e68c6eb59ea5@mail.gmail.com> Message-ID: <14577605.post@talk.nabble.com> Good point. By fold/unfold transformation you get the following: contains = flip elem [Eureka] = contains xs e = flip elem xs e [Expose data structures] = contains [] e = False contains (x:xs) e = flip elem (x:xs) e [Instantiate] = contains [] e = False contains (x:xs) e = elem e x:[] || flip elem xs e [Unfold flip one step] = contains [] e = False contains (x:xs) e = elem e x:[] || contains xs e [Fold back to original defintion] = contains [] e = False contains (x:xs) = e==x || contains xs e [Substitute] Apparently, the fold/unfold transformation law will always yield an equally or more efficient computation. So this begs the question... contains [] e = False contains (x:xs) = e==x || contains xs e OR contains = flip elem Neil Mitchell wrote: > > Hi > >> > contains :: Eq a => [a]->a->Bool >> > contains [] e = False >> > contains (x:xs) e = if x==e then True else contains xs e >> >> contains = flip elem > > And even if not using the elem function, the expression: > > if x==e then True else contains xs e > > can be written as: > > x==e || contains xs e > > Thanks > > Neil > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > -- View this message in context: http://www.nabble.com/Knowledge-tp14423007p14577605.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. From gale at sefer.org Wed Jan 2 08:49:42 2008 From: gale at sefer.org (Yitzchak Gale) Date: Wed Jan 2 08:43:42 2008 Subject: [Haskell-cafe] Basic question concerning the category Hask (was: concerning data constructors) Message-ID: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> Hi Andrew, Andrew Bromage wrote: > I still say it "isn't a set" in the same way that a group "isn't a set". > Haskell data types have structure that is respected by Haskell > homomorphisms. Sets don't. Ah, that's certainly true. But what is that additional structure? In categories that have a forgetful functor to Set, the interesting part of their structure comes from the fact that their morphisms are only a proper subset of the morphisms in Set. So in what way are Set morphisms restricted from being Hask morphisms? In two ways, I think: 1. They must be computable. 2. They must satisfy certain strictness criteria involving undefined and seq. (1) can be rather boring, since computability is rarely is an issue in real-life programming problems. It seems that some people using concepts from categories in Haskell would prefer to ignore (2) as well. If so, we have been reduced to viewing Hask as more or less the same as a small subcategory of Set, with no additional structure that is of interest. In this view, there is nothing special about Haskell, except for the fact that category-theoretic concepts are a bit easier to express in Haskell than in many other languages. So perhaps a better name for this category would be Turing. I don't think that ignoring (2) is the right approach. I would like Hask to reflect the non-strict nature of Haskell, which is one of its most interesting features. Some people are worried that this version of Hask is missing certain nice properties that one would like to have. For example, it was recently claimed on this list that tuples are not products in that category. (Or some such. I would be interested to see a demonstration of that.) I am not impressed by those complaints. As usual in category theory, you define corresponding notions in Hask, and prove that they are preserved under the appropriate functors. That should always be easy. And if ever it is not, then you have discovered an interesting non-trivial consequence of laziness that deserves study. For example: I think that "monads" in Haskell should satisfy the monad laws in Hask, not just after applying the forgetful functor to Turing. That means that (>>=) must be strict in its second argument. That would very likely not break any existing programs, yet almost none of the existing monads satisfy this, not even IO. Regards, Yitz From cristian.baboi at gmail.com Wed Jan 2 09:18:19 2008 From: cristian.baboi at gmail.com (Cristian Baboi) Date: Wed Jan 2 09:11:58 2008 Subject: [Haskell-cafe] Consensus about databases / serialization In-Reply-To: <000a01c84d35$b64d3de0$22e7b9a0$@be> References: <000a01c84d35$b64d3de0$22e7b9a0$@be> Message-ID: I recommend you read "Extending the database relational model to capture more meaning" by E.F. Codd. On Wed, 02 Jan 2008 13:50:46 +0200, Peter Verswyvelen wrote: > As I'm a selfmade man, I never really studied relational databases in > detail. My intuition told me that the "relational" part was not really > suitable for the 3D data, 2D images, animation curves, state machines, > and > other data I encountered in the videogame and animation business. I could > always get away with files, and for the applications I needed to deploy, > plugging in a couple of extra gigabytes of RAM and serializing the > "object" > state to disk was more practical, cheaper and faster. > > > However, a couple of years ago I started studying computer science (I > seem > to do the theory after the practice, weird behavior ;-) at the Open > University, and one of the exams I did was about databases. Initially > this > course convinced me that databases are actually very nice, but the course > ended with a topic on object oriented databases, which were designed to > make > storing data like "3D models, graphs, networks, and complex > datastructures" > more practical. Duh. > > > Since then, I did deploy a few commercial applications for customers > using > databases, which worked fine for the typical "simple/flat" database > data. I > hated embedding a dynamic untyped language like SQL, as much as I hated > embedding code in HTML or XML. IMHO it feels UGLY and unsafe. Regarding > the > other popular data storage format - XML - I did use that a lot, but it > seems > like going back to the stone ages, when hierarchical stores/databases got > invented (and ditched?) > > > Now, initially after an introduction to Microsoft's LINQ, and recently > having read a very brief overview of HAppS, it seems I'm not the only one > with those "feelings". > > > Ouch, this introduction got way to long, sorry about that ;-) > > > Finally some practical questions: > > . regarding Haskell and databases, the page > http://haskell.org/haskellwiki/Libraries_and_tools/Database_interfaces > describes a few, but which are the ones that are stable and practical? > Any > user experiences? > > . HApps is not listed in the page above, because it does not use > databases? Is HApps reliable or experimental, and does it scale well? Any > success stories? > > . regarding Haskell and serialization, I don't think that > implementing Read/Show is a good way for real serialization, so what > other > options exist? I could find some libraries at > http://hackage.haskell.org/packages/archive/pkg-list.html#cat:Data, but > again which are the most practical and stable? When programming in > C++/MFC > and C#/.NET, I tended to develop my own serialization frameworks because > I > used that for many things, like logging commands to disk, performing > undo/redo, intra and inter process cut/copy/paste, save/load, etc. > > . Regarding serialization, I'm kinda curious how ADTs and even > GADTs > are stored and retrieved in a relational database? I guess it could be > done > using BLOBs and serialization to ByteStrings, so bypassing a lot of the > database table structures? > > . If I would want to experiment with say HAppS, the way I > understand > it, I first would first have to study "Scratch your boilerplate" and > Template Haskell, and maybe some other language features? I'm still new > to > Haskell, and the road to understanding all language elements and > extensions > is very long, so sequentially learning it would be insane I guess. I > have no > practical experience with TH, but I spent a long time trying to do > "aspect > oriented programming" in C# without success, so TH looks uber to me. > > > Thanks a lot and best wishes for 2008? > > > Peter > From benja.fallenstein at gmail.com Wed Jan 2 09:38:56 2008 From: benja.fallenstein at gmail.com (Benja Fallenstein) Date: Wed Jan 2 09:32:54 2008 Subject: [Haskell-cafe] Basic question concerning data constructors In-Reply-To: <2608b8a80801020134y584f52f2t612554f44364365a@mail.gmail.com> References: <49a77b7a0712301219y6959db9y967a9cb75427443d@mail.gmail.com> <20071231011748.sq6ryegp6o8cg4c0@webmail.spamcop.net> <2608b8a80801010733q3f5f4a6ewfba794151757578a@mail.gmail.com> <2608b8a80801010743m33409e52w97ba1ad8da9518d9@mail.gmail.com> <7ca3f0160801011557x8fc901bv795da1d81662dacb@mail.gmail.com> <2608b8a80801020134y584f52f2t612554f44364365a@mail.gmail.com> Message-ID: Hi Yitz, On Jan 2, 2008 10:34 AM, Yitzchak Gale wrote: > No, only countably many. By the type expression Integer -> Integer > we mean all Haskell functions mapping Integers to Integers. > There are only countably many of those. ... > But that was not the context in this thread. The category > Hask that we often mention in discussions about Haskell > the programming language is most certainly a small category. I don't know. My understanding has been that at least part of the benefit of denotational semantics is that you can define what an expression means without referring back to the syntactic construction or the operational semantics of that expression -- and thus use the denotational semantics to check whether the operational semantics are "right." But if you start with "all Haskell functions," you already have to know what a Haskell function *is*. I think it should be "allowed" to think of the semantics of Haskell as being defined independently of the (relatively operational) notion of "computable function," and then define "computable function" to be that subset of the functions in the model that you can actually write in Haskell. And the only explicit non-syntactic constructions of models for Haskell-like languages that I'm familiar with aren't countable (they contain all continuous functions, which in the case of (Integer -> Integer) comes out to all monotonous functions). So I disagree that the function types of Hask should automatically be taken to be countable. If you want to assume it for some given purpose, sure, fine, but IMO that's an additional assumption, not something inherent in the Haskell language. Best, - Benja From Christian.Maeder at dfki.de Wed Jan 2 09:39:36 2008 From: Christian.Maeder at dfki.de (Christian Maeder) Date: Wed Jan 2 09:33:37 2008 Subject: [Haskell-cafe] Re: Problem building hdbc-sqlite3 with ghc 6.8.2 In-Reply-To: <49E913CA-C853-451A-9E6C-FA460EFC6B39@citycampus.com> References: <49E913CA-C853-451A-9E6C-FA460EFC6B39@citycampus.com> Message-ID: <477BA228.9030406@dfki.de> manu wrote: > hello, > > has anybody managed to build hdbc-sqlite3 with ghc 6.8.2 ? > > I get the following error : > > Macintosh:HDBC-sqlite3-1.1.3.0 manu$ runhaskell Setup.lhs build > Preprocessing library HDBC-sqlite3-1.1.3.0... > ghc-6.8.2: unrecognised flags: -F/Users/manu/Library/Frameworks > Usage: For basic information, try the `--help' option. > compiling dist/build/Database/HDBC/Sqlite3/Statement_hsc_make.c failed > command was: /usr/local/bin/ghc -c -package base-3.0.1.0 -package > mtl-1.1.0.0 -package HDBC-1.1.3 -I. -F/Users/manu/Library/Frameworks > dist/build/Database/HDBC/Sqlite3/Statement_hsc_make.c -o > dist/build/Database/HDBC/Sqlite3/Statement_hsc_make.o > > > if somebody has an idea... I seems you used my binary dist that I made with a modified utils/hsc2hs/Main.hs http://article.gmane.org/gmane.comp.lang.haskell.glasgow.user/13583 http://hackage.haskell.org/trac/ghc/ticket/1395 hsc2hs only worked for me when gcc was used instead ghc (when bootstrapping ghc-6.8.2 itself). Maybe I should build new binary-dists. Is it for ppc or x86? Cheers Christian From jeff.polakow at db.com Wed Jan 2 09:54:31 2008 From: jeff.polakow at db.com (Jeff Polakow) Date: Wed Jan 2 09:48:37 2008 Subject: [Haskell-cafe] Consensus about databases / serialization In-Reply-To: <000a01c84d35$b64d3de0$22e7b9a0$@be> Message-ID: Hello, I use HDBC for ODBC database access, and HAppS as a web server. I am fairly happy with both. Here are some further thoughts... > Finally some practical questions: > ? regarding Haskell and databases, the page http://haskell. > org/haskellwiki/Libraries_and_tools/Database_interfaces describes a > few, but which are the ones that are stable and practical? Any user > experiences? > HDBC is fairly stable (although its ODBC driver crashes ghc 6.8 on windows). I think HSQL is similarly stable. Takusen offers a slightly higher-level interface and some performance guarantees; it is a nice system but lacks support for ODBC (supposedly this is in the works). HaskelDB is probably the ideal database access system for Haskell, however the distribution was in bad shape (no documentation, hard to compile, etc.) the last I looked maybe 6 months ago. > ? HApps is not listed in the page above, because it does not > use databases? Is HApps reliable or experimental, and does it scale > well? Any success stories? > HAppS is a general server framework for Haskell. HAppS is very appealing because it allows you to dynamically create pages directly with Haskell. HAppS encourages storing your server state in memory, but it is easy to read in state on the fly from external sources. The only caveat with HAppS is that the system has been in active development for the past few months is just starting (I hope) to settle down; thus useful documentation/examples are hard to find, but the HAppS developers are pretty good at replying to help requests on the HAppS IRC and the HAppS mailing list. I am currently using an old (and stable) version of HAppS but expect to upgrade to the latest version soon. > ? If I would want to experiment with say HAppS, the way I > understand it, I first would first have to study ?Scratch your > boilerplate? and Template Haskell, and maybe some other language > features? I?m still new to Haskell, and the road to understanding > all language elements and extensions is very long, so sequentially > learning it would be insane I guess. I have no practical experience > with TH, but I spent a long time trying to do ?aspect oriented > programming? in C# without success, so TH looks uber to me? > While HAppS does use SYB and TH, you don't need to understand them to effectively use HAppS; of course you'll need to understand them, at least basic TH, to understand the details of what HAppS is doing. hope that helps, Jeff --- This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080102/61713847/attachment-0001.htm From jonathanccast at fastmail.fm Wed Jan 2 10:26:37 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Wed Jan 2 10:20:41 2008 Subject: [Haskell-cafe] Basic question concerning the category Hask (was: concerning data constructors) In-Reply-To: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> Message-ID: <25C23866-F3AB-4510-9DDD-48A50B72835B@fastmail.fm> On 2 Jan 2008, at 5:49 AM, Yitzchak Gale wrote: > Hi Andrew, > > Andrew Bromage wrote: >> I still say it "isn't a set" in the same way that a group "isn't a >> set". >> Haskell data types have structure that is respected by Haskell >> homomorphisms. Sets don't. > > Ah, that's certainly true. But what is that additional structure? > > In categories that have a forgetful functor to Set, the interesting > part of their structure comes from the fact that their > morphisms are only a proper subset of the morphisms > in Set. > > So in what way are Set morphisms restricted from being > Hask morphisms? The normal view taken by Haskellers is that the denotations of Haskell types are CPPOs. So: (1) Must be monotone (2) Must be continuous (Needn't be strict, even though that messes up the resulting category substantially). jcc From simonmarhaskell at gmail.com Wed Jan 2 10:30:02 2008 From: simonmarhaskell at gmail.com (Simon Marlow) Date: Wed Jan 2 10:24:06 2008 Subject: [Haskell-cafe] Re: Haskell performance In-Reply-To: <20071222061434.u21waxhcms8wwwc4@webmail.spamcop.net> References: <1197707105.479.2.camel@localhost.localdomain> <20071220190214.GF29838@scytale.galois.com> <200712201919.33104.jon@ffconsultancy.com> <20071222061434.u21waxhcms8wwwc4@webmail.spamcop.net> Message-ID: <477BADFA.1080505@microsoft.com> ajb@spamcop.net wrote: > G'day all. > > Quoting Jon Harrop : > >> I would recommend adding: >> >> 1. FFT. >> >> 2. Graph traversal, e.g. "n"th-nearest neighbor. > > I'd like to put in a request for Pseudoknot. Does anyone still have it? This is it, I think: http://darcs.haskell.org/nofib/spectral/hartel/nucleic2 Cheers, Simon From h._h._h._ at hotmail.com Wed Jan 2 11:00:26 2008 From: h._h._h._ at hotmail.com (H. Mayer) Date: Wed Jan 2 10:54:25 2008 Subject: [Haskell-cafe] Escape Codes Message-ID: Hello, Some days ago I needed escape codes on Win32. I didn't find any library for that, so I wrote a simple one. I thought, perhaps someone else will have the same problem, so I put it on my website:http://0hc.net/?what=downloads_sup_AWin32Console I've tested it with the ghc 6.6.1, and everything works as I expected it. I would be happy if someone else could test it and/or report if some important escape codes are missing. --Sincerely H. _________________________________________________________________ Erweitere dein digitales Leben. Hol dir jetzt gratis das neue Windows Live. http://get.live.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080102/5a16c57d/attachment.htm From ndmitchell at gmail.com Wed Jan 2 11:21:50 2008 From: ndmitchell at gmail.com (Neil Mitchell) Date: Wed Jan 2 11:15:49 2008 Subject: [Haskell-cafe] Escape Codes In-Reply-To: References: Message-ID: <404396ef0801020821j185f4b6eoe2f14462eb154b62@mail.gmail.com> Hi > Some days ago I needed escape codes on Win32. I didn't find any library for > that, so I wrote a simple one. I have a simple module which does them as part of Hoogle: http://www.cs.york.ac.uk/fp/darcs/hoogle/src/General/Type.hs - see TagStr, the type for defining text with basic formatting and outputting it to the console. It doesn't attempt to be comprehensive at all, and probably solves a different problem from your one. > I thought, perhaps someone else will have the same problem, so I put it on > my website: > http://0hc.net/?what=downloads_sup_AWin32Console It would be nice if you could package this and release it on hackage. http://hackage.haskell.org/packages/hackage.html Thanks Neil From simonmarhaskell at gmail.com Wed Jan 2 11:21:51 2008 From: simonmarhaskell at gmail.com (Simon Marlow) Date: Wed Jan 2 11:15:56 2008 Subject: [Haskell-cafe] Re: [16/16] SBM: Discussion and Conclusion In-Reply-To: <20071222091730.D01201604896C@csmtp2.b-one.net> References: <20071222091730.D01201604896C@csmtp2.b-one.net> Message-ID: <477BBA1F.7010606@microsoft.com> Peter Firefly Brodersen Lund wrote: > Using top together with huge input files convinced me that -sstderr was > untrustworthy so I developed the pause-at-end preloading hack. Paranoia paid > off big time there. In what way did you find -sstderr untrustworthy? Perhaps it is because the "memory in use" figure only counts memory that the RTS knows about, and doesn't include malloc()'d memory. If it's anything else, I need to know about it. > o can the core/stg code be made easier to read? By all means - submit tickets with specific suggestions, or better still send patches. Cheers, Simon From stevelihn at gmail.com Wed Jan 2 11:23:13 2008 From: stevelihn at gmail.com (Steve Lihn) Date: Wed Jan 2 11:17:18 2008 Subject: [Haskell-cafe] Consensus about databases / serialization In-Reply-To: References: <000a01c84d35$b64d3de0$22e7b9a0$@be> Message-ID: I have started documenting the Database Wikibook, in particular, about HDBC. It is still very rough at this time, but something is better than nothing :-) If you want to add more content, certainly welcome! http://en.wikibooks.org/wiki/Haskell/Database On 1/2/08, Jeff Polakow wrote: > Hello, > I use HDBC for ODBC database access, and HAppS as a web server. I am fairly happy with both. Here are some further thoughts... > > Finally some practical questions: > > ? regarding Haskell and databases, the page http://haskell. > > org/haskellwiki/Libraries_and_tools/Database_interfaces describes a > > few, but which are the ones that are stable and practical? Any user > > experiences? > > > HDBC is fairly stable (although its ODBC driver crashes ghc 6.8 on windows). I think HSQL is similarly stable. Takusen offers a slightly higher-level interface and some performance guarantees; it is a nice system but lacks support for ODBC (supposedly this is in the works). HaskelDB is probably the ideal database access system for Haskell, however the distribution was in bad shape (no documentation, hard to compile, etc.) the last I looked maybe 6 months ago. From ndmitchell at gmail.com Wed Jan 2 11:30:21 2008 From: ndmitchell at gmail.com (Neil Mitchell) Date: Wed Jan 2 11:24:19 2008 Subject: [Haskell-cafe] Hackage web page Message-ID: <404396ef0801020830t7a6f8bc3ydf01ca829a2af778@mail.gmail.com> Hi, The hackage web page confuses me: http://hackage.haskell.org/packages/hackage.html As a user, when I go to that page, I would be seeking one of four pieces of information: 1) How to install a cabal package 2) How to create and upload a cabal package 3) What packages are on hackage 4) What is hackage The first paragraph answers question 4, before pointing off at the trac pages, which contain similar and overlapping information, as well as completely other stuff. The second paragraph basically answers 3 and 1, but in rather roundabout ways, not including a link to the answer to 3, but including a link about CabalInstall which you can't use yet. The rest of the page is notes for the hackage developers. I just went to hackage looking for the answer to question 2. I can't find it. I have a rough idea where some of the information might be hiding, but we really need a walkthrough tutorial - and I'm sure I've seen one of these before. I would think something more like the style of this might work better: http://www-users.york.ac.uk/~socs235/welcome.htm Hackage has now graduated from being a nice idea to being a critial user-focused thingy, which is great. Perhaps the website needs a little bit of thought along those lines. This isn't intended to be a complaint at all - just a new perspective to the people who develop it and probably don't read the web page at all. Thanks Neil From Malcolm.Wallace at cs.york.ac.uk Wed Jan 2 11:32:14 2008 From: Malcolm.Wallace at cs.york.ac.uk (Malcolm Wallace) Date: Wed Jan 2 11:26:45 2008 Subject: [Haskell-cafe] Newbie question: can laziness lead to space compression? In-Reply-To: References: Message-ID: <20080102163214.029f1701.Malcolm.Wallace@cs.york.ac.uk> Brian Hurt wrote: > But I was wondering if it is possible that lazy evaluation > could lead to space compression, especially under heavily persistant > usage patterns? > > Note that the benefit isn't *big*- we're talking about 40 words of > memory when the main data structure is taking up 5K plus words of > memory- so it's less than 1% different. But there is a (small) > upside in memory usage at least occassionally, right? Actually, a lazy evaluation strategy can sometimes change the entire complexity class of space usage, not just the constant factors. For instance, lazy streaming algorithms (where the data is produced and consumed in lock-step) may use a small constant amount of memory, independent of the size of the data, whereas an eager strategy would use memory linearly proportional to the dataset size. Regards, Malcolm From simonmarhaskell at gmail.com Wed Jan 2 11:39:36 2008 From: simonmarhaskell at gmail.com (Simon Marlow) Date: Wed Jan 2 11:33:38 2008 Subject: [Haskell-cafe] Re: Importing Data.Char speeds up ghc around 70% In-Reply-To: References: <200712222038.01632.daniel.is.fischer@web.de> <200712222155.30842.daniel.is.fischer@web.de> <404396ef0712221434i56fb5677sfb71662ccc6a356f@mail.gmail.com> Message-ID: <477BBE48.1030300@microsoft.com> Joost Behrends wrote: > Neil Mitchell gmail.com> writes: > >> If it can be reproduced on anyones machine, it is a bug. If you can >> bundle up two programs which don't read from stdin (i.e. no getLine >> calls) or the standard arguments (i.e. getArgs) which differ only by >> the Data.Char import, and have massive speed difiference, then report >> a bug. >> >> You should probably also give your GHC versions and platforms etc. > > Thanks for your attention too ! > > Now i tried a version without input (just computing the primefactors of the > constant 2^61+1, what it did correctly in spite of its bugginess). And it > didn't have the Data.Char bug (and Data.List bug) too. > > As my original code hasn't on Linux also it seems. > > Thus it happens only in an exotic configuration. Windows will stay exotic > in the Haskell community. Before should noone > has reproduced it at least on Windows (XPpro SP2 is my version), i will do > nothing more. > > The hardware is Intel Celeron 2.2GHZ, 512 MB Ram. ghc 6.8.1 lives on > D:\\Programme (not on the system drive C:, which poses problems to Cabal, > told aside). Even if it only happens on Windows, if it isn't specific to your hardware then it could still be a bug. I have seen strange artifacts like this before that turned out to be caused by one of two things: - bad cache interactions, e.g. we just happen to have laid out the code in such a way that frequently accessed code sequences push each other out of the cache, or the relative position of the heap and stack have a bad interaction. This happens less frequently these days with 4-way and 8-way associative caches on most CPUs. - alignment issues, such as storing or loading a lot of misaligned Doubles in the second case, I've seen the same program run +/- 50% in performance from run to run, just based on random alignment of the stack. But it's not likely to be the issue here, I'm guessing. If it is code misalignment, that's something we can easily fix (but I don't *think* we're doing anything wrong in that respect). I have an Opteron box here that regularly gives +/- 20% from run to run of the same program with no other load on the machine. I have no idea why... Cheers, Simon From Nicholls.Mark at mtvne.com Wed Jan 2 11:40:31 2008 From: Nicholls.Mark at mtvne.com (Nicholls, Mark) Date: Wed Jan 2 11:35:52 2008 Subject: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? In-Reply-To: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> Message-ID: I'm trying to translate some standard C# constucts into Haskell... some of this seems easy.... Specifically 1) Interface IX { } 2) Interface IX { } 3) Interface IX Where A : IY { } 4) Interface IX : IZ Where A : IY { } I can take a punt at the first 2....but then it all falls apart From duncan.coutts at worc.ox.ac.uk Wed Jan 2 12:20:04 2008 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Wed Jan 2 12:14:02 2008 Subject: [Haskell-cafe] Re: Hackage web page In-Reply-To: <404396ef0801020830t7a6f8bc3ydf01ca829a2af778@mail.gmail.com> Message-ID: <20080102172004.3C121A8002@webmail223.herald.ox.ac.uk> In message <404396ef0801020830t7a6f8bc3ydf01ca829a2af778@mail.gmail.com> "Neil Mitchell" writes: > Hi, > > The hackage web page confuses me: > http://hackage.haskell.org/packages/hackage.html > Hackage has now graduated from being a nice idea to being a critial > user-focused thingy, which is great. Perhaps the website needs a > little bit of thought along those lines. This isn't intended to be a > complaint at all - just a new perspective to the people who develop it > and probably don't read the web page at all. You're quite right. We'd welcome a rewrite. You or anyone else is most welcome to send us a new version in .html or any other format. If there are no immediate volunteers then someone should file a bug against the HackageDB component in our tracker so we do not forget. http://hackage.haskell.org/trac/hackage Duncan From ryani.spam at gmail.com Wed Jan 2 12:40:53 2008 From: ryani.spam at gmail.com (Ryan Ingram) Date: Wed Jan 2 12:34:51 2008 Subject: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? In-Reply-To: References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> Message-ID: <2f9b2d30801020940g228f5fa3h2a7d6592d5c16acd@mail.gmail.com> Of course it depends what's inside the braces, and what you want to do with it, but I'd be inclined to do something like this: 1) data IX a = IX { constructor :: Int -> a, ... } 2) data IX a b = IX { constructor :: Int -> b, func :: a -> b, ... } 3) data IX a b = IX { iy :: IY a, ... } 4) data IX a b = IX { iz :: IZ b, iy :: IY a, ... } Can you specify more clearly what the goal of the conversion is? If you want "OO" style behavior the thing that is most important is existential quantification. -- ryan On 1/2/08, Nicholls, Mark wrote: > > I'm trying to translate some standard C# constucts into Haskell... some > of this seems easy.... > > Specifically > > 1) > > Interface IX > { > } > > 2) > > Interface IX > { > } > > 3) > > Interface IX > Where A : IY > { > } > > 4) > > Interface IX : IZ > Where A : IY > { > } > > > I can take a punt at the first 2....but then it all falls apart > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080102/f4a0d716/attachment.htm From bulat.ziganshin at gmail.com Wed Jan 2 12:10:29 2008 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Wed Jan 2 14:00:54 2008 Subject: [Haskell-cafe] Hackage web page In-Reply-To: <404396ef0801020830t7a6f8bc3ydf01ca829a2af778@mail.gmail.com> References: <404396ef0801020830t7a6f8bc3ydf01ca829a2af778@mail.gmail.com> Message-ID: <918353021.20080102201029@gmail.com> Hello Neil, Wednesday, January 2, 2008, 7:30:21 PM, you wrote: > The hackage web page confuses me: > http://hackage.haskell.org/packages/hackage.html btw, i very like idea of using wiki pages which allows all users to participate in development of docs. may be it will be better to wikify this page too -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From vigalchin at gmail.com Wed Jan 2 14:18:46 2008 From: vigalchin at gmail.com (Galchin Vasili) Date: Wed Jan 2 14:12:45 2008 Subject: [Haskell-cafe] I am looking for the source code for STM implementation ... Message-ID: <5ae4f2ba0801021118w2bfc5fd6hb96684ca0944234e@mail.gmail.com> Hello, I found STM.c(lower layer), but cannot find the top layer code written Haskell.?? Vasya -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080102/b38539fe/attachment.htm From ryani.spam at gmail.com Wed Jan 2 15:22:55 2008 From: ryani.spam at gmail.com (Ryan Ingram) Date: Wed Jan 2 15:16:53 2008 Subject: [Haskell-cafe] I am looking for the source code for STM implementation ... In-Reply-To: <5ae4f2ba0801021118w2bfc5fd6hb96684ca0944234e@mail.gmail.com> References: <5ae4f2ba0801021118w2bfc5fd6hb96684ca0944234e@mail.gmail.com> Message-ID: <2f9b2d30801021222p478eaf66s51cded69c90134fe@mail.gmail.com> http://www.haskell.org/ghc/docs/latest/html/libraries/base/src/GHC-Conc.html -- ryan On 1/2/08, Galchin Vasili wrote: > > Hello, > > I found STM.c(lower layer), but cannot find the top layer code written > Haskell.?? > > > Vasya > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080102/63fa50e9/attachment.htm From bulat.ziganshin at gmail.com Wed Jan 2 15:29:21 2008 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Wed Jan 2 15:28:30 2008 Subject: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? In-Reply-To: References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> Message-ID: <1965805939.20080102232921@gmail.com> Hello Mark, Wednesday, January 2, 2008, 7:40:31 PM, you wrote: > I'm trying to translate some standard C# constucts into Haskell... some it's meaningless. read http://haskell.org/haskellwiki/OOP_vs_type_classes and especially papers mentioned in the References -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bf3 at telenet.be Wed Jan 2 15:35:15 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Wed Jan 2 15:29:13 2008 Subject: FW: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? Message-ID: <005501c84d7e$fb0a8d90$f11fa8b0$@be> I'm also new to Haskell, but I'm a C++/C# veteran, so I'll give it a shot. C#'s interfaces look a bit like Haskell's type classes. Although not exactly the same, you could try something like this: -- C#: interface IX1 { String foo1(int); } class IX1 obj where foo1 :: Int -> obj -> String -- C#: interface IX2 { String foo2(A); } class IX2 obj a where foo2 :: a -> obj -> String --C#: interface IX3 where A : IY { String foo3(A); } class IY a where {- ... -} class IY a => IX3 obj a where foo3 :: a -> obj -> String --C#: interface IX4 : IZ where A : IY class IZ a where {- ... -} class (IY a, IZ obj) => IX4 obj a where foo4 :: a -> obj -> String The C# "class" is called an "instance" in Haskell, so to implement an interface, you would do e.g. data X2 = X2 { x2Bla :: String, ... } instance IX2 X2 String where foo2 s o = (x2Bla o) ++ s This assumes your "objects" are immutable, otherwise you would have to return (obj,String) instead of just String and then you most likely want to use the state monad and "do notation" to make functional programming look more like imperative programming. You really have to drop the OO way of thinking, which I find the hardest :) Haskell's type classes are more powerful in some sense than C# interfaces; for example, in C# you can't attach an interface to any class (take for example the Point struct), it has to be your own class, while in Haskell, you can implement an instance of a type class for any datatype! Hope this helps a bit. As I'm new myself to Haskell, so take this with a "grain of salt". Once you bite the bullet, I found Haskell a lot more fun than C#, although C# of course comes with a gigantic .NET framework and tools... Peter -----Original Message----- From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Nicholls, Mark Sent: Wednesday, January 02, 2008 5:41 PM To: haskell-cafe@haskell.org Subject: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? I'm trying to translate some standard C# constucts into Haskell... some of this seems easy.... Specifically 1) Interface IX { } 2) Interface IX { } 3) Interface IX Where A : IY { } 4) Interface IX : IZ Where A : IY { } I can take a punt at the first 2....but then it all falls apart _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe From moonlite at dtek.chalmers.se Wed Jan 2 16:36:36 2008 From: moonlite at dtek.chalmers.se (Mattias Bengtsson) Date: Wed Jan 2 18:04:21 2008 Subject: [Haskell-cafe] Re: Web server continued In-Reply-To: References: Message-ID: <1199309796.16506.8.camel@localhost.localdomain> On Mon, 2007-12-31 at 12:36 +0000, Joost Behrends wrote: > And concerning SQL: I like the parts of the language - all capitalized - as > landmarks in my code, even in modified forms like: > > "SELECT number, customer FROM " ++ currcols ++ .... > > Here i see from afar, what the code around this line does. And the backside of treating SQL as strings, like you do here, is that you are able to construct malformed SQL and the errors you get from this can only be handled at runtime. This is the reason HaskellDB (and other similar projects?) exists. I too am not sure that HaskellDB is the perfect solution though. It provides both type safety and an abstraction. Personally i'd be fine with just the type safety. Not sure if it's feasible to embed the whole SQL-syntax in Haskell using just ADT's and combinators though. Mattias -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080102/ac76a147/attachment.bin From jgbailey at gmail.com Wed Jan 2 18:22:08 2008 From: jgbailey at gmail.com (Justin Bailey) Date: Wed Jan 2 18:16:07 2008 Subject: [Haskell-cafe] Consensus about databases / serialization In-Reply-To: <000a01c84d35$b64d3de0$22e7b9a0$@be> References: <000a01c84d35$b64d3de0$22e7b9a0$@be> Message-ID: I can speak to haskelldb a little, see below: On Jan 2, 2008 3:50 AM, Peter Verswyvelen wrote: > ? regarding Haskell and databases, the page > http://haskell.org/haskellwiki/Libraries_and_tools/Database_interfaces > describes a few, but which are the ones that are stable and practical? Any > user experiences? I started looking at haskell database libraries to generate SQL for me. Haskelldb does this well - it uses a higher-level representation of queries based on "relational algebra" (also the basis of SQL) which is pretty easy to understand if you know SQL. It takes care of a lof the details of generating SQL strings, and does it in a mostly type-safe way. It is a bit complicated to install the library and all its dependencies, because it can work with 3+ (mysql, postgres, odbc) databases using two different backends (hdbc and hsql). I chose to go with HDBC because it compiled on Windows and postgres because thats what we have at my workplace. Once I got it built and installed its worked well for me. Until the most recent versions though, it added a "distinct" operator to all select statements. I submitted a patch which was accepted and now that behavior is no longer the default. It is semi-actively maintained by the original authors and Bjorn, at least, has been very responsive to my queries on the haskelldb-users mailing list. He also has made minor updates to keep it compiling with the latest GHC and Cabal. Hope that helps! Justin From bjorn.buckwalter at gmail.com Wed Jan 2 21:08:31 2008 From: bjorn.buckwalter at gmail.com (Bjorn Buckwalter) Date: Wed Jan 2 21:02:33 2008 Subject: [Haskell-cafe] ANN: Dimensional 0.7.2 Message-ID: <8b2a1a960801021808k4f91b871j1158e49b1c6dae66@mail.gmail.com> Dear all, I've released version 0.7.2 of the Dimensional library. The only change from version 0.7.1 is that the CGS module has been re-enabled. Unless you use the CGS module there is no need to upgrade from 0.7.1. Note that this version is incompatible with GHC 6.8.1 due to bug #1919 (introduced in GHC 6.8.1 and fixed in 6.8.2). For GHC 6.8.1 use version Dimensional 0.7.1 which lacks the CGS module. Thanks, Bjorn Buckwalter http://dimensional.googlecode.com http://hackage.haskell.org/cgi-bin/hackage-scripts/package/dimensional On Nov 23, 2007 8:32 AM, Bjorn Buckwalter wrote: > Dear all, > > The Dimensional library has been ported to GHC 6.8.1 (it remains > backwards-compatible with GHC 6.6.1, and also with Cabal 1.1.6 I > believe). The new version number is 0.7.1. > > Due to a GHC 6.8.1 bug (#1919) the CGS module will not compile and has > been disabled. > > Thanks, > Bjorn Buckwalter > > http://dimensional.googlecode.com > http://hackage.haskell.org/cgi-bin/hackage-scripts/package/dimensional > http://hackage.haskell.org/trac/ghc/ticket/1919 > From dons at galois.com Thu Jan 3 02:38:51 2008 From: dons at galois.com (Don Stewart) Date: Thu Jan 3 02:32:51 2008 Subject: [Haskell-cafe] Re: [16/16] SBM: Discussion and Conclusion In-Reply-To: <477BBA1F.7010606@microsoft.com> References: <20071222091730.D01201604896C@csmtp2.b-one.net> <477BBA1F.7010606@microsoft.com> Message-ID: <20080103073851.GD3148@scytale.galois.com> simonmarhaskell: > Peter Firefly Brodersen Lund wrote: > > >Using top together with huge input files convinced me that -sstderr was > >untrustworthy so I developed the pause-at-end preloading hack. Paranoia > >paid > >off big time there. > > In what way did you find -sstderr untrustworthy? Perhaps it is because the > "memory in use" figure only counts memory that the RTS knows about, and > doesn't include malloc()'d memory. If it's anything else, I need to know > about it. > > > o can the core/stg code be made easier to read? > > By all means - submit tickets with specific suggestions, or better still > send patches. It's also easier to read if you pipe it into hscolour. A little trick I use to get dynamic syntax highlighting of core: ghc A.hs -O2 -ddump-simpl --make | HsColour -tty | less -r will give you coloured, scrollable syntax highlighted core. -- Don From gale at sefer.org Thu Jan 3 03:33:14 2008 From: gale at sefer.org (Yitzchak Gale) Date: Thu Jan 3 03:27:11 2008 Subject: [Haskell-cafe] Basic question concerning the category Hask (was: concerning data constructors) In-Reply-To: <25C23866-F3AB-4510-9DDD-48A50B72835B@fastmail.fm> References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <25C23866-F3AB-4510-9DDD-48A50B72835B@fastmail.fm> Message-ID: <2608b8a80801030033g184cb3e5sb51056b92ae67355@mail.gmail.com> Hi Jonathan, I wrote: >> So in what way are Set morphisms restricted from being >> Hask morphisms? Jonathan Cast wrote: > The normal view taken by Haskellers is that the denotations of > Haskell types are CPPOs. CPPO? > So: > > (1) Must be monotone > (2) Must be continuous Could you please define what you mean by those terms in this context? > (Needn't be strict, even though that messes up the resulting category > substantially). I'm not convinced that the category is all that "messed up". Thanks, Yitz From Nicholls.Mark at mtvne.com Thu Jan 3 04:55:23 2008 From: Nicholls.Mark at mtvne.com (Nicholls, Mark) Date: Thu Jan 3 04:51:21 2008 Subject: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? In-Reply-To: <2f9b2d30801020940g228f5fa3h2a7d6592d5c16acd@mail.gmail.com> References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <2f9b2d30801020940g228f5fa3h2a7d6592d5c16acd@mail.gmail.com> Message-ID: I was thinking more along type classes....and then I was going to throw some spanners in the works.... ________________________________ From: Ryan Ingram [mailto:ryani.spam@gmail.com] Sent: 02 January 2008 17:41 To: Nicholls, Mark Cc: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? Of course it depends what's inside the braces, and what you want to do with it, but I'd be inclined to do something like this: 1) data IX a = IX { constructor :: Int -> a, ... } 2) data IX a b = IX { constructor :: Int -> b, func :: a -> b, ... } 3) data IX a b = IX { iy :: IY a, ... } 4) data IX a b = IX { iz :: IZ b, iy :: IY a, ... } Can you specify more clearly what the goal of the conversion is? If you want "OO" style behavior the thing that is most important is existential quantification. -- ryan On 1/2/08, Nicholls, Mark wrote: I'm trying to translate some standard C# constucts into Haskell... some of this seems easy.... Specifically 1) Interface IX { } 2) Interface IX { } 3) Interface IX Where A : IY { } 4) Interface IX : IZ Where A : IY { } I can take a punt at the first 2....but then it all falls apart _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080103/09a59005/attachment.htm From barsoap at web.de Thu Jan 3 04:59:16 2008 From: barsoap at web.de (Achim Schneider) Date: Thu Jan 3 04:53:21 2008 Subject: [Haskell-cafe] The Worker/Wrapper Transformation Message-ID: <20080103105916.7d562d17@solaris.tower> ...is a paper about automatic specialisation of functions by unboxing arguments, one could say. I'm only on page 6, but already survived the first formalisms, which is bound to mean that the rest of the paper is likewise accessible, as hinted on at ltu. http://www.cs.nott.ac.uk/~gmh/wrapper.pdf The transformation itself is mindbogglingly easy, which makes this a good start: You only have to understand the formalisms, not so much what the formalisms are representing. To quote spj: It usually turns out to be more interesting and challenging than it seemed at first. I'm tempted to write that this is a paper for everyone trying to figure out what the heck Jonathan is talking about. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From Nicholls.Mark at mtvne.com Thu Jan 3 05:06:25 2008 From: Nicholls.Mark at mtvne.com (Nicholls, Mark) Date: Thu Jan 3 05:01:08 2008 Subject: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? In-Reply-To: <004a01c84d7e$556a3160$003e9420$@vers@telenet.be> References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <004a01c84d7e$556a3160$003e9420$@vers@telenet.be> Message-ID: [snip] >-- C#: interface IX1 { String foo1(int); } >class IX1 obj where > foo1 :: Int -> obj -> String Yep...I think that's what I'd do....though I would have done... "foo1 :: obj -> Int -> String" Does that matter? >-- C#: interface IX2 { String foo2(A); } >class IX2 obj a where > foo2 :: a -> obj -> String Ok same here >--C#: interface IX3 where A : IY { String foo3(A); } >class IY a where {- ... -} >class IY a => IX3 obj a where > foo3 :: a -> obj -> String Yep I think again I would have guessed at that >--C#: interface IX4 : IZ where A : IY >class IZ a where {- ... -} >class (IY a, IZ obj) => IX4 obj a where > foo4 :: a -> obj -> String Hmmmm...this would have been one of my guesses....but let me have a go... >This assumes your "objects" are immutable, otherwise you would have to >return (obj,String) instead of just String and then you most likely want to >use the state monad and "do notation" to make functional programming look >more like imperative programming. This is fine....my oop is largely immutable. >You really have to drop the OO way of thinking, >which I find the hardest :) >Haskell's type classes are more powerful in some sense than C# interfaces; >for example, in C# you can't attach an interface to any class (take for >example the Point struct), it has to be your own class, while in Haskell, >you can implement an instance of a type class for any datatype! OK but I was going to go onto Interface IX where A : IX { } And Interface IX where A : B { } Where I cannot see a way to do the above in Haskell at all....as interfaces effectively operator on type classes not types....which seems inherently more powerful But if these could be done in Haskell the see what could be made of stuff like....which is obviously problematic in C# it obviously doesn't work....but potentially does make 'sense'. Interface IX : A { } >Hope this helps a bit. As I'm new myself to Haskell, so take this with a >"grain of salt". It does...I will have a go with your sample answers. >Once you bite the bullet, I found Haskell a lot more fun than C#, although >C# of course comes with a gigantic .NET framework and tools... I'm looking at Haskell because of the formality of it's type system....but I'm actually not convinced it is as powerful as an OO one....i.e. OO ones operatate principally (in Haskell speak) on "type classes" not "types" >Peter -----Original Message----- From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Nicholls, Mark Sent: Wednesday, January 02, 2008 5:41 PM To: haskell-cafe@haskell.org Subject: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? I'm trying to translate some standard C# constucts into Haskell... some of this seems easy.... Specifically 1) Interface IX { } 2) Interface IX { } 3) Interface IX Where A : IY { } 4) Interface IX : IZ Where A : IY { } I can take a punt at the first 2....but then it all falls apart _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe From Nicholls.Mark at mtvne.com Thu Jan 3 05:22:26 2008 From: Nicholls.Mark at mtvne.com (Nicholls, Mark) Date: Thu Jan 3 05:16:40 2008 Subject: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? In-Reply-To: <1965805939.20080102232921@gmail.com> References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <1965805939.20080102232921@gmail.com> Message-ID: Can you give me a summary of why it's meaningless.....both would seem to describe/construct values/objects....they may not be equivalent, but I would expect some considerable overlap. -----Original Message----- From: Bulat Ziganshin [mailto:bulat.ziganshin@gmail.com] Sent: 02 January 2008 20:29 To: Nicholls, Mark Cc: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? Hello Mark, Wednesday, January 2, 2008, 7:40:31 PM, you wrote: > I'm trying to translate some standard C# constucts into Haskell... some it's meaningless. read http://haskell.org/haskellwiki/OOP_vs_type_classes and especially papers mentioned in the References -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bulat.ziganshin at gmail.com Thu Jan 3 05:54:18 2008 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Jan 3 05:53:37 2008 Subject: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? In-Reply-To: References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <1965805939.20080102232921@gmail.com> Message-ID: <915864007.20080103135418@gmail.com> Hello Mark, Thursday, January 3, 2008, 1:22:26 PM, you wrote: because they have different models. i recommend you to start from learning this model, otherwise you will don't understand how Haskell really works and erroneously apply your OOP knowledge to Haskell data structures. shortly said, there are 3 ways to polymorphism: 1) C++ templates - type-specific code generated at compile time 2) OOP classes - every object carries VMT which allows to select type-specific operation 3) type classes - dictionary of type-specific operations is given as additional hidden argument to each function Haskell uses t.c. and its abilities are dictated by this implementation. there is no simple and direct mapping between features provided by OOP and t.c. > Can you give me a summary of why it's meaningless.....both would seem to > describe/construct values/objects....they may not be equivalent, but I > would expect some considerable overlap. > -----Original Message----- > From: Bulat Ziganshin [mailto:bulat.ziganshin@gmail.com] > Sent: 02 January 2008 20:29 > To: Nicholls, Mark > Cc: haskell-cafe@haskell.org > Subject: Re: [Haskell-cafe] Is there anyone out there who can translate > C# generics into Haskell? > Hello Mark, > Wednesday, January 2, 2008, 7:40:31 PM, you wrote: >> I'm trying to translate some standard C# constucts into Haskell... > some > it's meaningless. read > http://haskell.org/haskellwiki/OOP_vs_type_classes > and especially papers mentioned in the References -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From lemming at henning-thielemann.de Thu Jan 3 06:06:11 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Thu Jan 3 06:00:09 2008 Subject: [Haskell-cafe] Re: check if program uses haskell 98 only? In-Reply-To: References: Message-ID: On Thu, 6 Dec 2007, Henning Thielemann wrote: > On Thu, 6 Dec 2007, Thomas Hartman wrote: > > > On a related note... is there some easy way to be sure that a program I am > > compiling uses only haskell 98? (Because any pure haskell 98 should always > > compile on yhc... right?) > > You can for instance use 'haskell98' as dependent package instead of > 'base' in the Cabal description. If you import other modules, I don't know > how to check that these are Haskell 98. I weakly remember corner cases > where GHC accepts more than Haskell 98 in Haskell 98 mode. (At least it > sometimes suggests fixes for errors that are not Haskell 98, e.g. class > constraints in signatures. :-) Now I have an example: GHC-6.4.1 accepts multi parameter type class constraints without '-fglasgow-exts'. > > I compile this with ghc, no options, and iIt doesn't have any {-#-#} > > options, so according to what I understand, it is using pure haskell 98. > > So I might think this was a candidate for using on yhc. > > I could not always pass a GHC-certified module to Hugs or even Haddock. I > remember there is some difference with respect to the trailing 'where' in > the 'instance' head, if the instance declaration is empty. Haddock expect > some spaces in infix operators (I believe ( # ) instead of (#)), which are > not required by Hugs and GHC. From barsoap at web.de Thu Jan 3 06:08:47 2008 From: barsoap at web.de (Achim Schneider) Date: Thu Jan 3 06:02:53 2008 Subject: [Haskell-cafe] Re: The Worker/Wrapper Transformation References: <20080103105916.7d562d17@solaris.tower> Message-ID: <20080103120847.13725ce6@solaris.tower> Achim Schneider wrote: > [...] I'm trying to grok that [] = id ++ = . in the context of Hughes lists. I guess it would stop to slip away if I knew what : corresponds to. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From simonmarhaskell at gmail.com Thu Jan 3 06:11:40 2008 From: simonmarhaskell at gmail.com (Simon Marlow) Date: Thu Jan 3 06:05:40 2008 Subject: [Haskell-cafe] Re: announcing darcs 2.0.0pre2 In-Reply-To: <20071221143254.GO11036@darcs.net> References: <20071216211722.GI11101@darcs.net> <47666BA0.2080408@microsoft.com> <20071221143254.GO11036@darcs.net> Message-ID: <477CC2EC.2030302@microsoft.com> David Roundy wrote: > Anyhow, could you retry this test with the above change in methodology, and > let me know if (a) the pull is still slow the first time and (b) if it's > much faster the second time (after the reverse unpull/pull)? I think I've done it in both directions now, and it got faster, but still much slower than darcs1: $ time darcs2 unpull --from-tag 2007-09-25 -a Finished unpulling. 58.68s real 50.64s user 6.36s system 97% darcs2 unpull --from-tag 2007-09-25 -a $ time darcs2 pull -a ../ghc-darcs2 Pulling from "../ghc-darcs2"... Finished pulling and applying. 53.28s real 44.62s user 7.10s system 97% darcs2 pull -a ../ghc-darcs2 This is still an order of magnitude slower than darcs1 for the same operation. (these times are now on the local filesystem, BTW) Cheers, Simon From Nicholls.Mark at mtvne.com Thu Jan 3 06:13:08 2008 From: Nicholls.Mark at mtvne.com (Nicholls, Mark) Date: Thu Jan 3 06:07:07 2008 Subject: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? In-Reply-To: <915864007.20080103135418@gmail.com> References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <1965805939.20080102232921@gmail.com> <915864007.20080103135418@gmail.com> Message-ID: I loosely do understand....but very loosely....but I'm not, as yet, convinced it is completely relevant. The implementation may differ, but that does not mean that there is no overlap....I am not expecting one model to be a superset of the other, but I am expecting some sort of overlap between 'interface' implementation and type class instance declaration. -----Original Message----- From: Bulat Ziganshin [mailto:bulat.ziganshin@gmail.com] Sent: 03 January 2008 10:54 To: Nicholls, Mark Cc: Bulat Ziganshin; haskell-cafe@haskell.org Subject: Re[2]: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? Hello Mark, Thursday, January 3, 2008, 1:22:26 PM, you wrote: because they have different models. i recommend you to start from learning this model, otherwise you will don't understand how Haskell really works and erroneously apply your OOP knowledge to Haskell data structures. shortly said, there are 3 ways to polymorphism: 1) C++ templates - type-specific code generated at compile time 2) OOP classes - every object carries VMT which allows to select type-specific operation 3) type classes - dictionary of type-specific operations is given as additional hidden argument to each function Haskell uses t.c. and its abilities are dictated by this implementation. there is no simple and direct mapping between features provided by OOP and t.c. > Can you give me a summary of why it's meaningless.....both would seem to > describe/construct values/objects....they may not be equivalent, but I > would expect some considerable overlap. > -----Original Message----- > From: Bulat Ziganshin [mailto:bulat.ziganshin@gmail.com] > Sent: 02 January 2008 20:29 > To: Nicholls, Mark > Cc: haskell-cafe@haskell.org > Subject: Re: [Haskell-cafe] Is there anyone out there who can translate > C# generics into Haskell? > Hello Mark, > Wednesday, January 2, 2008, 7:40:31 PM, you wrote: >> I'm trying to translate some standard C# constucts into Haskell... > some > it's meaningless. read > http://haskell.org/haskellwiki/OOP_vs_type_classes > and especially papers mentioned in the References -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From jens.blanck at gmail.com Thu Jan 3 06:40:01 2008 From: jens.blanck at gmail.com (Jens Blanck) Date: Thu Jan 3 06:33:58 2008 Subject: [Haskell-cafe] Re: Haskell-Cafe Digest, Vol 53, Issue 2 In-Reply-To: <20080103101645.90F9F3242E7@www.haskell.org> References: <20080103101645.90F9F3242E7@www.haskell.org> Message-ID: <7b1ffbe0801030340j2676fe2x272b9a836c59773f@mail.gmail.com> > The normal view taken by Haskellers is that the denotations of > > Haskell types are CPPOs. > > CPPO? > > > So: > > > > (1) Must be monotone > > (2) Must be continuous > > Could you please define what you mean by those terms > in this context? > > > (Needn't be strict, even though that messes up the resulting category > > substantially). > > I'm not convinced that the category is all that "messed up". > > The extra P would stand for "pointed" (has a least element, bottom), this is common in some communities. To me though, a cpo (complete partial order) is closed under directed suprema and the empty set is directed so bottom is already required. The category of cpos in not cartesian closed. For denotational semantics I believe the subcategory of Scott domains are what is usually considered. Continuous functions on cpos are by definition monotone and they respect directed suprema. Jens -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080103/069257f7/attachment.htm From bos at serpentine.com Thu Jan 3 06:43:49 2008 From: bos at serpentine.com (Bryan O'Sullivan) Date: Thu Jan 3 06:37:45 2008 Subject: [Haskell-cafe] ANN / CFP - LLVM bindings for Haskell Message-ID: <477CCA75.4090101@serpentine.com> This is an early release of Haskell bindings for the popular LLVM compiler infrastructure project. If you don't know what LLVM is, it's a wonderful toybox of compiler components, from a complete toolchain supporting multiple architectures through a set of well-defined APIs and IR formats that are designed for building interesting software with. The official LLVM home page is here: http://llvm.org/ The Haskell bindings are based on Gordon Henriksen's C bindings. The C bindings are almost untyped, but the Haskell bindings re-add type safety to prevent runtime crashes and general badness. Currently, the entire code generation system is implemented, with most LLVM data types supported (notably absent are structs). Also plugged in is JIT support, so you can generate code at runtime from Haskell and run it immediately. I've attached an example. Please join in the hacking fun! darcs get http://darcs.serpentine.com/llvm If you want a source tarball, fetch it from here: http://darcs.serpentine.com/llvm/llvm-0.0.2.tar.gz (Hackage can't host code that uses GHC 6.8.2's language extension names yet.) There's very light documentation at present, but it ought to be enough to get you going. :1 [#uses=1] br i1 %1, label %return, label %recurse return: ; preds = %entry ret i32 1 recurse: ; preds = %entry sub i32 %0, 1 ; :2 [#uses=1] call i32 @fib( i32 %2 ) ; :3 [#uses=1] sub i32 %0, 2 ; :4 [#uses=1] call i32 @fib( i32 %4 ) ; :5 [#uses=1] add i32 %3, %5 ; :6 [#uses=1] ret i32 %6 } fib 10 = 55 From byorgey at gmail.com Thu Jan 3 06:54:04 2008 From: byorgey at gmail.com (Brent Yorgey) Date: Thu Jan 3 06:48:00 2008 Subject: [Haskell-cafe] Re: The Worker/Wrapper Transformation In-Reply-To: <20080103120847.13725ce6@solaris.tower> References: <20080103105916.7d562d17@solaris.tower> <20080103120847.13725ce6@solaris.tower> Message-ID: <22fcbd520801030354x5e0211f6m45eb6220785acaab@mail.gmail.com> On Jan 3, 2008 6:08 AM, Achim Schneider wrote: > Achim Schneider wrote: > > > [...] > > I'm trying to grok that > > [] = id > ++ = . > > in the context of Hughes lists. > > I guess it would stop to slip away if I knew what : corresponds to. > Well, (:) has type a -> [a] -> [a], so a function corresponding to (:) for Hughes lists should have type foo :: a -> H a -> H a that is, foo :: a -> ([a] -> [a]) -> [a] -> [a] so it can be written foo x h = (x:) . h which lambdabot informs me can also be written as (.) . (:). But in the end I'm not sure how helpful that is for understanding Hughes lists! I think the key sentence from the paper is this: "by representing a list xs as the function (xs ++) that appends this list to another list that has still to be supplied." If you understand that sentence, then you can understand why [] is id and (++) is (.). -Brent -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080103/b48a6e3f/attachment.htm From bf3 at telenet.be Thu Jan 3 07:02:07 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Thu Jan 3 06:56:02 2008 Subject: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? In-Reply-To: References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <004a01c84d7e$556a3160$003e9420$@vers@telenet.be> Message-ID: <002c01c84e00$76b74d30$6425e790$@be> Hi Mark, >> "foo1 :: Int -> obj -> String" > Yep...I think that's what I'd do....though I would have done... > "foo1 :: obj -> Int -> String" > Does that matter? Well, it's a good habit in Haskell to move the "most important" parameter to the end of the argument list. See e.g. http://www.haskell.org/haskellwiki/Parameter_order. > OK but I was going to go onto > Interface IX where A : IX {} > and > Interface IX where A : B {} No, I would not know how to that in Haskell using type classes. It seems Haskell does not allow cycles in type class definitions. But as I'm new, this does not mean it's not possible. It's more important to know *what* you are trying to do, than to give a solution in a different language, since OO and FP are kind of orthogonal languages. > Where I cannot see a way to do the above in Haskell at all....as > interfaces effectively operator on type classes not types....which seems > inherently more powerful Yeah, kind of makes sense. I liked interfaces in C# a lot, but when I started doing everything with interfaces, I found the lack of support for "mixins" or "default implementations" problematic. This ended up in a lot of copy/paste or encapsulating the implementations into a static class with plain functions, a mess. > But if these could be done in Haskell the see what could be made of > stuff like....which is obviously problematic in C# it obviously doesn't > work....but potentially does make 'sense'. > Interface IX : A {} Ah! That's one of the bigger restrictions in C# yes! C++ can do that; ATL uses it a lot, and I also like that approach. You can emulate "mixins" with that, and still stay in the single inheritance paradigm. In Haskell you don't do that at all of course, since you avoid thinking about "objects and inheritance" in the first place. OO is strange. They offer you the nice concept of inheritance, and then the guidelines tell you: "don't use too many levels of inheritance"... Although I've build huge projects using OO, it always felt a bit like unsafe hacking. I don't really have that feeling with Haskell, but that could also be because I'm too new to the language ;-) > I'm looking at Haskell because of the formality of it's type > system....but I'm actually not convinced it is as powerful as an OO > one....i.e. OO ones operatate principally (in Haskell speak) on "type > classes" not "types" Maybe you are right, I don't know, my theoritical skills are not high enough to answer that. Haskell just "feels" better to me, although the lack of a friendly productive IDE and large standard framework remains a bit of a burden. Good luck, Peter -----Original Message----- From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Nicholls, Mark Sent: Wednesday, January 02, 2008 5:41 PM To: haskell-cafe@haskell.org Subject: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? I'm trying to translate some standard C# constucts into Haskell... some of this seems easy.... Specifically 1) Interface IX { } 2) Interface IX { } 3) Interface IX Where A : IY { } 4) Interface IX : IZ Where A : IY { } I can take a punt at the first 2....but then it all falls apart _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe From barsoap at web.de Thu Jan 3 07:15:15 2008 From: barsoap at web.de (Achim Schneider) Date: Thu Jan 3 07:09:27 2008 Subject: [Haskell-cafe] Re: The Worker/Wrapper Transformation References: <20080103105916.7d562d17@solaris.tower> <20080103120847.13725ce6@solaris.tower> <22fcbd520801030354x5e0211f6m45eb6220785acaab@mail.gmail.com> Message-ID: <20080103131515.17058b6a@solaris.tower> "Brent Yorgey" wrote: > > Well, (:) has type a -> [a] -> [a], so a function corresponding to > (:) for Hughes lists should have type > > foo :: a -> H a -> H a > > [...] > I think the key sentence from the paper is this: "by > representing a list xs as the function (xs ++) that appends this list > to another list that has still to be supplied." If you understand > that sentence, then you can understand why [] is id and (++) is (.). > Yes, I did. They key was not thinking that : has type (:) :: a -> a -> [a] , or, put differently, beat the lisp out of me, thanks. The problem is merely that Haskell and lisp are too similar in a much too different way. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From barsoap at web.de Thu Jan 3 07:34:26 2008 From: barsoap at web.de (Achim Schneider) Date: Thu Jan 3 07:28:35 2008 Subject: [Haskell-cafe] Re: The Worker/Wrapper Transformation References: <20080103105916.7d562d17@solaris.tower> <20080103120847.13725ce6@solaris.tower> <22fcbd520801030354x5e0211f6m45eb6220785acaab@mail.gmail.com> <20080103131515.17058b6a@solaris.tower> Message-ID: <20080103133426.4d9bc0b9@solaris.tower> Achim Schneider wrote: > "Brent Yorgey" wrote: > > > > > Well, (:) has type a -> [a] -> [a], so a function corresponding to > > (:) for Hughes lists should have type > > > > foo :: a -> H a -> H a > > > > [...] > > I think the key sentence from the paper is this: "by > > representing a list xs as the function (xs ++) that appends this > > list to another list that has still to be supplied." If you > > understand that sentence, then you can understand why [] is id and > > (++) is (.). > > > Yes, I did. > > They key was not thinking that : has type > > (:) :: a -> a -> [a] > > , or, put differently, beat the lisp out of me, thanks. > What the hell am I talking about? (define (cons x y) (lambda (m) (m x y))) (define (car z) (z (lambda (p q) p))) (define (cdr z) (z (lambda (p q) q))) : is, in a sense, \. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From isaacdupree at charter.net Thu Jan 3 07:46:32 2008 From: isaacdupree at charter.net (Isaac Dupree) Date: Thu Jan 3 07:40:28 2008 Subject: [Haskell-cafe] The Worker/Wrapper Transformation In-Reply-To: <20080103105916.7d562d17@solaris.tower> References: <20080103105916.7d562d17@solaris.tower> Message-ID: <477CD928.20706@charter.net> Achim Schneider wrote: > ...is a paper about automatic specialisation of functions by unboxing > arguments, one could say. I'm only on page 6, but already survived the > first formalisms, which is bound to mean that the rest of the paper is > likewise accessible, as hinted on at ltu. > > http://www.cs.nott.ac.uk/~gmh/wrapper.pdf > > The transformation itself is mindbogglingly easy, which makes this a > good start: You only have to understand the formalisms, not so much what > the formalisms are representing. To quote spj: It usually turns out to > be more interesting and challenging than it seemed at first. > > I'm tempted to write that this is a paper for everyone trying to figure > out what the heck Jonathan is talking about. > I like it! Of course the technique itself doesn't provide guidance on what type you want to transform a function to. on page 6, stronger vs weaker seemed backwards to me... isn't (wrap ? unwrap = idA) a stronger condition than (wrap ? unwrap ? body = body), because it tells you more, and is true in fewer cases? (which is also why you want to assume (wrap ? unwrap = idA) when you can, because it's the most useful one for subsequent program transformation) and then the inevitable minor copy-editing :-) p. 22. intentional properties --> intensional (right?) p. 27. typo 'unwarp' for 'unwrap' BTW. GHC currently does allow e.g. (I# (1# +# 2#)), not just (case (1# +# 2#) of n# -> I# n#) -- the strictness implications seem pretty straightforwards (it's trivial to transform away). p. 29. "in both these system" -> systems ~Isaac From Nicholls.Mark at mtvne.com Thu Jan 3 07:48:17 2008 From: Nicholls.Mark at mtvne.com (Nicholls, Mark) Date: Thu Jan 3 07:42:25 2008 Subject: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? In-Reply-To: <002c01c84e00$76b74d30$6425e790$@be> References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <004a01c84d7e$556a3160$003e9420$@vers@telenet.be> <002c01c84e00$76b74d30$6425e790$@be> Message-ID: Ahh ok I see what is meant by the parameter order.... -----Original Message----- From: Peter Verswyvelen [mailto:peter.vers@telenet.be] On Behalf Of Peter Verswyvelen Sent: 03 January 2008 12:02 To: Nicholls, Mark Cc: haskell-cafe@haskell.org Subject: RE: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? Hi Mark, >> "foo1 :: Int -> obj -> String" > Yep...I think that's what I'd do....though I would have done... > "foo1 :: obj -> Int -> String" > Does that matter? Well, it's a good habit in Haskell to move the "most important" parameter to the end of the argument list. See e.g. http://www.haskell.org/haskellwiki/Parameter_order. > OK but I was going to go onto > Interface IX where A : IX {} > and > Interface IX where A : B {} No, I would not know how to that in Haskell using type classes. It seems Haskell does not allow cycles in type class definitions. But as I'm new, this does not mean it's not possible. It's more important to know *what* you are trying to do, than to give a solution in a different language, since OO and FP are kind of orthogonal languages. > Where I cannot see a way to do the above in Haskell at all....as > interfaces effectively operator on type classes not types....which seems > inherently more powerful Yeah, kind of makes sense. I liked interfaces in C# a lot, but when I started doing everything with interfaces, I found the lack of support for "mixins" or "default implementations" problematic. This ended up in a lot of copy/paste or encapsulating the implementations into a static class with plain functions, a mess. > But if these could be done in Haskell the see what could be made of > stuff like....which is obviously problematic in C# it obviously doesn't > work....but potentially does make 'sense'. > Interface IX : A {} Ah! That's one of the bigger restrictions in C# yes! C++ can do that; ATL uses it a lot, and I also like that approach. You can emulate "mixins" with that, and still stay in the single inheritance paradigm. In Haskell you don't do that at all of course, since you avoid thinking about "objects and inheritance" in the first place. OO is strange. They offer you the nice concept of inheritance, and then the guidelines tell you: "don't use too many levels of inheritance"... Although I've build huge projects using OO, it always felt a bit like unsafe hacking. I don't really have that feeling with Haskell, but that could also be because I'm too new to the language ;-) > I'm looking at Haskell because of the formality of it's type > system....but I'm actually not convinced it is as powerful as an OO > one....i.e. OO ones operatate principally (in Haskell speak) on "type > classes" not "types" Maybe you are right, I don't know, my theoritical skills are not high enough to answer that. Haskell just "feels" better to me, although the lack of a friendly productive IDE and large standard framework remains a bit of a burden. Good luck, Peter -----Original Message----- From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Nicholls, Mark Sent: Wednesday, January 02, 2008 5:41 PM To: haskell-cafe@haskell.org Subject: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? I'm trying to translate some standard C# constucts into Haskell... some of this seems easy.... Specifically 1) Interface IX { } 2) Interface IX { } 3) Interface IX Where A : IY { } 4) Interface IX : IZ Where A : IY { } I can take a punt at the first 2....but then it all falls apart _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe From isaacdupree at charter.net Thu Jan 3 07:49:36 2008 From: isaacdupree at charter.net (Isaac Dupree) Date: Thu Jan 3 07:43:31 2008 Subject: [Haskell-cafe] Re: The Worker/Wrapper Transformation In-Reply-To: <20080103120847.13725ce6@solaris.tower> References: <20080103105916.7d562d17@solaris.tower> <20080103120847.13725ce6@solaris.tower> Message-ID: <477CD9E0.6060604@charter.net> Achim Schneider wrote: > Achim Schneider wrote: > >> [...] > > I'm trying to grok that > > [] = id > ++ = . > > in the context of Hughes lists. they are also known as "difference lists", and also used at type String in the Prelude as "ShowS", to help avoid quadratic behavior when making complicated Strings. the [a]->[a] is not an ordinary function -- it's expected not to examine its argument, just to use it exactly once (is there a formal way to say that?) ~Isaac From barsoap at web.de Thu Jan 3 08:21:09 2008 From: barsoap at web.de (Achim Schneider) Date: Thu Jan 3 08:15:12 2008 Subject: [Haskell-cafe] Re: The Worker/Wrapper Transformation References: <20080103105916.7d562d17@solaris.tower> <20080103120847.13725ce6@solaris.tower> <22fcbd520801030354x5e0211f6m45eb6220785acaab@mail.gmail.com> <20080103131515.17058b6a@solaris.tower> <20080103133426.4d9bc0b9@solaris.tower> Message-ID: <20080103142109.6d3de8ee@solaris.tower> Achim Schneider wrote: > (define (cons x y) > (lambda (m) (m x y))) > > (define (car z) > (z (lambda (p q) p))) > > (define (cdr z) > (z (lambda (p q) q))) > , which, just for completeness, can be of course also be done in Haskell: cons :: a -> b -> (a -> b -> c) -> c cons x y m = m x y car :: ((a -> b -> a) -> c) -> c car z = z $ \p q -> p cdr :: ((a -> b -> b) -> c) -> c cdr z = z $ \p q -> q Prelude> car $ cdr $ cdr $ cons 1 $ cons 2 $ cons 3 () 3 -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From lemming at henning-thielemann.de Thu Jan 3 08:48:58 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Thu Jan 3 08:42:54 2008 Subject: [Haskell-cafe] Difference lists and ShowS (Was: The Worker/Wrapper Transformation) In-Reply-To: <477CD9E0.6060604@charter.net> References: <20080103105916.7d562d17@solaris.tower> <20080103120847.13725ce6@solaris.tower> <477CD9E0.6060604@charter.net> Message-ID: On Thu, 3 Jan 2008, Isaac Dupree wrote: > Achim Schneider wrote: > > Achim Schneider wrote: > > > >> [...] > > > > I'm trying to grok that > > > > [] = id > > ++ = . > > > > in the context of Hughes lists. > > they are also known as "difference lists", and also used at type String > in the Prelude as "ShowS", to help avoid quadratic behavior when making > complicated Strings. Sometimes I believed that I understand this reason, but then again I do not understand. I see that left-associative (++) like in ((a0 ++ a1) ++ a2) ++ a3 would cause quadratic time. But (++) is right-associative and 'concat' is 'foldr'. They should not scan the leading lists more than once. Also http://en.wikipedia.org/wiki/Difference_list doesn't answer this question. Where exactly is the problem? From bf3 at telenet.be Thu Jan 3 08:58:47 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Thu Jan 3 08:52:57 2008 Subject: [Haskell-cafe] Consensus about databases / serialization In-Reply-To: References: <000a01c84d35$b64d3de0$22e7b9a0$@be> Message-ID: <477CEA17.2090306@telenet.be> Looks good! I liked relational algebra much much more than SQL, so I'll certainly have to look into that. Thanks, Peter Justin Bailey wrote: > I can speak to haskelldb a little, see below: > > On Jan 2, 2008 3:50 AM, Peter Verswyvelen wrote: > >> ? regarding Haskell and databases, the page >> http://haskell.org/haskellwiki/Libraries_and_tools/Database_interfaces >> describes a few, but which are the ones that are stable and practical? Any >> user experiences? >> > > I started looking at haskell database libraries to generate SQL for > me. Haskelldb does this well - it uses a higher-level representation > of queries based on "relational algebra" (also the basis of SQL) which > is pretty easy to understand if you know SQL. It takes care of a lof > the details of generating SQL strings, and does it in a mostly > type-safe way. > > It is a bit complicated to install the library and all its > dependencies, because it can work with 3+ (mysql, postgres, odbc) > databases using two different backends (hdbc and hsql). I chose to go > with HDBC because it compiled on Windows and postgres because thats > what we have at my workplace. Once I got it built and installed its > worked well for me. > > Until the most recent versions though, it added a "distinct" operator > to all select statements. I submitted a patch which was accepted and > now that behavior is no longer the default. It is semi-actively > maintained by the original authors and Bjorn, at least, has been very > responsive to my queries on the haskelldb-users mailing list. He also > has made minor updates to keep it compiling with the latest GHC and > Cabal. > > Hope that helps! > > Justin > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080103/c544602a/attachment.htm From gale at sefer.org Thu Jan 3 09:25:08 2008 From: gale at sefer.org (Yitzchak Gale) Date: Thu Jan 3 09:19:04 2008 Subject: [Haskell-cafe] Basic question concerning data constructors In-Reply-To: References: <49a77b7a0712301219y6959db9y967a9cb75427443d@mail.gmail.com> <20071231011748.sq6ryegp6o8cg4c0@webmail.spamcop.net> <2608b8a80801010733q3f5f4a6ewfba794151757578a@mail.gmail.com> <2608b8a80801010743m33409e52w97ba1ad8da9518d9@mail.gmail.com> <7ca3f0160801011557x8fc901bv795da1d81662dacb@mail.gmail.com> <2608b8a80801020134y584f52f2t612554f44364365a@mail.gmail.com> Message-ID: <2608b8a80801030625s2a8b3eebh69db2efbc26600e9@mail.gmail.com> Hi Benja, I wrote: >> By the type expression Integer -> Integer >> we mean all Haskell functions mapping Integers to Integers. >> There are only countably many of those. > ... >> But that was not the context in this thread. The category >> Hask that we often mention in discussions about Haskell >> the programming language is most certainly a small category. Benja Fallenstein wrote: > I don't know. My understanding has been that at least part of the > benefit of denotational semantics is that you can define what an > expression means without referring back to the syntactic construction > or the operational semantics of that expression -- and thus use the > denotational semantics to check whether the operational semantics are > "right." But if you start with "all Haskell functions," you already > have to know what a Haskell function *is*. Denotational semantics maps expressions in a language - hence, syntax - into something that represents their semantics. You can choose different such mappings to represent different semantics of the same expressions. The Haskell Report clearly defines what a Haskell function is in terms of syntax. So my semantics are well-defined, and they represent what I understand when I read a Haskell program. In fact, these semantics do not really depend on all aspects of the syntax - only the existence of certain primitive functions, and certain constructions such as function definition, pattern matching, ADTs, etc. The same assumptions are made for any semantics of Haskell. Benja Fallenstein wrote: > I think it should be "allowed" to think of the semantics of Haskell as > being defined independently of the (relatively operational) notion of > "computable function," and then define "computable function" to be > that subset of the functions in the model that you can actually write > in Haskell. "Computable function" is not operational - it just means functions that are lambdas, if you'd like. It just so happens that, so far, those are the only functions we know how to compute operationally. Maybe that quantum stuff... But yes, sure you can do that. That seems to be the approach in some papers. In particular, the one by Reynolds in which he proves that Haskell types cannot be represented by sets. Sounds like strong evidence that those are the wrong semantics to choose when studying Haskell as a programming language. Though it is certainly interesting to do so in a theoretical setting. > And the only explicit non-syntactic constructions of > models for Haskell-like languages that I'm familiar with aren't > countable (they contain all continuous functions, which in the case of > (Integer -> Integer) comes out to all monotonous functions). It is not any less syntactic than mine. It only differs in the semantics assigned to the symbol Integer -> Integer. > So I disagree that the function types of Hask should automatically be > taken to be countable. No, I agree with you. It's not automatic. It depends on your choice of semantics. > If you want to assume it for some given > purpose, sure, fine, but IMO that's an additional assumption, not > something inherent in the Haskell language. Agreed. Thanks, Yitz From h._h._h._ at hotmail.com Thu Jan 3 09:29:30 2008 From: h._h._h._ at hotmail.com (H.) Date: Thu Jan 3 09:23:34 2008 Subject: [Haskell-cafe] Re: Escape Codes References: <404396ef0801020821j185f4b6eoe2f14462eb154b62@mail.gmail.com> Message-ID: Hi, > It would be nice if you could package this and release it on hackage. > http://hackage.haskell.org/packages/hackage.html I packaged it, perhaps you can have a look at it, if it is, what you thought... When I get a username, I'll put it on hackage :) -- H. From gale at sefer.org Thu Jan 3 09:32:44 2008 From: gale at sefer.org (Yitzchak Gale) Date: Thu Jan 3 09:26:39 2008 Subject: [Haskell-cafe] Basic question concerning the category Hask (was: concerning data constructors) In-Reply-To: <2608b8a80801030033g184cb3e5sb51056b92ae67355@mail.gmail.com> References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <25C23866-F3AB-4510-9DDD-48A50B72835B@fastmail.fm> <2608b8a80801030033g184cb3e5sb51056b92ae67355@mail.gmail.com> Message-ID: <2608b8a80801030632v1c731c06x8b4327a4dbec12e6@mail.gmail.com> Jonathan Cast wrote: >>> The normal view taken by Haskellers is that the denotations of >>> Haskell types are CPPOs. I wrote: >> CPPO? >>> (1) Must be monotone >>> (2) Must be continuous >> Could you please define what you mean by those terms >> in this context? Jens Blanck wrote: > The extra P would stand for "pointed" (has a least element, bottom), this is > common in some communities. To me though, a cpo (complete partial order) is > closed under directed suprema and the empty set is directed so bottom is > already required. The category of cpos in not cartesian closed. For > denotational semantics I believe the subcategory of Scott domains are what > is usually considered. > > Continuous functions on cpos are by definition monotone and they respect > directed suprema. Thanks! Yitz From bulat.ziganshin at gmail.com Thu Jan 3 09:38:43 2008 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Jan 3 09:35:02 2008 Subject: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? In-Reply-To: References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <1965805939.20080102232921@gmail.com> <915864007.20080103135418@gmail.com> Message-ID: <8627368.20080103173843@gmail.com> Hello Mark, Thursday, January 3, 2008, 2:13:08 PM, you wrote: of course *some* overlap exists but in order to understand it you should know exact shape of both methods when i tried to develop complex library without understanding t.c. implementation, i constantly goes into the troubles - things that i (using my OOP experience) considered as possible, was really impossible in Haskell so i'm really wonder why you don't want to learn the topic thoroughly > I loosely do understand....but very loosely....but I'm not, as yet, > convinced it is completely relevant. > The implementation may differ, but that does not mean that there is no > overlap....I am not expecting one model to be a superset of the other, > but I am expecting some sort of overlap between 'interface' > implementation and type class instance declaration. > -----Original Message----- > From: Bulat Ziganshin [mailto:bulat.ziganshin@gmail.com] > Sent: 03 January 2008 10:54 > To: Nicholls, Mark > Cc: Bulat Ziganshin; haskell-cafe@haskell.org > Subject: Re[2]: [Haskell-cafe] Is there anyone out there who can > translate C# generics into Haskell? > Hello Mark, > Thursday, January 3, 2008, 1:22:26 PM, you wrote: > because they have different models. i recommend you to start from > learning this model, otherwise you will don't understand how Haskell > really works and erroneously apply your OOP knowledge to Haskell data > structures. > shortly said, there are 3 ways to polymorphism: > 1) C++ templates - type-specific code generated at compile time > 2) OOP classes - every object carries VMT which allows to select > type-specific operation > 3) type classes - dictionary of type-specific operations is given as > additional hidden argument to each function > Haskell uses t.c. and its abilities are dictated by this > implementation. there is no simple and direct mapping between > features provided by OOP and t.c. >> Can you give me a summary of why it's meaningless.....both would seem > to >> describe/construct values/objects....they may not be equivalent, but I >> would expect some considerable overlap. >> -----Original Message----- >> From: Bulat Ziganshin [mailto:bulat.ziganshin@gmail.com] >> Sent: 02 January 2008 20:29 >> To: Nicholls, Mark >> Cc: haskell-cafe@haskell.org >> Subject: Re: [Haskell-cafe] Is there anyone out there who can > translate >> C# generics into Haskell? >> Hello Mark, >> Wednesday, January 2, 2008, 7:40:31 PM, you wrote: >>> I'm trying to translate some standard C# constucts into Haskell... >> some >> it's meaningless. read >> http://haskell.org/haskellwiki/OOP_vs_type_classes >> and especially papers mentioned in the References -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From barsoap at web.de Thu Jan 3 09:41:15 2008 From: barsoap at web.de (Achim Schneider) Date: Thu Jan 3 09:35:20 2008 Subject: [Haskell-cafe] Re: Difference lists and ShowS (Was: The Worker/Wrapper Transformation) References: <20080103105916.7d562d17@solaris.tower> <20080103120847.13725ce6@solaris.tower> <477CD9E0.6060604@charter.net> Message-ID: <20080103154115.28a84ce3@solaris.tower> Henning Thielemann wrote: > Sometimes I believed that I understand this reason, but then again I > do not understand. I see that left-associative (++) like in > ((a0 ++ a1) ++ a2) ++ a3 > would cause quadratic time. But (++) is right-associative and > 'concat' is 'foldr'. They should not scan the leading lists more than > once. Also > http://en.wikipedia.org/wiki/Difference_list > doesn't answer this question. Where exactly is the problem? > | The shows functions return a function that prepends the output String | to an existing String. This allows constant-time concatenation of | results using function composition. I figure it's (constant vs. linear) vs. (linear vs. quadratic), for more involved examples. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From gale at sefer.org Thu Jan 3 09:45:42 2008 From: gale at sefer.org (Yitzchak Gale) Date: Thu Jan 3 09:39:39 2008 Subject: [Haskell-cafe] Consensus about databases / serialization In-Reply-To: <477CEA17.2090306@telenet.be> References: <000a01c84d35$b64d3de0$22e7b9a0$@be> <477CEA17.2090306@telenet.be> Message-ID: <2608b8a80801030645w1581fde6pe87b72497555b396@mail.gmail.com> Peter Verswyvelen wrote: > Looks good! I liked relational algebra much much more than SQL, so I'll > certainly have to look into that. I agree. I have not tried haskelldb yet, but I would like to. My impression from some previous posts is that because of the high-level approach, it is difficult to control the precise SQL that is generated. In practice, you almost always have to do some tweaking that is at least DB-dependent, and often application dependent. Is there any way to do that in haskelldb? If not, is there an obvious way to add it? Thanks, Yitz From lemming at henning-thielemann.de Thu Jan 3 09:55:40 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Thu Jan 3 09:52:17 2008 Subject: [Haskell-cafe] Re: Difference lists and ShowS In-Reply-To: <20080103154115.28a84ce3@solaris.tower> References: <20080103105916.7d562d17@solaris.tower> <20080103120847.13725ce6@solaris.tower> <477CD9E0.6060604@charter.net> <20080103154115.28a84ce3@solaris.tower> Message-ID: On Thu, 3 Jan 2008, Achim Schneider wrote: > Henning Thielemann wrote: > > > Sometimes I believed that I understand this reason, but then again I > > do not understand. I see that left-associative (++) like in > > ((a0 ++ a1) ++ a2) ++ a3 > > would cause quadratic time. But (++) is right-associative and > > 'concat' is 'foldr'. They should not scan the leading lists more than > > once. Also > > http://en.wikipedia.org/wiki/Difference_list > > doesn't answer this question. Where exactly is the problem? > > > > | The shows functions return a function that prepends the output String > | to an existing String. This allows constant-time concatenation of > | results using function composition. How is "constant-time concatenation" meant? If I process all list elements, it will need linear time. If I do not touch any element, I will need no time due to lazy evaluation. As far as I know, lazy evaluation is implemented by returning a union of a routine generating the actual value and the value, if it was already computed. Thus, calling (++) returns a function internally. > I figure it's (constant vs. linear) vs. (linear vs. quadratic), for > more involved examples. I can't see it. If I consider (x++y) but I do not evaluate any element of (x++y) or only the first element, then this will need constant time. If I evaluate the first n elements I need n computation time units. How is (.) on difference lists faster than (++) here? From rendel at rbg.informatik.tu-darmstadt.de Thu Jan 3 09:58:56 2008 From: rendel at rbg.informatik.tu-darmstadt.de (Tillmann Rendel) Date: Thu Jan 3 09:52:59 2008 Subject: [Haskell-cafe] Difference lists and ShowS (Was: The Worker/Wrapper Transformation) In-Reply-To: References: <20080103105916.7d562d17@solaris.tower> <20080103120847.13725ce6@solaris.tower> <477CD9E0.6060604@charter.net> Message-ID: <477CF830.6040906@rbg.informatik.tu-darmstadt.de> Henning Thielemann wrote: > Sometimes I believed that I understand this reason, but then again I do > not understand. I see that left-associative (++) like in > ((a0 ++ a1) ++ a2) ++ a3 > would cause quadratic time. But (++) is right-associative and 'concat' is > 'foldr'. They should not scan the leading lists more than once the point is that the the right-associativity of (++) doesn't prevent terms of the form ((a0 ++ a1) ++ a2) ++ a3 to arise due to explicit parentheses or (more important) recursive processing of data structures. consider showing a tree-like structure of the form ((a0 `Cons` a1) `Cons` a2) `Cons` a3 A naive Show instance will basically replace every Cons by (++) and produce a string concatenation of the offending left-associative form: ((show a0 ++ show a1) ++ show a2) ++ show a3 Tillmann From daniel.is.fischer at web.de Thu Jan 3 10:04:14 2008 From: daniel.is.fischer at web.de (Daniel Fischer) Date: Thu Jan 3 09:56:48 2008 Subject: [Haskell-cafe] Difference lists and ShowS (Was: The Worker/Wrapper Transformation) In-Reply-To: References: <20080103105916.7d562d17@solaris.tower> <477CD9E0.6060604@charter.net> Message-ID: <200801031604.14557.daniel.is.fischer@web.de> Am Donnerstag, 3. Januar 2008 14:48 schrieb Henning Thielemann: > On Thu, 3 Jan 2008, Isaac Dupree wrote: > > Achim Schneider wrote: > > > Achim Schneider wrote: > > >> [...] > > > > > > I'm trying to grok that > > > > > > [] = id > > > ++ = . > > > > > > in the context of Hughes lists. > > > > they are also known as "difference lists", and also used at type String > > in the Prelude as "ShowS", to help avoid quadratic behavior when making > > complicated Strings. > > Sometimes I believed that I understand this reason, but then again I do > not understand. I see that left-associative (++) like in > ((a0 ++ a1) ++ a2) ++ a3 > would cause quadratic time. But (++) is right-associative and 'concat' is > 'foldr'. They should not scan the leading lists more than once. > Also > http://en.wikipedia.org/wiki/Difference_list > doesn't answer this question. Where exactly is the problem? Show a binary tree inorder? L-T-R gives (show L) ++ (show T ++ (show R)) gives ((show LL) ++ (showLT ++ (show LR))) ++ (show T ++ (show R)) gives (((show LLL) ++ (show LLT ++ (show LLR))) ++ (show LT ++ (show LR))) ++ (show T ++ (show R)) etc. If the tree is large, you end up with a pretty large left association for the left subtree. True, there's lot of right association, too, but bad enough, I think. Cheers, Daniel From barsoap at web.de Thu Jan 3 10:13:17 2008 From: barsoap at web.de (Achim Schneider) Date: Thu Jan 3 10:07:20 2008 Subject: [Haskell-cafe] Re: Difference lists and ShowS References: <20080103105916.7d562d17@solaris.tower> <20080103120847.13725ce6@solaris.tower> <477CD9E0.6060604@charter.net> <20080103154115.28a84ce3@solaris.tower> Message-ID: <20080103161317.3b8b3159@solaris.tower> Henning Thielemann wrote: > > I figure it's (constant vs. linear) vs. (linear vs. quadratic), for > > more involved examples. > > I can't see it. If I consider (x++y) but I do not evaluate any > element of (x++y) or only the first element, then this will need > constant time. If I evaluate the first n elements I need n > computation time units. How is (.) on difference lists faster than > (++) here? > It's in multiple calls to length if you do ((x++y)++z), the first run over x can be avoided. It basically gets rewritten to (x++y++z) by another level of abstraction. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From lemming at henning-thielemann.de Thu Jan 3 10:27:43 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Thu Jan 3 10:21:38 2008 Subject: [Haskell-cafe] Difference lists and ShowS (Was: The Worker/Wrapper Transformation) In-Reply-To: <200801031604.14557.daniel.is.fischer@web.de> References: <20080103105916.7d562d17@solaris.tower> <477CD9E0.6060604@charter.net> <200801031604.14557.daniel.is.fischer@web.de> Message-ID: On Thu, 3 Jan 2008, Daniel Fischer wrote: > Am Donnerstag, 3. Januar 2008 14:48 schrieb Henning Thielemann: > > > Sometimes I believed that I understand this reason, but then again I do > > not understand. I see that left-associative (++) like in > > ((a0 ++ a1) ++ a2) ++ a3 > > would cause quadratic time. But (++) is right-associative and 'concat' is > > 'foldr'. They should not scan the leading lists more than once. > > Also > > http://en.wikipedia.org/wiki/Difference_list > > doesn't answer this question. Where exactly is the problem? > > Show a binary tree inorder? > L-T-R gives (show L) ++ (show T ++ (show R)) > gives ((show LL) ++ (showLT ++ (show LR))) ++ (show T ++ (show R)) > gives (((show LLL) ++ (show LLT ++ (show LLR))) ++ (show LT ++ (show LR))) ++ > (show T ++ (show R)) > > etc. > If the tree is large, you end up with a pretty large left association for the > left subtree. True, there's lot of right association, too, but bad enough, I > think. With difference lists I write shows L . (shows T . shows R) (shows LL . (showsLT . shows LR)) . (shows T . shows R) ((shows LLL . (shows LLT . shows LLR)) . (showsLT . shows LR)) . (shows T . shows R) I still need to resolve three (.) until I get to the first character of the result string, but for the subsequent characters I do not need to resolve those dots. In the end, resolution of all (.) may need some time but then concatenation is performed entirely right-associative. Seems to be that this is the trick ... From Nicholls.Mark at mtvne.com Thu Jan 3 10:40:13 2008 From: Nicholls.Mark at mtvne.com (Nicholls, Mark) Date: Thu Jan 3 10:36:10 2008 Subject: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? In-Reply-To: <8627368.20080103173843@gmail.com> References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <1965805939.20080102232921@gmail.com> <915864007.20080103135418@gmail.com> <8627368.20080103173843@gmail.com> Message-ID: I do not necessarily disagree.... But if I can identify the overlap....then I have leant the overlap...on the cheap. -----Original Message----- From: Bulat Ziganshin [mailto:bulat.ziganshin@gmail.com] Sent: 03 January 2008 14:39 To: Nicholls, Mark Cc: Bulat Ziganshin; haskell-cafe@haskell.org Subject: Re[4]: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? Hello Mark, Thursday, January 3, 2008, 2:13:08 PM, you wrote: of course *some* overlap exists but in order to understand it you should know exact shape of both methods when i tried to develop complex library without understanding t.c. implementation, i constantly goes into the troubles - things that i (using my OOP experience) considered as possible, was really impossible in Haskell so i'm really wonder why you don't want to learn the topic thoroughly > I loosely do understand....but very loosely....but I'm not, as yet, > convinced it is completely relevant. > The implementation may differ, but that does not mean that there is no > overlap....I am not expecting one model to be a superset of the other, > but I am expecting some sort of overlap between 'interface' > implementation and type class instance declaration. > -----Original Message----- > From: Bulat Ziganshin [mailto:bulat.ziganshin@gmail.com] > Sent: 03 January 2008 10:54 > To: Nicholls, Mark > Cc: Bulat Ziganshin; haskell-cafe@haskell.org > Subject: Re[2]: [Haskell-cafe] Is there anyone out there who can > translate C# generics into Haskell? > Hello Mark, > Thursday, January 3, 2008, 1:22:26 PM, you wrote: > because they have different models. i recommend you to start from > learning this model, otherwise you will don't understand how Haskell > really works and erroneously apply your OOP knowledge to Haskell data > structures. > shortly said, there are 3 ways to polymorphism: > 1) C++ templates - type-specific code generated at compile time > 2) OOP classes - every object carries VMT which allows to select > type-specific operation > 3) type classes - dictionary of type-specific operations is given as > additional hidden argument to each function > Haskell uses t.c. and its abilities are dictated by this > implementation. there is no simple and direct mapping between > features provided by OOP and t.c. >> Can you give me a summary of why it's meaningless.....both would seem > to >> describe/construct values/objects....they may not be equivalent, but I >> would expect some considerable overlap. >> -----Original Message----- >> From: Bulat Ziganshin [mailto:bulat.ziganshin@gmail.com] >> Sent: 02 January 2008 20:29 >> To: Nicholls, Mark >> Cc: haskell-cafe@haskell.org >> Subject: Re: [Haskell-cafe] Is there anyone out there who can > translate >> C# generics into Haskell? >> Hello Mark, >> Wednesday, January 2, 2008, 7:40:31 PM, you wrote: >>> I'm trying to translate some standard C# constucts into Haskell... >> some >> it's meaningless. read >> http://haskell.org/haskellwiki/OOP_vs_type_classes >> and especially papers mentioned in the References -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bf3 at telenet.be Thu Jan 3 10:56:30 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Thu Jan 3 10:50:24 2008 Subject: [Haskell-cafe] Consensus about databases / serialization In-Reply-To: <2608b8a80801030645w1581fde6pe87b72497555b396@mail.gmail.com> References: <000a01c84d35$b64d3de0$22e7b9a0$@be> <477CEA17.2090306@telenet.be> <2608b8a80801030645w1581fde6pe87b72497555b396@mail.gmail.com> Message-ID: <000c01c84e21$34a33e60$9de9bb20$@be> Yitz wrote: > My impression from some previous posts is that > because of the high-level approach, it is difficult > to control the precise SQL that is generated. In practice, > you almost always have to do some tweaking that is > at least DB-dependent, and often application dependent. Can't the same be said regarding SQL itself? It sometimes needs tweaking. That's the problem with any high level abstraction no? Just like in Haskell you sometimes have to use strictness tweaks. Of course having an extra layer on top of SQL will make the tweaking more difficult :) Peter From jonathanccast at fastmail.fm Thu Jan 3 11:18:17 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Thu Jan 3 11:12:19 2008 Subject: [Haskell-cafe] Re: The Worker/Wrapper Transformation In-Reply-To: <477CD9E0.6060604@charter.net> References: <20080103105916.7d562d17@solaris.tower> <20080103120847.13725ce6@solaris.tower> <477CD9E0.6060604@charter.net> Message-ID: <6786D2AF-F5B5-4995-B13C-077458E8F135@fastmail.fm> On 3 Jan 2008, at 4:49 AM, Isaac Dupree wrote: > Achim Schneider wrote: >> Achim Schneider wrote: >>> [...] >> I'm trying to grok that >> [] = id >> ++ = . >> in the context of Hughes lists. > > they are also known as "difference lists", and also used at type > String in the Prelude as "ShowS", to help avoid quadratic behavior > when making complicated Strings. the [a]->[a] is not an ordinary > function -- it's expected not to examine its argument, just to use > it exactly once (is there a formal way to say that?) f xn = f [] ++ xn is the first thing off the top of my head. OTOH, examining your argument (while, strictly speaking unsafe) is pretty darn cool: f [] = "foo" f (c:s) | isAlphaNum c = "foo "++c:s | otherwise = "foo"++c:s Token prepend. jcc From jonathanccast at fastmail.fm Thu Jan 3 11:29:36 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Thu Jan 3 11:23:37 2008 Subject: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? In-Reply-To: References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <1965805939.20080102232921@gmail.com> <915864007.20080103135418@gmail.com> <8627368.20080103173843@gmail.com> Message-ID: <81AA9BE2-1CC3-4F09-84B0-C9EF5BD64830@fastmail.fm> On 3 Jan 2008, at 7:40 AM, Nicholls, Mark wrote: > I do not necessarily disagree.... > > But if I can identify the overlap....then I have leant the > overlap...on > the cheap. Not really. You still don't have the context which allows you to fit the Haskell features into a complete system. Meaning is derived from context, it's not inherent --- and the meaning and use of even those features that translate between Haskell and C++ is completely different, because the context they need to fit into makes them suitable for different sorts of applications. jcc From jonathanccast at fastmail.fm Thu Jan 3 12:04:09 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Thu Jan 3 11:58:10 2008 Subject: [Haskell-cafe] Basic question concerning the category Hask (was: concerning data constructors) In-Reply-To: <7b1ffbe0801030340j2676fe2x272b9a836c59773f@mail.gmail.com> References: <20080103101645.90F9F3242E7@www.haskell.org> <7b1ffbe0801030340j2676fe2x272b9a836c59773f@mail.gmail.com> Message-ID: <6A26B181-D657-45A8-9F3E-B7761E9142FD@fastmail.fm> On 3 Jan 2008, at 3:40 AM, Jens Blanck wrote: > > The normal view taken by Haskellers is that the denotations of > > Haskell types are CPPOs. > > CPPO? > > > So: > > > > (1) Must be monotone > > (2) Must be continuous > > Could you please define what you mean by those terms > in this context? > > > (Needn't be strict, even though that messes up the resulting > category > > substantially). > > I'm not convinced that the category is all that "messed up". Well, no coproducts (Haskell uses a lifted version of the coproduct from CPO). Of course, Haskell makes things even worse by lifting the product and exponential objects, as well, which come to think of it is unnecessary even in the category of CPPOs and not necessarily strict continuous functions. The extra P would stand for "pointed" (has a least element, bottom), this is common in some communities. To me though, a cpo (complete partial order) is closed under directed suprema and the empty set is directed so bottom is already required. Not so. A set is directed iff every finite subset has an upper bound in the set; {} is finite, so it must have an upper bound in the set. So directed sets must be non-empty. (So CPOs needn't be pointed). jcc From droundy at darcs.net Thu Jan 3 12:09:25 2008 From: droundy at darcs.net (David Roundy) Date: Thu Jan 3 12:03:20 2008 Subject: [Haskell-cafe] Re: [darcs-devel] announcing darcs 2.0.0pre2 In-Reply-To: <477CC2EC.2030302@microsoft.com> References: <20071216211722.GI11101@darcs.net> <47666BA0.2080408@microsoft.com> <20071221143254.GO11036@darcs.net> <477CC2EC.2030302@microsoft.com> Message-ID: <20080103170924.GE11036@darcs.net> On Thu, Jan 03, 2008 at 11:11:40AM +0000, Simon Marlow wrote: > David Roundy wrote: > > Anyhow, could you retry this test with the above change in methodology, and > > let me know if (a) the pull is still slow the first time and (b) if it's > > much faster the second time (after the reverse unpull/pull)? > > I think I've done it in both directions now, and it got faster, but still > much slower than darcs1: > > $ time darcs2 unpull --from-tag 2007-09-25 -a > Finished unpulling. > 58.68s real 50.64s user 6.36s system 97% darcs2 unpull --from-tag > 2007-09-25 -a > $ time darcs2 pull -a ../ghc-darcs2 > Pulling from "../ghc-darcs2"... > Finished pulling and applying. > 53.28s real 44.62s user 7.10s system 97% darcs2 pull -a ../ghc-darcs2 > > This is still an order of magnitude slower than darcs1 for the same > operation. (these times are now on the local filesystem, BTW) Is this with the latest darcs-unstable? I made some improvements shortly before Christmas (or was it after Christmas?) that ought to improve the speed of pulls dramatically. We were doing O(N^2) operations in our handling of "pending" changes, which I fixed (I think). So I'll wait on investigating this until you've confirmed which version this was tested with. And thanks for the testing! -- David Roundy Department of Physics Oregon State University From apfelmus at quantentunnel.de Thu Jan 3 12:22:51 2008 From: apfelmus at quantentunnel.de (apfelmus) Date: Thu Jan 3 12:16:59 2008 Subject: [Haskell-cafe] Re: Difference lists and ShowS In-Reply-To: References: <20080103105916.7d562d17@solaris.tower> <20080103120847.13725ce6@solaris.tower> <477CD9E0.6060604@charter.net> <20080103154115.28a84ce3@solaris.tower> Message-ID: Henning Thielemann wrote: > I can't see it. If I consider (x++y) but I do not evaluate any element of > (x++y) or only the first element, then this will need constant time. If I > evaluate the first n elements I need n computation time units. How is (.) > on difference lists faster than (++) here? That's a very good question. Basically, the problem is: how to specify the time complexity of an operation under lazy evaluation? You argue that (++) is constant time in the sense that evaluating (x ++ y) to WHNF is O(1) when x and y are already in WHNF. Same for (.). This is indeed correct but apparently fails to explain why (.) is any better than (++). Help! Of course, this very paradox shows that just looking at WHNF is not enough. The next best description is to pretend that our language is strict and to consider full normal form x in NF, y in NF --> (x++y) evaluates to NF in O(length x) time Even when x and y are not in normal form, we know that evaluating the expression (x ++ y) takes O(x ++ y) ~ O(length x) + O(x) + O(y) time to evaluate to NF. Here, O(e) is the time needed to bring the expression e into NF first. This approach now explains that (++) takes quadratic time when used left-associatively O((x ++ y) ++ z) ~ O(length x + length y) + O(length x) + O(x) + O(y) + O(z) instead of the expected O((x ++ y) ++ z) ~ O(x) + O(y) + O(z) or something (only up to constant factors and stuff, but you get the idea). Note that considering NFs is still only an approximation since O(head (qsort xs)) ~ O(n) + O(xs) where n = length xs instead of the expected O(head (qsort xs)) ~ O(qsort xs) ~ O(n log n) + O(xs) where n = length xs thanks to lazy evaluation. Also note that despite considering full normal forms, we can express some laziness with this by giving timings for an expression in different contexts like O(take n ys) O(head ys) instead of only O(ys). Same for parameters with something like O(const x) ~ O(1) instead of the anticipated O(const x) ~ O(x). (For lazy data structures, there are better ways to take laziness into account.) > With difference lists I write > > shows L . (shows T . shows R) > (shows LL . (showsLT . shows LR)) . (shows T . shows R) > ((shows LLL . (shows LLT . shows LLR)) . (showsLT . shows LR)) . (shows T . shows R) > > I still need to resolve three (.) until I get to the first character of > the result string, but for the subsequent characters I do not need to > resolve those dots. In the end, resolution of all (.) may need some time > but then concatenation is performed entirely right-associative. Seems to > be that this is the trick ... So far so good, but the problem now is that analyzing (.) with full normal forms is doomed since this would mean to evaluate things under the lambda which may take less time than doing call-by-need reductions. Still, we somehow have O(x . y) ~ O(x) + O(y) which is better than O(x ++ y) but I'm not quite sure how to make this exact yet. In the end, the above O(e)s are just random doodles conjured out of the hat, I don't know a formalism for easy reasoning about time in a lazy language. Anyone any pointers? Note that the problem is already present for difference lists in strict languages. Regards, apfelmus From barsoap at web.de Thu Jan 3 12:42:37 2008 From: barsoap at web.de (Achim Schneider) Date: Thu Jan 3 12:36:41 2008 Subject: [Haskell-cafe] Re: Difference lists and ShowS References: <20080103105916.7d562d17@solaris.tower> <20080103120847.13725ce6@solaris.tower> <477CD9E0.6060604@charter.net> <20080103154115.28a84ce3@solaris.tower> Message-ID: <20080103184237.468ea44b@solaris.tower> apfelmus wrote: > O((x ++ y) ++ z) ~ O(length x + length y) + O(length x) > + O(x) + O(y) + O(z) I would say that it's ~ O(length x) + O(length $ x ++ y) + O(2 * list mangling) -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From ahey at iee.org Thu Jan 3 13:12:05 2008 From: ahey at iee.org (Adrian Hey) Date: Thu Jan 3 13:06:01 2008 Subject: [Haskell-cafe] HsColour version confusion Message-ID: <477D2575.1040306@iee.org> Hello, I'm confused about which HsColour version I should be using with Haddock/Cabal (on Windows). According to this page.. http://www.cs.york.ac.uk/fp/darcs/hscolour/ ..the latest version is 1.9. But the latest version in Hackage is 1.6, the latest version in the ftp downloads dir is 1.8, unless you want a pre-compiled windows version in which case you're stuck with 1.3 :-) Anyone know what's going on? Thanks -- Adrian Hey From bf3 at telenet.be Thu Jan 3 13:13:27 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Thu Jan 3 13:07:21 2008 Subject: [Haskell-cafe] Refactoring status Message-ID: <002001c84e34$569c9f30$03d5dd90$@be> Hi all, Is any work being done on Haskell refactoring support, like HaRe or others? Is anyone actively using refactoring? When using C#, I used Resharper a lot, and ever since, I'm really hooked to refactoring, so I miss it a lot when doing Haskelling. (I never seem to get a function name or signature right the first time. is it just me? J) I'm currently using Emacs with Haskell Mode (which does not offer refactoring support) but I think many of you use VIM (which does support it?) Can one use refactoring outside of an editor? This does not really sound practical, but maybe it works? Thank you, Peter PS: IMHO I don't think text should be the source format of our files. I think we should use a standarized decorated AST as the source, from which we can derive a textual (but also graphical) view and editor. Any comments on that? J -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080103/9ff52807/attachment.htm From r.kelsall at millstream.com Thu Jan 3 13:20:48 2008 From: r.kelsall at millstream.com (Richard Kelsall) Date: Thu Jan 3 13:15:08 2008 Subject: [Haskell-cafe] Re: Importing Data.Char speeds up ghc around 70% In-Reply-To: <477BBE48.1030300@microsoft.com> References: <200712222038.01632.daniel.is.fischer@web.de> <200712222155.30842.daniel.is.fischer@web.de> <404396ef0712221434i56fb5677sfb71662ccc6a356f@mail.gmail.com> <477BBE48.1030300@microsoft.com> Message-ID: <477D2780.6010201@millstream.com> Simon Marlow wrote: ... > I have seen strange artifacts like this before that turned out to be > caused by one of two things: > > - bad cache interactions, e.g. we just happen to have laid out the code in > such a way that frequently accessed code sequences push each other out > of the cache, or the relative position of the heap and stack have a bad > interaction. This happens less frequently these days with 4-way and > 8-way associative caches on most CPUs. > > - alignment issues, such as storing or loading a lot of misaligned Doubles > > in the second case, I've seen the same program run +/- 50% in > performance from run to run, just based on random alignment of the > stack. But it's not likely to be the issue here, I'm guessing. If it > is code misalignment, that's something we can easily fix (but I don't > *think* we're doing anything wrong in that respect). > > I have an Opteron box here that regularly gives +/- 20% from run to run > of the same program with no other load on the machine. I have no idea > why... > ... This got me wondering how I could test for code misalignment problems. I expect there's a cleverer way, but how about a single executable containing several copies of the same code to be tested and a loop that runs and times the different copies. A consistently higher or lower runtime from one copy would indicate a misalignment problem. (I'm assuming the different copies of the code would probably load at fairly random alignments, random padding could be added.) It might have to run the copies in a different order each time round the loop to avoid the possibility of external periodic events affecting a particular copy. Richard. From horng_twu_lihn at merck.com Thu Jan 3 13:34:29 2008 From: horng_twu_lihn at merck.com (Lihn, Steve) Date: Thu Jan 3 13:28:43 2008 Subject: [Haskell-cafe] Consensus about databases / serialization In-Reply-To: <000c01c84e21$34a33e60$9de9bb20$@be> References: <000a01c84d35$b64d3de0$22e7b9a0$@be> <477CEA17.2090306@telenet.be> <2608b8a80801030645w1581fde6pe87b72497555b396@mail.gmail.com> <000c01c84e21$34a33e60$9de9bb20$@be> Message-ID: <6BD267D89E66B9499514F119920E583C020A3F6D@usctmx1110.merck.com> For small queries, it does not matter much which approach you choose. But for large, complex queries, such 3-table join (especial Star Transformation) and/or large data set (millions of rows involved in large data warehouses), the performance will differ by order of magnitude, depending on how things are optimized. Steve -----Original Message----- From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Peter Verswyvelen Subject: RE: [Haskell-cafe] Consensus about databases / serialization Yitz wrote: > My impression from some previous posts is that > because of the high-level approach, it is difficult > to control the precise SQL that is generated. In practice, > you almost always have to do some tweaking that is > at least DB-dependent, and often application dependent. Can't the same be said regarding SQL itself? It sometimes needs tweaking. That's the problem with any high level abstraction no? Just like in Haskell you sometimes have to use strictness tweaks. Of course having an extra layer on top of SQL will make the tweaking more difficult :) Peter ------------------------------------------------------------------------------ Notice: This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station, New Jersey, USA 08889), and/or its affiliates (which may be known outside the United States as Merck Frosst, Merck Sharp & Dohme or MSD and in Japan, as Banyu - direct contact information for affiliates is available at http://www.merck.com/contact/contacts.html) that may be confidential, proprietary copyrighted and/or legally privileged. It is intended solely for the use of the individual or entity named on this message. If you are not the intended recipient, and have received this message in error, please notify us immediately by reply e-mail and then delete it from your system. ------------------------------------------------------------------------------ From dons at galois.com Thu Jan 3 13:44:18 2008 From: dons at galois.com (Don Stewart) Date: Thu Jan 3 13:38:24 2008 Subject: [Haskell-cafe] ANN / CFP - LLVM bindings for Haskell In-Reply-To: <477CCA75.4090101@serpentine.com> References: <477CCA75.4090101@serpentine.com> Message-ID: <20080103184418.GB4775@scytale.galois.com> bos: > This is an early release of Haskell bindings for the popular LLVM > compiler infrastructure project. > > If you don't know what LLVM is, it's a wonderful toybox of compiler > components, from a complete toolchain supporting multiple architectures > through a set of well-defined APIs and IR formats that are designed for > building interesting software with. > > The official LLVM home page is here: > > http://llvm.org/ > > The Haskell bindings are based on Gordon Henriksen's C bindings. The C > bindings are almost untyped, but the Haskell bindings re-add type safety > to prevent runtime crashes and general badness. > > Currently, the entire code generation system is implemented, with most > LLVM data types supported (notably absent are structs). Also plugged in > is JIT support, so you can generate code at runtime from Haskell and run > it immediately. I've attached an example. > > Please join in the hacking fun! > > darcs get http://darcs.serpentine.com/llvm > > If you want a source tarball, fetch it from here: > > http://darcs.serpentine.com/llvm/llvm-0.0.2.tar.gz Woot. More codegen fun! > (Hackage can't host code that uses GHC 6.8.2's language extension names > yet.) {-# LANGUAGE XYZ #-} pragmas? If so, I'm pretty sure they're supported, since xmonad uses them, and is on hackage. -- Don From cmb21 at kent.ac.uk Thu Jan 3 13:48:05 2008 From: cmb21 at kent.ac.uk (C.M.Brown) Date: Thu Jan 3 13:42:33 2008 Subject: [Haskell-cafe] Refactoring status In-Reply-To: <002001c84e34$569c9f30$03d5dd90$@be> References: <002001c84e34$569c9f30$03d5dd90$@be> Message-ID: Hi Peter, > Is any work being done on Haskell refactoring support, like HaRe or others? HaRe is still very active and is due for a new release very soon. There are probably in excess of 40 refactorings for HaRe in total now, and I intend to add more! Sadly, I am currently the only maintainer left on the project, so I am busy trying to implement new refactorings and finish off my thesis. > Is anyone actively using refactoring? When using C#, I used Resharper a lot, > and ever since, I'm really hooked to refactoring, so I miss it a lot when > doing Haskelling. (I never seem to get a function name or signature right > the first time. is it just me? J) The greatest problem that the HaRe group have experienced is that HaRe supports Haskell 98. While this is the perfect model for academic investigation and Haskell tool design, most of the real world use the de facto standard of GHC haskell. We would really like HaRe to be ported over to GHC at some point in the near future. > I'm currently using Emacs with Haskell Mode (which does not offer > refactoring support) but I think many of you use VIM (which does support > it?) > Can one use refactoring outside of an editor? This does not really sound > practical, but maybe it works? HaRe works with both Emacs and VIM; you can also use it from a command prompt meaning that it can be integrated into any tool that you require. Indeed, there was even some investigation of porting it to Sub Etha Edit with great success! > PS: IMHO I don't think text should be the source format of our files. I > think we should use a standarized decorated AST as the source, from which we > can derive a textual (but also graphical) view and editor. Any comments on > that? J You mean a syntax-directed editor, right? Kind regards, Chris. From bos at serpentine.com Thu Jan 3 13:49:20 2008 From: bos at serpentine.com (Bryan O'Sullivan) Date: Thu Jan 3 13:43:16 2008 Subject: [Haskell-cafe] ANN / CFP - LLVM bindings for Haskell In-Reply-To: <20080103184418.GB4775@scytale.galois.com> References: <477CCA75.4090101@serpentine.com> <20080103184418.GB4775@scytale.galois.com> Message-ID: <477D2E30.7000308@serpentine.com> Don Stewart wrote: >> (Hackage can't host code that uses GHC 6.8.2's language extension names >> yet.) > > {-# LANGUAGE XYZ #-} pragmas? If so, I'm pretty sure they're > supported, since xmonad uses them, and is on hackage. Language pragmas in general are fine, but I believe I'm using a few that are new to Cabal 1.2.3.0, which isn't being used to power Hackage yet. Or thus quoth Duncan. References: <002001c84e34$569c9f30$03d5dd90$@be> Message-ID: <404396ef0801031057u1a76b1efy37acd60e752cbe24@mail.gmail.com> Hi > PS: IMHO I don't think text should be the source format of our files? I > think we should use a standarized decorated AST as the source, from which we > can derive a textual (but also graphical) view and editor? Any comments on > that? J Yes - I think you're wrong. I've seen non-textual editors for programming languages, and they are severely unpleasant for all but the most new beginners and restricted tasks. There is a good chance that you can derive graphical views of source code (call flow graphs, module dependencies etc) which perhaps could be used to modify one particular sort of information in the code. Other than that, I'd say text is going to remain the way forward. Thanks Neil From dons at galois.com Thu Jan 3 13:58:38 2008 From: dons at galois.com (Don Stewart) Date: Thu Jan 3 13:52:35 2008 Subject: [Haskell-cafe] ANN / CFP - LLVM bindings for Haskell In-Reply-To: <477D2E30.7000308@serpentine.com> References: <477CCA75.4090101@serpentine.com> <20080103184418.GB4775@scytale.galois.com> <477D2E30.7000308@serpentine.com> Message-ID: <20080103185838.GC4775@scytale.galois.com> bos: > Don Stewart wrote: > > >> (Hackage can't host code that uses GHC 6.8.2's language extension names > >> yet.) > > > > {-# LANGUAGE XYZ #-} pragmas? If so, I'm pretty sure they're > > supported, since xmonad uses them, and is on hackage. > > Language pragmas in general are fine, but I believe I'm using a few that > are new to Cabal 1.2.3.0, which isn't being used to power Hackage yet. > Or thus quoth Duncan. Ah yes, good point! There are some that can't be placed in the .cabal file -- though they can go in the .hs file (with -fglasgow-exts in the .cabal as needed). -- Don From bulat.ziganshin at gmail.com Thu Jan 3 13:58:34 2008 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Jan 3 13:54:05 2008 Subject: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? In-Reply-To: References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <1965805939.20080102232921@gmail.com> <915864007.20080103135418@gmail.com> <8627368.20080103173843@gmail.com> Message-ID: <1762133336.20080103215834@gmail.com> Hello Mark, Thursday, January 3, 2008, 6:40:13 PM, you wrote: it would be hard to understand overlap without knowing both systems. you will believe that you understand it, but things will go strange ways :) > I do not necessarily disagree.... > But if I can identify the overlap....then I have leant the overlap...on > the cheap. > > -----Original Message----- > From: Bulat Ziganshin [mailto:bulat.ziganshin@gmail.com] > Sent: 03 January 2008 14:39 > To: Nicholls, Mark > Cc: Bulat Ziganshin; haskell-cafe@haskell.org > Subject: Re[4]: [Haskell-cafe] Is there anyone out there who can > translate C# generics into Haskell? > Hello Mark, > Thursday, January 3, 2008, 2:13:08 PM, you wrote: > of course *some* overlap exists but in order to understand it you > should know exact shape of both methods > when i tried to develop complex library without understanding t.c. > implementation, i constantly goes into the troubles - things that i > (using my OOP experience) considered as possible, was really > impossible in Haskell > so i'm really wonder why you don't want to learn the topic thoroughly >> I loosely do understand....but very loosely....but I'm not, as yet, >> convinced it is completely relevant. >> The implementation may differ, but that does not mean that there is no >> overlap....I am not expecting one model to be a superset of the other, >> but I am expecting some sort of overlap between 'interface' >> implementation and type class instance declaration. >> -----Original Message----- >> From: Bulat Ziganshin [mailto:bulat.ziganshin@gmail.com] >> Sent: 03 January 2008 10:54 >> To: Nicholls, Mark >> Cc: Bulat Ziganshin; haskell-cafe@haskell.org >> Subject: Re[2]: [Haskell-cafe] Is there anyone out there who can >> translate C# generics into Haskell? >> Hello Mark, >> Thursday, January 3, 2008, 1:22:26 PM, you wrote: >> because they have different models. i recommend you to start from >> learning this model, otherwise you will don't understand how Haskell >> really works and erroneously apply your OOP knowledge to Haskell data >> structures. >> shortly said, there are 3 ways to polymorphism: >> 1) C++ templates - type-specific code generated at compile time >> 2) OOP classes - every object carries VMT which allows to select >> type-specific operation >> 3) type classes - dictionary of type-specific operations is given as >> additional hidden argument to each function >> Haskell uses t.c. and its abilities are dictated by this >> implementation. there is no simple and direct mapping between >> features provided by OOP and t.c. >>> Can you give me a summary of why it's meaningless.....both would seem >> to >>> describe/construct values/objects....they may not be equivalent, but > I >>> would expect some considerable overlap. >>> -----Original Message----- >>> From: Bulat Ziganshin [mailto:bulat.ziganshin@gmail.com] >>> Sent: 02 January 2008 20:29 >>> To: Nicholls, Mark >>> Cc: haskell-cafe@haskell.org >>> Subject: Re: [Haskell-cafe] Is there anyone out there who can >> translate >>> C# generics into Haskell? >>> Hello Mark, >>> Wednesday, January 2, 2008, 7:40:31 PM, you wrote: >>>> I'm trying to translate some standard C# constucts into Haskell... >>> some >>> it's meaningless. read >>> http://haskell.org/haskellwiki/OOP_vs_type_classes >>> and especially papers mentioned in the References -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bf3 at telenet.be Thu Jan 3 14:05:07 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Thu Jan 3 13:59:03 2008 Subject: [Haskell-cafe] Refactoring status In-Reply-To: References: <002001c84e34$569c9f30$03d5dd90$@be> Message-ID: <002b01c84e3b$8e7c7fe0$ab757fa0$@be> > HaRe works with both Emacs and VIM; you can also use it from a command > prompt meaning that it can be integrated into any tool that you require. > Indeed, there was even some investigation of porting it to Sub Etha Edit > with great success! Cool! I'll check it out. However, I'm using some GHC extensions, so that is indeed a show stopper :) > You mean a syntax-directed editor, right? Yes, but also that a compiler should directly read the syntax tree; the frontend part of the compiler should really be the editor, providing round-trip editing between text <-> AST. Nothing new really, I used to work with a 6502 assembler on the Commodore 64 that did exactly that :) Cheers, Peter From cmb21 at kent.ac.uk Thu Jan 3 14:11:18 2008 From: cmb21 at kent.ac.uk (C.M.Brown) Date: Thu Jan 3 14:05:29 2008 Subject: [Haskell-cafe] Refactoring status In-Reply-To: <002b01c84e3b$8e7c7fe0$ab757fa0$@be> References: <002001c84e34$569c9f30$03d5dd90$@be> <002b01c84e3b$8e7c7fe0$ab757fa0$@be> Message-ID: > Cool! I'll check it out. However, I'm using some GHC extensions, so that is > indeed a show stopper :) Which extensions are you using that are not Haskell 98? I would be very interested to know what users would generally require from a refactorer. > > You mean a syntax-directed editor, right? > > Yes, but also that a compiler should directly read the syntax tree; the > frontend part of the compiler should really be the editor, providing > round-trip editing between text <-> AST. Nothing new really, I used to work > with a 6502 assembler on the Commodore 64 that did exactly that :) I agree with Neil, AST editors are generally ugly and hard to use. There is also the problem of laying out Haskell code. Everyone uses their own layout style and pretty printing ASTs is generally a bad thing to do in this context. Cheers, Chris. From bulat.ziganshin at gmail.com Thu Jan 3 14:06:17 2008 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Jan 3 14:07:04 2008 Subject: [Haskell-cafe] Refactoring status In-Reply-To: <002001c84e34$569c9f30$03d5dd90$@be> References: <002001c84e34$569c9f30$03d5dd90$@be> Message-ID: <1713055262.20080103220617@gmail.com> Hello Peter, Thursday, January 3, 2008, 9:13:27 PM, you wrote: well, i use refactoring without help of any tool. according to my own experience, it's much easier in Haskell than in other languages i know - basically, you just cut-n-paste your code around. i don't use type signatures at all - this creates some problems when i wrote large portion of code and try to make it compile, but nothing more > > > > Hi all, > > ? > > Is any work being done on Haskell refactoring support, like HaRe or others? > > ? > > Is anyone actively using refactoring? When using C#, I used > Resharper a lot, and ever since, I?m really hooked to refactoring, > so I miss it a lot when doing Haskelling. (I never seem to get a > function name or signature right the first time? is it just me? J) > > ? > > I?m currently using Emacs with Haskell Mode (which does not offer > refactoring support) but I think many of you use VIM (which does support it?) > > ? > > Can one use refactoring outside of an editor? This does not really > sound practical,? but maybe it works? > > ? > > Thank you, > > Peter > > ? > > PS: IMHO I don?t think text should be the source format of our > files? I think we should use a standarized decorated AST as the > source, from which we can derive a textual (but also graphical) view > and editor? Any comments on that? J > > ? > > ? > > ? > > ? > > > > > ? > > > -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bulat.ziganshin at gmail.com Thu Jan 3 14:11:55 2008 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Jan 3 14:07:10 2008 Subject: [Haskell-cafe] Refactoring status In-Reply-To: <404396ef0801031057u1a76b1efy37acd60e752cbe24@mail.gmail.com> References: <002001c84e34$569c9f30$03d5dd90$@be> <404396ef0801031057u1a76b1efy37acd60e752cbe24@mail.gmail.com> Message-ID: <28944056.20080103221155@gmail.com> Hello Neil, Thursday, January 3, 2008, 9:57:10 PM, you wrote: > Yes - I think you're wrong. I've seen non-textual editors for > programming languages, and they are severely unpleasant for all but > the most new beginners and restricted tasks. what sort of code you are tried to develop? visual designers are successfully used for GUI design (not surprising) and SQL pure parts of my haskell program is just functions which takes some input (as arguments) and produce some output (as result). these functions are built from other functions and i don't see why it should be bad to represent this graphically instead of textually. moreover, Haskell is known as hard-to-read language (at least for beginners) due to its great power of function composition, and graphical representation of complex expressions may make easier their understanding -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bf3 at telenet.be Thu Jan 3 14:19:53 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Thu Jan 3 14:13:48 2008 Subject: [Haskell-cafe] Refactoring status In-Reply-To: <404396ef0801031057u1a76b1efy37acd60e752cbe24@mail.gmail.com> References: <002001c84e34$569c9f30$03d5dd90$@be> <404396ef0801031057u1a76b1efy37acd60e752cbe24@mail.gmail.com> Message-ID: <002c01c84e3d$9e1bc210$da534630$@be> > Yes - I think you're wrong. I've seen non-textual editors for > programming languages, and they are severely unpleasant for all but > the most new beginners and restricted tasks. For programmers and mathematicians, you are absolutely right. For beginners and people who have highly developed visual skills (like computer graphic artists), I'm afraid you are wrong. Most of the latter would never even try to look at something like Haskell, while many of them are actually using a (subset of) a dataflow or functional language (Apple's Shake, SideFX Houdini, Digital Fusion, the Unreal 3 Game Engine, the Spirops AI system, just to name a few). Most of these application also provide a textual interface, but artists mostly prefer the graphical view. > There is a good chance that you can derive graphical views of source > code (call flow graphs, module dependencies etc) which perhaps could > be used to modify one particular sort of information in the code. > Other than that, I'd say text is going to remain the way forward. But now everybody is developing their own parsers and structured data representation for Haskell tools no, because text is the standard? Cheers, Peter From dons at galois.com Thu Jan 3 14:20:02 2008 From: dons at galois.com (Don Stewart) Date: Thu Jan 3 14:14:05 2008 Subject: [Haskell-cafe] Fusion of lists and chunky sequences In-Reply-To: References: Message-ID: <20080103192002.GF4775@scytale.galois.com> lemming: > > On the one hand I like to use lists in my code because element types can > be freely chosen and maximum laziness allows feedback and other tricks. On > the other hand there are ByteString.Lazy and one could build chunky > sequences from other fast array implementations. They have constraints on > the element types like Storable in > http://code.haskell.org/~sjanssen/storablevector > and IArray multi-parameter type class for UArray. > > I like to continue writing code for lists, and let the optimizer replace > it by operations on chunky sequences whereever possible. E.g. > Chunky.fromList (List.map f (List.unfoldr g x)) > might be transformed to > Chunky.unfoldr (f ... g) x > > Chunky.fromList serves two purposes: > 1. I obtain the result in a data structure that can be quickly accessed > by further operations. > 2. It tells the optimizer that element granularity for laziness is not > needed and that the element type fulfills the constraint of the fast array > type, and thus fusion can go on safely. (As far as I can see.) > > Is there some framework which fuses lists and chunky sequences? When > writing fusion rules like the above one by myself, then they interfer with > Prelude's fusion rules (and they would probably also interfer with those > of an alternative list fusion framework). The 'map' and 'unfoldr' is > certainly already fused to the internal 'build' or to another auxiliary > function. As far as I know, I cannot disable the Prelude rules and give > the List-Chunk rules priority higher than Prelude's ones. You can, with some caveats, use a single fusion system across data structures, and avoid the built in build/foldr system. I'd start by installing the stream-fusion list library, from hackage, which gives you the list api, and a fusion mechanism. To avoid the build in fusion system, you need to: * avoid list comprehensions * avoid .. (use Stream.enumFromTo instead) then you can write fusion rules for your structure in terms of streams, and they'll fuse with list operations as well. Duncan, Roman and I plan to have strict and lazy bytestrings fusing on top of the stream-fusion package in Q1 this year, but you can start now looking at other data structures. > I hoped to be able to apply application specific fusion rules by defining > a newtype wrapper around the chunky sequence type, while keeping the rest > of the list code unchanged. You might argue, that code cannot be > application specific if it still relies on the generic list type. Maybe > it's the best to wrap the list type in a newtype and lift all of the > application relevant list functions to this type and then define fusion > rules on the lifted functions. -- Don From bf3 at telenet.be Thu Jan 3 14:21:23 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Thu Jan 3 14:15:16 2008 Subject: [Haskell-cafe] Refactoring status In-Reply-To: References: <002001c84e34$569c9f30$03d5dd90$@be> <002b01c84e3b$8e7c7fe0$ab757fa0$@be> Message-ID: <002d01c84e3d$d3dd5ad0$7b981070$@be> > I agree with Neil, AST editors are generally ugly and hard to use. There > is also the problem of laying out Haskell code. Everyone uses their own > layout style and pretty printing ASTs is generally a bad thing to do in > this context. I actually meant something more like http://en.wikipedia.org/wiki/Intentional_programming Cheers, Peter From cmb21 at kent.ac.uk Thu Jan 3 14:46:54 2008 From: cmb21 at kent.ac.uk (C.M.Brown) Date: Thu Jan 3 14:40:58 2008 Subject: [Haskell-cafe] Refactoring status In-Reply-To: <1713055262.20080103220617@gmail.com> References: <002001c84e34$569c9f30$03d5dd90$@be> <1713055262.20080103220617@gmail.com> Message-ID: Hi Bulat, > i don't use > type signatures at all - this creates some problems when i wrote large > portion of code and try to make it compile, but nothing more I believe type signatures are the very essence of Haskell documentation! I'd much rather see a program with type signatures for functions and little (or no) comments over programs with no type signatures and ambigious comments (if any comments at all!). Type signatures really does make dealing with someone elses code that much easier. Regards, Chris. > > > > > > > > > Hi all, > > > > ? > > > > Is any work being done on Haskell refactoring support, like HaRe or others? > > > > ? > > > > Is anyone actively using refactoring? When using C#, I used > > Resharper a lot, and ever since, I?m really hooked to refactoring, > > so I miss it a lot when doing Haskelling. (I never seem to get a > > function name or signature right the first time? is it just me? J) > > > > ? > > > > I?m currently using Emacs with Haskell Mode (which does not offer > > refactoring support) but I think many of you use VIM (which does support it?) > > > > ? > > > > Can one use refactoring outside of an editor? This does not really > > sound practical,? but maybe it works? > > > > ? > > > > Thank you, > > > > Peter > > > > ? > > > > PS: IMHO I don?t think text should be the source format of our > > files? I think we should use a standarized decorated AST as the > > source, from which we can derive a textual (but also graphical) view > > and editor? Any comments on that? J > > > > ? > > > > ? > > > > ? > > > > ? > > > > > > > > > > > ? > > > > > > > > > From yaru22 at gmail.com Thu Jan 3 14:49:09 2008 From: yaru22 at gmail.com (Brian Park) Date: Thu Jan 3 14:43:05 2008 Subject: [Haskell-cafe] haskell package installation problem Message-ID: <8f4ec6fc0801031149q5b11cab5wbe655efaa4048d2f@mail.gmail.com> Hi, I was installing various haskell packages from hackage. When I was installing HaXml, I think it was complaining about Text.PrettyPrint.HughesPJ not installed or something. (can't remember the specific message and I can't reproduce now...) So I installed "pretty-1.0.0.0" package as well. Ever since then, when I try to install other haskell packages, I get the following error message: "brian@bp-desktop:~/Download/mtl-1.1.0.0$ runghc Setup.hs configure : /usr/local/lib/ghc-6.8.2/lib/Cabal-1.2.3.0/HSCabal-1.2.3.0.o: unknown symbol `prettyzm1zi0zi0zi0_TextziPrettyPrintziHughesPJ_lvl18_closure' ghc-6.8.2: unable to load package `Cabal-1.2.3.0'" Does anyone know what the problem is? Currently installed packages are: ========= /usr/local/lib/ghc-6.8.2/package.conf: Cabal-1.2.3.0, HTTP-3001.0.4, HUnit-1.2.0.0, X11-1.4.1, array-0.1.0.0, base-3.0.1.0, bytestring-0.9.0.1, containers-0.1.0.1, directory-1.0.0.0, filepath-1.1.0.0, (ghc-6.8.2), haskell98-1.0.1.0, hpc-0.5.0.0, hxt-7.4, mtl-1.1.0.0, network-2.1.0.0, old-locale-1.0.0.0, old-time-1.0.0.0, packedstring-0.1.0.0, parsec-2.1.0.0, polyparse-1.1, pretty-1.0.0.0, process-1.0.0.0, random-1.0.0.0, readline-1.0.1.0, rts-1.0, template-haskell-2.2.0.0, unix-2.3.0.0, xmonad-0.5, xmonad-contrib-0.5 ========= Thank you, - Brian -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080103/63b23cbe/attachment.htm From bf3 at telenet.be Thu Jan 3 14:55:35 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Thu Jan 3 14:49:27 2008 Subject: [Haskell-cafe] Refactoring status In-Reply-To: References: <002001c84e34$569c9f30$03d5dd90$@be> <002b01c84e3b$8e7c7fe0$ab757fa0$@be> Message-ID: <003401c84e42$9b14f870$d13ee950$@be> > Which extensions are you using that are not Haskell 98? I would be very > interested to know what users would generally require from a refactorer. I don't see myself as typical Haskell user yet, I'm way to new to the language to consider myself a real "user". Currently, I'm trying to learn arrows and Yampa (mainly to see how well it compares to my own dataflow/reactive stuff that was written in C#, C++ and assembler) I also needed functional dependencies, and usually my code does not compile without -fglasgow-exts, and I really don't know why :) > I agree with Neil, AST editors are generally ugly and hard to use. There > is also the problem of laying out Haskell code. Everyone uses their own > layout style and pretty printing ASTs is generally a bad thing to do in > this context. First of all, let's see if I get the concept of a "syntax directed editor" right. The idea is, that I (or my company), has a specific indentation rule, naming convention rule, etc... When I get code from someone else (in a syntax tree form ala XML), it will immediately show the text using my conventions. Furthermore, when I need to perform refactoring, a rename is just *one* change to the entire system, no matter how many other files use the name; no more merging for stupid renames. When diffing, whitespace, indentation, etc does not matter; the structure of the files is compared instead. A lot of metadata (for different views) can be attached to the syntax tree without cluttering my text files (like e.g. most version control systems do). I could go on like that, but the intentional programming website explains most of it. Cheers, Peter From bf3 at telenet.be Thu Jan 3 15:03:58 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Thu Jan 3 14:57:52 2008 Subject: [Haskell-cafe] Refactoring status In-Reply-To: References: <002001c84e34$569c9f30$03d5dd90$@be> <1713055262.20080103220617@gmail.com> Message-ID: <003501c84e43$c6df2fb0$549d8f10$@be> > I believe type signatures are the very essence of Haskell documentation! > I'd much rather see a program with type signatures for functions and > little (or no) comments over programs with no type signatures and > ambigious comments (if any comments at all!). Okay, but when using a syntax directed editor, type signatures can be automatically provided because the types are known. Furthermore, IMHO, type signatures alone are not enough, a good parameter name says at least as much as the type. E.g. what does a function Int -> Int -> Bool do? I have no idea. A good function name helps, e.g. isDivisible:: Int -> Int -> Bool. But then I still don't know which parameter is the numerator and denominator. So good names for the parameters are at least as important, e.g. isDivisible :: numerator:Int -> denonimator:Int -> Bool > Type signatures really does make dealing with someone elses code that > much easier. Yes, as is good documentation, which unfortunately is still limited to ASCII. I would prefer to have rich documentation right inside my source code, with math symbols, drawings, pictures, animations, whatever... Cheers, Peter From cmb21 at kent.ac.uk Thu Jan 3 15:12:52 2008 From: cmb21 at kent.ac.uk (C.M.Brown) Date: Thu Jan 3 15:06:56 2008 Subject: [Haskell-cafe] Refactoring status In-Reply-To: <003401c84e42$9b14f870$d13ee950$@be> References: <002001c84e34$569c9f30$03d5dd90$@be> <002b01c84e3b$8e7c7fe0$ab757fa0$@be> <003401c84e42$9b14f870$d13ee950$@be> Message-ID: > Currently, I'm trying to learn arrows and Yampa (mainly to see how well it > compares to my own dataflow/reactive stuff that was written in C#, C++ and > assembler) Arrows won't work with HaRe at the moment, therefore Yampa won't either; which is a shame. > First of all, let's see if I get the concept of a "syntax directed editor" > right. The idea is, that I (or my company), has a specific indentation rule, > naming convention rule, etc... When I get code from someone else (in a > syntax tree form ala XML), it will immediately show the text using my > conventions. Yep, this was what I was thinking to some extent. Furthermore, when I need to perform refactoring, a rename is > just *one* change to the entire system, no matter how many other files use > the name; no more merging for stupid renames. I'm a little confused as to what you mean here. A renaming renames all (and only those) uses of an identifier within a particular definition, and not every use of a particular name. The binding structure of the program must not be affected; and there must be no introduction of ambiguity in the namespace. You can do this with HaRe, but HaRe currently refactors Programatica data types. If you can somehow convert your AST into what HaRe expects then the refactoring will work, but you will need to tweak our pretty printer (and turn off layout preservation). When diffing, whitespace, > indentation, etc does not matter; the structure of the files is compared > instead. There is also (preliminary at the moment) duplicate code detection built into HaRe. This is based on the principle of looking at the shape of functions and expressions, concentrating on where variables are bound and whether one term is an intance of another. Duplicate expressions can be converted into a more general abstraction, transforming the duplicate expressions into function calls (parameterised by their differences). Cheers, Chris. From cmb21 at kent.ac.uk Thu Jan 3 15:16:24 2008 From: cmb21 at kent.ac.uk (C.M.Brown) Date: Thu Jan 3 15:10:29 2008 Subject: [Haskell-cafe] Refactoring status In-Reply-To: <003501c84e43$c6df2fb0$549d8f10$@be> References: <002001c84e34$569c9f30$03d5dd90$@be> <1713055262.20080103220617@gmail.com> <003501c84e43$c6df2fb0$549d8f10$@be> Message-ID: > Furthermore, IMHO, type signatures alone are not enough, a good parameter > name says at least as much as the type. Yes! A very good point! :) > > E.g. what does a function Int -> Int -> Bool do? I have no idea. A good > function name helps, e.g. isDivisible:: Int -> Int -> Bool. But then I still > don't know which parameter is the numerator and denominator. So good names > for the parameters are at least as important, e.g. isDivisible :: > numerator:Int -> denonimator:Int -> Bool > I agree. But I was generally thinking of more complex functions than this, especially if they use some kind of user-defined monad and have implicit parameters, say. Cheers, Chris. From ketil+haskell at ii.uib.no Thu Jan 3 15:56:44 2008 From: ketil+haskell at ii.uib.no (Ketil Malde) Date: Thu Jan 3 15:50:46 2008 Subject: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? In-Reply-To: <002c01c84e00$76b74d30$6425e790$@be> (Peter Verswyvelen's message of "Thu\, 3 Jan 2008 13\:02\:07 +0100") References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <004a01c84d7e$556a3160$003e9420$@vers@telenet.be> <002c01c84e00$76b74d30$6425e790$@be> Message-ID: <87sl1ebpbn.fsf@nmd9999.imr.no> "Peter Verswyvelen" writes: > Well, it's a good habit in Haskell to move the "most important" parameter to > the end of the argument list. See e.g. > http://www.haskell.org/haskellwiki/Parameter_order. I must say I like these recommendations. As for the Data.Map examples, the parameter order was changed compared to the old FiniteMap, and I was sure there was some rationale given? -k -- If I haven't seen further, it is by standing in the footprints of giants From bf3 at telenet.be Thu Jan 3 15:59:11 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Thu Jan 3 15:53:05 2008 Subject: [Haskell-cafe] Refactoring status In-Reply-To: References: <002001c84e34$569c9f30$03d5dd90$@be> <002b01c84e3b$8e7c7fe0$ab757fa0$@be> <003401c84e42$9b14f870$d13ee950$@be> Message-ID: <003601c84e4b$7d6cb890$784629b0$@be> >> Furthermore, when I need to perform refactoring, a rename is >> just *one* change to the entire system, no matter how many other files use >> the name; no more merging for stupid renames. > I'm a little confused as to what you mean here. A renaming renames all > (and only those) uses of an identifier within a particular definition, and > not every use of a particular name. The binding structure of the program Suppose we have a file Foo.hs, with the content: foo ::Int foo = 42 Translated into a syntax tree, this might look like (majorly simplified) and a file Bar.hs, with bar :: Int bar = foo + 27 or translated If you rename foo, using textual representation, both Foo.hs and Bar.hs will be touched / checked-out. However, if you work directly on the structure, then only the Foo XML file is changed, Bar is not changed at all. Of course this might only be the case with renames, more complex refactorings usually require modifying other files :) Anyway, I hate merges caused by renames by others. And many developers tend to leave names as they are, because you get used to strange names anyway... A good example is Microsoft's Windows Presentation Foundation code: what do you think the method FindName on an element tree does? It searches for an element with a particular name, and returns that element ;) > There is also (preliminary at the moment) duplicate code detection built > into HaRe. This is based on the principle of looking at the shape of functions and > expressions, concentrating on where variables are bound and whether one > term is an intance of another. Duplicate expressions can be converted into > a more general abstraction, transforming the duplicate expressions into > function calls (parameterised by their differences). Impressive! Cheers, Peter From gale at sefer.org Thu Jan 3 16:09:03 2008 From: gale at sefer.org (Yitzchak Gale) Date: Thu Jan 3 16:02:58 2008 Subject: [Haskell-cafe] Consensus about databases / serialization In-Reply-To: <000c01c84e21$34a33e60$9de9bb20$@be> References: <000a01c84d35$b64d3de0$22e7b9a0$@be> <477CEA17.2090306@telenet.be> <2608b8a80801030645w1581fde6pe87b72497555b396@mail.gmail.com> <000c01c84e21$34a33e60$9de9bb20$@be> Message-ID: <2608b8a80801031309x3796eedbgae4f40440094f78b@mail.gmail.com> I wrote: >>... to control the precise SQL that is generated. In practice, >> you almost always have to do some tweaking that is >> at least DB-dependent, and often application dependent. Peter Verswyvelen wrote: > Can't the same be said regarding SQL itself? It sometimes needs tweaking. > That's the problem with any high level abstraction no? Certainly. In an ideal world, you could just write your queries in straightforward SQL and the DB would figure out what to do. But in real life, that is not how it works. So that complexity then gets passed up to the Haskell interface layers. Again, in an ideal world you would like to imagine that a high-level interface like haskelldb would be smart enough to compile any relational algebraic expression into SQL that will do the Right Thing for the given backend. But that would be very difficult. For example - there may be things you need to tweak that are both application-dependent and DB dependent. So to be usable in a serious DB project, there would have to be some kind of hooks that would allow you to tweak the SQL. After doing that - what have we gained by taking the high-level approach to begin with? I'm not sure. I would like to hear about people's thoughts and experiences on this. -Yitz From gale at sefer.org Thu Jan 3 16:15:56 2008 From: gale at sefer.org (Yitzchak Gale) Date: Thu Jan 3 16:09:51 2008 Subject: [Haskell-cafe] Consensus about databases / serialization In-Reply-To: <6BD267D89E66B9499514F119920E583C020A3F6D@usctmx1110.merck.com> References: <000a01c84d35$b64d3de0$22e7b9a0$@be> <477CEA17.2090306@telenet.be> <2608b8a80801030645w1581fde6pe87b72497555b396@mail.gmail.com> <000c01c84e21$34a33e60$9de9bb20$@be> <6BD267D89E66B9499514F119920E583C020A3F6D@usctmx1110.merck.com> Message-ID: <2608b8a80801031315u4f3cd897y18545bd774005c52@mail.gmail.com> Lihn, Steve wrote: > For small queries, it does not matter much which approach you choose. > But for large, complex queries, such 3-table join (especial Star > Transformation) and/or large data set (millions of rows involved in > large data warehouses), the performance will differ by order of > magnitude, depending on how things are optimized. Ah, yes. and that brings up another issue - how do the various backends scale for: - large SQL passed in - results with many records - records with many fields - records/fields with many bytes - several cursors What laziness options are available? -Yitz From magnus at therning.org Thu Jan 3 16:26:28 2008 From: magnus at therning.org (Magnus Therning) Date: Thu Jan 3 16:20:27 2008 Subject: [Haskell-cafe] Supporting both cabals? Message-ID: <477D5304.3030007@therning.org> GHC 6.8 has just made it into Debian in a usable form. (w00t!) Due to the library split my old cabal files don't work any longer. updating them isn't the problem, the problem is keeping them compatible with both versions of Cabal. I searched the wiki (quickly) but didn't find anything on this topic. Is there a cookbook out there for it? /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus?therning?org Jabber: magnus?therning?gmail?com http://therning.org/magnus What if I don't want to obey the laws? Do they throw me in jail with the other bad monads? -- Daveman -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 189 bytes Desc: OpenPGP digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080103/ae6a696a/signature.bin From bf3 at telenet.be Thu Jan 3 16:32:13 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Thu Jan 3 16:26:06 2008 Subject: [Haskell-cafe] Consensus about databases / serialization In-Reply-To: <2608b8a80801031309x3796eedbgae4f40440094f78b@mail.gmail.com> References: <000a01c84d35$b64d3de0$22e7b9a0$@be> <477CEA17.2090306@telenet.be> <2608b8a80801030645w1581fde6pe87b72497555b396@mail.gmail.com> <000c01c84e21$34a33e60$9de9bb20$@be> <2608b8a80801031309x3796eedbgae4f40440094f78b@mail.gmail.com> Message-ID: <003701c84e50$1aa3c5f0$4feb51d0$@be> I see. But ouch, exactly the same could be said for Haskell no? :) Naaah... -----Original Message----- From: sefer.org@gmail.com [mailto:sefer.org@gmail.com] On Behalf Of Yitzchak Gale Sent: Thursday, January 03, 2008 10:09 PM To: Peter Verswyvelen Cc: Justin Bailey; Haskell-Cafe Subject: Re: [Haskell-cafe] Consensus about databases / serialization I wrote: >>... to control the precise SQL that is generated. In practice, >> you almost always have to do some tweaking that is >> at least DB-dependent, and often application dependent. Peter Verswyvelen wrote: > Can't the same be said regarding SQL itself? It sometimes needs tweaking. > That's the problem with any high level abstraction no? Certainly. In an ideal world, you could just write your queries in straightforward SQL and the DB would figure out what to do. But in real life, that is not how it works. So that complexity then gets passed up to the Haskell interface layers. Again, in an ideal world you would like to imagine that a high-level interface like haskelldb would be smart enough to compile any relational algebraic expression into SQL that will do the Right Thing for the given backend. But that would be very difficult. For example - there may be things you need to tweak that are both application-dependent and DB dependent. So to be usable in a serious DB project, there would have to be some kind of hooks that would allow you to tweak the SQL. After doing that - what have we gained by taking the high-level approach to begin with? I'm not sure. I would like to hear about people's thoughts and experiences on this. -Yitz From judah.jacobson at gmail.com Thu Jan 3 16:34:24 2008 From: judah.jacobson at gmail.com (Judah Jacobson) Date: Thu Jan 3 16:28:19 2008 Subject: [Haskell-cafe] Supporting both cabals? In-Reply-To: <477D5304.3030007@therning.org> References: <477D5304.3030007@therning.org> Message-ID: <6d74b0d20801031334i71db3704w722f7191b75a5610@mail.gmail.com> On Jan 3, 2008 4:26 PM, Magnus Therning wrote: > GHC 6.8 has just made it into Debian in a usable form. (w00t!) > > Due to the library split my old cabal files don't work any longer. > updating them isn't the problem, the problem is keeping them compatible > with both versions of Cabal. I searched the wiki (quickly) but didn't > find anything on this topic. Is there a cookbook out there for it? The standard fix is to use Cabal configurations: http://www.haskell.org/haskellwiki/Upgrading_packages Best, -Judah From vigalchin at gmail.com Thu Jan 3 16:36:03 2008 From: vigalchin at gmail.com (Galchin Vasili) Date: Thu Jan 3 16:29:58 2008 Subject: [Haskell-cafe] US Homeland Security program language security risks Message-ID: <5ae4f2ba0801031336x45b4c14dw34771cbc9ef0d3f4@mail.gmail.com> Hello, https://buildsecurityin.us-cert.gov/daisy/bsi/articles/knowledge/coding/295.html I stumbled across this page. It seems that Haskell and other strongly typed functional languages like Ml/OCaml will fare much, much better, e.g. buffer overrun. Thoughts . .... comments. Vasili -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080103/7a675933/attachment.htm From felipe.lessa at gmail.com Thu Jan 3 16:48:22 2008 From: felipe.lessa at gmail.com (Felipe Lessa) Date: Thu Jan 3 16:42:21 2008 Subject: [Haskell-cafe] An interesting monad: "Prompt" In-Reply-To: <2f9b2d30711181622v4bb2c33bn69dbc263c514d580@mail.gmail.com> References: <2f9b2d30711181622v4bb2c33bn69dbc263c514d580@mail.gmail.com> Message-ID: On Nov 18, 2007 10:22 PM, Ryan Ingram wrote: [snip] > > data Prompt (p :: * -> *) :: (* -> *) where > > PromptDone :: result -> Prompt p result > > -- a is the type needed to continue the computation > > Prompt :: p a -> (a -> Prompt p result) -> Prompt p result [snip] > > runPromptM :: Monad m => (forall a. p a -> m a) -> Prompt p r -> m r > > runPromptM _ (PromptDone r) = return r > > runPromptM f (Prompt pa c) = f pa >>= runPromptM f . c [snip] How can we prove that (runPromptM prompt === id)? I was trying to go with runPromptM prompt (PromptDone r) = return r = PromptDone r runPromptM prompt (Prompt pa c) = prompt pa >>= runPromptM prompt . c = Prompt pa return >>= runPromptM prompt . c = Prompt pa ((>>= (runPromptM prompt . c) . return) = Prompt pa (runPromptM prompt . c) ... and I got stuck here. It "seems obvious" that we can strip out the 'runPromptM prompt' down there to finish the proof, but that doesn't sound very nice, as I'd need to suppose what I'm trying to prove. Am I missing something here? Thank you, -- Felipe. From gale at sefer.org Thu Jan 3 17:01:34 2008 From: gale at sefer.org (Yitzchak Gale) Date: Thu Jan 3 16:55:30 2008 Subject: [Haskell-cafe] Consensus about databases / serialization In-Reply-To: <003701c84e50$1aa3c5f0$4feb51d0$@be> References: <000a01c84d35$b64d3de0$22e7b9a0$@be> <477CEA17.2090306@telenet.be> <2608b8a80801030645w1581fde6pe87b72497555b396@mail.gmail.com> <000c01c84e21$34a33e60$9de9bb20$@be> <2608b8a80801031309x3796eedbgae4f40440094f78b@mail.gmail.com> <003701c84e50$1aa3c5f0$4feb51d0$@be> Message-ID: <2608b8a80801031401s7acf8158h4f88473cdb3e9c01@mail.gmail.com> Peter Verswyvelen wrote: > I see. But ouch, exactly the same could be said for Haskell no? :) > Naaah... Actually, that is one of the things that is so impressive about Haskell. It starts at such a high level, with such beautiful and powerful abstractions. But if needed, you can optimize down through many layers. All the way down to what they do on the Shootout, where they compete against C. It took a huge amount of effort over many years to achieve that. DB support still has a long way to go, but it is great to see that people are working on it at varying levels of abstraction. -Yitz From duncan.coutts at worc.ox.ac.uk Thu Jan 3 17:21:37 2008 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Thu Jan 3 17:15:33 2008 Subject: [Haskell-cafe] Supporting both cabals? In-Reply-To: <477D5304.3030007@therning.org> Message-ID: <20080103222137.DD13850060@webmail217.herald.ox.ac.uk> In message <477D5304.3030007@therning.org> Magnus Therning writes: > GHC 6.8 has just made it into Debian in a usable form. (w00t!) > > Due to the library split my old cabal files don't work any longer. > updating them isn't the problem, the problem is keeping them compatible > with both versions of Cabal. I searched the wiki (quickly) but didn't > find anything on this topic. Is there a cookbook out there for it? Cabal is backwards compatible for .cabal files, so if it works with the old one it'll still be ok. If you need a complex custom Setup.hs file then that's quite a different matter and there's no sensible way of making that work with both (unless you can find some hack using type classes or cpp). If you want to take advantage of new features in Cabal then unless it's something very simple like using new fields (which old cabal versions will warn about but otherwise ignore) then you can't really use them and remain compatible with older cabal versions. This applies particularly to the new configurations which uses new syntax that the Cabal-1.1.x versions to not understand. Duncan From duncan.coutts at worc.ox.ac.uk Thu Jan 3 17:25:28 2008 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Thu Jan 3 17:19:23 2008 Subject: [Haskell-cafe] ANN / CFP - LLVM bindings for Haskell In-Reply-To: <20080103185838.GC4775@scytale.galois.com> References: <477CCA75.4090101@serpentine.com> <20080103184418.GB4775@scytale.galois.com> <477D2E30.7000308@serpentine.com> <20080103185838.GC4775@scytale.galois.com> Message-ID: <20080103222528.B06485009B@webmail217.herald.ox.ac.uk> In message <20080103185838.GC4775@scytale.galois.com> Don Stewart writes: > bos: > > Don Stewart wrote: > > > > >> (Hackage can't host code that uses GHC 6.8.2's language extension names > > >> yet.) > > > > > > {-# LANGUAGE XYZ #-} pragmas? If so, I'm pretty sure they're > > > supported, since xmonad uses them, and is on hackage. > > > > Language pragmas in general are fine, but I believe I'm using a few that > > are new to Cabal 1.2.3.0, which isn't being used to power Hackage yet. > > Or thus quoth Duncan. > > Ah yes, good point! > > There are some that can't be placed in the .cabal file -- though they > can go in the .hs file (with -fglasgow-exts in the .cabal as needed). Yes, this is what got fixed in Cabal-1.2.3.0 which comes with GHC-6.8.2 and is available on hackage for users of other GHC versions and other haskell implementations. Duncan From trebla at vex.net Thu Jan 3 17:25:58 2008 From: trebla at vex.net (Albert Y. C. Lai) Date: Thu Jan 3 17:19:55 2008 Subject: [Haskell-cafe] Re: Difference lists and ShowS In-Reply-To: References: <20080103105916.7d562d17@solaris.tower> <20080103120847.13725ce6@solaris.tower> <477CD9E0.6060604@charter.net> <20080103154115.28a84ce3@solaris.tower> Message-ID: <477D60F6.5090408@vex.net> apfelmus wrote: > I don't know a formalism for easy reasoning about time in a lazy > language. Anyone any pointers? Note that the problem is already present > for difference lists in strict languages. http://homepages.inf.ed.ac.uk/wadler/topics/strictness-analysis.html especially "strictness analysis aids time analysis". Much CPO math is involved, but I view it as: a function gives you output; if you know how much of the output you use, you can deduce how much work the function goes through. From bbrown at botspiritcompany.com Thu Jan 3 18:13:10 2008 From: bbrown at botspiritcompany.com (bbrown) Date: Thu Jan 3 18:07:05 2008 Subject: [Haskell-cafe] Instance classes and error (also, related to Data.Binary.GET) Message-ID: <20080103231030.M8262@www.botspiritcompany.com> I am using the Data.Binary module and having some issues reading big endian files (actually, just reading the file). I can read the header but not the rest of the data which contains a set of row information. Also, go ahead and make fun my style of coding. Anyway, This is the my code and the error at the bottom. The issue stems from here, it says I didn't define an instance, but I did: instance Binary URLSet where put _ = do BinaryPut.putWord8 0 get = do remainingByteData <- BinaryGet.getRemainingLazyByteString i :: URLInfo <- decode remainingByteData j :: TitleInfo <- decode remainingByteData k :: DescrInfo <- decode remainingByteData x :: KeywordsInfo <- decode remainingByteData return (URLSet {urlinfo=i, titleinfo=j, descrinfo=k, keywordsinfo=x}) ----- module Main where import Data.Word import Data.Binary import qualified Data.ByteString.Lazy.Char8 as BSLC8 import Data.ByteString.Lazy (ByteString) import Data.Binary.Get as BinaryGet import Data.Binary.Put as BinaryPut import IO import Text.Printf import System.Environment import Control.Monad (replicateM, liftM) {- ********************************************************* Define the Database Data Types SpiderDatabase represents a singleton wrapper for an entire database. ********************************************************* -} data SpiderDatabase = SpiderDatabase { magicNumberA :: Word16, magicNumberB :: Word16, majorVers :: Word16, minorVers :: Word16, headerTag :: Word16, poolLen :: Word16, spiderpool :: [URLSet] } data URLSet = URLSet { urlinfo :: URLInfo, titleinfo :: TitleInfo, descrinfo :: DescrInfo, keywordsinfo :: KeywordsInfo } data URLInfo = URLInfo { tag :: Word8, urlid :: Word16, urllen :: Word16, url :: ByteString } data TitleInfo = TitleInfo { titletag :: Word8, titlelen :: Word16, title :: ByteString } data DescrInfo = DescrInfo { descrtag :: Word8, descrlen :: Word16, descr :: ByteString } data KeywordsInfo = KeywordsInfo { keywordstag :: Word8, keywordslen :: Word16, keywords :: ByteString } {- ********************************************************* Class instances ********************************************************* -} instance Show SpiderDatabase where show db = let magicb = (magicNumberB db) header = (headerTag db) poolct = (poolLen db) in "<<>>\n" ++ (((printf "Magic: %X %X\n") (magicNumberA db)) (magicNumberB db)) ++ printf "URL Pool Count: %d\n" poolct ++ "<<>>" instance Binary URLInfo where put _ = do BinaryPut.putWord8 0 get = do urltag <- getWord8 idx <- getWord16be len <- getWord16be strdata <- BinaryGet.getLazyByteString (fromIntegral len) return (URLInfo {tag=urltag, urlid=idx, urllen=len, url=strdata}) instance Binary DescrInfo where put _ = do BinaryPut.putWord8 0 get = do tag <- getWord8 len <- getWord16be strdata <- BinaryGet.getLazyByteString (fromIntegral len) return (DescrInfo {descrtag=tag, descrlen=len, descr=strdata}) instance Binary TitleInfo where put _ = do BinaryPut.putWord8 0 get = do tag <- getWord8 len <- getWord16be strdata <- BinaryGet.getLazyByteString (fromIntegral len) return (TitleInfo {titletag=tag, titlelen=len, title=strdata}) instance Binary KeywordsInfo where put _ = do BinaryPut.putWord8 0 get = do tag <- getWord8 len <- getWord16be strdata <- BinaryGet.getLazyByteString (fromIntegral len) return (KeywordsInfo {keywordstag=tag, keywordslen=len, keywords=strdata}) instance Binary URLSet where put _ = do BinaryPut.putWord8 0 get = do remainingByteData <- BinaryGet.getRemainingLazyByteString i :: URLInfo <- decode remainingByteData j :: TitleInfo <- decode remainingByteData k :: DescrInfo <- decode remainingByteData x :: KeywordsInfo <- decode remainingByteData return (URLSet {urlinfo=i, titleinfo=j, descrinfo=k, keywordsinfo=x}) instance Binary SpiderDatabase where put _ = do BinaryPut.putWord8 0 get = do magicnumbera <- BinaryGet.getWord16be magicnumberb <- BinaryGet.getWord16be major <- BinaryGet.getWord16be minor <- BinaryGet.getWord16be header <- BinaryGet.getWord16be poolct <- BinaryGet.getWord16be -- ******************************* -- Get the remaining byte string data, -- So that we can use lazy bytestring to load to load the -- the data types. -- ******************************* remainingByteData <- BinaryGet.getRemainingLazyByteString -- pool <- (replicate (fromIntegral poolct) (decode remainingByteData)) z :: URLSet <- decode remainingByteData return (SpiderDatabase {magicNumberA=magicnumbera, magicNumberB=magicnumberb, majorVers=major, minorVers=minor, headerTag=header, poolLen=poolct }) main = do putStrLn "Running Spider Database Reader" args <- getArgs db :: SpiderDatabase <- decodeFile (args !! 0) putStrLn $ show db putStrLn "Done" *** *** Error: DbReader.hs:119:22: No instance for (Binary (Get URLInfo)) arising from a use of `decode' at DbReader.hs:119:22-45 Possible fix: add an instance declaration for (Binary (Get URLInfo)) In a 'do' expression: i :: URLInfo <- decode remainingByteData In the expression: do remainingByteData <- getRemainingLazyByteString i :: URLInfo <- decode remainingByteData j :: TitleInfo <- decode remainingByteData k :: DescrInfo <- decode remainingByteData .... In the definition of `get': get = do remainingByteData <- getRemainingLazyByteString i :: URLInfo <- decode remainingByteData j :: TitleInfo <- decode remainingByteData .... DbReader.hs:120:24: No instance for (Binary (Get TitleInfo)) arising from a use of `decode' at DbReader.hs:120:24-47 Possible fix: add an instance declaration for (Binary (Get TitleInfo)) In a 'do' expression: j :: TitleInfo <- decode remainingByteData In the expression: do remainingByteData <- getRemainingLazyByteString i :: URLInfo <- decode remainingByteData j :: TitleInfo <- decode remainingByteData k :: DescrInfo <- decode remainingByteData .... In the definition of `get': get = do remainingByteData <- getRemainingLazyByteString i :: URLInfo <- decode remainingByteData j :: TitleInfo <- decode remainingByteData .... DbReader.hs:121:24: No instance for (Binary (Get DescrInfo)) arising from a use of `decode' at DbReader.hs:121:24-47 Possible fix: add an instance declaration for (Binary (Get DescrInfo)) In a 'do' expression: k :: DescrInfo <- decode remainingByteData In the expression: do remainingByteData <- getRemainingLazyByteString i :: URLInfo <- decode remainingByteData j :: TitleInfo <- decode remainingByteData k :: DescrInfo <- decode remainingByteData .... In the definition of `get': get = do remainingByteData <- getRemainingLazyByteString i :: URLInfo <- decode remainingByteData j :: TitleInfo <- decode remainingByteData .... DbReader.hs:122:27: No instance for (Binary (Get KeywordsInfo)) arising from a use of `decode' at DbReader.hs:122:27-50 Possible fix: add an instance declaration for (Binary (Get KeywordsInfo)) In a 'do' expression: x :: KeywordsInfo <- decode remainingByteData In the expression: do remainingByteData <- getRemainingLazyByteString i :: URLInfo <- decode remainingByteData j :: TitleInfo <- decode remainingByteData k :: DescrInfo <- decode remainingByteData .... In the definition of `get': get = do remainingByteData <- getRemainingLazyByteString i :: URLInfo <- decode remainingByteData j :: TitleInfo <- decode remainingByteData .... DbReader.hs:142:21: No instance for (Binary (Get URLSet)) arising from a use of `decode' at DbReader.hs:142:21-44 Possible fix: add an instance declaration for (Binary (Get URLSet)) In a 'do' expression: z :: URLSet <- decode remainingByteData In the expression: do magicnumbera <- getWord16be magicnumberb <- getWord16be major <- getWord16be minor <- getWord16be .... In the definition of `get': get = do magicnumbera <- getWord16be magicnumberb <- getWord16be major <- getWord16be .... make: *** [dbreader] Error 1 -- Berlin Brown [berlin dot brown at gmail dot com] http://botspiritcompany.com/botlist/? From bulat.ziganshin at gmail.com Thu Jan 3 18:13:57 2008 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Jan 3 18:18:44 2008 Subject: [Haskell-cafe] US Homeland Security program language security risks In-Reply-To: <5ae4f2ba0801031336x45b4c14dw34771cbc9ef0d3f4@mail.gmail.com> References: <5ae4f2ba0801031336x45b4c14dw34771cbc9ef0d3f4@mail.gmail.com> Message-ID: <1576558140.20080104021357@gmail.com> Hello Galchin, Friday, January 4, 2008, 12:36:03 AM, you wrote: > I stumbled across this page. It seems that Haskell and other > strongly typed functional languages like Ml/OCaml will fare much, > much better, e.g. buffer overrun. Thoughts . .... comments. for me, it looks like saying that haskell better uses CPU registers :) the truth is that modern languages (including Java/C#) doesn't use buffers directly. i don't have experience of their usage, but for Haskell i had memory referencing problems only when using unsafe* tricks -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bulat.ziganshin at gmail.com Thu Jan 3 18:15:00 2008 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Jan 3 18:18:49 2008 Subject: [Haskell-cafe] Refactoring status In-Reply-To: <003501c84e43$c6df2fb0$549d8f10$@be> References: <002001c84e34$569c9f30$03d5dd90$@be> <1713055262.20080103220617@gmail.com> <003501c84e43$c6df2fb0$549d8f10$@be> Message-ID: <41495718.20080104021500@gmail.com> Hello Peter, Thursday, January 3, 2008, 11:03:58 PM, you wrote: > Okay, but when using a syntax directed editor, type signatures can be > automatically provided because the types are known. the same is possible for Haskell - it's possible to add to code type signatures deduced by the compiler -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bulat.ziganshin at gmail.com Thu Jan 3 18:23:31 2008 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Jan 3 18:18:52 2008 Subject: [Haskell-cafe] Refactoring status In-Reply-To: References: <002001c84e34$569c9f30$03d5dd90$@be> <1713055262.20080103220617@gmail.com> Message-ID: <1302893850.20080104022331@gmail.com> Hello C.M.Brown, Thursday, January 3, 2008, 10:46:54 PM, you wrote: >> i don't use >> type signatures at all - this creates some problems when i wrote large >> portion of code and try to make it compile, but nothing more > I believe type signatures are the very essence of Haskell documentation! > I'd much rather see a program with type signatures for functions and > little (or no) comments over programs with no type signatures and > ambigious comments (if any comments at all!). > Type signatures really does make dealing with someone elses code that > much easier. well, i don't worry about types of things with which i work. i know that it is a file, for example. its actual type depends on the information i need inside this function. it may start as FileInfo type, then after refactoring it will become CompressedFile or (fileInfo,FileSize) type. while it's great to know types of every variable to better understand how program works, adding type signatures means more work when writing program and when changing it. i want to express only data processing algorithm leaving all the details to compiler. for me, ghc just "reads thoughts" types and type signatures was required in classic languages to fight with errors. but in haskell omitting type signatures doesn't make program less reliable, so i don't need to write this extra code in addition to the essential - algorithm itself. for the same reason, i like pointless notation -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From droundy at darcs.net Thu Jan 3 18:29:50 2008 From: droundy at darcs.net (David Roundy) Date: Thu Jan 3 18:23:44 2008 Subject: [Haskell-cafe] Refactoring status In-Reply-To: <1302893850.20080104022331@gmail.com> References: <002001c84e34$569c9f30$03d5dd90$@be> <1713055262.20080103220617@gmail.com> <1302893850.20080104022331@gmail.com> Message-ID: <20080103232949.GK11036@darcs.net> On Fri, Jan 04, 2008 at 02:23:31AM +0300, Bulat Ziganshin wrote: > Thursday, January 3, 2008, 10:46:54 PM, you wrote: > >> i don't use > >> type signatures at all - this creates some problems when i wrote large > >> portion of code and try to make it compile, but nothing more > > > I believe type signatures are the very essence of Haskell documentation! > > I'd much rather see a program with type signatures for functions and > > little (or no) comments over programs with no type signatures and > > ambigious comments (if any comments at all!). > > > Type signatures really does make dealing with someone elses code that > > much easier. > > well, i don't worry about types of things with which i work. i know > that it is a file, for example. its actual type depends on the > information i need inside this function. it may start as FileInfo type, > then after refactoring it will become CompressedFile or > (fileInfo,FileSize) type. while it's great to know types of every > variable to better understand how program works, adding type > signatures means more work when writing program and when changing it. > i want to express only data processing algorithm leaving all the > details to compiler. for me, ghc just "reads thoughts" > > types and type signatures was required in classic languages to fight > with errors. but in haskell omitting type signatures doesn't make > program less reliable, so i don't need to write this extra code in > addition to the essential - algorithm itself. for the same reason, i > like pointless notation True, it's not necessary to *write* the type signatures, but it's often helpful for those who want to read your code. Of course, they could always fire up ghci (with the right incantations) to find out the types of your function, but that's not always convenient. Also, type signatures often make bugs much easier to pinpoint. -- David Roundy Department of Physics Oregon State University From hjgtuyl at chello.nl Thu Jan 3 18:32:00 2008 From: hjgtuyl at chello.nl (hjgtuyl@chello.nl) Date: Thu Jan 3 18:25:56 2008 Subject: [Haskell-cafe] Refactoring status In-Reply-To: References: <002001c84e34$569c9f30$03d5dd90$@be> Message-ID: On Thu, 03 Jan 2008 19:48:05 +0100, C.M.Brown wrote: > HaRe is still very active and is due for a new release very soon. > There are probably in excess of 40 refactorings for HaRe in total now, > and > I intend to add more! Sadly, I am currently the only maintainer left > on the project, so I am busy trying to implement new refactorings and > finish off my thesis. > A possible first goal would be, to add extensions that are definitely in Haskell prime, see: http://hackage.haskell.org/trac/haskell-prime/wiki/Status'#definitely-inProposalStatus > > HaRe works with both Emacs and VIM; you can also use it from a command > prompt meaning that it can be integrated into any tool that you require. > Indeed, there was even some investigation of porting it to Sub Etha Edit > with great success! > It would be nice to have it built in to the functional programming extensions of Eclipse ( http://eclipsefp.sourceforge.net/ ) -- Met vriendelijke groet, Henk-Jan van Tuyl -- http://functor.bamikanarie.com http://Van.Tuyl.eu/ -- From daniel.is.fischer at web.de Thu Jan 3 18:48:07 2008 From: daniel.is.fischer at web.de (Daniel Fischer) Date: Thu Jan 3 18:43:06 2008 Subject: [Haskell-cafe] Instance classes and error (also, related to Data.Binary.GET) In-Reply-To: <20080103231030.M8262@www.botspiritcompany.com> References: <20080103231030.M8262@www.botspiritcompany.com> Message-ID: <200801040048.08104.daniel.is.fischer@web.de> I've no experience with Data.Binary, but I noticed you declared instance Binary YourType where... and the compiler says instance Binary (Get YourType) is missing. That might be worth looking into. Cheers, Daniel Am Freitag, 4. Januar 2008 00:13 schrieb bbrown: > I am using the Data.Binary module and having some issues reading big endian > files (actually, just reading the file). I can read the header but not the > rest of the data which contains a set of row information. Also, go ahead > and make fun my style of coding. > > Anyway, This is the my code and the error at the bottom. > > > The issue stems from here, it says I didn't define an instance, but I did: > > instance Binary URLSet where > put _ = do BinaryPut.putWord8 0 > get = do > remainingByteData <- BinaryGet.getRemainingLazyByteString > i :: URLInfo <- decode remainingByteData > j :: TitleInfo <- decode remainingByteData > k :: DescrInfo <- decode remainingByteData > x :: KeywordsInfo <- decode remainingByteData > return (URLSet {urlinfo=i, titleinfo=j, > descrinfo=k, keywordsinfo=x}) > > ----- > > module Main where > > import Data.Word > import Data.Binary > import qualified Data.ByteString.Lazy.Char8 as BSLC8 > import Data.ByteString.Lazy (ByteString) > import Data.Binary.Get as BinaryGet > import Data.Binary.Put as BinaryPut > import IO > import Text.Printf > import System.Environment > import Control.Monad (replicateM, liftM) > > {- ********************************************************* > Define the Database Data Types > SpiderDatabase represents a singleton wrapper for an > entire database. > ********************************************************* -} > data SpiderDatabase = SpiderDatabase { > magicNumberA :: Word16, > magicNumberB :: Word16, > majorVers :: Word16, > minorVers :: Word16, > headerTag :: Word16, > poolLen :: Word16, > spiderpool :: [URLSet] > } > data URLSet = URLSet { > urlinfo :: URLInfo, > titleinfo :: TitleInfo, > descrinfo :: DescrInfo, > keywordsinfo :: KeywordsInfo > } > data URLInfo = URLInfo { > tag :: Word8, > urlid :: Word16, > urllen :: Word16, > url :: ByteString > } > data TitleInfo = TitleInfo { > titletag :: Word8, > titlelen :: Word16, > title :: ByteString > } > data DescrInfo = DescrInfo { > descrtag :: Word8, > descrlen :: Word16, > descr :: ByteString > } > data KeywordsInfo = KeywordsInfo { > keywordstag :: Word8, > keywordslen :: Word16, > keywords :: ByteString > } > {- ********************************************************* > Class instances > ********************************************************* -} > instance Show SpiderDatabase where > show db = let magicb = (magicNumberB db) > header = (headerTag db) > poolct = (poolLen db) > in "<<>>\n" ++ > (((printf "Magic: %X %X\n") (magicNumberA db)) > (magicNumberB db)) ++ > printf "URL Pool Count: %d\n" poolct ++ > "<<>>" > > instance Binary URLInfo where > put _ = do BinaryPut.putWord8 0 > get = do > urltag <- getWord8 > idx <- getWord16be > len <- getWord16be > strdata <- BinaryGet.getLazyByteString (fromIntegral len) > return (URLInfo {tag=urltag, urlid=idx, > urllen=len, url=strdata}) > instance Binary DescrInfo where > put _ = do BinaryPut.putWord8 0 > get = do > tag <- getWord8 > len <- getWord16be > strdata <- BinaryGet.getLazyByteString (fromIntegral len) > return (DescrInfo {descrtag=tag, > descrlen=len, > descr=strdata}) > instance Binary TitleInfo where > put _ = do BinaryPut.putWord8 0 > get = do > tag <- getWord8 > len <- getWord16be > strdata <- BinaryGet.getLazyByteString (fromIntegral len) > return (TitleInfo {titletag=tag, > titlelen=len, > title=strdata}) > instance Binary KeywordsInfo where > put _ = do BinaryPut.putWord8 0 > get = do > tag <- getWord8 > len <- getWord16be > strdata <- BinaryGet.getLazyByteString (fromIntegral len) > return (KeywordsInfo {keywordstag=tag, > keywordslen=len, > keywords=strdata}) > instance Binary URLSet where > put _ = do BinaryPut.putWord8 0 > get = do > remainingByteData <- BinaryGet.getRemainingLazyByteString > i :: URLInfo <- decode remainingByteData > j :: TitleInfo <- decode remainingByteData > k :: DescrInfo <- decode remainingByteData > x :: KeywordsInfo <- decode remainingByteData > return (URLSet {urlinfo=i, titleinfo=j, > descrinfo=k, keywordsinfo=x}) > > instance Binary SpiderDatabase where > put _ = do BinaryPut.putWord8 0 > get = do > magicnumbera <- BinaryGet.getWord16be > magicnumberb <- BinaryGet.getWord16be > major <- BinaryGet.getWord16be > minor <- BinaryGet.getWord16be > header <- BinaryGet.getWord16be > poolct <- BinaryGet.getWord16be > -- ******************************* > -- Get the remaining byte string data, > -- So that we can use lazy bytestring to load to load the > -- the data types. > -- ******************************* > remainingByteData <- BinaryGet.getRemainingLazyByteString > -- pool <- (replicate (fromIntegral poolct) (decode > remainingByteData)) z :: URLSet <- decode remainingByteData > return (SpiderDatabase {magicNumberA=magicnumbera, > magicNumberB=magicnumberb, > majorVers=major, > minorVers=minor, > headerTag=header, > poolLen=poolct > }) > main = do > putStrLn "Running Spider Database Reader" > args <- getArgs > db :: SpiderDatabase <- decodeFile (args !! 0) > putStrLn $ show db > putStrLn "Done" > > > *** > *** Error: > > > DbReader.hs:119:22: > No instance for (Binary (Get URLInfo)) > arising from a use of `decode' at DbReader.hs:119:22-45 > Possible fix: > add an instance declaration for (Binary (Get URLInfo)) > In a 'do' expression: i :: URLInfo <- decode remainingByteData > In the expression: > do remainingByteData <- getRemainingLazyByteString > i :: URLInfo <- decode remainingByteData > j :: TitleInfo <- decode remainingByteData > k :: DescrInfo <- decode remainingByteData > .... > In the definition of `get': > get = do remainingByteData <- getRemainingLazyByteString > i :: URLInfo <- decode remainingByteData > j :: TitleInfo <- decode remainingByteData > .... > > DbReader.hs:120:24: > No instance for (Binary (Get TitleInfo)) > arising from a use of `decode' at DbReader.hs:120:24-47 > Possible fix: > add an instance declaration for (Binary (Get TitleInfo)) > In a 'do' expression: j :: TitleInfo <- decode remainingByteData > In the expression: > do remainingByteData <- getRemainingLazyByteString > i :: URLInfo <- decode remainingByteData > j :: TitleInfo <- decode remainingByteData > k :: DescrInfo <- decode remainingByteData > .... > In the definition of `get': > get = do remainingByteData <- getRemainingLazyByteString > i :: URLInfo <- decode remainingByteData > j :: TitleInfo <- decode remainingByteData > .... > > DbReader.hs:121:24: > No instance for (Binary (Get DescrInfo)) > arising from a use of `decode' at DbReader.hs:121:24-47 > Possible fix: > add an instance declaration for (Binary (Get DescrInfo)) > In a 'do' expression: k :: DescrInfo <- decode remainingByteData > In the expression: > do remainingByteData <- getRemainingLazyByteString > i :: URLInfo <- decode remainingByteData > j :: TitleInfo <- decode remainingByteData > k :: DescrInfo <- decode remainingByteData > .... > In the definition of `get': > get = do remainingByteData <- getRemainingLazyByteString > i :: URLInfo <- decode remainingByteData > j :: TitleInfo <- decode remainingByteData > .... > > DbReader.hs:122:27: > No instance for (Binary (Get KeywordsInfo)) > arising from a use of `decode' at DbReader.hs:122:27-50 > Possible fix: > add an instance declaration for (Binary (Get KeywordsInfo)) > In a 'do' expression: x :: KeywordsInfo <- decode remainingByteData > In the expression: > do remainingByteData <- getRemainingLazyByteString > i :: URLInfo <- decode remainingByteData > j :: TitleInfo <- decode remainingByteData > k :: DescrInfo <- decode remainingByteData > .... > In the definition of `get': > get = do remainingByteData <- getRemainingLazyByteString > i :: URLInfo <- decode remainingByteData > j :: TitleInfo <- decode remainingByteData > .... > > DbReader.hs:142:21: > No instance for (Binary (Get URLSet)) > arising from a use of `decode' at DbReader.hs:142:21-44 > Possible fix: add an instance declaration for (Binary (Get URLSet)) > In a 'do' expression: z :: URLSet <- decode remainingByteData > In the expression: > do magicnumbera <- getWord16be > magicnumberb <- getWord16be > major <- getWord16be > minor <- getWord16be > .... > In the definition of `get': > get = do magicnumbera <- getWord16be > magicnumberb <- getWord16be > major <- getWord16be > .... > make: *** [dbreader] Error 1 > > -- > Berlin Brown > [berlin dot brown at gmail dot com] > http://botspiritcompany.com/botlist/? > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From ajb at spamcop.net Thu Jan 3 19:12:11 2008 From: ajb at spamcop.net (ajb@spamcop.net) Date: Thu Jan 3 19:06:05 2008 Subject: [Haskell-cafe] Refactoring status In-Reply-To: <002d01c84e3d$d3dd5ad0$7b981070$@be> References: <002001c84e34$569c9f30$03d5dd90$@be> <002b01c84e3b$8e7c7fe0$ab757fa0$@be> <002d01c84e3d$d3dd5ad0$7b981070$@be> Message-ID: <20080103191211.imy5fb3pssswgg4c@webmail.spamcop.net> G'day all. Quoting Peter Verswyvelen : > I actually meant something more like > http://en.wikipedia.org/wiki/Intentional_programming I'm pretty sure that "Intentional programming" is Hungarian for "I want to sell you another IDE". Cheers, Andrew Bromage From cmb21 at kent.ac.uk Thu Jan 3 19:26:34 2008 From: cmb21 at kent.ac.uk (C.M.Brown) Date: Thu Jan 3 19:20:37 2008 Subject: [Haskell-cafe] Refactoring status In-Reply-To: References: <002001c84e34$569c9f30$03d5dd90$@be> Message-ID: Hi, > A possible first goal would be, to add extensions that are definitely in > Haskell prime, see: > http://hackage.haskell.org/trac/haskell-prime/wiki/Status'#definitely-inProposalStatus Oh great! Thanks for the link, I think the main issue is moving over to a platform that is heavily maintained (such as GHC) and then working towards, say, haskell prime coverage as a first goal. > It would be nice to have it built in to the functional programming > extensions of Eclipse > ( http://eclipsefp.sourceforge.net/ ) Yes, I actually did some work on this but due to time restrictions it was never finished. However, it wouldn't be difficult to add HaRe to any type of interactive environment. HaRe is called from the command prompt and requires positional and region information from the editor together with the facility to display a prompt and read answers. I would love to be able to work with people who may be interested in porting HaRe to editors such as Eclipse... :) Cheers, Chris. From cmb21 at kent.ac.uk Thu Jan 3 19:29:04 2008 From: cmb21 at kent.ac.uk (C.M.Brown) Date: Thu Jan 3 19:23:10 2008 Subject: [Haskell-cafe] Refactoring status In-Reply-To: <41495718.20080104021500@gmail.com> References: <002001c84e34$569c9f30$03d5dd90$@be> <1713055262.20080103220617@gmail.com> <003501c84e43$c6df2fb0$549d8f10$@be> <41495718.20080104021500@gmail.com> Message-ID: On Fri, 4 Jan 2008, Bulat Ziganshin wrote: > Hello Peter, > > Thursday, January 3, 2008, 11:03:58 PM, you wrote: > > > Okay, but when using a syntax directed editor, type signatures can be > > automatically provided because the types are known. > > the same is possible for Haskell - it's possible to add to code type > signatures deduced by the compiler Ha! Yes, HaRe also has the facility to do this.... have I plugged it enough yet? :-) Cheers, Chris. From ross at soi.city.ac.uk Thu Jan 3 20:23:08 2008 From: ross at soi.city.ac.uk (Ross Paterson) Date: Thu Jan 3 20:17:19 2008 Subject: [Haskell-cafe] ANN / CFP - LLVM bindings for Haskell In-Reply-To: <477CCA75.4090101@serpentine.com> References: <477CCA75.4090101@serpentine.com> <20080103184418.GB4775@scytale.galois.com> <477D2E30.7000308@serpentine.com> <20080103185838.GC4775@scytale.galois.com> Message-ID: <20080104012308.GA4809@soi.city.ac.uk> On Thu, 03 Jan 2008 03:43:49 -0800, Bryan O'Sullivan wrote: > (Hackage can't host code that uses GHC 6.8.2's language extension names > yet.) It should be able to now. From allbery at ece.cmu.edu Thu Jan 3 20:23:30 2008 From: allbery at ece.cmu.edu (Brandon S. Allbery KF8NH) Date: Thu Jan 3 20:17:29 2008 Subject: [Haskell-cafe] Instance classes and error (also, related to Data.Binary.GET) In-Reply-To: <20080103231030.M8262@www.botspiritcompany.com> References: <20080103231030.M8262@www.botspiritcompany.com> Message-ID: <9E8BA02D-D2C9-4636-978D-7336803A1A1D@ece.cmu.edu> On Jan 3, 2008, at 18:13 , bbrown wrote: > DbReader.hs:119:22: > No instance for (Binary (Get URLInfo)) > arising from a use of `decode' at DbReader.hs:119:22-45 Without looking more closely, this suggests to me that you have mismatched or incorrectly encapsulated monads (for example, treating a value in the Get monad as if it were pure). This might be related to the way you specify the types of the values obtained from decode. (I haven't used Data.Binary.) -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH From allbery at ece.cmu.edu Thu Jan 3 20:32:27 2008 From: allbery at ece.cmu.edu (Brandon S. Allbery KF8NH) Date: Thu Jan 3 20:26:21 2008 Subject: [Haskell-cafe] Consensus about databases / serialization In-Reply-To: <003701c84e50$1aa3c5f0$4feb51d0$@be> References: <000a01c84d35$b64d3de0$22e7b9a0$@be> <477CEA17.2090306@telenet.be> <2608b8a80801030645w1581fde6pe87b72497555b396@mail.gmail.com> <000c01c84e21$34a33e60$9de9bb20$@be> <2608b8a80801031309x3796eedbgae4f40440094f78b@mail.gmail.com> <003701c84e50$1aa3c5f0$4feb51d0$@be> Message-ID: <1735BCE9-4BAB-4A3F-9842-654B2C3255E2@ece.cmu.edu> On Jan 3, 2008, at 16:32 , Peter Verswyvelen wrote: > I see. But ouch, exactly the same could be said for Haskell no? :) Optimization by quasirandom insertion of bangs / seq? Already there :) -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH From duncan.coutts at worc.ox.ac.uk Thu Jan 3 20:46:51 2008 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Thu Jan 3 20:40:45 2008 Subject: [Haskell-cafe] ANN / CFP - LLVM bindings for Haskell In-Reply-To: <20080104012308.GA4809@soi.city.ac.uk> References: <477CCA75.4090101@serpentine.com> <20080103184418.GB4775@scytale.galois.com> <477D2E30.7000308@serpentine.com> <20080103185838.GC4775@scytale.galois.com> <20080104012308.GA4809@soi.city.ac.uk> Message-ID: <20080104014651.45A4A5001C@webmail217.herald.ox.ac.uk> In message <20080104012308.GA4809@soi.city.ac.uk> Ross Paterson writes: > On Thu, 03 Jan 2008 03:43:49 -0800, Bryan O'Sullivan wrote: > > (Hackage can't host code that uses GHC 6.8.2's language extension names > > yet.) > > It should be able to now. Thanks very much Ross. BTW, I think we should put some HackageDB hacking and admin instructions on the hackage wiki so we don't have to pester you so much for this kind of routine admin stuff. Duncan From bos at serpentine.com Thu Jan 3 21:16:10 2008 From: bos at serpentine.com (Bryan O'Sullivan) Date: Thu Jan 3 21:10:04 2008 Subject: [Haskell-cafe] ANN / CFP - LLVM bindings for Haskell In-Reply-To: <20080104012308.GA4809@soi.city.ac.uk> References: <477CCA75.4090101@serpentine.com> <20080103184418.GB4775@scytale.galois.com> <477D2E30.7000308@serpentine.com> <20080103185838.GC4775@scytale.galois.com> <20080104012308.GA4809@soi.city.ac.uk> Message-ID: <477D96EA.2050309@serpentine.com> Ross Paterson wrote: > It should be able to now. Thank you! References: <20080103231030.M8262@www.botspiritcompany.com> Message-ID: <477D9C3E.30007@brettingham-moore.net> Like the previous no experience with Data.Binary, but my (rusty) monad experience is enough to see the source of the problem: bbrown wrote: > The issue stems from here, it says I didn't define an instance, but I did: > > instance Binary URLSet where > put _ = do BinaryPut.putWord8 0 > get = do > remainingByteData <- BinaryGet.getRemainingLazyByteString > i :: URLInfo <- decode remainingByteData > j :: TitleInfo <- decode remainingByteData > k :: DescrInfo <- decode remainingByteData > x :: KeywordsInfo <- decode remainingByteData > return (URLSet {urlinfo=i, titleinfo=j, > descrinfo=k, keywordsinfo=x}) > > Data.Binary seems to use the Get monad which looks to be a garden variety parsing monad. For line in the do block: i :: URLInfo <- decode remainingByteData Because of the way do notation works x::a <- is expecting a value of M a for a monad M, above Get URLInfo, inplying a type of ByteString -> (Get URLInfo) for decode and therefore the comiler is looking for the corresponding Binary instance (and of course, not finding it since, quite properly, your binary instance is URLInfo not Get URLInfo). If you can't follow this, find a monad tutorial and look at how do notation expands to >>= and >>. The code you have almost certainly isn't doing what you want/expect (even if you fix the bad monad nesting you are trying to repeatedly decode the same data as different types). Not knowing exactly how your data is encoded it is hard to be certain of the correct code but something like this seems more likely (untried): instance Binary URLSet where put _ = do BinaryPut.putWord8 0 get = do i :: URLInfo <- get j :: TitleInfo <- get k :: DescrInfo <- get x :: KeywordsInfo <- get return (URLSet {urlinfo=i, titleinfo=j, descrinfo=k, keywordsinfo=x}) This assumes that the data contains the structures serialized in order. In this case for i the type of get is inferred to Get URLInfo - which will work since URLInfo has a Binary instance. You also have a similar issue in the SpiderDatabase instance. Clive From goalieca at gmail.com Fri Jan 4 01:31:12 2008 From: goalieca at gmail.com (Ryan Dickie) Date: Fri Jan 4 01:25:06 2008 Subject: [Haskell-cafe] ANN / CFP - LLVM bindings for Haskell In-Reply-To: <477CCA75.4090101@serpentine.com> References: <477CCA75.4090101@serpentine.com> Message-ID: <4c69c1be0801032231j587da7dex79f53ca10d262307@mail.gmail.com> On Jan 3, 2008 3:43 AM, Bryan O'Sullivan wrote: > This is an early release of Haskell bindings for the popular LLVM > compiler infrastructure project. > > If you don't know what LLVM is, it's a wonderful toybox of compiler > components, from a complete toolchain supporting multiple architectures > through a set of well-defined APIs and IR formats that are designed for > building interesting software with. > > The official LLVM home page is here: > > http://llvm.org/ > > The Haskell bindings are based on Gordon Henriksen's C bindings. The C > bindings are almost untyped, but the Haskell bindings re-add type safety > to prevent runtime crashes and general badness. > > Currently, the entire code generation system is implemented, with most > LLVM data types supported (notably absent are structs). Also plugged in > is JIT support, so you can generate code at runtime from Haskell and run > it immediately. I've attached an example. > > Please join in the hacking fun! > > darcs get http://darcs.serpentine.com/llvm > > If you want a source tarball, fetch it from here: > > http://darcs.serpentine.com/llvm/llvm-0.0.2.tar.gz > > (Hackage can't host code that uses GHC 6.8.2's language extension names > yet.) > > There's very light documentation at present, but it ought to be enough > to get you going. > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > Maybe I am asking an uninformed n00b question but how come GHC has fvia-C and are also working on an asm backend. Is there any reason why they could not build off the work of LLVM (which supports various architectures) then ditch those two backends and call it a day? --ryan -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080103/cfe6bffe/attachment.htm From jvlask at hotmail.com Fri Jan 4 03:01:55 2008 From: jvlask at hotmail.com (john lask) Date: Fri Jan 4 02:55:47 2008 Subject: [Haskell-cafe] isFunction Message-ID: Oleg provided the following code to test whether a is a function, this code will not type check in hugs, due to the overlapping instances in IsFunction (x->y) f IsFunction x f and the functional dependency | a-> b ERROR "isfunction.lhs":43 - Instances are not consistent with dependencies *** This instance : IsFunction a b *** Conflicts with : IsFunction (a -> b) c *** For class : IsFunction a b *** Under dependency : a -> b is there a way to acheive the same effect in hugs ? > data HTrue > data HFalse > > class IsFunction a b | a -> b > instance TypeCast f HTrue => IsFunction (x->y) f > instance TypeCast f HFalse => IsFunction x f > > -- literally lifted from the HList library > class TypeCast a b | a -> b, b->a where typeCast :: a -> b > class TypeCast' t a b | t a -> b, t b -> a where typeCast' :: t->a->b > class TypeCast'' t a b | t a -> b, t b -> a where typeCast'' :: t->a->b > instance TypeCast' () a b => TypeCast a b where typeCast x = typeCast' () x > instance TypeCast'' t a b => TypeCast' t a b where typeCast' = typeCast'' > instance TypeCast'' () a a where typeCast'' _ x = x _________________________________________________________________ New music from the Rogue Traders - listen now! http://ninemsn.com.au/share/redir/adTrack.asp?mode=click&clientID=832&referral=hotmailtaglineOct07&URL=http://music.ninemsn.com.au/roguetraders From lemming at henning-thielemann.de Fri Jan 4 04:50:16 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Fri Jan 4 04:44:54 2008 Subject: [Haskell-cafe] Refactoring status In-Reply-To: <003501c84e43$c6df2fb0$549d8f10$@be> References: <002001c84e34$569c9f30$03d5dd90$@be> <1713055262.20080103220617@gmail.com> <003501c84e43$c6df2fb0$549d8f10$@be> Message-ID: On Thu, 3 Jan 2008, Peter Verswyvelen wrote: > > I believe type signatures are the very essence of Haskell documentation! > > I'd much rather see a program with type signatures for functions and > > little (or no) comments over programs with no type signatures and > > ambigious comments (if any comments at all!). > > Okay, but when using a syntax directed editor, type signatures can be > automatically provided because the types are known. Types cannot always be derived automatically, especially when coming to Haskell extensions. Sometimes you also want to restrict the type. E.g. for asTypeOf _ y = y you explicitly want the type asTypeOf :: a -> a -> a not the automatically derived one: asTypeOf :: b -> a -> a > Furthermore, IMHO, type signatures alone are not enough, a good parameter > name says at least as much as the type. > > E.g. what does a function Int -> Int -> Bool do? I have no idea. A good > function name helps, e.g. isDivisible:: Int -> Int -> Bool. But then I still > don't know which parameter is the numerator and denominator. So good names > for the parameters are at least as important, e.g. isDivisible :: > numerator:Int -> denonimator:Int -> Bool It's a problem in Haskell that there are no unique parameter names, due to pattern matching. E.g. isDivisible _ 0 = error "division by zero" isDivisible x y = ... I'm tempted to write Haddock comments like {- | check whether @x@ can be divided by @y@ -} isDivisible :: Integral a => a -> a -> a But this does not work, because unique parameter names cannot be extracted from the code and are thus missing in Haddock documentation. If there would not be pattern matching but only 'case' there wouldn't be a problem. isDivisible x y = case (x,y) of (_,0) -> error "division by zero" (x',y') -> ... Or even better, with a fictitious anonymous 'case' you could write: isDivisible = curry $ case (_,0) -> error "division by zero" (x,y) -> ... > > Type signatures really does make dealing with someone elses code that > > much easier. > > Yes, as is good documentation, which unfortunately is still limited to > ASCII. I would prefer to have rich documentation right inside my source > code, with math symbols, drawings, pictures, animations, whatever... ... interactive Haskell sandbox ... From Nicholls.Mark at mtvne.com Fri Jan 4 05:00:21 2008 From: Nicholls.Mark at mtvne.com (Nicholls, Mark) Date: Fri Jan 4 04:54:15 2008 Subject: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? In-Reply-To: <1762133336.20080103215834@gmail.com> References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <1965805939.20080102232921@gmail.com> <915864007.20080103135418@gmail.com> <8627368.20080103173843@gmail.com> <1762133336.20080103215834@gmail.com> Message-ID: You may be right...but learning is not an atomic thing....wherever I start I will get strange things happening. -----Original Message----- From: Bulat Ziganshin [mailto:bulat.ziganshin@gmail.com] Sent: 03 January 2008 18:59 To: Nicholls, Mark Cc: Bulat Ziganshin; haskell-cafe@haskell.org Subject: Re[6]: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? Hello Mark, Thursday, January 3, 2008, 6:40:13 PM, you wrote: it would be hard to understand overlap without knowing both systems. you will believe that you understand it, but things will go strange ways :) > I do not necessarily disagree.... > But if I can identify the overlap....then I have leant the overlap...on > the cheap. > > -----Original Message----- > From: Bulat Ziganshin [mailto:bulat.ziganshin@gmail.com] > Sent: 03 January 2008 14:39 > To: Nicholls, Mark > Cc: Bulat Ziganshin; haskell-cafe@haskell.org > Subject: Re[4]: [Haskell-cafe] Is there anyone out there who can > translate C# generics into Haskell? > Hello Mark, > Thursday, January 3, 2008, 2:13:08 PM, you wrote: > of course *some* overlap exists but in order to understand it you > should know exact shape of both methods > when i tried to develop complex library without understanding t.c. > implementation, i constantly goes into the troubles - things that i > (using my OOP experience) considered as possible, was really > impossible in Haskell > so i'm really wonder why you don't want to learn the topic thoroughly >> I loosely do understand....but very loosely....but I'm not, as yet, >> convinced it is completely relevant. >> The implementation may differ, but that does not mean that there is no >> overlap....I am not expecting one model to be a superset of the other, >> but I am expecting some sort of overlap between 'interface' >> implementation and type class instance declaration. >> -----Original Message----- >> From: Bulat Ziganshin [mailto:bulat.ziganshin@gmail.com] >> Sent: 03 January 2008 10:54 >> To: Nicholls, Mark >> Cc: Bulat Ziganshin; haskell-cafe@haskell.org >> Subject: Re[2]: [Haskell-cafe] Is there anyone out there who can >> translate C# generics into Haskell? >> Hello Mark, >> Thursday, January 3, 2008, 1:22:26 PM, you wrote: >> because they have different models. i recommend you to start from >> learning this model, otherwise you will don't understand how Haskell >> really works and erroneously apply your OOP knowledge to Haskell data >> structures. >> shortly said, there are 3 ways to polymorphism: >> 1) C++ templates - type-specific code generated at compile time >> 2) OOP classes - every object carries VMT which allows to select >> type-specific operation >> 3) type classes - dictionary of type-specific operations is given as >> additional hidden argument to each function >> Haskell uses t.c. and its abilities are dictated by this >> implementation. there is no simple and direct mapping between >> features provided by OOP and t.c. >>> Can you give me a summary of why it's meaningless.....both would seem >> to >>> describe/construct values/objects....they may not be equivalent, but > I >>> would expect some considerable overlap. >>> -----Original Message----- >>> From: Bulat Ziganshin [mailto:bulat.ziganshin@gmail.com] >>> Sent: 02 January 2008 20:29 >>> To: Nicholls, Mark >>> Cc: haskell-cafe@haskell.org >>> Subject: Re: [Haskell-cafe] Is there anyone out there who can >> translate >>> C# generics into Haskell? >>> Hello Mark, >>> Wednesday, January 2, 2008, 7:40:31 PM, you wrote: >>>> I'm trying to translate some standard C# constucts into Haskell... >>> some >>> it's meaningless. read >>> http://haskell.org/haskellwiki/OOP_vs_type_classes >>> and especially papers mentioned in the References -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From apfelmus at quantentunnel.de Fri Jan 4 06:59:59 2008 From: apfelmus at quantentunnel.de (apfelmus) Date: Fri Jan 4 06:54:10 2008 Subject: [Haskell-cafe] Re: An interesting monad: "Prompt" In-Reply-To: References: <2f9b2d30711181622v4bb2c33bn69dbc263c514d580@mail.gmail.com> Message-ID: Felipe Lessa wrote: > Ryan Ingram wrote: > [snip] >>> data Prompt (p :: * -> *) :: (* -> *) where >>> PromptDone :: result -> Prompt p result >>> -- a is the type needed to continue the computation >>> Prompt :: p a -> (a -> Prompt p result) -> Prompt p result > [snip] >>> runPromptM :: Monad m => (forall a. p a -> m a) -> Prompt p r -> m r >>> runPromptM _ (PromptDone r) = return r >>> runPromptM f (Prompt pa c) = f pa >>= runPromptM f . c > [snip] > > How can we prove that (runPromptM prompt === id)? I was trying to go with You probably mean runPromptM id = id > runPromptM prompt (PromptDone r) > = return r > = PromptDone r > > runPromptM prompt (Prompt pa c) > = prompt pa >>= runPromptM prompt . c > = Prompt pa return >>= runPromptM prompt . c > = Prompt pa ((>>= (runPromptM prompt . c) . return) > = Prompt pa (runPromptM prompt . c) > > .... and I got stuck here. It "seems obvious" that we can strip out the > 'runPromptM prompt' down there to finish the proof, but that doesn't > sound very nice, as I'd need to suppose what I'm trying to prove. Am I > missing something here? You want to deduce runPromptM id (Prompt pa c) = Prompt pa c from runPromptM id (Prompt pa c) = Prompt pa (runPromptM id . c) by somehow assuming that runPromptM id = id at least when applied to c . If it were a problem about lists like foldr (:) [] = id you could use mathematical induction . You can do the same here, but you need to use coinduction. For more, see also http://www.cs.nott.ac.uk/~gmh/bib.html#corecursion Regards, apfelmus From simonmarhaskell at gmail.com Fri Jan 4 07:08:24 2008 From: simonmarhaskell at gmail.com (Simon Marlow) Date: Fri Jan 4 07:02:22 2008 Subject: [Haskell-cafe] Re: [darcs-devel] announcing darcs 2.0.0pre2 In-Reply-To: <20080103170924.GE11036@darcs.net> References: <20071216211722.GI11101@darcs.net> <47666BA0.2080408@microsoft.com> <20071221143254.GO11036@darcs.net> <477CC2EC.2030302@microsoft.com> <20080103170924.GE11036@darcs.net> Message-ID: <477E21B8.4020405@microsoft.com> David Roundy wrote: > On Thu, Jan 03, 2008 at 11:11:40AM +0000, Simon Marlow wrote: >> David Roundy wrote: >>> Anyhow, could you retry this test with the above change in methodology, and >>> let me know if (a) the pull is still slow the first time and (b) if it's >>> much faster the second time (after the reverse unpull/pull)? >> I think I've done it in both directions now, and it got faster, but still >> much slower than darcs1: >> >> $ time darcs2 unpull --from-tag 2007-09-25 -a >> Finished unpulling. >> 58.68s real 50.64s user 6.36s system 97% darcs2 unpull --from-tag >> 2007-09-25 -a >> $ time darcs2 pull -a ../ghc-darcs2 >> Pulling from "../ghc-darcs2"... >> Finished pulling and applying. >> 53.28s real 44.62s user 7.10s system 97% darcs2 pull -a ../ghc-darcs2 >> >> This is still an order of magnitude slower than darcs1 for the same >> operation. (these times are now on the local filesystem, BTW) > > Is this with the latest darcs-unstable? I made some improvements shortly > before Christmas (or was it after Christmas?) that ought to improve the > speed of pulls dramatically. We were doing O(N^2) operations in our > handling of "pending" changes, which I fixed (I think). So I'll wait on > investigating this until you've confirmed which version this was tested > with. And thanks for the testing! This is using a binary I compiled up from the latest sources yesterday, so it should have those improvements. Cheers, Simon From felipe.lessa at gmail.com Fri Jan 4 08:46:13 2008 From: felipe.lessa at gmail.com (Felipe Lessa) Date: Fri Jan 4 08:40:06 2008 Subject: [Haskell-cafe] Re: An interesting monad: "Prompt" In-Reply-To: References: <2f9b2d30711181622v4bb2c33bn69dbc263c514d580@mail.gmail.com> Message-ID: On Jan 4, 2008 9:59 AM, apfelmus wrote: > Felipe Lessa wrote: > > How can we prove that (runPromptM prompt === id)? I was trying to go with > > You probably mean > > runPromptM id = id > Actually, I meant an specialization of 'runPromptM prompt': runPromptM id :: (Monad p) => Prompt p r -> p r runPromptM prompt :: (MonadPrompt p m) => Prompt p r -> m r runPromptM (prompt :: p a -> Prompt p a) :: Prompt p r -> Prompt p r [snip] > you could use mathematical induction . You can do the same here, but > you need to use coinduction. For more, see also > > http://www.cs.nott.ac.uk/~gmh/bib.html#corecursion > Thanks for the tip! So I can define > approx :: Integer -> Prompt p r -> Prompt p r > approx (n+1) (PromptDone r) = PromptDone r > approx (n+1) (Prompt p c) = Prompt p (approx n . c) > > runId :: Prompt p r -> Prompt p r > runId = runPromptM prompt and try to prove that ?n. approx n (id x) == approx n (runId x) We can see trivially that approx n (id (PromptDone r)) == approx n (runId (PromptDone r)) For the case that x is (Prompt p c), we'll prove using induction. The base case n = 0 is trivially proven as ?x. approx 0 x == ?. For the indutive case, approx (m+1) (runId (Prompt p c)) -- definition of runId = approx (m+1) (runPromptM prompt (Prompt p c)) -- definition of runPromptM for the Prompt case = approx (m+1) (prompt p >>= runPromptM prompt . c) -- definition of prompt in the Prompt instance = approx (m+1) (Prompt p return >>= runPromptM prompt . c) -- definition of (>>=) in the Prompt instance = approx (m+1) (Prompt p ((>>= runPromptM prompt . c) . return)) -- monad law '(return x >>= f) == f x' = approx (m+1) (Prompt p (runPromptM prompt . c)) -- definition of approx = Prompt p (approx m . runPromptM prompt . c) -- definition of runId = Prompt p (approx m . runId . c) -- definition of (.) twice = Prompt p (\x -> approx m (runId (c x))) -- induction hypothesis = Prompt p (\x -> approx m (id (c x)) -- definition of (.) twice = Prompt p (approx m . id . c) -- definition of approx = approx (m+1) (Prompt p (id . c)) -- law 'id . f == f' = approx (m+1) (Prompt p c) -- law 'x == id x' = approx (m+1) (id (Prompt p c)) Which was to be proven. ? I think I didn't commit any mistake above =). Thanks again for help, -- Felipe. From jules at jellybean.co.uk Fri Jan 4 12:46:12 2008 From: jules at jellybean.co.uk (Jules Bean) Date: Fri Jan 4 12:40:05 2008 Subject: [Haskell-cafe] GHC on LLVM (was Re: ANN / CFP - LLVM bindings for Haskell) In-Reply-To: <4c69c1be0801032231j587da7dex79f53ca10d262307@mail.gmail.com> References: <477CCA75.4090101@serpentine.com> <4c69c1be0801032231j587da7dex79f53ca10d262307@mail.gmail.com> Message-ID: <477E70E4.1000002@jellybean.co.uk> Ryan Dickie wrote: > Maybe I am asking an uninformed n00b question but how come GHC has > fvia-C and are also working on an asm backend. Is there any reason why > they could not build off the work of LLVM (which supports various > architectures) then ditch those two backends and call it a day? You are not the first to think of it, and surely not the last! Whilst it's a very interesting idea, I believe there are reasons why it may not solve all our problems: http://www.haskell.org/pipermail/glasgow-haskell-users/2006-December/011794.html http://www.haskell.org/pipermail/glasgow-haskell-users/2006-December/011795.html and others in that thread. Jules From bf3 at telenet.be Fri Jan 4 13:19:40 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Fri Jan 4 13:13:46 2008 Subject: [Haskell-cafe] Refactoring status In-Reply-To: References: <002001c84e34$569c9f30$03d5dd90$@be> <1713055262.20080103220617@gmail.com> <003501c84e43$c6df2fb0$549d8f10$@be> Message-ID: <001e01c84efe$5f386410$1da92c30$@be> > Types cannot always be derived automatically, especially when coming to > Haskell extensions. Sometimes you also want to restrict the type. E.g. for > asTypeOf _ y = y > you explicitly want the type > asTypeOf :: a -> a -> a > not the automatically derived one: > asTypeOf :: b -> a -> a Yes, sometimes it is neccerary to give an explicit type. But in so many cases, type inference works fine no? What I usually do, is use the GHCi t: command, copy/paste that in my code, and then make the type signature more specific if it has to be. It's often funny to see how generic the code really is :) I wonder what a typical LISP/Scheme programmer thinks of type signatures... > It's a problem in Haskell that there are no unique parameter names, due to > pattern matching. Yes, but it would be nice to attach some "parameter-comment" to the types no? Now a lot of documentation is written in the style "the 7th parameter is...". Not very user friendly :) Cheers, Peter From bf3 at telenet.be Fri Jan 4 13:23:12 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Fri Jan 4 13:17:03 2008 Subject: [Haskell-cafe] Refactoring status In-Reply-To: References: <002001c84e34$569c9f30$03d5dd90$@be> <1713055262.20080103220617@gmail.com> <003501c84e43$c6df2fb0$549d8f10$@be> <41495718.20080104021500@gmail.com> Message-ID: <001f01c84efe$dd9c0af0$98d420d0$@be> >> the same is possible for Haskell - it's possible to add to code type >> signatures deduced by the compiler > Ha! Yes, HaRe also has the facility to do this.... have I plugged it > enough yet? :-) Sounds great! But could you add support for arrows so I can use it for my Yampa experiments? Please? :) ;) From felipe.lessa at gmail.com Fri Jan 4 13:38:43 2008 From: felipe.lessa at gmail.com (Felipe Lessa) Date: Fri Jan 4 13:32:36 2008 Subject: [Haskell-cafe] Refactoring status In-Reply-To: <001e01c84efe$5f386410$1da92c30$@be> References: <002001c84e34$569c9f30$03d5dd90$@be> <1713055262.20080103220617@gmail.com> <003501c84e43$c6df2fb0$549d8f10$@be> <001e01c84efe$5f386410$1da92c30$@be> Message-ID: On Jan 4, 2008 4:19 PM, Peter Verswyvelen wrote: > Yes, but it would be nice to attach some "parameter-comment" to the types > no? Now a lot of documentation is written in the style "the 7th parameter > is...". Not very user friendly :) Haddock allows you to put documentation inside the parameters. If you function has that number of arguments, you can name them in the parameter docs. -- Felipe. From lemming at henning-thielemann.de Fri Jan 4 14:37:53 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Fri Jan 4 14:31:47 2008 Subject: [Haskell-cafe] Refactoring status In-Reply-To: <001e01c84efe$5f386410$1da92c30$@be> References: <002001c84e34$569c9f30$03d5dd90$@be> <1713055262.20080103220617@gmail.com> <003501c84e43$c6df2fb0$549d8f10$@be> <001e01c84efe$5f386410$1da92c30$@be> Message-ID: On Fri, 4 Jan 2008, Peter Verswyvelen wrote: > Yes, sometimes it is neccerary to give an explicit type. But in so many > cases, type inference works fine no? What I usually do, is use the GHCi t: > command, copy/paste that in my code, and then make the type signature more > specific if it has to be. It's often funny to see how generic the code > really is :) Indeed. > > It's a problem in Haskell that there are no unique parameter names, due to > > pattern matching. > > Yes, but it would be nice to attach some "parameter-comment" to the types > no? Now a lot of documentation is written in the style "the 7th parameter > is...". Not very user friendly :) It's already possible to write asTypeOf :: a {- ^ the input value to be passed through -} -> a {- ^ the value is ignored, but the type is unified with the first parameter -} -> a {- ^ the value of the first parameter -} From bf3 at telenet.be Fri Jan 4 14:52:37 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Fri Jan 4 14:46:26 2008 Subject: [Haskell-cafe] Refactoring status In-Reply-To: References: <002001c84e34$569c9f30$03d5dd90$@be> <1713055262.20080103220617@gmail.com> <003501c84e43$c6df2fb0$549d8f10$@be> <001e01c84efe$5f386410$1da92c30$@be> Message-ID: <002301c84f0b$5b3fedd0$11bfc970$@be> > It's already possible to write > asTypeOf :: > a {- ^ the input value to be passed through -} > -> a {- ^ the value is ignored, but the type is unified with the first parameter -} > -> a {- ^ the value of the first parameter -} Nice. Still using "first parameter" though ;-) From felipe.lessa at gmail.com Fri Jan 4 15:13:26 2008 From: felipe.lessa at gmail.com (Felipe Lessa) Date: Fri Jan 4 15:07:19 2008 Subject: [Haskell-cafe] Refactoring status In-Reply-To: <002301c84f0b$5b3fedd0$11bfc970$@be> References: <002001c84e34$569c9f30$03d5dd90$@be> <1713055262.20080103220617@gmail.com> <003501c84e43$c6df2fb0$549d8f10$@be> <001e01c84efe$5f386410$1da92c30$@be> <002301c84f0b$5b3fedd0$11bfc970$@be> Message-ID: On Jan 4, 2008 5:52 PM, Peter Verswyvelen wrote: > > It's already possible to write > > asTypeOf :: > > a {- ^ the input value to be passed through -} > > -> a {- ^ the value is ignored, but the type is unified with the first > parameter -} > > -> a {- ^ the value of the first parameter -} > > Nice. Still using "first parameter" though ;-) -- | Pass through the input value but forces unification -- of its type with the type of the other argument. asTypeOf :: a -- ^ The input value to be passed through. -> a -- ^ The other value whose type will be unified. -> a -- ^ The input value. asTypeOf = const -- Felipe. From paulrbrown+haskell-cafe at gmail.com Fri Jan 4 15:43:59 2008 From: paulrbrown+haskell-cafe at gmail.com (Paul Brown) Date: Fri Jan 4 15:37:52 2008 Subject: [Haskell-cafe] ANN / CFC: minimalistic haskell blogging web application (perpubplat) Message-ID: <4249453d0801041243i2b656ec7y1038e05a6aa44480@mail.gmail.com> All -- I've spent some time on cleaning up my hobby blog publishing software and setting up a darcs repository, so I'll throw it out there for criticism or suggestions: darcs get http://datapr0n.com/repos/perpubplat It's running my blog (http://mult.ifario.us). It's relatively lightweight in that it doesn't use a framework but still weighs in at <1500 LOC with comments, but it does rely on the (Thanks, Bjorn!) FastCGI and XHTML combinator libraries. I have some plans for handling comments and the like, but things I'd like to figure out: - Turn the blog data model into a monad. - An idiomatic approach to handling conditional GET and E-Tag, i.e., send a 304 response if things aren't modified. Thanks in advance. -- paulrbrown@gmail.com http://mult.ifario.us/ From lemming at henning-thielemann.de Fri Jan 4 15:46:38 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Fri Jan 4 15:40:30 2008 Subject: [Haskell-cafe] Refactoring status In-Reply-To: <002301c84f0b$5b3fedd0$11bfc970$@be> References: <002001c84e34$569c9f30$03d5dd90$@be> <1713055262.20080103220617@gmail.com> <003501c84e43$c6df2fb0$549d8f10$@be> <001e01c84efe$5f386410$1da92c30$@be> <002301c84f0b$5b3fedd0$11bfc970$@be> Message-ID: On Fri, 4 Jan 2008, Peter Verswyvelen wrote: > > It's already possible to write > > asTypeOf :: > > a {- ^ the input value to be passed through -} > > -> a {- ^ the value is ignored, but the type is unified with the first > parameter -} > > -> a {- ^ the value of the first parameter -} > > Nice. Still using "first parameter" though ;-) This was the problem I mentioned earlier. I tend to write comments like {- | @asTypeOf x y@ returns the value of @x@, while the types of @x@ and @y@ are unified -} asTypeOf :: a -> a -> a This way I can introduce parameter names for the reader. From bf3 at telenet.be Fri Jan 4 16:20:09 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Fri Jan 4 16:14:01 2008 Subject: [Haskell-cafe] Refactoring status In-Reply-To: References: <002001c84e34$569c9f30$03d5dd90$@be> <1713055262.20080103220617@gmail.com> <003501c84e43$c6df2fb0$549d8f10$@be> <001e01c84efe$5f386410$1da92c30$@be> <002301c84f0b$5b3fedd0$11bfc970$@be> Message-ID: <002401c84f17$95f96210$c1ec2630$@be> >> Nice. Still using "first parameter" though ;-) > This was the problem I mentioned earlier. > I tend to write comments like > {- | @asTypeOf x y@ returns the value of @x@, while the types of @x@ and @y@ are unified -} > asTypeOf :: a -> a -> a > This way I can introduce parameter names for the reader. Ah, okay, I get it now. Sorry, I did not get much sleep yesterday ;-) From igloo at earth.li Fri Jan 4 17:05:47 2008 From: igloo at earth.li (Ian Lynagh) Date: Fri Jan 4 16:59:38 2008 Subject: [Haskell-cafe] HsColour version confusion In-Reply-To: <477D2575.1040306@iee.org> References: <477D2575.1040306@iee.org> Message-ID: <20080104220547.GA16488@matrix.chaos.earth.li> On Thu, Jan 03, 2008 at 06:12:05PM +0000, Adrian Hey wrote: > > ..the latest version is 1.9. But the latest version in Hackage is 1.6, > the latest version in the ftp downloads dir is 1.8, unless you want a > pre-compiled windows version in which case you're stuck with 1.3 :-) The "history" looks like it is just a changelog, so it can contain changes that have been made in darcs but not yet released. 1.8 is the latest released version (use the tarball/zip, don't get it from darcs), but not everywhere is up-to-date. Thanks Ian From gwern0 at gmail.com Fri Jan 4 17:53:26 2008 From: gwern0 at gmail.com (gwern0@gmail.com) Date: Fri Jan 4 17:48:10 2008 Subject: [Haskell-cafe] Re: Hackage web page In-Reply-To: <20080102172004.3C121A8002@webmail223.herald.ox.ac.uk> References: <404396ef0801020830t7a6f8bc3ydf01ca829a2af778@mail.gmail.com> <20080102172004.3C121A8002@webmail223.herald.ox.ac.uk> Message-ID: <20080104225326.GA2044@localhost> On 2008.01.02 17:20:04 +0000, Duncan Coutts scribbled 0.8K characters: > In message <404396ef0801020830t7a6f8bc3ydf01ca829a2af778@mail.gmail.com> "Neil > Mitchell" writes: > > Hi, > > > > The hackage web page confuses me: > > http://hackage.haskell.org/packages/hackage.html > > > Hackage has now graduated from being a nice idea to being a critial > > user-focused thingy, which is great. Perhaps the website needs a > > little bit of thought along those lines. This isn't intended to be a > > complaint at all - just a new perspective to the people who develop it > > and probably don't read the web page at all. > > You're quite right. We'd welcome a rewrite. You or anyone else is most welcome > to send us a new version in .html or any other format. > > If there are no immediate volunteers then someone should file a bug against the > HackageDB component in our tracker so we do not forget. > http://hackage.haskell.org/trac/hackage > > Duncan Is there any Darcs repo for the Hackage HTML, or does it just sort of exist by itself on the servers? -- gwern Ridge 9705 Rubin WID Venezuela Analyzer NAIAG naphthalene Privacy AGT. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080104/4067b644/attachment.bin From dons at galois.com Sat Jan 5 00:37:41 2008 From: dons at galois.com (Don Stewart) Date: Sat Jan 5 00:31:42 2008 Subject: [Haskell-cafe] bytestring 0.9.0.4 Message-ID: <20080105053741.GA15950@scytale.galois.com> 2.5 years after the first release, bytestring 0.9.0.4 is now available on hackage, http://hackage.haskell.org/cgi-bin/hackage-scripts/package/bytestring-0.9.0.4 Changes since the 0.9 release include: * support for bytestring literals (use -XOverloadedStrings) * make Data.ByteString.Lazy.Char8.lines lazier * fixes Handle resource leak in getContents/readFile * faster isSpace operations * performance improvements The most notable change is the instance IsString for strict and lazy bytestrings, enabling bytestrings to be written as direct string literals, without needing 'pack'. That is, the following is valid: import Data.ByteString.Char8 main = print ("abcdef" :: ByteString) (and the compile will even turn the pack into a no-op at compile time). Or, using the (soon to be released pcre-light package), bytestring regex literals can be written as: compile "a(.*)b" where compile :: ByteString -> Either String Regex With -XOverloadedStrings, the 'pack'for the regex is inferred. -- Don & Duncan From golubovsky at gmail.com Sat Jan 5 10:14:47 2008 From: golubovsky at gmail.com (Dimitry Golubovsky) Date: Sat Jan 5 10:08:40 2008 Subject: [Haskell-cafe] CouchDB module in Yhc source tree: clarification, and small problems with other packages Message-ID: Hi, Don asked: > Are we likely to see the couchdb bindings released as a standalone > library for the wider community? Let me explain a little bit why the CouchDB module appears in the Yhc repo. As the next stage of the Yhc/Javascript project, I am trying to set up a web service where people might upload some Haskell code (or reference to such code, these details haven't been clarified yet), and get it compiled by background Yhc/ycr2js batch job, returning a HTML page with Javascript in response. CouchDB was picked* as intermediate storage for this project. Therefore an interface module was needed, so I wrote one. This module, `Database.CouchDB' is not 100% finished; it was coded up to satisfy the needs of the first utility I wrote, `cdbup' which is currently capable of uploading a text (utf-8 expected) or a binary file as a document attachment to CouchDB. So some functionality hasn't been coded yet, although it will definitely be, as the project develops. Regarding packaging, I hope I will eventually put it on Hackage, but there are some problems with another packages which I'll try to explain here, so maybe those packages' developers suggest something. 1. Text.JSON. This module was picked from Jun Mukai's haskellnet package (http://darcs.haskell.org/SoC/haskellnet/). One problem with this package, it needs too many dependencies (while JSON module relies only on Packrat parser). I had to extract the JSON module into Yhc tree; can the haskellnet package be split somehow into orthogonal sub-packages, and maybe one toplevel package which would pull all parts together if used? 2. Text.JSON again. I had to change the pNumber function (parser for numeric nodes) replacing the '1'..'9' digits range with '0' .. '9'. Otherwise it did not handle JSON-encoded numbers equal to zero. I am not sure I was 100% right, so perhaps some JSON experts here might correct me. 3. Packrat parser does not seem to be packaged anywhere else, does it? 4. The dataenc package (http://code.haskell.org/dataenc/devo/) from which I pulled the Codec.Binary.Base64 module. The package may need some adjustment to GHC 6.8.x packages structure as only "base" listed in build-depends does not seem to be enough: when building it, Cabal complains for hidden packages such as collections (which I had to add manually to the cabal file), etc. Is it some problem with my GHC setup, or does just the dataenc.cabal need to be updated? So, in order to get things done quicker, I pulled the said pieces from their packages into Yhc tree. For packaging the CouchDB interface, definitely these duplicates need to be removed. Other packages that CouchDB relies upon, are**: base, network, HTTP, filepath, base64-string, utf8-string Thanks for the interest in CouchDB interface, and feel free to ask any questions. --- * before support form IBM/Apache was announced, but this recent development definitely increases interest to CouchDB ** Just from the -package options I used to compile it; I may have something omitted here. -- Dimitry Golubovsky Anywhere on the Web From dave at zednenem.com Sat Jan 5 14:52:52 2008 From: dave at zednenem.com (David Menendez) Date: Sat Jan 5 14:46:44 2008 Subject: [Haskell-cafe] Re: bytestring 0.9.0.4 In-Reply-To: <20080105053741.GA15950@scytale.galois.com> References: <20080105053741.GA15950@scytale.galois.com> Message-ID: <49a77b7a0801051152i8c2d869m3b5560d4aaecbe20@mail.gmail.com> On Jan 5, 2008 12:37 AM, Don Stewart wrote: > The most notable change is the instance IsString for strict and > lazy bytestrings, enabling bytestrings to be written as direct string > literals, without needing 'pack'. > > That is, the following is valid: > > import Data.ByteString.Char8 > > main = print ("abcdef" :: ByteString) > What encoding is used? -- Dave Menendez -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080105/129f22bc/attachment.htm From dons at galois.com Sat Jan 5 15:19:33 2008 From: dons at galois.com (Don Stewart) Date: Sat Jan 5 15:13:22 2008 Subject: [Haskell-cafe] Re: bytestring 0.9.0.4 In-Reply-To: <49a77b7a0801051152i8c2d869m3b5560d4aaecbe20@mail.gmail.com> References: <20080105053741.GA15950@scytale.galois.com> <49a77b7a0801051152i8c2d869m3b5560d4aaecbe20@mail.gmail.com> Message-ID: <20080105201933.GC17767@scytale.galois.com> dave: > On Jan 5, 2008 12:37 AM, Don Stewart <[1]dons@galois.com> wrote: > > The most notable change is the instance IsString for strict and > lazy bytestrings, enabling bytestrings to be written as direct string > literals, without needing 'pack'. > > That is, the following is valid: > > import Data.ByteString.Char8 > > main = print ("abcdef" :: ByteString) > > What encoding is used? The 'Data.ByteString.Char8' encodin: -- ... these byte strings are taken to be in the -- subset of Unicode covered by code points 0-255. This covers -- Unicode Basic Latin, Latin-1 Supplement and C0+C1 Controls. You'll need to import Data.ByteString.Char8 to get the instance, so the encoding should be clear in this case. -- Don From ben.franksen at online.de Sat Jan 5 17:30:55 2008 From: ben.franksen at online.de (Ben Franksen) Date: Sat Jan 5 17:26:32 2008 Subject: [Haskell-cafe] Re: The Worker/Wrapper Transformation References: <20080103105916.7d562d17@solaris.tower> Message-ID: Achim Schneider wrote: > ...is a paper about automatic specialisation of functions by unboxing > arguments, one could say. I'm only on page 6, but already survived the > first formalisms, which is bound to mean that the rest of the paper is > likewise accessible, as hinted on at ltu. > > http://www.cs.nott.ac.uk/~gmh/wrapper.pdf > > The transformation itself is mindbogglingly easy, which makes this a > good start: You only have to understand the formalisms, not so much what > the formalisms are representing. To quote spj: It usually turns out to > be more interesting and challenging than it seemed at first. > > I'm tempted to write that this is a paper for everyone trying to figure > out what the heck Jonathan is talking about. Hey Achim many thanks for bringing this wonderful paper to my attention. Dijkstra's soul breethes out of every equation... Cheers Ben From ben.franksen at online.de Sat Jan 5 18:08:46 2008 From: ben.franksen at online.de (Ben Franksen) Date: Sat Jan 5 18:04:22 2008 Subject: [Haskell-cafe] Re: The Worker/Wrapper Transformation References: <20080103105916.7d562d17@solaris.tower> <477CD928.20706@charter.net> Message-ID: Isaac Dupree wrote: > Achim Schneider wrote: >> http://www.cs.nott.ac.uk/~gmh/wrapper.pdf >> > on page 6, stronger vs weaker seemed backwards to me... isn't (wrap ? > unwrap = idA) a stronger condition than (wrap ? unwrap ? body = body), > because it tells you more, and is true in fewer cases? (which is also > why you want to assume (wrap ? unwrap = idA) when you can, because it's > the most useful one for subsequent program transformation) Ah, thanks you say that, I have been asking myself if that was just me, having things backward. In my book, stronger => weaker, too. Cheers Ben From dons at galois.com Sat Jan 5 19:20:46 2008 From: dons at galois.com (Don Stewart) Date: Sat Jan 5 19:14:37 2008 Subject: [Haskell-cafe] Haskell Weekly News: Issue 68 - January 05, 2008 Message-ID: <20080106002046.GA18375@scytale.galois.com> --------------------------------------------------------------------------- Haskell Weekly News Issue 68 - January 05, 2008 --------------------------------------------------------------------------- Welcome to issue 68 of HWN, a newsletter covering developments in the [1]Haskell community. This HWN features new releases of the GHC and nhc98 Haskell compilers, a pre-release of darcs 2.0, several new user groups formed, and of course, more than 100 updated and new libraries 1. http://haskell.org/ Announcements GHC 6.8.2. The GHC Team [2]announced the release of GHC 6.8.2, featuring optimisation improvements, improvements to ghci and fixes to standalone deriving. 2. http://www.haskell.org/ghc/download_ghc_682.html nhc98 1.2 released. Malcolm Wallace [3]announced the release of nhc98 1.2. 1.20 is a refreshed release with many of the current core library packages included, and a variety of small bugfixes since the last release. It successfully compiles and runs more programs from the nobench suite than jhc, hbc, Hugs, or yhc. It generates an interpreted bytecode that, on the whole runs faster than that generated by Hugs or yhc, and in many cases is also faster than ghci. Although nhc98 is written in Haskell, you don't need an existing Haskell compiler on your platform to build nhc98 - a C compiler will do. Hence, it is portable to almost any unix-like machine with a 32-bit compatibility mode. Many useful build tools come included: hmake (the inspiration for ghc --make), hi (interactive read-eval-print, like Hugs or ghci), cpphs (Haskell-aware replacement for cpp) and hsc2hs (preprocessor for FFI code) 3. http://article.gmane.org/gmane.comp.lang.haskell.general/15770 darcs 2.0.0pre2. David Roundy [4]announced the availability of the second prerelease of [5]darcs two, darcs 2.0.0pre2. This release fixes several severe performance bugs that were present in the first prerelease. These issues were identified and fixed thanks to the helpful testing of Simon Marlow and Peter Rockai. We also added support for compilation under ghc 6.4, so even more users should be able to test this release. 4. http://article.gmane.org/gmane.comp.lang.haskell.cafe/33483 5. http://darcs.net/ The Monad.Reader Issue 9: SoC special. Wouter Swierstra [6]announced a new issue of The Monad.Reader, a 'Summer of Code Special' - it consists of three articles from student participants of Google's Summer of Code, describing the projects they worked on. 6. http://article.gmane.org/gmane.comp.lang.haskell.cafe/31848 What's happening with Haskell? The 13th HCAR. Andres Loeh [7]announced the 13th edition of the Haskell Communities and Activities Report 7. http://www.haskell.org/communities/ Teach yourself gtk2hs in 21 hours. Hans van Thiel [8]announced a Gtk2Hs basics tutorial, based on the Tony Gale and Ian Main GTK+2.0 tutorial, is now available for review and comment. 8. http://article.gmane.org/gmane.comp.lang.haskell.cafe/32671 Minimalistic Haskell blog framework. Paul Brown [9]announced a lightweight, experimental blog publishing application, [10]perpubplat 9. http://article.gmane.org/gmane.comp.lang.haskell.cafe/34503 10. http://datapr0n.com/repos/perpubplat atom. Tom Hawkins [11]announced the release of atom 2007.12; atom is a domain-specific language embedded in Haskell for describing real-time control applications 11. http://www.haskell.org/pipermail/haskell-cafe/2007-December/035742.html Hackage New and updated libraries in [12]the Hackage library database. 12. http://hackage.haskell.org/ * bytestring 0.9.0.4. Uploaded by DonaldStewart. [13]bytestring: Fast, packed, strict and lazy byte arrays with a list interface. * uuagc 0.9.5. Uploaded by ArieMiddelkoop. [14]uuagc: Attribute Grammar System of Universiteit Utrecht. * uulib 0.9.5. Uploaded by ArieMiddelkoop. [15]uulib: Haskell Utrecht Tools Library. * llvm 0.0.2. Uploaded by BryanOSullivan. [16]llvm: Bindings to the LLVM compiler toolkit. * HDBC-sqlite3 1.1.3.1. Uploaded by JohnGoerzen. [17]HDBC-sqlite3: Sqlite v3 driver for HDBC. * HDBC-odbc 1.1.3.1. Uploaded by JohnGoerzen. [18]HDBC-odbc: ODBC driver for HDBC. * dimensional 0.7.2. Uploaded by BjornBuckwalter. [19]dimensional: Statically checked physical dimensions.. * uulib 0.9.5. Uploaded by ArieMiddelkoop. [20]uulib: Haskell Utrecht Tools Library. * hsc3 0.1. Uploaded by RohanDrape. [21]hsc3: Haskell SuperCollider. * hosc 0.1. Uploaded by RohanDrape. [22]hosc: Haskell Open Sound Control. 13. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/bytestring-0.9.0.4 14. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/uuagc-0.9.5 15. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/uulib-0.9.5 16. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/llvm-0.0.2 17. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HDBC-sqlite3-1.1.3.1 18. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HDBC-odbc-1.1.3.1 19. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/dimensional-0.7.2 20. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/uulib-0.9.5 21. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hsc3-0.1 22. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hosc-0.1 * GLFW 0.2. Uploaded by PaulLiu. [23]GLFW: A binding for GLFW, An OpenGL Framework. * control-timeout 0.1. Uploaded by AdamLangley. [24]control-timeout: Timeout handling. * hiccup 0.35. Uploaded by KyleConsalus. [25]hiccup: Relatively efficient Tcl interpreter with support for basic operations. * phooey 2.0. Uploaded by ConalElliott. [26]phooey: Functional user interfaces. * reactive 0.0. Uploaded by ConalElliott. [27]reactive: Simple foundation for functional reactive programming. * phooey 1.4. Uploaded by ConalElliott. [28]phooey: Functional user interfaces. * hburg 1.1.1. Uploaded by IgorBohm. [29]hburg: Haskell Bottom Up Rewrite Generator. * hinotify 0.2. Uploaded by LennartKolmodin. [30]hinotify: Haskell binding to INotify. * cabal-rpm 0.3.3. Uploaded by BryanOSullivan. [31]cabal-rpm: RPM package builder for Haskell Cabal source packages.. * codec-libevent 0.1. Uploaded by AdamLangley. [32]codec-libevent: Cross-platform structure serialisation. 23. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/GLFW-0.2 24. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/control-timeout-0.1 25. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hiccup-0.35 26. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/phooey-2.0 27. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/reactive-0.0 28. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/phooey-1.4 29. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hburg-1.1.1 30. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hinotify-0.2 31. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/cabal-rpm-0.3.3 32. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/codec-libevent-0.1 * irc 0.4. Uploaded by TrevorElliott. [33]irc: A small library for parsing IRC messages.. * dlist 0.4. Uploaded by DonaldStewart. [34]dlist: Differences lists. * AutoForms 0.4.0. Uploaded by MadsLindstroem. [35]AutoForms: GUI library based upon generic programming (SYB3). * bktrees 0.2.1. Uploaded by JosefSvenningsson. [36]bktrees: A set data structure with approximate searching. * bktrees 0.2. Uploaded by JosefSvenningsson. [37]bktrees: A set data structure with approximate searching. * binary-strict 0.1. Uploaded by AdamLangley. [38]binary-strict: Binary deserialisation using strict ByteStrings. * haddock 0.9. Uploaded by SimonMarlow. [39]haddock: Haddock is a documentation-generation tool for Haskell libraries. * bytestring-mmap 0.2.0. Uploaded by DonaldStewart. [40]bytestring-mmap: mmap support for strict ByteStrings. * bytestring 0.9.0.3. Uploaded by DonaldStewart. [41]bytestring: Fast, packed, strict and lazy byte arrays with a list interface. * hiccup 0.3. Uploaded by KyleConsalus. [42]hiccup: Added by KyleConsalus, Wed Dec 19 17:00:42 PST 2007.. 33. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/irc-0.4 34. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/dlist-0.4 35. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/AutoForms-0.4.0 36. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/bktrees-0.2.1 37. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/bktrees-0.2 38. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/binary-strict-0.1 39. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/haddock-0.9 40. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/bytestring-mmap-0.2.0 41. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/bytestring-0.9.0.3 42. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hiccup-0.3 * cedict 0.1.1. Uploaded by JasonDusek. [43]cedict: Convenient Chinese character lookup.. * TypeCompose 0.3. Uploaded by ConalElliott. [44]TypeCompose: Type composition classes & instances. * bytestring-mmap 0.1.2. Uploaded by DonaldStewart. [45]bytestring-mmap: mmap support for strict ByteStrings. * bytestring 0.9.0.2. Uploaded by DonaldStewart. [46]bytestring: Fast, packed, strict and lazy byte arrays with a list interface. * bytestring-mmap 0.1.1. Uploaded by DonaldStewart. [47]bytestring-mmap: mmap support for strict ByteStrings. * mkcabal 0.3. Uploaded by DonaldStewart. [48]mkcabal: Generate cabal files for a Haskell project. * terminfo 0.1. Uploaded by Judah Jacobson. [49]terminfo: Haskell bindings to the terminfo library.. * Cabal 1.2.3.0. Uploaded by Duncan Coutts. [50]Cabal: A framework for packaging Haskell software. * hxt 7.4. Uploaded by UweSchmidt. [51]hxt: A collection of tools for processing XML with Haskell.. * X11 1.4.1. Uploaded by Spencer Janssen. [52]X11: A binding to the X11 graphics library. 43. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/cedict-0.1.1 44. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/TypeCompose-0.3 45. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/bytestring-mmap-0.1.2 46. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/bytestring-0.9.0.2 47. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/bytestring-mmap-0.1.1 48. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/mkcabal-0.3 49. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/terminfo-0.1 50. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Cabal-1.2.3.0 51. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hxt-7.4 52. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/X11-1.4.1 * dataenc 0.10.1. Uploaded by Magnus Therning. [53]dataenc: Data encoding library currently providing Uuencode, Base64, Base64Url, Base32, Base32Hex, and Base16.. * bytestringreadp 0.1. Uploaded by Gracjan Polak. [54]bytestringreadp: A ReadP style parser library for ByteString. * encoding 0.3. Uploaded by HenningGuenther. [55]encoding: A library for various character encodings. * hslua 0.2. Uploaded by Gracjan Polak. [56]hslua: A Lua language interpreter embedding in Haskell. * xmonad-contrib 0.5. Uploaded by Spencer Janssen. [57]xmonad-contrib: Third party extensions for xmonad. * xmonad 0.5. Uploaded by SpencerJanssen. [58]xmonad: A tiling window manager. * pandoc 0.45. Uploaded by John MacFarlane. [59]pandoc: Conversion between markup formats. * markov-chain 0.0.1. Uploaded by Henning Thielemann. [60]markov-chain: Markov Chains for generating random sequences with a user definable behaviour.. * parsedate 3000.0.0. Uploaded by Bjorn Bringert. [61]parsedate: Data and time parsing for CalendarTime. * hackage2hwn 0.1. Uploaded by Don Stewart. [62]hackage2hwn: Convert hackage = Hackage RSS feeds to Haskell Weekly News format. 53. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/dataenc-0.10.1 54. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/bytestringreadp-0.1 55. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/encoding-0.3 56. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hslua-0.2 57. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/xmonad-contrib-0.5 58. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/xmonad-0.5 59. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/pandoc-0.45 60. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/markov-chain-0.0.1 61. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/parsedate-3000.0.0 62. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hackage2hwn-0.1 * hask-home 2007.12.6. Uploaded by BjornBringert. [63]hask-home: Generate homepages for cabal packages. * hmarkup 3000.0.1. Uploaded by BjornBringert. [64]hmarkup: Simple wikitext-like markup format implementation.. * hspread 0.2. Uploaded by AndreaVezzosi. [65]hspread: A client library for the spread toolkit. * pcap 0.4.2. Uploaded by BryanOSullivan. [66]pcap: A system-independent interface for user-level packet capture. * hogg 0.3.0. Uploaded by ConradParker. [67]hogg: Library and tools to manipulate the Ogg container format. * Finance-Quote-Yahoo 0.4.1. Uploaded by BradClawsie. [68]Finance-Quote-Yahoo: Obtain quote data from finance.yahoo.com. * Monadius 0.9.20071204. Uploaded by GwernBranwen. [69]Monadius: 2-D arcade scroller. * Shu-thing 1.0.20071203. Uploaded by GwernBranwen. [70]Shu-thing: A vector shooter game. * hmatrix 0.1.1.0. Uploaded by AlbertoRuiz. [71]hmatrix: Linear algebra and numerical computations. * HTTP 3001.0.3. Uploaded by BjornBringert. [72]HTTP: Added by BjornBringert, Fri Nov 30 14:50:55 PST 2007.. 63. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hask-home-2007.12.6 64. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hmarkup-3000.0.1 65. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hspread-0.2 66. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/pcap-0.4.2 67. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hogg-0.3.0 68. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Finance-Quote-Yahoo-0.4.1 69. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Monadius-0.9.20071204 70. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Shu-thing-1.0.20071203 71. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hmatrix-0.1.1.0 72. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HTTP-3001.0.3 * rss 3000.0.1. Uploaded by BjornBringert. [73]rss: A library for generating RSS 2.0 feeds.. * haxr 3000.0.1. Uploaded by BjornBringert. [74]haxr: XML-RPC client and server library.. * fitsio 0.1. Uploaded by EricSessoms. [75]fitsio: A library for reading and writing data files in the FITS data format.. * YamlReference 0.6. Uploaded by Oren Ben Kiki. [76]YamlReference, YAML reference implementation * LambdaShell 0.9.1. Uploaded by Robert Dockins. [77]LambdaShell, simple shell for evaluating lambda expressions * Shellac 0.9.1. Uploaded by Robert Dockins. [78]Shellac, a framework for creating shell envinronments * EdisonCore 1.2.1.1. Uploaded by Robert Dockins. [79]EdisonCore, a library of efficent, purely-functional data structures (Core Implementations) * hmatrix 0.1.0.0. Uploaded by Alberto Ruiz. [80]hmatrix, linear algebra and numerical computations * strict-concurrency 0.1. Uploaded by Don Stewart. [81]strict-concurrency, strict concurrency abstractions * X11 1.4.0. Uploaded by Don Stewart. [82]X11, binding to the X11 graphics library 73. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/rss-3000.0.1 74. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/haxr-3000.0.1 75. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/fitsio-0.1 76. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/YamlReference-0.6 77. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/LambdaShell-0.9.1 78. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Shellac-0.9.1 79. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/EdisonCore-1.2.1.1 80. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hmatrix-0.1.0.0 81. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/strict-concurrency-0.1 82. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/X11-1.4.0 * safecopy 0.3. Uploaded by David Himmelstrup. [83]safecopy, binary serialization with version control * HaXml 1.13.3. Uploaded by Malcolm Wallace. [84]HaXml, utilities for manipulating XML documents * c2hs 0.15.1. Uploaded by Duncan Coutts. [85]c2hs, C->Haskell Interface Generator * calc 0.1. Uploaded by Austin Seipp. [86]calc, small compiler for arithmetic expressions. * miniplex 0.2.1. Uploaded by Lukas Mai. [87]miniplex, simple 1-to-N interprocess communication * sat 1.1.1. Uploaded by Andrii Zvorygin. [88]sat, CNF SATisfier * dimensional 0.7.1. Uploaded by Bjorn Buckwalter. [89]dimensional, statically checked physical dimensions * hxt 7.4. Uploaded by Uwe Schmidt. [90]hxt, collection of tools for processing XML with Haskell. * dlist 0.3.2. Uploaded by Don Stewart. [91]dlist, difference lists. A list type supporting fast append. * mkcabal 0.2. Uploaded by Don Stewart. [92]mkcabal, generate cabal files for a Haskell project 83. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/safecopy-0.3 84. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HaXml-1.13.3 85. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/c2hs-0.15.1 86. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/calc-0.1 87. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/miniplex-0.2.1 88. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/sat-1.1.1 89. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/dimensional-0.7.1 90. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hxt-7.4 91. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/dlist-0.3.2 92. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/mkcabal-0.2 * Chart 0.5. Uploaded by Tim Docker. [93]Chart, a library for generating 2D Charts and Plots * MaybeT 0.1.1. Uploaded by Don Stewart. [94]MaybeT, MaybeT monad transformer * regex-pcre 0.93. Uploaded by Chris Kuklewicz. [95]regex-pcre, replaces Text.Regex * fixpoint 0.1. Uploaded by Roman Leshchinskiy. [96]fixpoint, data types as fixpoints * ChasingBottoms 1.2.2. Uploaded by Nils Anders Danielsson. [97]ChasingBottoms, support for testing partial and infinite values * GrowlNotify 0.3. Uploaded by Nicholas Burlett. [98]GrowlNotify, notification utility for Growl * pcap 0.4.1. Uploaded by Bryan OSullivan. [99]pcap, a system-independent interface for user-level packet capture * bencode 0.3. Uploaded by David Himmelstrup. [100]bencode, parser and printer for bencoded data. * stream-fusion 0.1.1. Uploaded by Don Stewart. [101]stream-fusion, provides the standard Haskell list library reimplemented to allow stream fusion. This should in general provide faster list operations, and faster code for list-heavy programs. * HTTP 3001.0.2. Uploaded by Bjorn Bringert. [102]HTTP, library for client-side HTTP 93. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Chart-0.5 94. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/MaybeT-0.1.1 95. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/regex-pcre-0.93 96. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/fixpoint-0.1 97. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/ChasingBottoms-1.2.2 98. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/GrowlNotify-0.3 99. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/pcap-0.4.1 100. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/bencode-0.3 101. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/stream-fusion-0.1.1 102. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HTTP-3001.0.2 * X11-xft 0.2. Uploaded by Clemens Fruhwirth. [103]X11-xft, bindings to the Xft, X Free Type interface library, and some Xrender parts * GrowlNotify 0.1. Uploaded by Nicholas Burlett. [104]GrowlNotify, notification utility for Growl. * HsHaruPDF 0.0.0. Uploaded by Audrey Tang. [105]HsHaruPDF, Haskell binding to libharu * unicode-normalization 0.1. Uploaded by Reinier Lamers. [106]unicode-normalization, Unicode normalization using the ICU library * uniplate 1.0.1. Uploaded by Neil Mitchell. [107]uniplate, uniform type generic traversals * lax-0.0.0. Uploaded by Wolfgang Jeltsch. [108]lax, Lax arrows are variants of other arrows which are ?less strict? than the original arrows. They can be used, for example, to produce I/O fixpoints in situations where fixIO would fail. * fastcgi 3001.0.1. Uploaded by Bjorn Bringert. [109]fastcgi, a Haskell library for writing FastCGI programs 103. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/X11-xft-0.2 104. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/GrowlNotify-0.1 105. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HsHaruPDF-0.0.0 106. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/unicode-normalization-0.1 107. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/uniplate-1.0.1 108. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/lax-0.0.0 109. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/fastcgi-3001.0.1 Conference roundup New user groups * [110]Portland Functional Programmers Group * [111]FPSIG @ Southampton * [112]SingHaskell 110. http://groups.google.com/group/pdxfunc 111. http://article.gmane.org/gmane.comp.lang.haskell.cafe/32753 112. http://article.gmane.org/gmane.comp.lang.haskell.cafe/32268 Jobs Prototyping. Peter Verswyvelen [113]announced a job using Haskell for prototyping computer animation and games 113. http://article.gmane.org/gmane.comp.lang.haskell.cafe/33377 Blog noise [114]Haskell news from the [115]blogosphere. 114. http://planet.haskell.org/ 115. http://haskell.org/haskellwiki/Blog_articles * [116]Small shots of lambda calculus * [117]Pattern Matching in Ruby * [118]Haskell 'words' and Perl 'split' * [119]Word numbers, Part 4: Sort the words, sum the numbers * [120]Improve Your C#! Borrow from F#... * [121]Sun battling Microsoft (over F#?) * [122]zip in F# and Haskell * [123]Random numbers in Haskell * [124]A survey of Haskell unicode support * [125]Using Haskell for scripting tasks 116. http://fmota.tk/2007/11/small-shots-of-lambda-calculus-part-iii.html 117. http://blog.pretheory.com/arch/2007/11/pattern_matching_in_ruby_1.php 118. http://osfameron.vox.com/library/post/haskell-words-and-perl-split.html 119. http://conway.rutgers.edu/~ccshan/wiki/blog/posts/WordNumbers4/ 120. http://diditwith.net/2007/11/14/ImproveYourCBorrowFromF.aspx 121. http://vanirsystems.com/danielsblog/?p=227 122. http://jyliao.blogspot.com/2007/11/learning-wpf-with-f-dock-and-grid.html 123. http://monadicheadaches.blogspot.com/2007/11/random-numbers-where-it-all-started.html 124. http://blog.kfish.org/2007/10/survey-haskell-unicode-support.html 125. http://pinderkent.blogsavy.com/archives/142 * [126]Princeton lost the DARPA Grand Challenge because of a C# memory leak * [127]Laziness in C#/LINQ * [128]Getting functional programming: currying * [129]The magic foldr * [130]Nested Parallel List Comprehensions * [131]FFI in Haskell * [132]Broadening ones horizons * [133]Monad Wars - 1: the Prompt * [134]Monad Wars - 2: the command line * [135]Holy Shmoly, GHC Haskell 6.8 smokes Python and Ruby away! 126. http://www.codeproject.com/showcase/IfOnlyWedUsedANTSProfiler.asp 127. http://gavinbierman.blogspot.com/2007/11/laziness-in-clinq.html 128. http://overwatering.blogspot.com/2007/11/currying.html 129. http://caos.di.uminho.pt/~ulisses/blog/2007/11/20/foldr-the-magic-function/ 130. http://tomschrijvers.blogspot.com/2007/11/nested-parallel-list-comprehensions.html 131. http://notes-on-haskell.blogspot.com/2007/02/ffi-in-haskell.html 132. http://ms-os.com/showthread.php?t=116050 133. http://osfameron.vox.com/library/post/monad-wars---1-the-prompt.html 134. http://osfameron.vox.com/library/post/monad-wars---2-the-command-line.html 135. http://www.cse.unsw.edu.au/~dons/blog/2007/11/29#smoking * [136]Use those extra cores and beat C today! (Parallel Haskell redux) * [137]Parallelizing Haskell * [138]Python, Haskell, Ruby Smackdown * [139]Legitimate uses of micro-benchmarks: parameter passing and function call costs * [140]Holy Shmoly, GHC does some magic all by itself! * [141]PARE - PARallel Execution in Erlang - a response to Haskell * [142]Haskell design patterns are (probably) needed * [143]Deriving a Virtual Machine * [144]Games, cores, and functional languages * [145]Structure of a functional Java, er, method 136. http://www.cse.unsw.edu.au/~dons/blog/2007/11/29#smoking-4core 137. http://cmssphere.blogspot.com/2007/11/parallelizing-haskell.html 138. http://feedingthesnake.wordpress.com/2007/11/30/python-haskell-ruby-smackdown/ 139. http://eigenclass.org/hiki/legitimate-microbenchmarks 140. http://geekrant.wordpress.com/2007/11/29/holy-shmoly-ghc-does-some-magic-all-by-itself/ 141. http://chlorophil.blogspot.com/2007/11/pare-parallel-execution-in-erlang.html 142. http://jpmoresmau.blogspot.com/2007/11/haskell-design-patterns-are-probably.html 143. http://www.iis.sinica.edu.tw/~scm/?p=42 144. http://www.antipode.ca/2007/games-cores-and-functional-languages/ 145. http://jpmoresmau.blogspot.com/2007/11/structure-of-functional-java-er-method.html * [146]Current Fixation: Haskell * [147]Multicores, F# and SPJ: leading people to Haskell * [148]The IO Monad for People who Simply Don't Care * [149]Why I chose to learn Haskell * [150]Some Playing with Derivatives * [151]Solve Ball Clock Puzzle in Python and Haskell * [152]Back to functional languages... at least for a while? * [153]Overloading Semicolon, or, monads from 10,000 Feet * [154]Getting started with Haskell * [155]Arrows first encounter 146. http://onerousmachinations.blogspot.com/2007/11/current-fixation-haskell.html 147. http://nxtgenug.spaces.live.com/Blog/cns!59F714755D6E2A69!221.entry 148. http://sigfpe.blogspot.com/2007/11/io-monad-for-people-who-simply-dont.html 149. http://offthelip.org/?p=91 150. http://cdsmith.wordpress.com/2007/11/29/some-playing-with-derivatives/ 151. http://the-little-haskeller.blogspot.com/2007/11/solve-ball-clock-puzzle-in-python-and.html 152. http://afurtado1980.spaces.live.com/Blog/cns!63514833CE40C143!518.entry 153. http://osteele.com/archives/2007/12/overloading-semicolon 154. http://talkingcode.co.uk/2007/12/03/getting-started-with-haskell/ 155. http://monadicheadaches.blogspot.com/2007/12/arrows-first-encounter.html * [156]Arithmetic for lists * [157]Functional Programming on .NET - Part 1 * [158]N-Queens in Haskell * [159]N-Queens in the writer monad * [160]Unit testing in Haskell * [161]Calculating the reflect-rotate-translate normal form for an isometry of the plane in Haskell, and verifying it with QuickCheck * [162]Visualizing 2D convex hull using Gtk and OpenGL in Haskell * [163]Hugs for the Nintendo DS * [164]Comparative terseness of Perl and Haskell * [165]Note on point-free programming style 156. http://wadler.blogspot.com/2007/12/arithmetic-for-lists.html 157. http://zerogradient.wordpress.com/2007/12/05/functional-programming-on-net-part-1/ 158. http://therning.org/magnus/archives/330 159. http://cdsmith.wordpress.com/2007/12/09/some-basic-stuff-the-writer-monad/ 160. http://hitesh-jasani.blogspot.com/2007/12/unit-testing-with-hunit-in-haskell.html 161. http://www.kennknowles.com/blog/2007/12/03/calculating-the-reflect-rotate-translate-normal-form-for-an-isometry-of-the-plane-in-haskell-and-verifying-it-with-quickcheck/ 162. http://www.kennknowles.com/blog/2007/11/20/visualizing-2d-convex-hull-using-gtk-and-opengl-in-haskell/ 163. http://closuretohome.blogspot.com/2007/12/hugs-for-nintendo-ds.html 164. http://blog.plover.com/2007/11/30/#pow-sqrt 165. http://blog.plover.com/prog/haskell/pointfree.html * [166]Haskell Fibonacci Revisited * [167]PXSL Tools 1.0: Your ticket out of XML Hell * [168]Haskell is kind of cool * [169]Learning Haskell with ProjectEuler * [170]Infinite lazy Knuth-Bendix completion for monoids in Haskell * [171]Hugs for the Nintendo DS * [172]My Type of Language... * [173]Catching pods with hpodder * [174]Hamming's problem * [175]Sharper function operators 166. http://chasethedevil.blogspot.com/2007/12/haskell-fibonacci-revisited.html 167. http://blog.moertel.com/articles/2007/12/17/pxsl-tools-1-0-your-ticket-out-of-xml-hell 168. http://www.goesping.org/archives/2007/12/18/haskell-is-kind-of-cool/ 169. http://www.robdickerson.net/?p=12 170. http://www.kennknowles.com/blog/2007/12/20/infinite-lazy-knuth-bendix-completion-for-monoids-in-haskell/ 171. http://blog.closuretohome.com/2007/12/hugs-for-nintendo-ds.html 172. http://lambdalounge.blogspot.com/2007/12/my-type-of-language.html 173. http://lorenzod8n.wordpress.com/2007/12/22/catching-pods-with-hpodder/ 174. http://conway.rutgers.edu/~ccshan/wiki/blog/posts/Hamming/ 175. http://blog.closuretohome.com/2008/01/sharper-function-operators.html * [176]Xiangqiboard: play Xiangqi against a computer opponent * [177]Haskell is kind of cool * [178]FParsec - A Parser Combinator Library for F# * [179]RSA-Haskell * [180]LLVM bindings for Haskell * [181]perpubplat 0.9 - You're Looking at It: blog framework for Haskell * [182]The point of pointfree * [183]qtHaskell * [184]Web Objects and the underappreciated recursive do * [185]Equality operators in PHP and Haskell 176. http://xiangqiboard.blogspot.com/2007/12/gnuxiangqi-angekndigt.html 177. http://www.goesping.org/archives/2007/12/18/haskell-is-kind-of-cool/ 178. http://www.quanttec.com/fparsec/ 179. http://netsuperbrain.com/rsa-haskell.html 180. http://www.serpentine.com/blog/2008/01/03/llvm-bindings-for-haskell/ 181. http://mult.ifario.us/p/perpubplat-0-9-you-re-looking-at-it 182. http://www.vex.net/~trebla/weblog/pointfree.html 183. http://qthaskell.sourceforge.net/ 184. http://www.alpheccar.org/en/posts/show/89 185. http://www.syntaxpolice.org/index.php/?q=node%2F419 * [186]Pushing Haskell's type system to the limits: A reflective JSON serializer * [187]A Wake Up Call for the Logic Programming Community * [188]Design your functions for partial application * [189]Taxicab Numbers * [190]Composing Contracts * [191]HTTP content-type comparison at the type level * [192]Haskell-Join-Rules * [193]Exploring JPEG * [194]What's interesting to me about SquirrelMail attack * [195]Haskell and F#: Language Design 186. http://lingnerd.blogspot.com/2007/12/pushing-haskells-type-system-to-limits.html 187. http://www.cs.kuleuven.ac.be/~dtai/projects/ALP/newsletter/dec07/content/Articles/tom/content.html 188. http://www.serpentine.com/blog/2007/12/26/design-your-functions-for-partial-application/ 189. http://notes-on-haskell.blogspot.com/2007/12/taxicab-numbers.html 190. http://contracts.scheming.org/ 191. http://www.alpheccar.org/en/posts/show/88 192. http://taichi.ddns.comp.nus.edu.sg/taichiwiki/HaskellJoinRules 193. http://www.imperialviolet.org/binary/jpeg/ 194. http://www.syntaxpolice.org/index.php/?q=node%2F418 195. http://corsis.blogspot.com/2008/01/haskell-and-f-language-design.html * [196]An example of Haskell's beauty * [197]My resolve to learn Haskell has become stronger after having watched 'A Taste of Haskell' * [198]Emacs love w/ Haskell * [199]Finding my way * [200]Why not Scala? * [201]A Different Kind of Obscurity * [202]Languages that save you some typing 196. http://blog.whoop.as/?p=1668 197. http://rmathew.blogspot.com/2008/01/taste-of-haskell.html 198. http://blog.whoop.as/?p=1665 199. http://nointernalmonologue.blogspot.com/2008/01/finding-my-way.html 200. http://unenterprise.blogspot.com/2008/01/why-not-scala.html 201. http://ddvlad.wordpress.com/2007/12/14/a-different-kind-of-obscurity/ 202. http://daltonic.blogspot.com/2008/01/language-that-saves-you-some-typing.html Quotes of the Week * Conal: For me, the heart of functional programming is exactly this separation between model and presentation. The former is naturally functional and compositional, while the latter is often imperative/sequential and not-so-compositional. IO belongs with the latter. * ddarius: has programmed too much in Haskell. He now produces code that -compiles- and works the first time * disspy: If all you know is C, everything begins to look like a segmentation fault. * markedtrees: (On the city of Haskell) Ah yes, Haskell. Where all the types are strong, all the men carry arrows, and all the children are above average. * ola-bini: Haskell's type system is really nice, for example, but OCaml's really feels like half of it exists just to cover up holes in the other half, I'm half way into Erlang, but for several reasons the language feels very primitive. * so1i.warazd: I'm more and more comfortable spending time with Haskell these days. Haskell may not be the next thing, but whatever the next big thing is, it's probably going to have Haskelly fingerprints all over it?.. * sylvan: think that the perceived difficulty in using purely functional programming is probably a bit exaggerated these days, as all it means is 'we're explicit about where side effects occur' * falvo: I really wish that someone would come up with a type-safe replacement for the likes of Python. Oh, wait, it's called Haskell! Unfortunately, I'm forbidden from using Haskell at work. Sigh * Tyler Spaulding: eventually even 'simple' programs will nned multiple threads. Does that mean developers will suddenly flock to Haskell? Again, no. Language designers are well aware of the situation. Sun and Microsoft are constantly working on improving the Java and .NET frameworks. And by the time the average programmer needs it, both will have plenty of support for easy threading * ricky clarkson: Haskell is full of Aha and Hah moments for me * five9a2: Concurrency aside, I find it common to write Haskell code that is as fast as C. It is true that for most things, the C can be tweaked to go a bit faster, but that tweaking needs to be done on a case-by-case basis. In Haskell, it is easier to compose optimized components. Better algorithms beat an optimized compiler any day and using the best algorithms everywhere in C code tends to be painful, error-prone, and usually disparaged as premature optimization. * Jeff Moser: It's been this fear of skills rot that has pushed me to look into Lisp, Haskell, F#, Erlang, and other languages to avoid The Blub Paradox. * NFJS 2008 predictions: If you've never programmed in Haskell, now's a good time to learn, because those concepts and syntax are fast making their way towards you... * The honey monster: With the advent of multi-core CPUs and the promise of many core processors in the near future it occurrs to me that my interest in functional programming languages could not of happened at a more opportune time. It is not that imperative programming languages are not as capable, merely that functional programming languages seem to be more natural fit About the Haskell Weekly News New editions are posted to [203]the Haskell mailing list as well as to [204]the Haskell Sequence and [205]Planet Haskell. [206]RSS is also available, and headlines appear on [207]haskell.org. Headlines are available as [208]PDF. To help create new editions of this newsletter, please see the [209]contributing information. Send stories to dons at galois.com. The darcs repository is available at darcs get [210]http://code.haskell.org/~dons/code/hwn/ 203. http://www.haskell.org/mailman/listinfo/haskell 205. http://planet.haskell.org/ 207. http://haskell.org/ 208. http://code.haskell.org/~dons/code/hwn/archives/20080105.pdf 209. http://haskell.org/haskellwiki/HWN 210. http://code.haskell.org/~dons/code/hwn/ From ac78f92aa421c5e2b9 at gazeta.pl Sat Jan 5 19:45:42 2008 From: ac78f92aa421c5e2b9 at gazeta.pl (Bob) Date: Sat Jan 5 19:39:47 2008 Subject: [Haskell-cafe] Re: Refactoring status In-Reply-To: <1302893850.20080104022331@gmail.com> References: <002001c84e34$569c9f30$03d5dd90$@be> <1713055262.20080103220617@gmail.com> <1302893850.20080104022331@gmail.com> Message-ID: <478024B6.4010903@gazeta.pl> On 2008-01-04 0:23, Bulat Ziganshin wrote: > Hello C.M.Brown, > > Thursday, January 3, 2008, 10:46:54 PM, you wrote: > >>> i don't use >>> type signatures at all - this creates some problems when i wrote large >>> portion of code and try to make it compile, but nothing more > >> I believe type signatures are the very essence of Haskell documentation! >> I'd much rather see a program with type signatures for functions and >> little (or no) comments over programs with no type signatures and >> ambigious comments (if any comments at all!). > >> Type signatures really does make dealing with someone elses code that >> much easier. > > well, i don't worry about types of things with which i work. i know > that it is a file, for example. its actual type depends on the > information i need inside this function. it may start as FileInfo type, > then after refactoring it will become CompressedFile or > (fileInfo,FileSize) type. while it's great to know types of every > variable to better understand how program works, adding type > signatures means more work when writing program and when changing it. > i want to express only data processing algorithm leaving all the > details to compiler. for me, ghc just "reads thoughts" > > types and type signatures was required in classic languages to fight > with errors. but in haskell omitting type signatures doesn't make > program less reliable, so i don't need to write this extra code in > addition to the essential - algorithm itself. for the same reason, i > like pointless notation > You are wrong. Without type signatures some type errors will not be caught by the compiler, resulting in erroneous program behaviour. An example: makeURI file index = "http://192.168.0.1/somescript.php?file=" ++ urlEncode file ++ "&index=" ++ show index the intended signature for the above function is: String -> Int -> String, but suppose I've used it that way: makeURI "somefile.txt" "1" this is a type error, String was used where Int was expected, but the program compiles just fine. So now the string: http://192.168.0.1/somescript.php?file=somefile.txt&index="1" will be sent to the server which is of course wrong because http://192.168.0.1/somescript.php?file=somefile.txt&index=1 is expected. Without type declarations You are not using the full power of static type checking. From gale at sefer.org Sat Jan 5 21:03:06 2008 From: gale at sefer.org (Yitzchak Gale) Date: Sat Jan 5 20:56:54 2008 Subject: [Haskell-cafe] Basic question concerning the category Hask (was: concerning data constructors) In-Reply-To: <6A26B181-D657-45A8-9F3E-B7761E9142FD@fastmail.fm> References: <20080103101645.90F9F3242E7@www.haskell.org> <7b1ffbe0801030340j2676fe2x272b9a836c59773f@mail.gmail.com> <6A26B181-D657-45A8-9F3E-B7761E9142FD@fastmail.fm> Message-ID: <2608b8a80801051803p692c3207mb207613faec13ce5@mail.gmail.com> Jonathan Cast wrote: >>> The normal view taken by Haskellers is that the denotations of >>> Haskell types are CPPOs. >>> So: >>> (1) Must be monotone >>> (2) Must be continuous >>> (Needn't be strict, even though that messes up the resulting >>> category substantially). I wrote: >> I'm not convinced that the category is all that "messed up". > Well, no coproducts (Haskell uses a lifted version of the coproduct > from CPO). What goes wrong with finite coproducts? The obvious thing to do would be to take the disjoint union of the sets representing the types, identifying the copies of _|_. What is the lifted version you are referring to? > Of course, Haskell makes things even worse by lifting the > product and exponential objects, OK, what goes wrong there, and what is the lifting? Thanks, Yitz From jonathanccast at fastmail.fm Sun Jan 6 00:12:00 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Sun Jan 6 00:05:54 2008 Subject: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? In-Reply-To: References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <1965805939.20080102232921@gmail.com> <915864007.20080103135418@gmail.com> <8627368.20080103173843@gmail.com> <1762133336.20080103215834@gmail.com> Message-ID: <83DE9074-6529-4B54-B2A5-D3285DC699B0@fastmail.fm> On 4 Jan 2008, at 2:00 AM, Nicholls, Mark wrote: > You may be right...but learning is not an atomic thing....wherever I > start I will get strange things happening. The best place to start learning Haskell is with the simplest type features, not the most complicated. And it's the simplest features that are most unlike OO. Yes, Haskell will be `strange'. But if you think you're `the intersection' between Haskell and OO, you'll think things are familiar, and you'll be surprised when they turn out to be different. I'd concentrate on watching out for differences --- but then I can't imagine how finding `familiar' ideas would help. jcc From jonathanccast at fastmail.fm Sun Jan 6 00:38:19 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Sun Jan 6 00:32:12 2008 Subject: [Haskell-cafe] Basic question concerning the category Hask (was: concerning data constructors) In-Reply-To: <2608b8a80801051803p692c3207mb207613faec13ce5@mail.gmail.com> References: <20080103101645.90F9F3242E7@www.haskell.org> <7b1ffbe0801030340j2676fe2x272b9a836c59773f@mail.gmail.com> <6A26B181-D657-45A8-9F3E-B7761E9142FD@fastmail.fm> <2608b8a80801051803p692c3207mb207613faec13ce5@mail.gmail.com> Message-ID: <55F0EA86-0962-403E-B133-0545648CA68E@fastmail.fm> On 5 Jan 2008, at 6:03 PM, Yitzchak Gale wrote: > Jonathan Cast wrote: >>>> The normal view taken by Haskellers is that the denotations of >>>> Haskell types are CPPOs. >>>> So: >>>> (1) Must be monotone >>>> (2) Must be continuous >>>> (Needn't be strict, even though that messes up the resulting >>>> category substantially). > > I wrote: >>> I'm not convinced that the category is all that "messed up". > >> Well, no coproducts (Haskell uses a lifted version of the coproduct >> from CPO). > > What goes wrong with finite coproducts? The obvious thing to > do would be to take the disjoint union of the sets representing the > types, identifying the copies of _|_. This isn't a coproduct. If we have f x = 1 and g y = 2, then there should exist a function h such that h . Left = f and h . Right = g, i.e., h (Left x) = f x = 1 and h (Right y) = g y = 2 But by your rule, Left undefined = Right undefined, so 1 = h (Left undefined) = h (Right undefined) = 2 Which is a contradiction. Identifying Left _|_ and Right _|_ produces a pointed CPO, but it's not a coproduct. Unless, of course, your require your functions to be strict --- then both f and g above become illegal, and repairing them removes the problem. > What is the lifted version you are referring to? Take the ordinary disjoint union, and then add a new _|_ element, distinct from both existing copies of _|_ (which are still distinct from each other). > >> Of course, Haskell makes things even worse by lifting the >> product and exponential objects, > > OK, what goes wrong there, and what is the lifting? Again, in Haskell, (_|_, _|_) /= _|_. The difference is in the function f (x, y) = 1 which gives f undefined = undefined but f (undefined, undefined) = 1. Unfortunately, this means that (alpha, beta) has an extra _|_ element < (_|_, _|_), so it's not the categorical product (which would lack such an element for the same reason as above). This is partly an implementation issue --- compiling pattern matching without introducing such a lifting requires a parallel implementation --- and partly a semantic issue --- data introduces a single level of lifting, every time it is used, and every constructor is completely lazy. Functions have the same issue --- in the presence of seq, undefined / = const undefined. Extensionality is a key part of the definition of all of these constructions. The categorical rules are designed to require, in concrete categories, that the range of the two injections into a coproduct form a partition of the coproduct, the surjective pairing law (fst x, snd x) = x holds, and the eta reduction law (\ x -> f x) = f holds. Haskell flaunts all three; while some categories have few enough morphisms to get away with this (at least some times), Hask is not one of them. jcc From barsoap at web.de Sun Jan 6 05:13:09 2008 From: barsoap at web.de (Achim Schneider) Date: Sun Jan 6 05:07:04 2008 Subject: [Haskell-cafe] Re: Is there anyone out there who can translate C# generics into Haskell? References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <1965805939.20080102232921@gmail.com> <915864007.20080103135418@gmail.com> <8627368.20080103173843@gmail.com> <1762133336.20080103215834@gmail.com> <83DE9074-6529-4B54-B2A5-D3285DC699B0@fastmail.fm> Message-ID: <20080106111309.3f0bc240@solaris.tower> Jonathan Cast wrote: > On 4 Jan 2008, at 2:00 AM, Nicholls, Mark wrote: > > > You may be right...but learning is not an atomic thing....wherever I > > start I will get strange things happening. > > The best place to start learning Haskell is with the simplest type > features, not the most complicated. And it's the simplest features > that are most unlike OO. > > Yes, Haskell will be `strange'. But if you think you're `the > intersection' between Haskell and OO, you'll think things are > familiar, and you'll be surprised when they turn out to be > different. I'd concentrate on watching out for differences --- but > then I can't imagine how finding `familiar' ideas would help. > just a sec... things like data State = State { winSize :: IORef Size , t :: IORef Int , fps :: IORef Float , showFPS :: IORef Bool , showHelp :: IORef Bool , grabMouse :: IORef Bool , mousePos :: IORef (Maybe Position) , mouseDelta :: IORef Position , viewRot :: IORef Vec3 , angle' :: IORef GLfloat , ballPos :: IORef Vec2 , ballVel :: IORef Vec2 } makeState :: IO State makeState = do size <- newIORef $ Size 0 0 t' <- newIORef 0 fps' <- newIORef 0 sfps <- newIORef False gm <- newIORef False mp <- newIORef Nothing md <- newIORef $ Position 0 0 sh <- newIORef False v <- newIORef (0, 0, 0) a <- newIORef 0 bp <- newIORef (0, 0) bv <- newIORef (0.002, 0.002) { winSize = size , t = t', fps = fps' , showFPS = sfps, showHelp = sh , grabMouse = gm, mousePos = mp, mouseDelta = md , viewRot = v, angle' = a , ballPos = bp, ballVel = bv } and keyboard state (Char 'f') Down _ _ = showFPS state $~ not modRot :: State -> View -> IO () modRot state (dx,dy,dz) = do (x, y, z) <- get $ viewRot state viewRot state $= (x + dx, y + dy, z + dz) postRedisplay Nothing come to mind. But then this has more to do with Monads than with classes. IO, in particular, and GL and GLUT, which are state machines and thus predestined for OOP. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From andrewcoppin at btinternet.com Sun Jan 6 06:21:29 2008 From: andrewcoppin at btinternet.com (Andrew Coppin) Date: Sun Jan 6 06:15:15 2008 Subject: [Haskell-cafe] Am I blind? In-Reply-To: <20080106002046.GA18375@scytale.galois.com> References: <20080106002046.GA18375@scytale.galois.com> Message-ID: <4780B9B9.9090308@btinternet.com> Don Stewart wrote: > --------------------------------------------------------------------------- > Haskell Weekly News > Issue 68 - January 05, 2008 > --------------------------------------------------------------------------- > > Announcements > > GHC 6.8.2. The GHC Team [2]announced the release of GHC 6.8.2, > featuring optimisation improvements, improvements to ghci and fixes to > standalone deriving. > I've searched all over the place, and I can't find this information actually "announced" anywhere except on the GHC homepage itself. And yet, I've seen emails bouncing around that appear to be replies to the announcement email. But I can't find the actual announcement email anywhere. Am I going mad? From andrewcoppin at btinternet.com Sun Jan 6 06:23:11 2008 From: andrewcoppin at btinternet.com (Andrew Coppin) Date: Sun Jan 6 06:16:56 2008 Subject: [Haskell-cafe] US Homeland Security program language security risks In-Reply-To: <5ae4f2ba0801031336x45b4c14dw34771cbc9ef0d3f4@mail.gmail.com> References: <5ae4f2ba0801031336x45b4c14dw34771cbc9ef0d3f4@mail.gmail.com> Message-ID: <4780BA1F.5070508@btinternet.com> Galchin Vasili wrote: > Hello, > > https://buildsecurityin.us-cert.gov/daisy/bsi/articles/knowledge/coding/295.html > > I stumbled across this page. It seems that Haskell and other strongly > typed functional languages like Ml/OCaml will fare much, much better, > e.g. buffer overrun. Thoughts . .... comments. Human kind has yet to design a programming language which eliminates all possible bugs. ;-) From andrewcoppin at btinternet.com Sun Jan 6 06:30:53 2008 From: andrewcoppin at btinternet.com (Andrew Coppin) Date: Sun Jan 6 06:24:37 2008 Subject: [Haskell-cafe] Concurrency questions Message-ID: <4780BBED.5020907@btinternet.com> Just a couple of things I was wondering about... 1. Is there some way to assign a "priority" to Haskell threads? (The behaviour I'd like is that high priority threads always run first, and low priority threads potentially never run at all unless there's an available processor which is completely idle.) 2. I have a situation where I have a thread generating some data and putting it into a mutable array, and another thread trying to read that data. Is there a way I can make the reader thread block if it tries to read a cell that hasn't been computed yet, but not introduce too much overhead for cells that have been filled in? 3. Would it be hard to make it so that the number of real threads (the RTS +N flag) could be adjusted at runtime? From a.d.clark at ed.ac.uk Sun Jan 6 06:34:16 2008 From: a.d.clark at ed.ac.uk (Allan Clark) Date: Sun Jan 6 06:28:03 2008 Subject: [Haskell-cafe] Am I blind? In-Reply-To: <4780B9B9.9090308@btinternet.com> References: <20080106002046.GA18375@scytale.galois.com> <4780B9B9.9090308@btinternet.com> Message-ID: <4780BCB8.5070702@ed.ac.uk> > > I've searched all over the place, and I can't find this information > actually "announced" anywhere except on the GHC homepage itself. And > yet, I've seen emails bouncing around that appear to be replies to the > announcement email. But I can't find the actual announcement email > anywhere. Am I going mad? > It was on just the Haskell rather than Haskell-cafe mailing list. http://www.mail-archive.com/haskell@haskell.org/msg20759.html regards allan From andrewcoppin at btinternet.com Sun Jan 6 06:41:04 2008 From: andrewcoppin at btinternet.com (Andrew Coppin) Date: Sun Jan 6 06:34:49 2008 Subject: [Haskell-cafe] Am I blind? In-Reply-To: <4780BCB8.5070702@ed.ac.uk> References: <20080106002046.GA18375@scytale.galois.com> <4780B9B9.9090308@btinternet.com> <4780BCB8.5070702@ed.ac.uk> Message-ID: <4780BE50.50404@btinternet.com> Allan Clark wrote: > >> >> I've searched all over the place, and I can't find this information >> actually "announced" anywhere except on the GHC homepage itself. And >> yet, I've seen emails bouncing around that appear to be replies to >> the announcement email. But I can't find the actual announcement >> email anywhere. Am I going mad? >> > It was on just the Haskell rather than Haskell-cafe mailing list. > http://www.mail-archive.com/haskell@haskell.org/msg20759.html You're quite right - there it is - and yet I still can't find this through Gname. [Even though I now know what date to look at.] Odd... From felipe.lessa at gmail.com Sun Jan 6 06:41:37 2008 From: felipe.lessa at gmail.com (Felipe Lessa) Date: Sun Jan 6 06:35:23 2008 Subject: [Haskell-cafe] Concurrency questions In-Reply-To: <4780BBED.5020907@btinternet.com> References: <4780BBED.5020907@btinternet.com> Message-ID: On Jan 6, 2008 9:30 AM, Andrew Coppin wrote: > 2. I have a situation where I have a thread generating some data and > putting it into a mutable array, and another thread trying to read that > data. Is there a way I can make the reader thread block if it tries to > read a cell that hasn't been computed yet, but not introduce too much > overhead for cells that have been filled in? If your thread fills the array linearly, you could maintain a variable shared by those threads that say the last cell computed, and have the read thread check that before reading. I think this wouldn't create too much overhead, although it seems like there must be something cleverer somewhere. -- Felipe. From barsoap at web.de Sun Jan 6 06:45:03 2008 From: barsoap at web.de (Achim Schneider) Date: Sun Jan 6 06:39:05 2008 Subject: [Haskell-cafe] Re: Concurrency questions References: <4780BBED.5020907@btinternet.com> Message-ID: <20080106124503.037d5c66@solaris.tower> Andrew Coppin wrote: > 2. I have a situation where I have a thread generating some data and > putting it into a mutable array, and another thread trying to read > that data. Is there a way I can make the reader thread block if it > tries to read a cell that hasn't been computed yet, but not introduce > too much overhead for cells that have been filled in? > This http://www.haskell.org/ghc/docs/latest/html/libraries/stm/Control-Concurrent-STM-TChan.html could be what you're looking for. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From andrewcoppin at btinternet.com Sun Jan 6 06:45:29 2008 From: andrewcoppin at btinternet.com (Andrew Coppin) Date: Sun Jan 6 06:39:14 2008 Subject: [Haskell-cafe] Concurrency questions In-Reply-To: References: <4780BBED.5020907@btinternet.com> Message-ID: <4780BF59.2000206@btinternet.com> Felipe Lessa wrote: > On Jan 6, 2008 9:30 AM, Andrew Coppin wrote: > >> 2. I have a situation where I have a thread generating some data and >> putting it into a mutable array, and another thread trying to read that >> data. Is there a way I can make the reader thread block if it tries to >> read a cell that hasn't been computed yet, but not introduce too much >> overhead for cells that have been filled in? >> > > If your thread fills the array linearly, you could maintain a variable > shared by those threads that say the last cell computed, and have the > read thread check that before reading. I think this wouldn't create > too much overhead, although it seems like there must be something > cleverer somewhere. > That's just it - it fills the array in a fairly random order. (The *scanning* is, however, in linear order.) It's not a big problem - I can wait for the entire array to be filled, and then scan it. But I'd like to do both in parallel if there's a reasonably easy way to do it. I suppose an array of MVars would do it, but 1. How big is an MVar? 2. You have to take the data out of an MVar to read it. In other words, only 1 thread can read an MVar at once [by design]. This isn't truly a problem in the current case, but it's irritating in principle that I can't make it so that once the cell is written, multiple threads can read it simultaneously... From gale at sefer.org Sun Jan 6 06:55:22 2008 From: gale at sefer.org (Yitzchak Gale) Date: Sun Jan 6 06:49:09 2008 Subject: [Haskell-cafe] Basic question concerning the category Hask (was: concerning data constructors) In-Reply-To: <55F0EA86-0962-403E-B133-0545648CA68E@fastmail.fm> References: <20080103101645.90F9F3242E7@www.haskell.org> <7b1ffbe0801030340j2676fe2x272b9a836c59773f@mail.gmail.com> <6A26B181-D657-45A8-9F3E-B7761E9142FD@fastmail.fm> <2608b8a80801051803p692c3207mb207613faec13ce5@mail.gmail.com> <55F0EA86-0962-403E-B133-0545648CA68E@fastmail.fm> Message-ID: <2608b8a80801060355y59b8fa30id334afdbad7e5cca@mail.gmail.com> I wrote: >> What goes wrong with finite coproducts? The obvious thing to >> do would be to take the disjoint union of the sets representing the >> types, identifying the copies of _|_. Jonathan Cast wrote: > This isn't a coproduct. If we have f x = 1 and g y = 2, then there > should exist a function h such that h . Left = f and h . Right = g... > But by your rule, Left undefined = Right undefined... > Which is a contradiction... OK, thanks. > Unless, of course, > your require your functions to be strict --- then both f and g above > become illegal, and repairing them removes the problem. You don't have to make them illegal - just not part of your notion of "coproduct". That is an entirely category-theoretic concept, since Empty is bi-universal, and a morphism is strict iff the diagram f A ---> B \ ^ v / Empty commutes. However, the coproduct you get is the one I suggested, namely Either !A !B, not the one we usually use. > > What is the lifted version you are referring to? > > Take the ordinary disjoint union, and then add a new _|_ element, > distinct from both existing copies of _|_ (which are still distinct > from each other). > > > > >> Of course, Haskell makes things even worse by lifting the > >> product and exponential objects, > > > > OK, what goes wrong there, and what is the lifting? > > Again, in Haskell, (_|_, _|_) /= _|_. The difference is in the function > > f (x, y) = 1 > > which gives f undefined = undefined but f (undefined, undefined) = > 1. Unfortunately, this means that (alpha, beta) has an extra _|_ > element < (_|_, _|_), so it's not the categorical product (which > would lack such an element for the same reason as above). > This is partly an implementation issue --- compiling pattern matching > without introducing such a lifting requires a parallel implementation > --- and partly a semantic issue --- data introduces a single level of > lifting, every time it is used, and every constructor is completely > lazy. > > Functions have the same issue --- in the presence of seq, undefined / > = const undefined. > > Extensionality is a key part of the definition of all of these > constructions. The categorical rules are designed to require, in > concrete categories, that the range of the two injections into a > coproduct form a partition of the coproduct, the surjective pairing > law (fst x, snd x) = x holds, and the eta reduction law (\ x -> f x) > = f holds. Haskell flaunts all three; while some categories have few > enough morphisms to get away with this (at least some times), Hask is > not one of them. > > jcc > > From derek.a.elkins at gmail.com Sun Jan 6 06:02:47 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Sun Jan 6 06:56:55 2008 Subject: [Haskell-cafe] Wikipedia on first-class object In-Reply-To: References: <2608b8a80712270110l38830795l5b9a0d05b7835ced@mail.gmail.com> <2608b8a80712270240g97b8601tc0898a5513e1b155@mail.gmail.com> <597F114C-5E60-48ED-9F7F-FF5BC3EE0F97@fastmail.fm> Message-ID: <1199617367.6843.7.camel@derek-laptop> On Fri, 2007-12-28 at 17:54 -0600, Jonathan Cast wrote: > Programming languages are generally classified into three groups, > imperative, functional, and logical. The difference is in the style > of programming encouraged (or mandated, for older languages) by the > language. Usually the divide is imperative v. declarative with the four major paradigms (procedural, OO and logic, FP respectively) being subgroups of those divisions. From derek.a.elkins at gmail.com Sun Jan 6 06:04:48 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Sun Jan 6 06:58:57 2008 Subject: [Haskell-cafe] Quanta. Was: Wikipedia on first-class object In-Reply-To: References: <2608b8a80712270110l38830795l5b9a0d05b7835ced@mail.gmail.com> <1934333921.20071227154048@gmail.com> <47767D39.4020007@btinternet.com> <20071229184005.702ab59c@solaris.tower> <1695012808.20071229213744@gmail.com> <4683d9370712291042w21873ae3xcb0376e05b0a3326@mail.gmail.com> <1995050719.20071229215903@gmail.com> <20071229201639.22c43260@solaris.tower> <1372887653.20071229223329@gmail.com> <000001c84a57$2c7b7e00$85727a00$@be> <568741883.20071230011816@gmail.com> <871w94fugj.fsf@nmd9999.imr.no> Message-ID: <1199617488.6843.10.camel@derek-laptop> On Sun, 2007-12-30 at 12:27 +0100, jerzy.karczmarczuk@info.unicaen.fr wrote: [...] > I don't understand your point. We know what swimming is: floating and > moving autonomously. Thinking is different, since our thinking is (at least > for some of us) conscious, and we have no idea what is the conscience. > For goodness sake, I have *REALLY* the impression that those guys who > speak about computability of the Universe, have the mentality of 18 century > thinkers for whom the world was simple and mechanistic. Or even the > mentality of people contemporary of Democritus, for whom everything > "reduced" to some dance of atoms. Or a wave function for the Universe... From derek.a.elkins at gmail.com Sun Jan 6 06:52:11 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Sun Jan 6 07:46:20 2008 Subject: [Haskell-cafe] Basic question concerning the category Hask (was: concerning data constructors) In-Reply-To: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> Message-ID: <1199620331.6843.33.camel@derek-laptop> On Wed, 2008-01-02 at 15:49 +0200, Yitzchak Gale wrote: [...] > Some people are worried that this version of Hask is missing > certain nice properties that one would like to have. For > example, it was recently claimed on this list that tuples > are not products in that category. (Or some such. I would be > interested to see a demonstration of that.) Johnathan has given such a demonstration (and it has been demonstrated many times on this list since it's creation, it's well-known). > I am not impressed by those complaints. As usual in category > theory, you define corresponding notions in Hask, and prove > that they are preserved under the appropriate functors. > That should always be easy. And if ever it is not, then you > have discovered an interesting non-trivial consequence of > laziness that deserves study. You are right not to be impressed by such complaints, but you misrepresent people's views on this by saying that the "worry" about such problems. As you say (people say), these properties [that Hask is cartesian closed to start] would be nice to have and are very convenient to assume which is often safe enough. Certainly computer scientists of a categorical bent have developed (weaker) notions to use; namely, monoidal, pre-monoidal, Freyd, and/or kappa categories and no doubt others. Using these, however, removes some of the allure of using a categorical approach. Also, there is a Haskell-specific problem at the very get-go. The most "obvious" choice for the categorical composition operator assuming the "obvious" choice for the arrows and objects does not work, it does not satisfy the laws of a category assuming the = used in them is observational equality. Namely, id . f /= f /= f . id for all functions f, in particular, it fails when f = undefined. This can easily be fixed by making the categorical (.) strict in both arguments and there is no formal problem with it being different from Haskell's (.), but it certainly is not intuitively appealing. From gale at sefer.org Sun Jan 6 08:32:55 2008 From: gale at sefer.org (Yitzchak Gale) Date: Sun Jan 6 08:26:41 2008 Subject: [Haskell-cafe] Basic question concerning the category Hask (was: concerning data constructors) In-Reply-To: <2608b8a80801060355y59b8fa30id334afdbad7e5cca@mail.gmail.com> References: <20080103101645.90F9F3242E7@www.haskell.org> <7b1ffbe0801030340j2676fe2x272b9a836c59773f@mail.gmail.com> <6A26B181-D657-45A8-9F3E-B7761E9142FD@fastmail.fm> <2608b8a80801051803p692c3207mb207613faec13ce5@mail.gmail.com> <55F0EA86-0962-403E-B133-0545648CA68E@fastmail.fm> <2608b8a80801060355y59b8fa30id334afdbad7e5cca@mail.gmail.com> Message-ID: <2608b8a80801060532x512d2b0bq2e186786f851fac7@mail.gmail.com> (sorry, I hit the send button) >> What is the lifted version you are referring to? > Take the ordinary disjoint union, and then add a new _|_ element, > distinct from both existing copies of _|_ (which are still distinct > from each other). Now why is that not the category-theoretic coproduct? h . Left = f and h . Right = g both for _|_ and for finite elements of the types. And it looks universal to me. >>> Of course, Haskell makes things even worse by lifting the >>> product and exponential objects, >> OK, what goes wrong there, and what is the lifting? > Again, in Haskell, (_|_, _|_) /= _|_. The difference is in the function > f (x, y) = 1 which gives f undefined = undefined but > f (undefined, undefined) = 1. I don't get that one. Given any f and g, we define h x = (f x, g x). Why do we not have fst . h = f and snd . h = g, both in Hask and StrictHask? fst and snd are strict. >> Unfortunately, this means that (alpha, beta) has an extra _|_ >> element < (_|_, _|_), so it's not the categorical product (which >> would lack such an element for the same reason as above). The reason you can't adjoin an extra element to (A,B) in, say, Set, is that you would have nowhere to map it under fst and snd. But here that is not a problem, _|_ goes to _|_ under both. >> This is partly an implementation issue --- compiling pattern matching >> without introducing such a lifting requires a parallel implementation That's interesting. So given a future platform where parallelizing is much cheaper than it is today, we could conceivably have a totally lazy version of Haskell. I wonder what it would be like to program in that environment, what new problems would arise and what new techniques would solve them. Sounds like a nice research topic. Who is working on it? >> --- and partly a semantic issue --- data introduces a single level of >> lifting, every time it is used, and every constructor is completely >> lazy. Unless you use bangs. So both options are available, and that essentially is what defines Haskell as being a non-strict language. >> Functions have the same issue --- in the presence of seq, undefined / >> = const undefined. Right. I am becoming increasingly convinced that the seq issue is a red herring. >> Extensionality is a key part of the definition of all of these >> constructions. The categorical rules are designed to require, in >> concrete categories, that the range of the two injections into a >> coproduct form a partition of the coproduct, the surjective pairing >> law (fst x, snd x) = x holds, and the eta reduction law (\ x -> f x) >> = f holds. Haskell flaunts all three; while some categories have few >> enough morphisms to get away with this (at least some times), Hask is >> not one of them. That interpretation is not something that is essential in the notion of category, only in certain specific examples of categories that you know. Product and coproduct in any given category - whether they exist, what they are like if they exist, and what alternative constructions exist if they do not - reflect the nature of the structure that the category is modeling. I am interested in understanding the category Hask that represents what Haskell really is like as a programming language. Not under some semantic mapping that includes non-computable functions, and that forgets some of the interesting structure that comes from laziness (though that is undoubtably also very interesting). -Yitz From mads_lindstroem at yahoo.dk Sun Jan 6 08:27:10 2008 From: mads_lindstroem at yahoo.dk (Mads =?ISO-8859-1?Q?Lindstr=F8m?=) Date: Sun Jan 6 08:30:40 2008 Subject: [Haskell-cafe] US Homeland Security program language security risks In-Reply-To: <4780BA1F.5070508@btinternet.com> References: <5ae4f2ba0801031336x45b4c14dw34771cbc9ef0d3f4@mail.gmail.com> <4780BA1F.5070508@btinternet.com> Message-ID: <1199626030.4156.3.camel@localhost.localdomain> Hi, Andrew Coppin wrote: > Galchin Vasili wrote: > > Hello, > > > > https://buildsecurityin.us-cert.gov/daisy/bsi/articles/knowledge/coding/295.html > > > > I stumbled across this page. It seems that Haskell and other strongly > > typed functional languages like Ml/OCaml will fare much, much better, > > e.g. buffer overrun. Thoughts . .... comments. > > Human kind has yet to design a programming language which eliminates all > possible bugs. ;-) And we never will. See http://en.wikipedia.org/wiki/Halting_problem . Greetings, Mads > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From daniel.is.fischer at web.de Sun Jan 6 09:08:31 2008 From: daniel.is.fischer at web.de (Daniel Fischer) Date: Sun Jan 6 09:00:59 2008 Subject: [Haskell-cafe] US Homeland Security program language security risks In-Reply-To: <1199626030.4156.3.camel@localhost.localdomain> References: <5ae4f2ba0801031336x45b4c14dw34771cbc9ef0d3f4@mail.gmail.com> <4780BA1F.5070508@btinternet.com> <1199626030.4156.3.camel@localhost.localdomain> Message-ID: <200801061508.32077.daniel.is.fischer@web.de> Am Sonntag, 6. Januar 2008 14:27 schrieb Mads Lindstr?m: > Hi, > > Andrew Coppin wrote: > > Galchin Vasili wrote: > > > Hello, > > > > > > https://buildsecurityin.us-cert.gov/daisy/bsi/articles/knowledge/coding > > >/295.html > > > > > > I stumbled across this page. It seems that Haskell and other strongly > > > typed functional languages like Ml/OCaml will fare much, much better, > > > e.g. buffer overrun. Thoughts . .... comments. > > > > Human kind has yet to design a programming language which eliminates all > > possible bugs. ;-) > > And we never will. See http://en.wikipedia.org/wiki/Halting_problem . > > > Greetings, > > Mads > Just because I don't know: what bugs would be possible in a language having only the instruction return () (';' for imperative programmers)? Cheers, Daniel From andrewcoppin at btinternet.com Sun Jan 6 09:07:48 2008 From: andrewcoppin at btinternet.com (Andrew Coppin) Date: Sun Jan 6 09:01:31 2008 Subject: [Haskell-cafe] US Homeland Security program language security risks In-Reply-To: <1199626030.4156.3.camel@localhost.localdomain> References: <5ae4f2ba0801031336x45b4c14dw34771cbc9ef0d3f4@mail.gmail.com> <4780BA1F.5070508@btinternet.com> <1199626030.4156.3.camel@localhost.localdomain> Message-ID: <4780E0B4.9050207@btinternet.com> Mads Lindstr?m wrote: > Hi, > > Andrew Coppin wrote: > >> Human kind has yet to design a programming language which eliminates all >> possible bugs. ;-) >> > And we never will. Quite so. How can a machine possibly tell whether a given behaviour is a "bug" or an "intended behaviour"? This is impossible. ;-) From andrewcoppin at btinternet.com Sun Jan 6 09:18:40 2008 From: andrewcoppin at btinternet.com (Andrew Coppin) Date: Sun Jan 6 09:12:23 2008 Subject: [Haskell-cafe] US Homeland Security program language security risks In-Reply-To: <200801061508.32077.daniel.is.fischer@web.de> References: <5ae4f2ba0801031336x45b4c14dw34771cbc9ef0d3f4@mail.gmail.com> <4780BA1F.5070508@btinternet.com> <1199626030.4156.3.camel@localhost.localdomain> <200801061508.32077.daniel.is.fischer@web.de> Message-ID: <4780E340.3020402@btinternet.com> Daniel Fischer wrote: > Just because I don't know: > what bugs would be possible in a language having only the instruction > return () > Bug #1: You cannot write any nontrivial programs. ;-) From barsoap at web.de Sun Jan 6 09:19:41 2008 From: barsoap at web.de (Achim Schneider) Date: Sun Jan 6 09:13:36 2008 Subject: [Haskell-cafe] Re: US Homeland Security program language security risks References: <5ae4f2ba0801031336x45b4c14dw34771cbc9ef0d3f4@mail.gmail.com> <4780BA1F.5070508@btinternet.com> <1199626030.4156.3.camel@localhost.localdomain> <200801061508.32077.daniel.is.fischer@web.de> Message-ID: <20080106151941.1aaaa37d@solaris.tower> Daniel Fischer wrote: > Just because I don't know: > what bugs would be possible in a language having only the instruction > return () > (';' for imperative programmers)? > /me waves meaningful with his hand. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From gale at sefer.org Sun Jan 6 09:21:33 2008 From: gale at sefer.org (Yitzchak Gale) Date: Sun Jan 6 09:15:19 2008 Subject: [Haskell-cafe] Basic question concerning the category Hask (was: concerning data constructors) In-Reply-To: <1199620331.6843.33.camel@derek-laptop> References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <1199620331.6843.33.camel@derek-laptop> Message-ID: <2608b8a80801060621t7f02a7b6w7f088abd18f7f93f@mail.gmail.com> I wrote: >> ...it was recently claimed on this list that tuples >> are not products in that category. Derek Elkins wrote: > Johnathan has given such a demonstration (and it has been demonstrated > many times on this list since it's creation, it's well-known). We're still working on it. I've not been convinced yet. Sorry about my thickness. Perhaps this should be on a nice wiki page somewhere. I tried to convince David House to put it in the Wikibook chapter, but he is right, that needs to simpler. There is some discussion on the talk page for that chapter, but no one spells out the details there, either. > You are right not to be impressed by such complaints, but you > misrepresent people's views on this by saying that they "worry" about > such problems. Sorry, I hope I am not misrepresenting anyone. I just notice that people make assumptions about a so-called category Hask, derive various conclusions, then mention that they are not really true. Perhaps it is only me who is worried. > As you say (people say), these properties [that Hask is cartesian closed > to start] would be nice to have and are very convenient to assume which > is often safe enough. I'd like to understand better what is true, so that I can understand what is safe. > Certainly computer scientists of a categorical > bent have developed (weaker) notions to use; namely, monoidal, > pre-monoidal, Freyd, and/or kappa categories and no doubt others. Using > these, however, removes some of the allure of using a categorical > approach. It would be nice to distill out of that the basics that are needed to get the properties that we need for day-to-day work in Haskell. > Also, there is a Haskell-specific problem at the very get-go. > The most "obvious" choice for the categorical composition operator > assuming the "obvious" choice for the arrows and objects does not work... > ...This can > easily be fixed by making the categorical (.) strict in both arguments > and there is no formal problem with it being different from Haskell's > (.), but it certainly is not intuitively appealing. I'm not sure it's so bad. First of all, not only is it not a formal problem, it's also not really a practical problem - there will rarely if ever be any difference between the two when applied in real programs. My opinion is that there would not be any problem with using that version as (.) in the Prelude. Even if we never do, at least we should then use (.!) when we state the so-called "Monad laws". It bothers me that Haskell's so-called "monads" really aren't. That is bound to cause problems. And it would be so easy to fix in most cases - just require monad bind to be strict on the second parameter. Thanks, Yitz From phercek at gmail.com Sun Jan 6 09:39:05 2008 From: phercek at gmail.com (Peter Hercek) Date: Sun Jan 6 09:33:51 2008 Subject: [Haskell-cafe] Re: US Homeland Security program language security risks In-Reply-To: <1199626030.4156.3.camel@localhost.localdomain> References: <5ae4f2ba0801031336x45b4c14dw34771cbc9ef0d3f4@mail.gmail.com> <4780BA1F.5070508@btinternet.com> <1199626030.4156.3.camel@localhost.localdomain> Message-ID: Mads Lindstr?m wrote: > Andrew Coppin wrote: >> Human kind has yet to design a programming language which eliminates all >> possible bugs. ;-) > And we never will. See http://en.wikipedia.org/wiki/Halting_problem . If you limit usage of general recursion (and rather favor structural recursion) then you can mitigate the halting problem. But there always will be specification bugs (when one implenetes something else than what was needed). Peter. From daniel.is.fischer at web.de Sun Jan 6 09:38:58 2008 From: daniel.is.fischer at web.de (Daniel Fischer) Date: Sun Jan 6 09:34:30 2008 Subject: [Haskell-cafe] US Homeland Security program language security risks In-Reply-To: <4780E340.3020402@btinternet.com> References: <5ae4f2ba0801031336x45b4c14dw34771cbc9ef0d3f4@mail.gmail.com> <200801061508.32077.daniel.is.fischer@web.de> <4780E340.3020402@btinternet.com> Message-ID: <200801061538.58319.daniel.is.fischer@web.de> Am Sonntag, 6. Januar 2008 15:18 schrieb Andrew Coppin: > Daniel Fischer wrote: > > Just because I don't know: > > what bugs would be possible in a language having only the instruction > > return () > > Bug #1: You cannot write any nontrivial programs. ;-) > That's not a bug, that's a feature. From jerzy.karczmarczuk at info.unicaen.fr Sun Jan 6 09:51:52 2008 From: jerzy.karczmarczuk at info.unicaen.fr (jerzy.karczmarczuk@info.unicaen.fr) Date: Sun Jan 6 09:45:38 2008 Subject: [Haskell-cafe] Re: US Homeland Security program blahBlah... In-Reply-To: References: <5ae4f2ba0801031336x45b4c14dw34771cbc9ef0d3f4@mail.gmail.com> <4780BA1F.5070508@btinternet.com> <1199626030.4156.3.camel@localhost.localdomain> Message-ID: Peter Hercek writes: >> Andrew Coppin wrote: >>> Human kind has yet to design a programming language which eliminates all >>> possible bugs. ;-) > ...you can mitigate the halting problem. > But there always will be specification bugs (when one implenetes something > else than what was needed). Look, you are descending an infinite ramp to conceptual hell, the hell of triviality. Now, you will discuss "what is needed", and from FP we get into politics! But, if it is something you need... Read then the passage of "Earthsea" of Ursula LeGuin. There is something about a language in which YOU COULD NOT LIE. It was the ancient tongue of dragons. Now we see why the dragons are extinct... They were incompatible with the Democracy, AND with Computing Technology... Jerzy Karczmarczuk From barsoap at web.de Sun Jan 6 09:54:00 2008 From: barsoap at web.de (Achim Schneider) Date: Sun Jan 6 09:47:55 2008 Subject: [Haskell-cafe] Re: US Homeland Security program language security risks References: <5ae4f2ba0801031336x45b4c14dw34771cbc9ef0d3f4@mail.gmail.com> <200801061508.32077.daniel.is.fischer@web.de> <4780E340.3020402@btinternet.com> <200801061538.58319.daniel.is.fischer@web.de> Message-ID: <20080106155400.7b733dd8@solaris.tower> Daniel Fischer wrote: > Am Sonntag, 6. Januar 2008 15:18 schrieb Andrew Coppin: > > Daniel Fischer wrote: > > > Just because I don't know: > > > what bugs would be possible in a language having only the > > > instruction return () > > > > Bug #1: You cannot write any nontrivial programs. ;-) > > > That's not a bug, that's a feature. > That's an interesting task: Design a non-touring complete, restricted language in which every expression is decidable, without making the language unusable for usual programming problems. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From apfelmus at quantentunnel.de Sun Jan 6 10:04:51 2008 From: apfelmus at quantentunnel.de (apfelmus) Date: Sun Jan 6 09:58:45 2008 Subject: [Haskell-cafe] Re: US Homeland Security program language security risks In-Reply-To: <20080106155400.7b733dd8@solaris.tower> References: <5ae4f2ba0801031336x45b4c14dw34771cbc9ef0d3f4@mail.gmail.com> <200801061508.32077.daniel.is.fischer@web.de> <4780E340.3020402@btinternet.com> <200801061538.58319.daniel.is.fischer@web.de> <20080106155400.7b733dd8@solaris.tower> Message-ID: Achim Schneider wrote: > That's an interesting task: Design a non-touring complete, > restricted language in which every expression is decidable, without > making the language unusable for usual programming problems. Have a look about dependently typed languages like Epigram: http://www.e-pig.org/ Regards, apfelmus From daniel.is.fischer at web.de Sun Jan 6 10:19:31 2008 From: daniel.is.fischer at web.de (Daniel Fischer) Date: Sun Jan 6 10:11:56 2008 Subject: [Haskell-cafe] Re: US Homeland Security program language security risks In-Reply-To: <20080106155400.7b733dd8@solaris.tower> References: <5ae4f2ba0801031336x45b4c14dw34771cbc9ef0d3f4@mail.gmail.com> <200801061538.58319.daniel.is.fischer@web.de> <20080106155400.7b733dd8@solaris.tower> Message-ID: <200801061619.31146.daniel.is.fischer@web.de> Am Sonntag, 6. Januar 2008 15:54 schrieb Achim Schneider: > Daniel Fischer wrote: > > Am Sonntag, 6. Januar 2008 15:18 schrieb Andrew Coppin: > > > Daniel Fischer wrote: > > > > Just because I don't know: > > > > what bugs would be possible in a language having only the > > > > instruction return () > > > > > > Bug #1: You cannot write any nontrivial programs. ;-) > > > > That's not a bug, that's a feature. > > That's an interesting task: Design a non-touring complete, > restricted language in which every expression is decidable, without > making the language unusable for usual programming problems. I'm not a logician, but didn't G?del prove that you couldn't express the (full) arithmetic of natural numbers in such a language? Of course it might be possible to express a sufficiently interesting part of it, but I should be surprised. From cristian.baboi at gmail.com Sun Jan 6 10:27:20 2008 From: cristian.baboi at gmail.com (Cristian Baboi) Date: Sun Jan 6 10:21:11 2008 Subject: [Haskell-cafe] Re: US Homeland Security program language security risks In-Reply-To: <200801061619.31146.daniel.is.fischer@web.de> References: <5ae4f2ba0801031336x45b4c14dw34771cbc9ef0d3f4@mail.gmail.com> <200801061538.58319.daniel.is.fischer@web.de> <20080106155400.7b733dd8@solaris.tower> <200801061619.31146.daniel.is.fischer@web.de> Message-ID: On Sun, 06 Jan 2008 17:19:31 +0200, Daniel Fischer wrote: > Am Sonntag, 6. Januar 2008 15:54 schrieb Achim Schneider: >> Daniel Fischer wrote: >> > Am Sonntag, 6. Januar 2008 15:18 schrieb Andrew Coppin: >> > > Daniel Fischer wrote: >> > > > Just because I don't know: >> > > > what bugs would be possible in a language having only the >> > > > instruction return () >> > > >> > > Bug #1: You cannot write any nontrivial programs. ;-) >> > >> > That's not a bug, that's a feature. >> >> That's an interesting task: Design a non-touring complete, >> restricted language in which every expression is decidable, without >> making the language unusable for usual programming problems. > I'm not a logician, but didn't G?del prove that you couldn't express the > (full) arithmetic of natural numbers in such a language? > Of course it might be possible to express a sufficiently interesting > part of > it, but I should be surprised. Neither do I, but if you have non turing algorithms, maybe you could do it. From apfelmus at quantentunnel.de Sun Jan 6 10:39:44 2008 From: apfelmus at quantentunnel.de (apfelmus) Date: Sun Jan 6 10:33:40 2008 Subject: [Haskell-cafe] Re: Basic question concerning the category Hask (was: concerning data constructors) In-Reply-To: <2608b8a80801060621t7f02a7b6w7f088abd18f7f93f@mail.gmail.com> References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <1199620331.6843.33.camel@derek-laptop> <2608b8a80801060621t7f02a7b6w7f088abd18f7f93f@mail.gmail.com> Message-ID: Yitzchak Gale wrote: > I wrote: >>> ...it was recently claimed on this list that tuples >>> are not products in that category. > > I've not been convinced yet. I'm going to try convince you :) The crucial problem of Haskell's product is that (_|_,_|_) ? _|_ but that the two projections fst :: (A,B) -> A snd :: (A,B) -> B cannot distinguish between both values. But if (,) were a categorial product, fst and snd would completely determine it. We would have the universal property that for every f :: C -> A g :: C -> B there is a _unique_ morphism f &&& g :: C -> (A,B) subject to f = fst . (f &&& g) g = snd . (f &&& g) In other words, there is a unique function (&&&) :: forall c . (c -> A) -> (c -> B) -> (c -> (A,B)) f &&& g = \c -> (f c, g c) In the particular case of C=(A,B), f=fst and g=snd , the identity function is such a morphism which means fst &&& snd = id due to uniqueness. But id _|_ ? id (_|_,_|_) while clearly (fst &&& snd) _|_ = (fst &&& snd) (_|_,_|_) > Derek Elkins wrote: >> Also, there is a Haskell-specific problem at the very get-go. >> The most "obvious" choice for the categorical composition operator >> assuming the "obvious" choice for the arrows and objects does not work... >> ...This can >> easily be fixed by making the categorical (.) strict in both arguments >> and there is no formal problem with it being different from Haskell's >> (.), but it certainly is not intuitively appealing. Note that the problem with (.) is "seq's fault" (pun intended :) Otherwise, it would be impossible to distinguish _|_ from its eta-expansion \x._|_ . Regards, apfelmus From derek.a.elkins at gmail.com Sun Jan 6 10:18:28 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Sun Jan 6 11:12:39 2008 Subject: [Haskell-cafe] Re: US Homeland Security program language security risks In-Reply-To: <200801061619.31146.daniel.is.fischer@web.de> References: <5ae4f2ba0801031336x45b4c14dw34771cbc9ef0d3f4@mail.gmail.com> <200801061538.58319.daniel.is.fischer@web.de> <20080106155400.7b733dd8@solaris.tower> <200801061619.31146.daniel.is.fischer@web.de> Message-ID: <1199632708.6843.70.camel@derek-laptop> On Sun, 2008-01-06 at 16:19 +0100, Daniel Fischer wrote: > Am Sonntag, 6. Januar 2008 15:54 schrieb Achim Schneider: > > Daniel Fischer wrote: > > > Am Sonntag, 6. Januar 2008 15:18 schrieb Andrew Coppin: > > > > Daniel Fischer wrote: > > > > > Just because I don't know: > > > > > what bugs would be possible in a language having only the > > > > > instruction return () > > > > > > > > Bug #1: You cannot write any nontrivial programs. ;-) > > > > > > That's not a bug, that's a feature. > > > > That's an interesting task: Design a non-touring complete, > > restricted language in which every expression is decidable, without > > making the language unusable for usual programming problems. > > I'm not a logician, but didn't G?del prove that you couldn't express the > (full) arithmetic of natural numbers in such a language? > Of course it might be possible to express a sufficiently interesting part of > it, but I should be surprised. What Goedel meant by "arithmetic" is a bit more than one usually associates with the term. One person mentioned Epigram. Most theorem provers and most? (of the few) dependently typed programming languages would fit Achim's criterion depending on the range of "usable" and "usual". Coq, for example, is likely to be capable of formalizing just about anything you'd want. Of course, there is one class of "programming problem" that we can already say can't be handled; namely implementing interpreters (for Turing complete languages). We can formalize analyses, make compilers, prove the compilers correct with respect to a semantics, and even prove that a -description- of an interpreter correctly implements the semantics, but we can't actually -run- the interpreter. From gwern0 at gmail.com Sun Jan 6 11:19:08 2008 From: gwern0 at gmail.com (gwern0@gmail.com) Date: Sun Jan 6 11:14:31 2008 Subject: [Haskell-cafe] Re: US Homeland Security program language security risks In-Reply-To: <20080106155400.7b733dd8@solaris.tower> References: <5ae4f2ba0801031336x45b4c14dw34771cbc9ef0d3f4@mail.gmail.com> <200801061508.32077.daniel.is.fischer@web.de> <4780E340.3020402@btinternet.com> <200801061538.58319.daniel.is.fischer@web.de> <20080106155400.7b733dd8@solaris.tower> Message-ID: <20080106161908.GA30576@localhost> On 2008.01.06 15:54:00 +0100, Achim Schneider scribbled 0.6K characters: > Daniel Fischer wrote: > > > Am Sonntag, 6. Januar 2008 15:18 schrieb Andrew Coppin: > > > Daniel Fischer wrote: > > > > Just because I don't know: > > > > what bugs would be possible in a language having only the > > > > instruction return () > > > > > > Bug #1: You cannot write any nontrivial programs. ;-) > > > > > That's not a bug, that's a feature. > > > That's an interesting task: Design a non-touring complete, > restricted language in which every expression is decidable, without > making the language unusable for usual programming problems. Total functional programming, yay: . -- gwern $ Majic shaped Grove infrastructure Spoke BOSS mercur SEIDM BX -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080106/2390efba/attachment.bin From miguelimo38 at yandex.ru Sun Jan 6 12:02:17 2008 From: miguelimo38 at yandex.ru (Miguel Mitrofanov) Date: Sun Jan 6 11:56:09 2008 Subject: [Haskell-cafe] Basic question concerning the category Hask (was: concerning data constructors) In-Reply-To: <2608b8a80801060532x512d2b0bq2e186786f851fac7@mail.gmail.com> References: <20080103101645.90F9F3242E7@www.haskell.org> <7b1ffbe0801030340j2676fe2x272b9a836c59773f@mail.gmail.com> <6A26B181-D657-45A8-9F3E-B7761E9142FD@fastmail.fm> <2608b8a80801051803p692c3207mb207613faec13ce5@mail.gmail.com> <55F0EA86-0962-403E-B133-0545648CA68E@fastmail.fm> <2608b8a80801060355y59b8fa30id334afdbad7e5cca@mail.gmail.com> <2608b8a80801060532x512d2b0bq2e186786f851fac7@mail.gmail.com> Message-ID: <07091784-9CA5-4C30-8DBB-7A47D5297C26@yandex.ru> >> Take the ordinary disjoint union, and then add a new _|_ element, >> distinct from both existing copies of _|_ (which are still distinct >> from each other). > > Now why is that not the category-theoretic coproduct? > h . Left = f and h . Right = g both for _|_ and for finite > elements of the types. And it looks universal to me. Yeah, but there could be more functions from Either X Y to Z than pairs of functions from X to Z and from Y to Z. For example, if z :: Z, then you have two functions h1 and h2 such that h1 . Left = const z and h1 . Right = const z and the same holds for h2. Namely, h1 = const z h2 = either (const z) (const z) This functions are different : h1 (_|_) = z while h2 (_|_) = (_|_). And if Either X Y was a category-theoretic coproduct, then the function from Either X Y to Z would be UNIQUELY determined by it's restrictions to X and Y. From jonathanccast at fastmail.fm Sun Jan 6 12:45:16 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Sun Jan 6 12:39:07 2008 Subject: [Haskell-cafe] Wikipedia on first-class object In-Reply-To: <1199617367.6843.7.camel@derek-laptop> References: <2608b8a80712270110l38830795l5b9a0d05b7835ced@mail.gmail.com> <2608b8a80712270240g97b8601tc0898a5513e1b155@mail.gmail.com> <597F114C-5E60-48ED-9F7F-FF5BC3EE0F97@fastmail.fm> <1199617367.6843.7.camel@derek-laptop> Message-ID: <246AF129-DD30-4132-85A8-32014BA73D7C@fastmail.fm> On 6 Jan 2008, at 3:02 AM, Derek Elkins wrote: > On Fri, 2007-12-28 at 17:54 -0600, Jonathan Cast wrote: > >> Programming languages are generally classified into three groups, >> imperative, functional, and logical. The difference is in the style >> of programming encouraged (or mandated, for older languages) by the >> language. > > Usually the divide is imperative v. declarative with the four major > paradigms (procedural, OO and logic, FP respectively) being > subgroups of > those divisions. And your explanation of this classification is? I find the term `declarative' to be almost completely meaningless. jcc From jonathanccast at fastmail.fm Sun Jan 6 12:50:06 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Sun Jan 6 12:43:57 2008 Subject: [Haskell-cafe] Re: Is there anyone out there who can translate C# generics into Haskell? In-Reply-To: <20080106111309.3f0bc240@solaris.tower> References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <1965805939.20080102232921@gmail.com> <915864007.20080103135418@gmail.com> <8627368.20080103173843@gmail.com> <1762133336.20080103215834@gmail.com> <83DE9074-6529-4B54-B2A5-D3285DC699B0@fastmail.fm> <20080106111309.3f0bc240@solaris.tower> Message-ID: <5DBC0A85-56E4-49D9-86BF-8AEBA6DFB529@fastmail.fm> On 6 Jan 2008, at 2:13 AM, Achim Schneider wrote: > Jonathan Cast wrote: > >> On 4 Jan 2008, at 2:00 AM, Nicholls, Mark wrote: >> >>> You may be right...but learning is not an atomic thing....wherever I >>> start I will get strange things happening. >> >> The best place to start learning Haskell is with the simplest type >> features, not the most complicated. And it's the simplest features >> that are most unlike OO. >> >> Yes, Haskell will be `strange'. But if you think you're `the >> intersection' between Haskell and OO, you'll think things are >> familiar, and you'll be surprised when they turn out to be >> different. I'd concentrate on watching out for differences --- but >> then I can't imagine how finding `familiar' ideas would help. >> > just a sec... > > things like > come to mind. > > But then this has more to do with Monads than with classes. IO, in > particular, and GL and GLUT, which are state machines and > thus predestined for OOP. Your example is very unintuitive and unidiomatic Haskell. The reference to GL makes me think this is for a `low-level' binding to an imperative library, no? Those are scarcely good places to learn Haskell. jcc From jonathanccast at fastmail.fm Sun Jan 6 12:54:15 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Sun Jan 6 12:48:06 2008 Subject: [Haskell-cafe] Basic question concerning the category Hask (was: concerning data constructors) In-Reply-To: <2608b8a80801060355y59b8fa30id334afdbad7e5cca@mail.gmail.com> References: <20080103101645.90F9F3242E7@www.haskell.org> <7b1ffbe0801030340j2676fe2x272b9a836c59773f@mail.gmail.com> <6A26B181-D657-45A8-9F3E-B7761E9142FD@fastmail.fm> <2608b8a80801051803p692c3207mb207613faec13ce5@mail.gmail.com> <55F0EA86-0962-403E-B133-0545648CA68E@fastmail.fm> <2608b8a80801060355y59b8fa30id334afdbad7e5cca@mail.gmail.com> Message-ID: <82EAAF1B-E691-41EA-AC75-7CE85980F575@fastmail.fm> On 6 Jan 2008, at 3:55 AM, Yitzchak Gale wrote: > I wrote: >>> What goes wrong with finite coproducts? The obvious thing to >>> do would be to take the disjoint union of the sets representing the >>> types, identifying the copies of _|_. > > Jonathan Cast wrote: >> This isn't a coproduct. If we have f x = 1 and g y = 2, then there >> should exist a function h such that h . Left = f and h . Right = g... >> But by your rule, Left undefined = Right undefined... >> Which is a contradiction... > > OK, thanks. > >> Unless, of course, >> your require your functions to be strict --- then both f and g above >> become illegal, and repairing them removes the problem. > > You don't have to make them illegal - just not part > of your notion of "coproduct". We're talking past each other --- what is the distinction you are making? jcc From jonathanccast at fastmail.fm Sun Jan 6 13:05:09 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Sun Jan 6 12:58:59 2008 Subject: [Haskell-cafe] Basic question concerning the category Hask (was: concerning data constructors) In-Reply-To: <2608b8a80801060532x512d2b0bq2e186786f851fac7@mail.gmail.com> References: <20080103101645.90F9F3242E7@www.haskell.org> <7b1ffbe0801030340j2676fe2x272b9a836c59773f@mail.gmail.com> <6A26B181-D657-45A8-9F3E-B7761E9142FD@fastmail.fm> <2608b8a80801051803p692c3207mb207613faec13ce5@mail.gmail.com> <55F0EA86-0962-403E-B133-0545648CA68E@fastmail.fm> <2608b8a80801060355y59b8fa30id334afdbad7e5cca@mail.gmail.com> <2608b8a80801060532x512d2b0bq2e186786f851fac7@mail.gmail.com> Message-ID: On 6 Jan 2008, at 5:32 AM, Yitzchak Gale wrote: > (sorry, I hit the send button) > >>> What is the lifted version you are referring to? > >> Take the ordinary disjoint union, and then add a new _|_ element, >> distinct from both existing copies of _|_ (which are still distinct >> from each other). > > Now why is that not the category-theoretic coproduct? > h . Left = f and h . Right = g both for _|_ and for finite > elements of the types. And it looks universal to me. Not quite. The only requirement for h _|_ is that it be <= f x for all x and <= g y for all y. If f x = 1 = g y for all x, y, then both h _|_ = _|_ and h _|_ = 1 are arrows of the category. So the universal property still fails. >>>> Of course, Haskell makes things even worse by lifting the >>>> product and exponential objects, > >>> OK, what goes wrong there, and what is the lifting? > >> Again, in Haskell, (_|_, _|_) /= _|_. The difference is in the >> function >> f (x, y) = 1 which gives f undefined = undefined but >> f (undefined, undefined) = 1. > > I don't get that one. Given any f and g, we define h x = (f x, g x). > Why do we not have fst . h = f and snd . h = g, both in Hask > and StrictHask? fst and snd are strict. Again, if f and g are both strict, we have a choice for h _|_ --- either h _|_ = _|_ or h _|_ = (_|_, _|_) will work (fst . h = f and snd . h = g), but again these are different morphisms. > >>> Unfortunately, this means that (alpha, beta) has an extra _|_ >>> element < (_|_, _|_), so it's not the categorical product (which >>> would lack such an element for the same reason as above). > > The reason you can't adjoin an extra element to (A,B) in, say, > Set, is that you would have nowhere to map it under fst > and snd. But here that is not a problem, _|_ goes to _|_ > under both. > >>> This is partly an implementation issue --- compiling pattern >>> matching >>> without introducing such a lifting requires a parallel >>> implementation > > That's interesting. So given a future platform where parallelizing > is much cheaper than it is today, we could conceivably have > a totally lazy version of Haskell. I wonder what it would be like > to program in that environment, what new problems would arise > and what new techniques would solve them. Sounds like a nice > research topic. Who is working on it? > >>> --- and partly a semantic issue --- data introduces a single >>> level of >>> lifting, every time it is used, and every constructor is completely >>> lazy. > > Unless you use bangs. So both options are available, and that > essentially is what defines Haskell as being a non-strict language. (!alpha, !beta) isn't a categorical product, either. snd (undefined, 1) = undefined with this type. > >>> Functions have the same issue --- in the presence of seq, >>> undefined / >>> = const undefined. > > Right. I am becoming increasingly convinced that the seq issue > is a red herring. Care to give an explanation? > >>> Extensionality is a key part of the definition of all of these >>> constructions. The categorical rules are designed to require, in >>> concrete categories, that the range of the two injections into a >>> coproduct form a partition of the coproduct, the surjective pairing >>> law (fst x, snd x) = x holds, and the eta reduction law (\ x -> f x) >>> = f holds. Haskell flaunts all three; while some categories have >>> few >>> enough morphisms to get away with this (at least some times), >>> Hask is >>> not one of them. > > That interpretation is not something that is essential in the notion > of category, only in certain specific examples of categories > that you know. I understand category theory. I also know that the definitions used are chosen to get Set `right', which means extensionality in that case, and are then extended uniformly across all categories. This has the effect of requiring similar constructions to those in Set in other concrete categories. > Product and coproduct in any given category - > whether they exist, what they are like if they exist, and what > alternative > constructions exist if they do not - reflect the nature of the > structure > that the category is modeling. I understand that. I'm not sure you do. > > I am interested in understanding the category Hask that represents > what Haskell really is like as a programming language. Good luck. > Not > under some semantic mapping that includes non-computable > functions, and that forgets some of the interesting structure > that comes from laziness (though that is undoubtably also > very interesting). Bear in mind in your quest, that at the end of it you'll most likely conclude, like everyone else, that good old equational reasoning is sound for the programs you actually right at least 90% of the time (with appropriate induction principles), and complete for at least 90% of what you want to right, and go back to using it exclusively for real programming. jcc From saihemanth at gmail.com Sun Jan 6 13:34:39 2008 From: saihemanth at gmail.com (Sai Hemanth K) Date: Sun Jan 6 13:28:25 2008 Subject: [Haskell-cafe] Newbie question related to list evaluation Message-ID: <650778a70801061034g1dff2351o39d120faf4961a0a@mail.gmail.com> Hi, I am new to functional and lazy programming languages ( that's correct, my life has been pretty pathetic so far) and am not able to understand GHC's behaviour for a particular function. Can someone help me please? I am trying to write a function which would compare two strings (from reverse) and return the position of first mismatch. This is part of the right-to-left scan of bayer-moore algorithm.. and it is essential for me to do it from reverse. Since my goal is to learn haskell, I am not using Data.ByteString. My function is as follows: matchReverse :: String -> String ->Int->(Bool,Int) matchReverse [] [] pos = (True,pos) matchReverse _ [] pos = (False,pos) matchReverse [] _ pos = (False,pos) matchReverse (x:xs) (y:ys) pos = let (matched,pos) = matchReverse xs ys (pos +1) in if matched then ((x==y),pos) else (False,pos) The behaviour I expected in four scenarios is as below: 1.matchReverse "kapilash" "kapilash" 0 --should return (True,0) 2.matchReverse "kapilash" "kapilast" 0 --should return (False,8) 3.matchReverse str1 str2 0 --should return (False,0) 4.matchReverse str1 str1 0 --should return (True,0) where str1 and str2 are defined as below: str1 = replicate 1000 'a' str2 = 'b':(replicate 999 'a') what confounds me is that it is able to identify the first element of the tuple in ALL the cases. Invoking fst on the each of the four calls instantly returns the expected value.(even for the cases 3 and 4 where, there are thousand elements) But it seems to go into an infinite loop while calculating the 'snd' of the tuple. Even for strings containing just one element each. can someone throw some light on this please? Why does it go into an infinite loop? Many thanks Kapilash -- I drink I am thunk. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080107/f9dc0a49/attachment.htm From overdrigzed at gmail.com Sun Jan 6 13:40:17 2008 From: overdrigzed at gmail.com (Rodrigo Queiro) Date: Sun Jan 6 13:34:04 2008 Subject: [Haskell-cafe] Newbie question related to list evaluation In-Reply-To: <650778a70801061034g1dff2351o39d120faf4961a0a@mail.gmail.com> References: <650778a70801061034g1dff2351o39d120faf4961a0a@mail.gmail.com> Message-ID: <2eb8984a0801061040j38789f38l6c9ee08e0cea6a0b@mail.gmail.com> You have used the name 'pos' twice, for both the parameter and the returned value of the recursive call. The reason this results in an infinite loop is that in code like let x = x + 1 Haskell treats both xs to be references to the same thing, so evaluates: x = x + 1 = (x + 1) + 1 = ((x + 1) + 1) + 1 ... which results in the infinite loop. On 06/01/2008, Sai Hemanth K wrote: > Hi, > > I am new to functional and lazy programming languages ( that's correct, my > life has been pretty pathetic so far) and am not able to understand GHC's > behaviour for a particular function. Can someone help me please? > > I am trying to write a function which would compare two strings (from > reverse) and return the position of first mismatch. This is part of the > right-to-left scan of bayer-moore algorithm.. and it is essential for me to > do it from reverse. > Since my goal is to learn haskell, I am not using Data.ByteString. > > My function is as follows: > > matchReverse :: String -> String ->Int->(Bool,Int) > matchReverse [] [] pos = (True,pos) > matchReverse _ [] pos = (False,pos) > matchReverse [] _ pos = (False,pos) > matchReverse (x:xs) (y:ys) pos = let (matched,pos) = matchReverse xs ys (pos > +1) > in if matched then > ((x==y),pos) > else (False,pos) > > > > The behaviour I expected in four scenarios is as below: > 1.matchReverse "kapilash" "kapilash" 0 --should return (True,0) > 2.matchReverse "kapilash" "kapilast" 0 --should return (False,8) > 3.matchReverse str1 str2 0 --should return (False,0) > 4.matchReverse str1 str1 0 --should return (True,0) > > where str1 and str2 are defined as below: > str1 = replicate 1000 'a' > str2 = 'b':(replicate 999 'a') > > what confounds me is that it is able to identify the first element of the > tuple in ALL the cases. > Invoking fst on the each of the four calls instantly returns the expected > value.(even for the cases 3 and 4 where, there are thousand elements) > But it seems to go into an infinite loop while calculating the 'snd' of the > tuple. Even for strings containing just one element each. > can someone throw some light on this please? Why does it go into an infinite > loop? > > Many thanks > Kapilash > > > -- > I drink I am thunk. > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > From jonathanccast at fastmail.fm Sun Jan 6 13:40:12 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Sun Jan 6 13:34:07 2008 Subject: [Haskell-cafe] Newbie question related to list evaluation In-Reply-To: <650778a70801061034g1dff2351o39d120faf4961a0a@mail.gmail.com> References: <650778a70801061034g1dff2351o39d120faf4961a0a@mail.gmail.com> Message-ID: <3AAB11DF-5C53-41E2-B2AE-9576D74D5F71@fastmail.fm> On 6 Jan 2008, at 10:34 AM, Sai Hemanth K wrote: > Hi, > > I am new to functional and lazy programming languages ( that's > correct, my life has been pretty pathetic so far) and am not able > to understand GHC's behaviour for a particular function. Can > someone help me please? > > I am trying to write a function which would compare two strings > (from reverse) and return the position of first mismatch. This is > part of the right-to-left scan of bayer-moore algorithm.. and it is > essential for me to do it from reverse. > Since my goal is to learn haskell, I am not using Data.ByteString. > > My function is as follows: > > matchReverse :: String -> String ->Int->(Bool,Int) > matchReverse [] [] pos = (True,pos) > matchReverse _ [] pos = (False,pos) > matchReverse [] _ pos = (False,pos) > matchReverse (x:xs) (y:ys) pos = let (matched,pos) = matchReverse > xs ys (pos +1) > in if matched > then ((x==y),pos) > else (False,pos) let is always recursive in Haskell, so this is a recursive definition of pos. To break the recursion, use matchReverse (x:xs) (y:ys) pos = let (matched, pos') = matchReverse xs ys (pos + 1) in if matched then ((x==y), pos') else (False, pos') > > > > > The behaviour I expected in four scenarios is as below: > 1.matchReverse "kapilash" "kapilash" 0 --should return (True,0) > 2.matchReverse "kapilash" "kapilast" 0 --should return (False,8) > 3.matchReverse str1 str2 0 --should return > (False,0) > 4.matchReverse str1 str1 0 --should return > (True,0) > > where str1 and str2 are defined as below: > str1 = replicate 1000 'a' > str2 = 'b':(replicate 999 'a') > > what confounds me is that it is able to identify the first element > of the tuple in ALL the cases. > Invoking fst on the each of the four calls instantly returns the > expected value.(even for the cases 3 and 4 where, there are > thousand elements) > But it seems to go into an infinite loop while calculating the > 'snd' of the tuple. Even for strings containing just one element each. > can someone throw some light on this please? Why does it go into an > infinite loop? > > Many thanks > Kapilash > > > -- > I drink I am thunk. > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From felipe.lessa at gmail.com Sun Jan 6 13:45:48 2008 From: felipe.lessa at gmail.com (Felipe Lessa) Date: Sun Jan 6 13:39:34 2008 Subject: [Haskell-cafe] Newbie question related to list evaluation In-Reply-To: <3AAB11DF-5C53-41E2-B2AE-9576D74D5F71@fastmail.fm> References: <650778a70801061034g1dff2351o39d120faf4961a0a@mail.gmail.com> <3AAB11DF-5C53-41E2-B2AE-9576D74D5F71@fastmail.fm> Message-ID: On Jan 6, 2008 4:40 PM, Jonathan Cast wrote: > let is always recursive in Haskell, so this is a recursive definition > of pos. To break the recursion, use > > > matchReverse (x:xs) (y:ys) pos = let (matched, pos') = matchReverse > xs ys (pos + 1) > in if matched then ((x==y), pos') > else (False, pos') Actually, I think he meant matchReverse (x:xs) (y:ys) pos = let (matched, pos') = matchReverse xs ys (pos + 1) in if matched then ((x==y), pos) else (False, pos') As as side note, GHC's flag -Wall would have warned about creating a variable with a name already in scope. -- Felipe. From saihemanth at gmail.com Sun Jan 6 13:45:57 2008 From: saihemanth at gmail.com (Sai Hemanth K) Date: Sun Jan 6 13:39:44 2008 Subject: [Haskell-cafe] Newbie question related to list evaluation In-Reply-To: <2eb8984a0801061040j38789f38l6c9ee08e0cea6a0b@mail.gmail.com> References: <650778a70801061034g1dff2351o39d120faf4961a0a@mail.gmail.com> <2eb8984a0801061040j38789f38l6c9ee08e0cea6a0b@mail.gmail.com> Message-ID: <650778a70801061045v7d62e6acs71fab76c81fc4fd0@mail.gmail.com> AAh! Thanks a ton! Hemanth K On Jan 7, 2008 12:10 AM, Rodrigo Queiro wrote: > You have used the name 'pos' twice, for both the parameter and the > returned value of the recursive call. The reason this results in an > infinite loop is that in code like > > let x = x + 1 > > Haskell treats both xs to be references to the same thing, so evaluates: > x > = x + 1 > = (x + 1) + 1 > = ((x + 1) + 1) + 1 > ... > > which results in the infinite loop. > > On 06/01/2008, Sai Hemanth K wrote: > > Hi, > > > > I am new to functional and lazy programming languages ( that's correct, > my > > life has been pretty pathetic so far) and am not able to understand > GHC's > > behaviour for a particular function. Can someone help me please? > > > > I am trying to write a function which would compare two strings (from > > reverse) and return the position of first mismatch. This is part of the > > right-to-left scan of bayer-moore algorithm.. and it is essential for me > to > > do it from reverse. > > Since my goal is to learn haskell, I am not using Data.ByteString. > > > > My function is as follows: > > > > matchReverse :: String -> String ->Int->(Bool,Int) > > matchReverse [] [] pos = (True,pos) > > matchReverse _ [] pos = (False,pos) > > matchReverse [] _ pos = (False,pos) > > matchReverse (x:xs) (y:ys) pos = let (matched,pos) = matchReverse xs ys > (pos > > +1) > > in if matched then > > ((x==y),pos) > > else (False,pos) > > > > > > > > The behaviour I expected in four scenarios is as below: > > 1.matchReverse "kapilash" "kapilash" 0 --should return (True,0) > > 2.matchReverse "kapilash" "kapilast" 0 --should return (False,8) > > 3.matchReverse str1 str2 0 --should return > (False,0) > > 4.matchReverse str1 str1 0 --should return (True,0) > > > > where str1 and str2 are defined as below: > > str1 = replicate 1000 'a' > > str2 = 'b':(replicate 999 'a') > > > > what confounds me is that it is able to identify the first element of > the > > tuple in ALL the cases. > > Invoking fst on the each of the four calls instantly returns the > expected > > value.(even for the cases 3 and 4 where, there are thousand elements) > > But it seems to go into an infinite loop while calculating the 'snd' of > the > > tuple. Even for strings containing just one element each. > > can someone throw some light on this please? Why does it go into an > infinite > > loop? > > > > Many thanks > > Kapilash > > > > > > -- > > I drink I am thunk. > > _______________________________________________ > > Haskell-Cafe mailing list > > Haskell-Cafe@haskell.org > > http://www.haskell.org/mailman/listinfo/haskell-cafe > > > > > -- I drink I am thunk. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080107/b4345758/attachment.htm From barsoap at web.de Sun Jan 6 13:48:13 2008 From: barsoap at web.de (Achim Schneider) Date: Sun Jan 6 13:42:09 2008 Subject: [Haskell-cafe] Re: Is there anyone out there who can translate C# generics into Haskell? References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <1965805939.20080102232921@gmail.com> <915864007.20080103135418@gmail.com> <8627368.20080103173843@gmail.com> <1762133336.20080103215834@gmail.com> <83DE9074-6529-4B54-B2A5-D3285DC699B0@fastmail.fm> <20080106111309.3f0bc240@solaris.tower> <5DBC0A85-56E4-49D9-86BF-8AEBA6DFB529@fastmail.fm> Message-ID: <20080106194813.72947367@solaris.tower> Jonathan Cast wrote: > On 6 Jan 2008, at 2:13 AM, Achim Schneider wrote: > > > Jonathan Cast wrote: > > > >> On 4 Jan 2008, at 2:00 AM, Nicholls, Mark wrote: > >> > >>> You may be right...but learning is not an atomic > >>> thing....wherever I start I will get strange things happening. > >> > >> The best place to start learning Haskell is with the simplest type > >> features, not the most complicated. And it's the simplest features > >> that are most unlike OO. > >> > >> Yes, Haskell will be `strange'. But if you think you're `the > >> intersection' between Haskell and OO, you'll think things are > >> familiar, and you'll be surprised when they turn out to be > >> different. I'd concentrate on watching out for differences --- but > >> then I can't imagine how finding `familiar' ideas would help. > >> > > just a sec... > > > > things like > > > > > come to mind. > > > > But then this has more to do with Monads than with classes. IO, in > > particular, and GL and GLUT, which are state machines and > > thus predestined for OOP. > > Your example is very unintuitive and unidiomatic Haskell. The > reference to GL makes me think this is for a `low-level' binding to > an imperative library, no? Those are scarcely good places to learn > Haskell. > Well, I learnt a lot, knowing GL quite well already and seeing how easy everything fit together and how easy it was to abstract things away, like stuffing a bunch of IO actions consisting of GL primitives into a map, automatically generating and managing display-lists... I don't speak C++, btw, just C and Java. You can't just take years of programming experience and then start again with calculating Fibonacci numbers, just this time implemented functionally... There's always this creepy feeling that you understand everything, although you didn't understand a thing. Shivers run down my spine when I think about how let amb = 0.2 ambm = 0.2 spec = 0.7 preservingMatrix $ do materialDiffuse FrontAndBack $= Color4 ambm ambm ambm 0.3 materialSpecular FrontAndBack $= Color4 spec spec spec 0.7 materialShininess FrontAndBack $= 50 border 30 40 (depth * 10) 0.01 True looks like in C. or, for that matter, what atrocious code gcc generates if you parametrise calls to vertex3f with functions. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From miguelimo38 at yandex.ru Sun Jan 6 14:04:01 2008 From: miguelimo38 at yandex.ru (Miguel Mitrofanov) Date: Sun Jan 6 13:57:55 2008 Subject: [Haskell-cafe] Re: US Homeland Security program language security risks In-Reply-To: <20080106155400.7b733dd8@solaris.tower> References: <5ae4f2ba0801031336x45b4c14dw34771cbc9ef0d3f4@mail.gmail.com> <200801061508.32077.daniel.is.fischer@web.de> <4780E340.3020402@btinternet.com> <200801061538.58319.daniel.is.fischer@web.de> <20080106155400.7b733dd8@solaris.tower> Message-ID: <7E10AC09-9888-4F92-996D-E3B45810D86C@yandex.ru> > That's an interesting task: Design a non-touring complete, > restricted language in which every expression is decidable, without > making the language unusable for usual programming problems. Well, I did something like that a few years ago - it was a sort of assembler language, allowing the programmer to, say, sort an array, but not to calculate Akkerman function. From andrewcoppin at btinternet.com Sun Jan 6 14:47:02 2008 From: andrewcoppin at btinternet.com (Andrew Coppin) Date: Sun Jan 6 14:40:49 2008 Subject: [Haskell-cafe] Newbie question related to list evaluation In-Reply-To: References: <650778a70801061034g1dff2351o39d120faf4961a0a@mail.gmail.com> <3AAB11DF-5C53-41E2-B2AE-9576D74D5F71@fastmail.fm> Message-ID: <47813036.30305@btinternet.com> Felipe Lessa wrote: > As as side note, GHC's flag -Wall would have warned about creating a > variable with a name already in scope. > *makes a mental note* I've created bugs like this far too many times... From ketil+haskell at ii.uib.no Sun Jan 6 15:02:17 2008 From: ketil+haskell at ii.uib.no (Ketil Malde) Date: Sun Jan 6 14:56:10 2008 Subject: [Haskell-cafe] Quanta. Was: Wikipedia on first-class object In-Reply-To: <1199617488.6843.10.camel@derek-laptop> (Derek Elkins's message of "Sun\, 06 Jan 2008 05\:04\:48 -0600") References: <2608b8a80712270110l38830795l5b9a0d05b7835ced@mail.gmail.com> <1934333921.20071227154048@gmail.com> <47767D39.4020007@btinternet.com> <20071229184005.702ab59c@solaris.tower> <1695012808.20071229213744@gmail.com> <4683d9370712291042w21873ae3xcb0376e05b0a3326@mail.gmail.com> <1995050719.20071229215903@gmail.com> <20071229201639.22c43260@solaris.tower> <1372887653.20071229223329@gmail.com> <000001c84a57$2c7b7e00$85727a00$@be> <568741883.20071230011816@gmail.com> <871w94fugj.fsf@nmd9999.imr.no> <1199617488.6843.10.camel@derek-laptop> Message-ID: <87y7b2vi2e.fsf@nmd9999.imr.no> Derek Elkins writes: >> I don't understand your point. We know what swimming is: floating and >> moving autonomously. You're the first one I've heard who would use the term 'swimming' for ships. (And to be pedantic, wouldn't you say that fish swim, except when they float?) The point - stolen from Dennet, I think -- is that it is not terribly relevant wheter machines can think or just, you know, float and move autonomously, forever voyaging through dark seas... >> For goodness sake, I have *REALLY* the impression that those guys who >> speak about computability of the Universe, Who is speaking about computability of the universe? This looks like a straw man to me. >> have the mentality of 18 century thinkers for whom the world was >> simple and mechanistic. Or even the mentality of people >> contemporary of Democritus, for whom everything "reduced" to some >> dance of atoms. > Or a wave function for the Universe... So - your counterclaim is that something complex and mystic and incomprehensible cannot arise from the simple, tangible and understood? Perhaps my views are *so* 1980s, but not 18th century, I think. Why is it that we cannot design roads so that we avoid traffic jams? Don't we understand cars and asphalt? Quantum effects in the combustion engine, perhaps? More seriously, perhaps "quantum" enters into the equation in how the brain works, perhaps it is even necessary for "thought". However, I get worried it's just another mystical mantra, a gratuitous factor that, lacking any theory about how and what it does, adds nothing to help understanding the issue. -k -- If I haven't seen further, it is by standing in the footprints of giants From dominic.steinitz at blueyonder.co.uk Sun Jan 6 15:27:04 2008 From: dominic.steinitz at blueyonder.co.uk (Dominic Steinitz) Date: Sun Jan 6 15:20:55 2008 Subject: [Haskell-cafe] Re: Basic question concerning the category Hask (was: concerning data constructors) References: <20080103101645.90F9F3242E7@www.haskell.org> <7b1ffbe0801030340j2676fe2x272b9a836c59773f@mail.gmail.com> <6A26B181-D657-45A8-9F3E-B7761E9142FD@fastmail.fm> <2608b8a80801051803p692c3207mb207613faec13ce5@mail.gmail.com> <55F0EA86-0962-403E-B133-0545648CA68E@fastmail.fm> <2608b8a80801060355y59b8fa30id334afdbad7e5cca@mail.gmail.com> <2608b8a80801060532x512d2b0bq2e186786f851fac7@mail.gmail.com> Message-ID: Jonathan Cast fastmail.fm> writes: > > > > >>> Extensionality is a key part of the definition of all of these > >>> constructions. The categorical rules are designed to require, in > >>> concrete categories, that the range of the two injections into a > >>> coproduct form a partition of the coproduct, the surjective pairing > >>> law (fst x, snd x) = x holds, and the eta reduction law (\ x -> f x) > >>> = f holds. Haskell flaunts all three; while some categories have > >>> few > >>> enough morphisms to get away with this (at least some times), > >>> Hask is > >>> not one of them. > > > > That interpretation is not something that is essential in the notion > > of category, only in certain specific examples of categories > > that you know. > > I understand category theory. I also know that the definitions used > are chosen to get Set `right', which means extensionality in that > case, and are then extended uniformly across all categories. This > has the effect of requiring similar constructions to those in Set in > other concrete categories. > Referring to my copy of "Sheaves in Geometry and Logic", Moerdijk and Mac Lane state that "in 1963 Lawvere embarked on the daring project of a purely categorical foundation of all mathematics". Did he fail? I'm probably misunderstanding what you are saying here but I didn't think you needed sets to define categories; in fact Set is a topos which has far more structure than a category. Can you be clearer what you mean by extensionality in this context? And how it relates to Set? On a broader note, I'm pleased that this discussion is taking place and I wish someone would actually write a wiki page on why Haskell isn't a nicely behaved category and what problems this causes / doesn't cause. I wish I had time. Dominic. From allbery at ece.cmu.edu Sun Jan 6 15:39:14 2008 From: allbery at ece.cmu.edu (Brandon S. Allbery KF8NH) Date: Sun Jan 6 15:33:03 2008 Subject: [Haskell-cafe] Quanta. Was: Wikipedia on first-class object In-Reply-To: <87y7b2vi2e.fsf@nmd9999.imr.no> References: <2608b8a80712270110l38830795l5b9a0d05b7835ced@mail.gmail.com> <1934333921.20071227154048@gmail.com> <47767D39.4020007@btinternet.com> <20071229184005.702ab59c@solaris.tower> <1695012808.20071229213744@gmail.com> <4683d9370712291042w21873ae3xcb0376e05b0a3326@mail.gmail.com> <1995050719.20071229215903@gmail.com> <20071229201639.22c43260@solaris.tower> <1372887653.20071229223329@gmail.com> <000001c84a57$2c7b7e00$85727a00$@be> <568741883.20071230011816@gmail.com> <871w94fugj.fsf@nmd9999.imr.no> <1199617488.6843.10.camel@derek-laptop> <87y7b2vi2e.fsf@nmd9999.imr.no> Message-ID: <772A83B9-7FC9-4A79-811C-4174AD89FEC0@ece.cmu.edu> On Jan 6, 2008, at 15:02 , Ketil Malde wrote: > More seriously, perhaps "quantum" enters into the equation in how the > brain works, perhaps it is even necessary for "thought". However, I > get worried it's just another mystical mantra, a gratuitous factor > that, lacking any theory about how and what it does, adds nothing to > help understanding the issue. I should not get into these off-topic things... but the viewpoint that worries you is only espoused by people looking for excuses to apply their favorite mystical mantra. Quantum effects are well defined, but nonintuitive (for example, particles "tunneling through" a barrier). -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH From ben.franksen at online.de Sun Jan 6 15:40:08 2008 From: ben.franksen at online.de (Ben Franksen) Date: Sun Jan 6 15:35:52 2008 Subject: [Haskell-cafe] Re: Re: US Homeland Security program language security risks References: <5ae4f2ba0801031336x45b4c14dw34771cbc9ef0d3f4@mail.gmail.com> <200801061508.32077.daniel.is.fischer@web.de> <4780E340.3020402@btinternet.com> <200801061538.58319.daniel.is.fischer@web.de> <20080106155400.7b733dd8@solaris.tower> <7E10AC09-9888-4F92-996D-E3B45810D86C@yandex.ru> Message-ID: Miguel Mitrofanov wrote: >> That's an interesting task: Design a non-touring complete, >> restricted language in which every expression is decidable, without >> making the language unusable for usual programming problems. > > Well, I did something like that a few years ago - it was a sort of > assembler language, allowing the programmer to, say, sort an array, > but not to calculate Akkerman function. P. Wadler, in his famous paper "Theorems for free!", writes on page 2: "Indeed, every recursive function that can be proved total in second order Peano arithmetic can be written as a term in the Girard/Reynolds calculus [...]. This includes, for instancs, Ackerman's function [...], but excludes interpreters for most languages (including the Girard/Reynolds calculus itself)." BTW, another name for the Girard/Reynolds calculus is "(pure) polymorphic lambda calculus"; and yes, it is strongly normalizing. (Wadler cites some papers to support the above claim.) It seems there is quite a lot of interesting stuff that can be done in a language where every expression is guaranteed to terminate. Cheers Ben From jonathanccast at fastmail.fm Sun Jan 6 15:58:45 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Sun Jan 6 15:52:38 2008 Subject: [Haskell-cafe] Re: Basic question concerning the category Hask (was: concerning data constructors) In-Reply-To: References: <20080103101645.90F9F3242E7@www.haskell.org> <7b1ffbe0801030340j2676fe2x272b9a836c59773f@mail.gmail.com> <6A26B181-D657-45A8-9F3E-B7761E9142FD@fastmail.fm> <2608b8a80801051803p692c3207mb207613faec13ce5@mail.gmail.com> <55F0EA86-0962-403E-B133-0545648CA68E@fastmail.fm> <2608b8a80801060355y59b8fa30id334afdbad7e5cca@mail.gmail.com> <2608b8a80801060532x512d2b0bq2e186786f851fac7@mail.gmail.com> Message-ID: <4C0F2AF8-A044-45AB-A87C-E77EC1A94C53@fastmail.fm> On 6 Jan 2008, at 12:27 PM, Dominic Steinitz wrote: > Jonathan Cast fastmail.fm> writes: > >> >>> >>>>> Extensionality is a key part of the definition of all of these >>>>> constructions. The categorical rules are designed to require, in >>>>> concrete categories, that the range of the two injections into a >>>>> coproduct form a partition of the coproduct, the surjective >>>>> pairing >>>>> law (fst x, snd x) = x holds, and the eta reduction law (\ x -> >>>>> f x) >>>>> = f holds. Haskell flaunts all three; while some categories have >>>>> few >>>>> enough morphisms to get away with this (at least some times), >>>>> Hask is >>>>> not one of them. >>> >>> That interpretation is not something that is essential in the notion >>> of category, only in certain specific examples of categories >>> that you know. >> >> I understand category theory. I also know that the definitions used >> are chosen to get Set `right', which means extensionality in that >> case, and are then extended uniformly across all categories. This >> has the effect of requiring similar constructions to those in Set in >> other concrete categories. >> > > Referring to my copy of "Sheaves in Geometry and Logic", Moerdijk > and Mac Lane > state that "in 1963 Lawvere embarked on the daring project of a purely > categorical foundation of all mathematics". Did he fail? I'm probably > misunderstanding what you are saying here but I didn't think you > needed sets to > define categories; Right. But category theory is nevertheless `backward compatible' with set theory, in the sense that the category theoretic constructions in a category satisfying ZFC will be the same constructions we are familiar with already. The category-theoretic definitions, when specialized to Set, are precise (up to natural isomorphism) definitions of the pre-existing concepts of cartesian products, functions, etc. in Set. Or, to put it another way, the category-theoretic definitions are generalizations of those pre- existing concepts to other categories. Hask has a structure that is Set-like enough that these concepts generalize very little when moving to Hask. > in fact Set is a topos which has far more structure than a > category. Can you be clearer what you mean by extensionality in > this context? By `extensionality' I mean the equalities which follow from using standard set-theoretic definitions for functions, products, coproducts, etc. --- surjective pairing, eta-contraction, etc. My understanding is that, in fact, the category-theoretic definitions are designed to capture those equations in diagrams that can be used as definitions in arbitrary categories. It's possible to view those definitions, then, as more fundamental descriptions of the concepts than what they generalize, but the fact that they are generalizations of the ideas from Set shows up in categories similar to Set (and Hask is certainly more similar to Set than, say, Vec). jcc From ben.franksen at online.de Sun Jan 6 16:03:08 2008 From: ben.franksen at online.de (Ben Franksen) Date: Sun Jan 6 15:58:42 2008 Subject: [Haskell-cafe] Re: Concurrency questions References: <4780BBED.5020907@btinternet.com> <4780BF59.2000206@btinternet.com> Message-ID: Andrew Coppin wrote: > Felipe Lessa wrote: >> On Jan 6, 2008 9:30 AM, Andrew Coppin >> wrote: >> >>> 2. I have a situation where I have a thread generating some data and >>> putting it into a mutable array, and another thread trying to read that >>> data. Is there a way I can make the reader thread block if it tries to >>> read a cell that hasn't been computed yet, but not introduce too much >>> overhead for cells that have been filled in? I am fairly sure that this is not possible with an MVar that contains the whole array. You could, however, keep the information about which elements have already been initialized in a separate data structure, for instance a set of indices (using e.g. Data.IntSet) >> If your thread fills the array linearly, you could maintain a variable >> shared by those threads that say the last cell computed, and have the >> read thread check that before reading. I think this wouldn't create >> too much overhead, although it seems like there must be something >> cleverer somewhere. >> > > That's just it - it fills the array in a fairly random order. (The > *scanning* is, however, in linear order.) > > It's not a big problem - I can wait for the entire array to be filled, > and then scan it. But I'd like to do both in parallel if there's a > reasonably easy way to do it. > > I suppose an array of MVars would do it, but > > 1. How big is an MVar? > > 2. You have to take the data out of an MVar to read it. In other words, > only 1 thread can read an MVar at once [by design]. This isn't truly a > problem in the current case, but it's irritating in principle that I > can't make it so that once the cell is written, multiple threads can > read it simultaneously... I first thought that Control.Concurrent.SampleVar would be your solution but nope, reading it still makes it empty. Have you tried STM and TVar? (I mean, an array of TVars). Cheers Ben From derek.a.elkins at gmail.com Sun Jan 6 15:13:13 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Sun Jan 6 16:07:23 2008 Subject: [Haskell-cafe] Wikipedia on first-class object In-Reply-To: <246AF129-DD30-4132-85A8-32014BA73D7C@fastmail.fm> References: <2608b8a80712270110l38830795l5b9a0d05b7835ced@mail.gmail.com> <2608b8a80712270240g97b8601tc0898a5513e1b155@mail.gmail.com> <597F114C-5E60-48ED-9F7F-FF5BC3EE0F97@fastmail.fm> <1199617367.6843.7.camel@derek-laptop> <246AF129-DD30-4132-85A8-32014BA73D7C@fastmail.fm> Message-ID: <1199650393.6843.102.camel@derek-laptop> On Sun, 2008-01-06 at 09:45 -0800, Jonathan Cast wrote: > On 6 Jan 2008, at 3:02 AM, Derek Elkins wrote: > > > On Fri, 2007-12-28 at 17:54 -0600, Jonathan Cast wrote: > > > >> Programming languages are generally classified into three groups, > >> imperative, functional, and logical. The difference is in the style > >> of programming encouraged (or mandated, for older languages) by the > >> language. > > > > Usually the divide is imperative v. declarative with the four major > > paradigms (procedural, OO and logic, FP respectively) being > > subgroups of > > those divisions. > > And your explanation of this classification is? > > I find the term `declarative' to be almost completely meaningless. I was originally thinking of having the final sentence: "There are no clear, accepted meanings for any of these terms." Many people find any, perhaps all, of the terms: "functional", "object oriented", "imperative" to be almost completely meaningless. Mostly the terms have no prescriptive meaning, but rather are defined by example. At any rate, I wasn't and didn't explain anything as that was not my intention. I was merely pointing out that your usage is against the "norms" and in a way similar in its disconcertingness to saying, "American politics is classified into three groups, conservatives, Democrats and libertarians." From jerzy.karczmarczuk at info.unicaen.fr Sun Jan 6 16:31:31 2008 From: jerzy.karczmarczuk at info.unicaen.fr (jerzy.karczmarczuk@info.unicaen.fr) Date: Sun Jan 6 16:25:16 2008 Subject: [Haskell-cafe] Wikipedia on first-class object In-Reply-To: <1199650393.6843.102.camel@derek-laptop> References: <2608b8a80712270110l38830795l5b9a0d05b7835ced@mail.gmail.com> <2608b8a80712270240g97b8601tc0898a5513e1b155@mail.gmail.com> <597F114C-5E60-48ED-9F7F-FF5BC3EE0F97@fastmail.fm> <1199617367.6843.7.camel@derek-laptop> <246AF129-DD30-4132-85A8-32014BA73D7C@fastmail.fm> <1199650393.6843.102.camel@derek-laptop> Message-ID: Derek Elkins writes: > Jonathan Cast wrote: >> I find the term `declarative' to be almost completely meaningless. > > I was originally thinking of having the final sentence: "There are no > clear, accepted meanings for any of these terms." Clear, no. Accepted, yes. Let Jonathan Cast repeat that statement to people who organise conferences on Declarative Programming, or those who assembled: http://en.wikipedia.org/wiki/Declarative_programming http://burks.brighton.ac.uk/burks/foldoc/90/29.htm (or http://foldoc.org/foldoc.cgi?declarative+language) I can't see what is the purpose of all your argument... Jerzy Karczmarczuk From haskell at list.mightyreason.com Sun Jan 6 16:34:11 2008 From: haskell at list.mightyreason.com (ChrisK) Date: Sun Jan 6 16:28:12 2008 Subject: [Haskell-cafe] Re: Quanta. Was: Wikipedia on first-class object In-Reply-To: <772A83B9-7FC9-4A79-811C-4174AD89FEC0@ece.cmu.edu> References: <2608b8a80712270110l38830795l5b9a0d05b7835ced@mail.gmail.com> <1934333921.20071227154048@gmail.com> <47767D39.4020007@btinternet.com> <20071229184005.702ab59c@solaris.tower> <1695012808.20071229213744@gmail.com> <4683d9370712291042w21873ae3xcb0376e05b0a3326@mail.gmail.com> <1995050719.20071229215903@gmail.com> <20071229201639.22c43260@solaris.tower> <1372887653.20071229223329@gmail.com> <000001c84a57$2c7b7e00$85727a00$@be> <568741883.20071230011816@gmail.com> <871w94fugj.fsf@nmd9999.imr.no> <1199617488.6843.10.camel@derek-laptop> <87y7b2vi2e.fsf@nmd9999.imr.no> <772A83B9-7FC9-4A79-811C-4174AD89FEC0@ece.cmu.edu> Message-ID: Brandon S. Allbery KF8NH wrote: > > On Jan 6, 2008, at 15:02 , Ketil Malde wrote: > >> More seriously, perhaps "quantum" enters into the equation in how the >> brain works, perhaps it is even necessary for "thought". However, I >> get worried it's just another mystical mantra, a gratuitous factor >> that, lacking any theory about how and what it does, adds nothing to >> help understanding the issue. The brain, being real, is best modeled by a final theory that physicists have not yet (noticed) written down. "how the brain works" appears to be though electro- and bio- chemistry, which are best modeled/described right now by quantum mechanics. There are observable quantum correlations that cannot be described by a "classical" theory. So long as the processes you care about (e.g. whatever the hell consciousness is) do not use these non-classical correlations then you can create a simplified model that avoids the complexity of quantum theory. > > I should not get into these off-topic things... but the viewpoint that > worries you is only espoused by people looking for excuses to apply > their favorite mystical mantra. Quantum effects are well defined, but > nonintuitive (for example, particles "tunneling through" a barrier). > Right. Even if there are some quantum correlations that are used in the brain, then you just use a more complicated mathematical model. Nothing mystical/spooky/special about it. Final note: Quantum tunneling is only surprising if you insist on thinking about particles or photons meeting some kind of impenetrable wall (made of what?). All real barriers are made of forces exerted by other particles. So the whole idea of a "barrier" is flawed in this regime. -- Chris From derek.a.elkins at gmail.com Sun Jan 6 15:47:21 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Sun Jan 6 16:41:31 2008 Subject: [Haskell-cafe] Wikipedia on first-class object In-Reply-To: References: <2608b8a80712270110l38830795l5b9a0d05b7835ced@mail.gmail.com> <2608b8a80712270240g97b8601tc0898a5513e1b155@mail.gmail.com> <597F114C-5E60-48ED-9F7F-FF5BC3EE0F97@fastmail.fm> <1199617367.6843.7.camel@derek-laptop> <246AF129-DD30-4132-85A8-32014BA73D7C@fastmail.fm> <1199650393.6843.102.camel@derek-laptop> Message-ID: <1199652441.6843.116.camel@derek-laptop> On Sun, 2008-01-06 at 22:31 +0100, jerzy.karczmarczuk@info.unicaen.fr wrote: > Derek Elkins writes: > > > Jonathan Cast wrote: > >> I find the term `declarative' to be almost completely meaningless. > > > > I was originally thinking of having the final sentence: "There are no > > clear, accepted meanings for any of these terms." > > Clear, no. > Accepted, yes. That was a conjunction: "clear AND accepted". From jonathanccast at fastmail.fm Sun Jan 6 16:48:53 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Sun Jan 6 16:42:53 2008 Subject: [Haskell-cafe] Wikipedia on first-class object In-Reply-To: References: <2608b8a80712270110l38830795l5b9a0d05b7835ced@mail.gmail.com> <2608b8a80712270240g97b8601tc0898a5513e1b155@mail.gmail.com> <597F114C-5E60-48ED-9F7F-FF5BC3EE0F97@fastmail.fm> <1199617367.6843.7.camel@derek-laptop> <246AF129-DD30-4132-85A8-32014BA73D7C@fastmail.fm> <1199650393.6843.102.camel@derek-laptop> Message-ID: <108CFD7D-173D-4335-B752-7E0B4BBA98B0@fastmail.fm> On 6 Jan 2008, at 1:31 PM, jerzy.karczmarczuk@info.unicaen.fr wrote: > Derek Elkins writes: >> Jonathan Cast wrote: >>> I find the term `declarative' to be almost completely meaningless. >> I was originally thinking of having the final sentence: "There are no >> clear, accepted meanings for any of these terms." > > Clear, no. > Accepted, yes. > Let Jonathan Cast repeat that statement to people who organise > conferences > on Declarative Programming, or those who assembled: > http://en.wikipedia.org/wiki/Declarative_programming > http://burks.brighton.ac.uk/burks/foldoc/90/29.htm > (or http://foldoc.org/foldoc.cgi?declarative+language) To quote your last citation: > declarative language: Any relational language or functional language. Yes, the term `declarative' means something in the sense that we can tell whether any given language is declarative or not, so I should have been more clear. To wit, I do not believe the term `declarative' has any single referent, even in the sense that the term `functional' has any single referent. I find the only similarity between Haskell and Prolog to be that neither is imperative. > I can't see what is the purpose of all your argument... Granted. jcc From jonathanccast at fastmail.fm Sun Jan 6 16:55:29 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Sun Jan 6 16:49:21 2008 Subject: [Haskell-cafe] Wikipedia on first-class object In-Reply-To: <1199650393.6843.102.camel@derek-laptop> References: <2608b8a80712270110l38830795l5b9a0d05b7835ced@mail.gmail.com> <2608b8a80712270240g97b8601tc0898a5513e1b155@mail.gmail.com> <597F114C-5E60-48ED-9F7F-FF5BC3EE0F97@fastmail.fm> <1199617367.6843.7.camel@derek-laptop> <246AF129-DD30-4132-85A8-32014BA73D7C@fastmail.fm> <1199650393.6843.102.camel@derek-laptop> Message-ID: On 6 Jan 2008, at 12:13 PM, Derek Elkins wrote: > On Sun, 2008-01-06 at 09:45 -0800, Jonathan Cast wrote: >> On 6 Jan 2008, at 3:02 AM, Derek Elkins wrote: >> >>> On Fri, 2007-12-28 at 17:54 -0600, Jonathan Cast wrote: >>> >>>> Programming languages are generally classified into three groups, >>>> imperative, functional, and logical. NB: I will stipulate that most people consider imperative vs. declarative to be a further hierarchy above this division. I will even stipulate that most people consider the procedural vs. OO distinction other than a distraction :) So I should have said: programming languages may be classified into three groups, ... --- where the groups themselves are generally agreed to exist, to be mutually exclusive, and to capture the vast majority of programming languages. >>>> The difference is in the style >>>> of programming encouraged (or mandated, for older languages) by the >>>> language. >>> >>> Usually the divide is imperative v. declarative with the four major >>> paradigms (procedural, OO and logic, FP respectively) being >>> subgroups of >>> those divisions. >> >> And your explanation of this classification is? >> >> I find the term `declarative' to be almost completely meaningless. > > I was originally thinking of having the final sentence: "There are no > clear, accepted meanings for any of these terms." > > Many people find any, perhaps all, of the terms: "functional", "object > oriented", "imperative" to be almost completely meaningless. > Mostly the > terms have no prescriptive meaning, but rather are defined by example. I was trying to work within this framework. Most languages support both imperative and functional paradigms, these days; but there are patterns which are awkward in some languages and natural in others. That is what I consider the main distinction. But, while there are patterns that are natural in all (at least structured) imperative languages and no or few non-imperative ones (like while loops), I don't know of any patterns that are natural in all declarative languages. > > At any rate, I wasn't and didn't explain anything as that was not my > intention. I was merely pointing out that your usage is against the > "norms" As a statistical statement, this may be true. > and in a way similar in its disconcertingness to saying, > "American politics is classified into three groups, conservatives, > Democrats and libertarians." Or like saying "American politics is classified into three groups, statists, Rothbardians, and Randians" :) jcc From barsoap at web.de Sun Jan 6 16:59:30 2008 From: barsoap at web.de (Achim Schneider) Date: Sun Jan 6 16:53:29 2008 Subject: [Haskell-cafe] Re: Quanta. Was: Wikipedia on first-class object References: <2608b8a80712270110l38830795l5b9a0d05b7835ced@mail.gmail.com> <1934333921.20071227154048@gmail.com> <47767D39.4020007@btinternet.com> <20071229184005.702ab59c@solaris.tower> <1695012808.20071229213744@gmail.com> <4683d9370712291042w21873ae3xcb0376e05b0a3326@mail.gmail.com> <1995050719.20071229215903@gmail.com> <20071229201639.22c43260@solaris.tower> <1372887653.20071229223329@gmail.com> <000001c84a57$2c7b7e00$85727a00$@be> <568741883.20071230011816@gmail.com> <871w94fugj.fsf@nmd9999.imr.no> <1199617488.6843.10.camel@derek-laptop> <87y7b2vi2e.fsf@nmd9999.imr.no> <772A83B9-7FC9-4A79-811C-4174AD89FEC0@ece.cmu.edu> Message-ID: <20080106225930.7ec6c56c@solaris.tower> ChrisK wrote: > "how the brain works" appears to be though electro- and bio- > chemistry, which are best modeled/described right now by quantum > mechanics. > Erm... There is this story about some military (US afair) training a neural net to detect tanks in images, I can't find the link right now. It worked, with amazing 100% accuracy. Then they threw another batch of images at the net. It worked, with devastating 50% accuracy. It turned out that in the first batch, all the pictures with tanks on them were shot in sunny weather, all the pictures without tanks were shot with cloudy sky. It's kind of claiming to understand every single program that ever has been written and ever will be written just because one understands touring-complete language X in detail. Or me claiming that I understand more than say 40% of what Jonathan says, although I do understand English. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From derek.a.elkins at gmail.com Sun Jan 6 16:08:09 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Sun Jan 6 17:02:18 2008 Subject: [Haskell-cafe] Wikipedia on first-class object In-Reply-To: <108CFD7D-173D-4335-B752-7E0B4BBA98B0@fastmail.fm> References: <2608b8a80712270110l38830795l5b9a0d05b7835ced@mail.gmail.com> <2608b8a80712270240g97b8601tc0898a5513e1b155@mail.gmail.com> <597F114C-5E60-48ED-9F7F-FF5BC3EE0F97@fastmail.fm> <1199617367.6843.7.camel@derek-laptop> <246AF129-DD30-4132-85A8-32014BA73D7C@fastmail.fm> <1199650393.6843.102.camel@derek-laptop> <108CFD7D-173D-4335-B752-7E0B4BBA98B0@fastmail.fm> Message-ID: <1199653689.6843.119.camel@derek-laptop> On Sun, 2008-01-06 at 13:48 -0800, Jonathan Cast wrote: > On 6 Jan 2008, at 1:31 PM, jerzy.karczmarczuk@info.unicaen.fr wrote: > > > Derek Elkins writes: > >> Jonathan Cast wrote: > >>> I find the term `declarative' to be almost completely meaningless. > >> I was originally thinking of having the final sentence: "There are no > >> clear, accepted meanings for any of these terms." > > > > Clear, no. > > Accepted, yes. > > Let Jonathan Cast repeat that statement to people who organise > > conferences > > on Declarative Programming, or those who assembled: > > http://en.wikipedia.org/wiki/Declarative_programming > > http://burks.brighton.ac.uk/burks/foldoc/90/29.htm > > (or http://foldoc.org/foldoc.cgi?declarative+language) > > To quote your last citation: > > > declarative language: Any relational language or functional language. > > Yes, the term `declarative' means something in the sense that we can > tell whether any given language is declarative or not, so I should > have been more clear. To wit, I do not believe the term > `declarative' has any single referent, even in the sense that the > term `functional' has any single referent. I find the only > similarity between Haskell and Prolog to be that neither is imperative. Indeed, you've discovered it. The definition of "declarative" is often "not imperative." (Or vice versa, where, as I said earlier, these are primarily defined by example rather than some predicate.) From jerzy.karczmarczuk at info.unicaen.fr Sun Jan 6 17:28:32 2008 From: jerzy.karczmarczuk at info.unicaen.fr (jerzy.karczmarczuk@info.unicaen.fr) Date: Sun Jan 6 17:22:17 2008 Subject: [Haskell-cafe] Wikipedia on first-class object In-Reply-To: <1199653689.6843.119.camel@derek-laptop> References: <2608b8a80712270110l38830795l5b9a0d05b7835ced@mail.gmail.com> <2608b8a80712270240g97b8601tc0898a5513e1b155@mail.gmail.com> <597F114C-5E60-48ED-9F7F-FF5BC3EE0F97@fastmail.fm> <1199617367.6843.7.camel@derek-laptop> <246AF129-DD30-4132-85A8-32014BA73D7C@fastmail.fm> <1199650393.6843.102.camel@derek-laptop> <108CFD7D-173D-4335-B752-7E0B4BBA98B0@fastmail.fm> <1199653689.6843.119.camel@derek-laptop> Message-ID: Derek Elkins writes: > Jonathan Cast wrote: >> I find the only >> similarity between Haskell and Prolog to be that neither is imperative. > > Indeed, you've discovered it. The definition of "declarative" is often > "not imperative." I disagree. Practically. (I won't discuss doctrinal matter nor linguistic hairsplitting). The relational syntax of Prolog is more "universal" than the functional notation, since you have logic variables and logical-non-determinism, and - thus - the possibility of making predicates where the roles of input and output parameters are not pre-assigned, - - but there is a *strong* (meaning important) functional layer within, and plenty of Prolog algorithms are expressed similarly in Lisp or in Haskell. Many non-deterministic ones have natural translation into the List monad. Some "circular" definitions using laziness are related to ones with non-instantiated logical variables. If you don't want to see similarities, you won't. But I assure you that I have profited enormously from tha *affinities* between functional and logic approaches, and you won't convince me that "declarative" is without substance. Jerzy Karczmarczuk From bf3 at telenet.be Sun Jan 6 17:44:51 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Sun Jan 6 17:38:37 2008 Subject: [Haskell-cafe] Implicit parameters and Arrows/Yampa? Message-ID: <001501c850b5$bfaf2b90$3f0d82b0$@be> If I understand it correctly, implicit parameters in Haskell allow you to pass values to functions with explicitly adding a parameter to each of the functions being "called" (I appologize for my imperative terminology here. How would I say this correctly? Being "evaluated"?) The arrows always use tuples to group the input and output parameters, like: foo :: SF (Int,Int,Int) (Int,Int) foo = proc (x,y,z) -> do p <- cat -< (x,y) q <- dog -< z returnA -< (p,q) where cat = proc (x,y) -> returnA -< (x+y) dog = proc z -> returnA -< 10*z Suppose I don't want to explicitly pass the x and y parameters to the cat (and deeper) arrows, but make them implicit. I guess that would be impossible? I mean, I can't use implicit parameters language extension to make the arrow input parameters implicit? Thanks, Peter -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080106/561e9abd/attachment.htm From bf3 at telenet.be Sun Jan 6 17:52:29 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Sun Jan 6 17:46:15 2008 Subject: [Haskell-cafe] Wikipedia on first-class object In-Reply-To: References: <2608b8a80712270110l38830795l5b9a0d05b7835ced@mail.gmail.com> <2608b8a80712270240g97b8601tc0898a5513e1b155@mail.gmail.com> <597F114C-5E60-48ED-9F7F-FF5BC3EE0F97@fastmail.fm> <1199617367.6843.7.camel@derek-laptop> <246AF129-DD30-4132-85A8-32014BA73D7C@fastmail.fm> <1199650393.6843.102.camel@derek-laptop> <108CFD7D-173D-4335-B752-7E0B4BBA98B0@fastmail.fm> <1199653689.6843.119.camel@derek-laptop> Message-ID: <002001c850b6$d0d9be20$728d3a60$@be> Jerzy wrote: > The relational syntax of Prolog is more "universal" than the functional > notation, since you have logic variables and logical-non-determinism, and Isn't this just because mathematically, a function *is* a relation, but not vice versa? A relation being just a subset of a Cartesian product of sets, while a function being a special kind of relation for which each element in the domain has exactly one image? So relations are inherently much more universal than functions, but they are not that practical to work with (for a computer and/or human?). Gee, I should not talk about math here, as you "category theory" guys know a thousand times more math than I do ;-) Cheers, Peter From bf3 at telenet.be Sun Jan 6 18:01:17 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Sun Jan 6 17:55:01 2008 Subject: [Haskell-cafe] GHC's dynamic linker and Windows Message-ID: <000001c850b8$0b712c70$22538550$@be> I recently tried the latest version of HS-PLUGINS, and it gave an error on Windows. After a bit of Googling it seemed Conal Elliot had the same problem. I reported this problem to the author. This is also (one of) the reason why I could not get YI running on Windows. Now, according to the documentation, HS-PLUGINS seems to be mainly a handy wrapper around GHC's dynamic linker and compiler. Suppose I would use GHC's dynamic linker, interpreter and compiler directly (aha "GHC as a library"); does this work on Windows, or are there known problems with these? Thanks, Peter -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080107/4b44251e/attachment-0001.htm From jerzy.karczmarczuk at info.unicaen.fr Sun Jan 6 18:11:10 2008 From: jerzy.karczmarczuk at info.unicaen.fr (jerzy.karczmarczuk@info.unicaen.fr) Date: Sun Jan 6 18:04:55 2008 Subject: [Haskell-cafe] Wikipedia on first-class object In-Reply-To: <002001c850b6$d0d9be20$728d3a60$@be> References: <2608b8a80712270110l38830795l5b9a0d05b7835ced@mail.gmail.com> <2608b8a80712270240g97b8601tc0898a5513e1b155@mail.gmail.com> <597F114C-5E60-48ED-9F7F-FF5BC3EE0F97@fastmail.fm> <1199617367.6843.7.camel@derek-laptop> <246AF129-DD30-4132-85A8-32014BA73D7C@fastmail.fm> <1199650393.6843.102.camel@derek-laptop> <108CFD7D-173D-4335-B752-7E0B4BBA98B0@fastmail.fm> <1199653689.6843.119.camel@derek-laptop> <002001c850b6$d0d9be20$728d3a60$@be> Message-ID: Peter Verswyvelen writes: > Jerzy wrote: >> The relational syntax of Prolog is more "universal" than the functional >> notation, since you have logic variables and logical-non-determinism, and > > Isn't this just because mathematically, a function *is* a relation, but not vice versa? A relation being just a subset of a Cartesian product of sets, while a function being a special kind of relation for which each element in the domain has exactly one image? So relations are inherently much more universal than functions, but they are not that practical to work with (for a computer and/or human?). You are right. Yes, functions are subsets of relations, and the affinity between logical and functional programming is all but accidental. But relations ARE PRACTICAL! Prolog, Mercury, etc. use them. Leda, Life ... Combined paradigms are not so exotic. > Gee, I should not talk about math here, as you "category theory" guys know a thousand times more math than I do ;-) On the contrary, you should. Tell what is interesting for you. Don't let hairsplitters monopolize the discussion of mathematical side of Haskell. I am sick seeing that 75% of true deep discussion turns around ... sorry for the swearword - ... bottom. Jerzy Karczmarczuk From derek.a.elkins at gmail.com Sun Jan 6 17:27:57 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Sun Jan 6 18:22:22 2008 Subject: [Haskell-cafe] Wikipedia on first-class object In-Reply-To: References: <2608b8a80712270110l38830795l5b9a0d05b7835ced@mail.gmail.com> <2608b8a80712270240g97b8601tc0898a5513e1b155@mail.gmail.com> <597F114C-5E60-48ED-9F7F-FF5BC3EE0F97@fastmail.fm> <1199617367.6843.7.camel@derek-laptop> <246AF129-DD30-4132-85A8-32014BA73D7C@fastmail.fm> <1199650393.6843.102.camel@derek-laptop> <108CFD7D-173D-4335-B752-7E0B4BBA98B0@fastmail.fm> <1199653689.6843.119.camel@derek-laptop> Message-ID: <1199658477.6843.154.camel@derek-laptop> On Sun, 2008-01-06 at 23:28 +0100, jerzy.karczmarczuk@info.unicaen.fr wrote: > Derek Elkins writes: > > > Jonathan Cast wrote: > > >> I find the only > >> similarity between Haskell and Prolog to be that neither is imperative. > > > > Indeed, you've discovered it. The definition of "declarative" is often > > "not imperative." > > I disagree. Practically. (I won't discuss doctrinal matter nor linguistic > hairsplitting). I wasn't being that serious there, though oftentimes "declarative" -is- used in a way that is mostly meaningless or as a buzzword. One thing I will stand by, however, is that the consensus is that "declarative" and "imperative" are meant to be exhaustive and ideally disjoint (though where to draw the line is tricky), and thus in that sense, "declarative" is "not imperative" (and, as I said originally though you elided it, vice versa.) > > The relational syntax of Prolog is more "universal" than the functional > notation, since you have logic variables and logical-non-determinism, and > - thus - the possibility of making predicates where the roles of input and > output parameters are not pre-assigned, - > > - but there is a *strong* (meaning important) functional layer within, > and plenty of Prolog algorithms are expressed similarly in Lisp or in > Haskell. > > Many non-deterministic ones have natural translation into the List monad. > Some "circular" definitions using laziness are related to ones with > non-instantiated logical variables. > > If you don't want to see similarities, you won't. But I assure you that > I have profited enormously from tha *affinities* between functional and > logic approaches, and you won't convince me that "declarative" is without > substance. "declarative" is often used in a way where HTML, XML and such are "declarative languages". At any rate, also in the elided part of my reply, was the statement that "imperative"/"declarative" are often defined by example, and the above is just such a case (unless you have a clear definition of "functional" and "logical"). This simply defines "declarative" to mean "functional"+"logical" making "declarative" a pure name devoid of any descriptive power. To make this email constructive, however, I will propose a slightly less fuzzy criterion: namely a declarative language is one that, via the Curry-Howard correspondence(s), corresponds strongly with (a relatively "standard") logic. This arguably can be used to give some oomph to the usage of the term "declarative" rather than it being just a name, though I'll not bother. This recovers the fact that "functional" and "logic" languages are declarative and gives a -specific- similarity. It agrees fairly well with the ordering "more declarative than" determined by consensus. Finally, it points the way to allowing other languages rather than "not (functional or logical) => not declarative." From derek.a.elkins at gmail.com Sun Jan 6 17:35:31 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Sun Jan 6 18:29:49 2008 Subject: [Haskell-cafe] Implicit parameters and Arrows/Yampa? In-Reply-To: <001501c850b5$bfaf2b90$3f0d82b0$@be> References: <001501c850b5$bfaf2b90$3f0d82b0$@be> Message-ID: <1199658931.6843.161.camel@derek-laptop> On Sun, 2008-01-06 at 23:44 +0100, Peter Verswyvelen wrote: > If I understand it correctly, implicit parameters in Haskell allow you > to pass values to functions with explicitly adding a parameter to each > of the functions being ?called? (I appologize for my imperative > terminology here. How would I say this correctly? Being ?evaluated??) No one is going to get upset if you use "call", but if you'd like, the more technical term in this context is "applied", instead of "call f passing x", we would say "apply f to x". > The arrows always use tuples to group the input and output parameters, > like: > > > > foo :: SF (Int,Int,Int) (Int,Int) > > foo = proc (x,y,z) -> do > > p <- cat -< (x,y) > > q <- dog -< z > > returnA -< (p,q) > > where > > cat = proc (x,y) -> returnA -< (x+y) > > dog = proc z -> returnA -< 10*z > > > > Suppose I don?t want to explicitly pass the x and y parameters to the > cat (and deeper) arrows, but make them implicit. I guess that would be > impossible? I mean, I can?t use implicit parameters language extension > to make the arrow input parameters implicit? Implicit parameters add an extra argument to a function conceptually. What you need is to "add an argument" to "SF" which implicit parameters don't know how to do since SF is just some data structure. One way to deal with this is the way you deal with the same problem in Haskell without implicit parameters. (I never use implicit parameters). In that case you would use the Reader monad (transformer). Similarly, you can use an equivalent Reader/Environment arrow transformer. From agl at imperialviolet.org Sun Jan 6 18:54:02 2008 From: agl at imperialviolet.org (Adam Langley) Date: Sun Jan 6 18:47:47 2008 Subject: [Haskell-cafe] ANN: A triple of new packages for talking to the outside world Message-ID: <396556a20801061554o3895ce88k87d4ecabc1860e7b@mail.gmail.com> Over the Xmas break I made some headway on writing an RPC package since many of the ideas that I want to play with involve such a thing as a basic building block. However, some might find some of the spin-off packages that I wrote along the way useful. * binary-strict: This is mostly a cut-n-paste job from the excellent binary package which provides Data.Binary.Strict.Get - a monad which is a drop in replacement for Get, but which parses strict ByteStrings and returns an Either, thus one can parse binary data without triggering an exception on failure. * codec-libevent: This parses the "tagging" IDL files introduced in libevent[1] 1.4.0-beta and later and can generate the Haskell code for them. These are platform-independent "structs" (in the C sense) and libevent provides the complementary C infrastructure for them. You should be able to understand almost everything these is to know about them from a quick example: struct msg { string from_name = 1; string to_name = 2; optional struct[kill] attack = 3; array struct[run] run = 4; } [1] http://monkey.org/~provos/libevent/ * control-timeout: This module provides simple timeouts - e.g. actions which occur after a given number of seconds and which can be canceled. It does it in a not-totally-stupid fashion so that you don't need to worry about setting hundreds of them. AGL -- Adam Langley agl@imperialviolet.org http://www.imperialviolet.org 650-283-9641 From wnoise at ofb.net Sun Jan 6 19:00:23 2008 From: wnoise at ofb.net (Aaron Denney) Date: Sun Jan 6 18:54:21 2008 Subject: [Haskell-cafe] Re: Wikipedia on first-class object References: <2608b8a80712270110l38830795l5b9a0d05b7835ced@mail.gmail.com> <2608b8a80712270240g97b8601tc0898a5513e1b155@mail.gmail.com> <597F114C-5E60-48ED-9F7F-FF5BC3EE0F97@fastmail.fm> <1199617367.6843.7.camel@derek-laptop> <246AF129-DD30-4132-85A8-32014BA73D7C@fastmail.fm> <1199650393.6843.102.camel@derek-laptop> <108CFD7D-173D-4335-B752-7E0B4BBA98B0@fastmail.fm> Message-ID: On 2008-01-06, Jonathan Cast wrote: > To wit, I do not believe the term `declarative' has any single > referent, even in the sense that the term `functional' has any single > referent. I find the only similarity between Haskell and Prolog to be > that neither is imperative. Have you tried comparing Prolog to GHC's multiparameter type-classes? -- Aaron Denney -><- From wnoise at ofb.net Sun Jan 6 19:04:43 2008 From: wnoise at ofb.net (Aaron Denney) Date: Sun Jan 6 18:58:50 2008 Subject: [Haskell-cafe] Re: Quanta. Was: Wikipedia on first-class object References: <2608b8a80712270110l38830795l5b9a0d05b7835ced@mail.gmail.com> <1934333921.20071227154048@gmail.com> <47767D39.4020007@btinternet.com> <20071229184005.702ab59c@solaris.tower> <1695012808.20071229213744@gmail.com> <4683d9370712291042w21873ae3xcb0376e05b0a3326@mail.gmail.com> <1995050719.20071229215903@gmail.com> <20071229201639.22c43260@solaris.tower> <1372887653.20071229223329@gmail.com> <000001c84a57$2c7b7e00$85727a00$@be> <568741883.20071230011816@gmail.com> <871w94fugj.fsf@nmd9999.imr.no> <1199617488.6843.10.camel@derek-laptop> <87y7b2vi2e.fsf@nmd9999.imr.no> <772A83B9-7FC9-4A79-811C-4174AD89FEC0@ece.cmu.edu> Message-ID: On 2008-01-06, ChrisK wrote: > Brandon S. Allbery KF8NH wrote: >> >> On Jan 6, 2008, at 15:02 , Ketil Malde wrote: >> >>> More seriously, perhaps "quantum" enters into the equation in how the >>> brain works, perhaps it is even necessary for "thought". However, I >>> get worried it's just another mystical mantra, a gratuitous factor >>> that, lacking any theory about how and what it does, adds nothing to >>> help understanding the issue. > > The brain, being real, is best modeled by a final theory that physicists have > not yet (noticed) written down. > > "how the brain works" appears to be though electro- and bio- chemistry, which > are best modeled/described right now by quantum mechanics. Quantum mechanics models these, but for most domains it's a substrate that is unnecessary -- modeling at the level of chemistry works. > There are observable quantum correlations that cannot be described by a > "classical" theory. Not in the brain. It's *way* too warm and squishy. > So long as the processes you care about (e.g. whatever the hell consciousness > is) do not use these non-classical correlations then you can create a simplified > model that avoids the complexity of quantum theory. Right. -- Aaron Denney -><- From jonathanccast at fastmail.fm Sun Jan 6 19:09:29 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Sun Jan 6 19:03:20 2008 Subject: [Haskell-cafe] Re: Wikipedia on first-class object In-Reply-To: References: <2608b8a80712270110l38830795l5b9a0d05b7835ced@mail.gmail.com> <2608b8a80712270240g97b8601tc0898a5513e1b155@mail.gmail.com> <597F114C-5E60-48ED-9F7F-FF5BC3EE0F97@fastmail.fm> <1199617367.6843.7.camel@derek-laptop> <246AF129-DD30-4132-85A8-32014BA73D7C@fastmail.fm> <1199650393.6843.102.camel@derek-laptop> <108CFD7D-173D-4335-B752-7E0B4BBA98B0@fastmail.fm> Message-ID: <04568CBA-DB1E-4FC9-8643-1608E3C66A90@fastmail.fm> On 6 Jan 2008, at 4:00 PM, Aaron Denney wrote: > On 2008-01-06, Jonathan Cast wrote: >> To wit, I do not believe the term `declarative' has any single >> referent, even in the sense that the term `functional' has any single >> referent. I find the only similarity between Haskell and Prolog >> to be >> that neither is imperative. > > Have you tried comparing Prolog to GHC's multiparameter type-classes? Well, they both express relations, they both stand in opposition to more basically functional approaches, and they are interpreted at entirely different points in the program's lifetime. So I guess you could find lots of points of comparison. Similarity? I'm still not convinced. jcc From gwern0 at gmail.com Sun Jan 6 21:57:27 2008 From: gwern0 at gmail.com (gwern0@gmail.com) Date: Sun Jan 6 21:51:47 2008 Subject: [Haskell-cafe] Software Tools in Haskell In-Reply-To: <47602DCE.10205@crsr.net> References: <475D9909.5000102@crsr.net> <20071211024132.GA15592@localhost> <47602DCE.10205@crsr.net> Message-ID: <20080107025727.GD7533@localhost> On 2007.12.12 12:51:58 -0600, Tommy M McGuire scribbled 2.7K characters: > Gwern Branwen wrote: >> Some of those really look like they could be simpler, like 'copy' - >> couldn't that simply be 'main = interact (id)'? >> Have you seen ? >> For example, 'charcount' could be a lot simpler - 'charcount = showln >> . length' would work, wouldn't it, for the core logic, and the whole >> thing might look like: >>> main = do (print . showln . length) =<< getContents >> Similarly wordcount could be a lot shorter, like 'wc_l = showln . >> length . lines' >> (showln is a convenience function: showln a = show a ++ "\n") > > Yes, that's absolutely true, and I am adding a section showing > implementations based on interact as soon as I send this message. The > reason I didn't do so before is that I was trying to (to an extent) > preserve the structure of the original implementations, which means using > an imperative style. Yes, I'm looking at it now. Pretty nice. > Strangely, I have considerably more confidence in the imperative-ish > Haskell code than I do in the imperative Pascal code, in spite of the fact > that they are essentially the same. Probably this is due to the > referential transparency that monadic IO preserves and that does not even > enter into the picture in traditional Pascal. For example, the > pseudo-nroff implementation has a giant, horrible block of a record > (containing the state taken directly from K&P) that is threaded through the > program, but I am tolerably happy with it because I know that is the *only* > state going through the program. > > Further, while interact could probably handle all of the filter-style > programs (and if I understand correctly, could also work for the main loop > of the interactive editor) If your editor is referentially transparent, I think. Something like ed or sed could be done, as long as you didn't implement any of the IO stuff (like ! for ed). > and a similar function could handle the later > file-reading programs, I do not see how to generalize that to the > out-of-core sort program. Well, for out-of-core sort, someone several many months back posted a very neat solution using ByteStrings which iirc had performance as competitive as GNU sort's out-of-core sort.... [much searching later] Ah! Here we go: "[Haskell-cafe] External Sort and unsafeInterleaveIO" . I at least found it interesting. > (Plus, interact is scary. :-D ) It's not scary! It's neat! >> I... I want to provide a one-liner for 'detab', but it looks >> impressively monstrous and I'm not sure I understand it. > > If you think that's bad.... :-) > > detab is one of the programs I do not like. I kept the "direct > translation" approach up through that, but I think it really hides the > simplicity there; detab copies its input to its output replacing tabs with > 1-8 spaces, based on where the tab occurs in a line. The only interesting > state dealt with is the count of characters on each line, but that gets > hidden, not emphasized. > > On the other hand, I'm not looking for one-liners; I really want clarity as > opposed to cleverness. Well, one-liners generally can be expanded to 2 or 3 lines if you want to add descriptive variable names. Better to start with a short version and expand it where unclear than have a long unclear one in the first place, right? >> One final comment: as regards run-length encoding, there's a really >> neat way to do it. I wrote a little article on how to do it a while >> ago, so I guess I'll just paste it in here. :) > > That *is* neat. > > -- > Tommy M. McGuire Thanks. It took a while to write, but I never really found any place to put it up for other people to read. -- gwern GSM Submarine E. 510 ddnp building y friends RDI JCET -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080106/e4f56854/attachment.bin From dons at galois.com Sun Jan 6 23:46:16 2008 From: dons at galois.com (Don Stewart) Date: Sun Jan 6 23:40:11 2008 Subject: [Haskell-cafe] map/reduce example In-Reply-To: <68774569.20071126143312@gmail.com> References: <68774569.20071126143312@gmail.com> Message-ID: <20080107044616.GN21631@scytale.galois.com> Just going back to this, the channel issue may be solved by the strict-concurrency package (strict Chans and MVars), and the general problem of distributing arrays seems to be solved more thoroughly by the data parallel array library (map, fold, scanl, filter, zip et al), not just map and reduce? It takes care of the problem of forking gang threads, distributing work, and does so with a pure interface. -- Don bulat.ziganshin: > Hello Haskell-Cafe, > > i've written small program which demonstrates how map/reduce may be > implemented in Haskell. it counts amount of words in file, splitting > it into 64kb blocks processed by two threads. their results are > combined by another two threads. how it may be made better? in > particular, is it strict in values send over channels? > > {-# LANGUAGE BangPatterns #-} > > import Control.Concurrent > import Control.Concurrent.Chan > import Control.Monad > import Data.IORef > import Data.ByteString.Char8 as B hiding (length) > import System.Environment > import System.IO > > main = do > (file:_) <- getArgs > h <- openBinaryFile file ReadMode > > map <- newChan > reduce <- newChan > result <- newChan > > replicateM_ 2 (forkIO$ mapThread map reduce) > replicateM_ 2 (forkIO$ reduceThread reduce result) > > jobs <- new 0 > untilM (hIsEOF h) $ do > str <- B.hGet h 65536 > writeChan map str > jobs += 1 > > jobs' <- val jobs > writeChan reduce (0,-jobs') > > res <- readChan result > print res > > > mapThread map reduce = > forever $ do > str <- readChan map > let !sum = length (B.words str) > writeChan reduce (sum,1) > > reduceThread reduce result = > forever $ do > (sum1,n1) <- readChan reduce > (sum2,n2) <- readChan reduce > let (!sum,!n) = (sum1+sum2,n1+n2) > case n of > 0 -> writeChan result sum > _ -> writeChan reduce (sum,n) > > > untilM cond action = do > deny <- cond > unless deny $ do > action > untilM cond action > > forever action = action >> forever action > > infixl 0 =:, += > new = newIORef > val = readIORef > a=:b = writeIORef a b > a+=b = modifyIORef a (\a->a+b) > > > -- > Best regards, > Bulat mailto:Bulat.Ziganshin@gmail.com > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From derek.a.elkins at gmail.com Sun Jan 6 22:46:44 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Sun Jan 6 23:40:53 2008 Subject: [Haskell-cafe] what does @ mean?..... In-Reply-To: <7ca3f0160712280851o5c90812fje3b95693dbed8383@mail.gmail.com> References: <477525C5.3070707@jellybean.co.uk> <7ca3f0160712280851o5c90812fje3b95693dbed8383@mail.gmail.com> Message-ID: <1199677604.6843.174.camel@derek-laptop> On Fri, 2007-12-28 at 09:51 -0700, Luke Palmer wrote: > On Dec 28, 2007 9:35 AM, Jules Bean wrote: > > In particular, adding sharing can stop something being GCed, which can > > convert an algorithm which runs in linear time and constant space to one > > which runs in linear space (and therefore, perhaps, quadratic time). > > I've heard of this before, but can you give an example? I don't know why they were so modest. Run the following two programs in the Haskell implementation of your choice 1) powerset [] = [[]] powerset (x:xs) = powerset xs ++ map (x:) (powerset xs) 2) powerset [] = [[]] powerset (x:xs) = xss ++ map (x:) xss where xss = powerset xs Compare it on programs such as length (powerset [1..n]) for n in the range of 20-30. Make sure you aren't doing anything important when you use the second version for larger inputs. These two programs are an extreme case of trading space for time, and an extreme case of why common subexpression elimination can be a massive pessimization. In this particular case, there is an exponential increase in the size of the live-set. From jpeliz at icmc.usp.br Sun Jan 6 23:48:59 2008 From: jpeliz at icmc.usp.br (Jorge Marques Pelizzoni) Date: Sun Jan 6 23:42:44 2008 Subject: [Haskell-cafe] reifying is-a Message-ID: <11366.200.158.222.185.1199681339.squirrel@mail2.icmc.usp.br> Hi, all! I guess what I am about to ask is currently impossible, but as you haskellers always manage to amaze me here it goes. Given two type classes A t and B t, I'd like to derive (two) different A t instances depending exactly on whether t is an instance of B. In other words, is it possible to define a type-level function/class IsB t f such that: IsB t HTrue <=> (B t) exists IsB t HFalse <=> otherwise? If not, is this wish intrisically pointless? Thanks in advance. Cheers, Jorge M. Pelizzoni ICMC - Universidade de S?o Paulo From dons at galois.com Mon Jan 7 00:12:23 2008 From: dons at galois.com (Don Stewart) Date: Mon Jan 7 00:06:08 2008 Subject: [Haskell-cafe] PHP/code generation libraries? In-Reply-To: References: Message-ID: <20080107051223.GQ21631@scytale.galois.com> jgbailey: > I'm working on a project which would generate a PHP data-access layer > from a Haskell model. I'm wondering what libraries might be already be > available for generating PHP or other types of code. The > pretty-printing library is one option. Any other suggestions? > i only know of pretty printers/parsers for C. not php. -- Don From bos at serpentine.com Mon Jan 7 00:13:46 2008 From: bos at serpentine.com (Bryan O'Sullivan) Date: Mon Jan 7 00:07:29 2008 Subject: [Haskell-cafe] ANN: A triple of new packages for talking to the outside world In-Reply-To: <396556a20801061554o3895ce88k87d4ecabc1860e7b@mail.gmail.com> References: <396556a20801061554o3895ce88k87d4ecabc1860e7b@mail.gmail.com> Message-ID: <4781B50A.2060007@serpentine.com> Adam Langley wrote: > This is mostly a cut-n-paste job from the excellent binary package > which provides Data.Binary.Strict.Get - a monad which is a drop in > replacement for Get, but which parses strict ByteStrings and returns > an Either, Ooh, nice. We could really do with an incremental version, too, which could be spoonfed chunks of bytes, and dole out values as deserialisation completes. Passing back a Left String is in some sense not much of an improvement over calling error, as if I merely doesn't have enough bytes accumulated yet, I can't restart parsing from the point the bytes ran out. Any chance you'd like to hand back a continuation instead? References: <2608b8a80712270110l38830795l5b9a0d05b7835ced@mail.gmail.com> <1934333921.20071227154048@gmail.com> <47767D39.4020007@btinternet.com> <20071229184005.702ab59c@solaris.tower> <1695012808.20071229213744@gmail.com> <4683d9370712291042w21873ae3xcb0376e05b0a3326@mail.gmail.com> <1995050719.20071229215903@gmail.com> <20071229201639.22c43260@solaris.tower> <1372887653.20071229223329@gmail.com> <000001c84a57$2c7b7e00$85727a00$@be> <568741883.20071230011816@gmail.com> <871w94fugj.fsf@nmd9999.imr.no> <1199617488.6843.10.camel@derek-laptop> <87y7b2vi2e.fsf@nmd9999.imr.no> <772A83B9-7FC9-4A79-811C-4174AD89FEC0@ece.cmu.edu> <20080106225930.7ec6c56c@solaris.tower> Message-ID: <4781B598.3000109@serpentine.com> Achim Schneider wrote: > There is this story about some military (US afair) training a neural > net to detect tanks in images, I can't find the link right now. > > It worked, with amazing 100% accuracy. > > Then they threw another batch of images at the net. > > It worked, with devastating 50% accuracy. Indeed. This is not the sort of thing you want to get wrong. http://blog.wired.com/defense/2007/10/robot-cannon-ki.html References: <002001c84e34$569c9f30$03d5dd90$@be> <1713055262.20080103220617@gmail.com> <1302893850.20080104022331@gmail.com> <478024B6.4010903@gazeta.pl> Message-ID: <1841482809.20080107120533@gmail.com> Hello Bob, Sunday, January 6, 2008, 3:45:42 AM, you wrote: > You are wrong. Without type signatures some type errors will not be > caught by the compiler, resulting in erroneous program behaviour. of course. moreover, the same applies to any type inference. are you give explicit type signature to every expression in the program? -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From emax at cs.chalmers.se Mon Jan 7 04:54:02 2008 From: emax at cs.chalmers.se (Emil Axelsson) Date: Mon Jan 7 04:43:28 2008 Subject: [Haskell-cafe] Refactoring status In-Reply-To: <001e01c84efe$5f386410$1da92c30$@be> References: <002001c84e34$569c9f30$03d5dd90$@be> <1713055262.20080103220617@gmail.com> <003501c84e43$c6df2fb0$549d8f10$@be> <001e01c84efe$5f386410$1da92c30$@be> Message-ID: <4781F6BA.7010109@cs.chalmers.se> One approach to programming in Haskell, which I use all the time, is to write the type signature before the function body. This means that if I'm trying to do something strange, I will often be warned by the type checker even before I've written the strange code. But I've also been bitten by the problem of having to change a lot of type signatures just because I want to e.g. show an overloaded variable. / Emil On 2008-01-04 19:19, Peter Verswyvelen wrote: > Yes, sometimes it is neccerary to give an explicit type. But in so many > cases, type inference works fine no? What I usually do, is use the GHCi t: > command, copy/paste that in my code, and then make the type signature more > specific if it has to be. It's often funny to see how generic the code > really is :) From apfelmus at quantentunnel.de Mon Jan 7 05:35:05 2008 From: apfelmus at quantentunnel.de (apfelmus) Date: Mon Jan 7 05:29:10 2008 Subject: [Haskell-cafe] Re: Concurrency questions In-Reply-To: <4780BF59.2000206@btinternet.com> References: <4780BBED.5020907@btinternet.com> <4780BF59.2000206@btinternet.com> Message-ID: Andrew Coppin wrote: > 2. You have to take the data out of an MVar to read it. In other words, > only 1 thread can read an MVar at once [by design]. This isn't truly a > problem in the current case, but it's irritating in principle that I > can't make it so that once the cell is written, multiple threads can > read it simultaneously... This is also known as I-structures i.e. IVar. I think you can simulate them via MVar with the readMVar function? Regards, apfelmus From lemming at henning-thielemann.de Mon Jan 7 06:06:21 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Mon Jan 7 06:00:05 2008 Subject: [Haskell-cafe] Show instances for error messages (Was: Refactoring status) In-Reply-To: <4781F6BA.7010109@cs.chalmers.se> References: <002001c84e34$569c9f30$03d5dd90$@be> <1713055262.20080103220617@gmail.com> <003501c84e43$c6df2fb0$549d8f10$@be> <001e01c84efe$5f386410$1da92c30$@be> <4781F6BA.7010109@cs.chalmers.se> Message-ID: On Mon, 7 Jan 2008, Emil Axelsson wrote: > One approach to programming in Haskell, which I use all the time, is to write > the type signature before the function body. This means that if I'm trying to do > something strange, I will often be warned by the type checker even before I've > written the strange code. > > But I've also been bitten by the problem of having to change a lot of type > signatures just because I want to e.g. show an overloaded variable. ... which is especially annoying if you need the Show instance for an 'error'. Since 'error' denotes a programming error it should never be evaluated and thus the Show instance is only for cases which must not happen. Paradoxical. It would be interesting if it is possible to tunnel Show class dictionaries through to an 'error' like IO is tunneled to 'trace'. From lemming at henning-thielemann.de Mon Jan 7 06:36:39 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Mon Jan 7 06:30:21 2008 Subject: Fusion vs. inlining (Was: [Haskell-cafe] Fusion of lists and chunky sequences) In-Reply-To: <20080103192002.GF4775@scytale.galois.com> References: <20080103192002.GF4775@scytale.galois.com> Message-ID: On Thu, 3 Jan 2008, Don Stewart wrote: > You can, with some caveats, use a single fusion system across data > structures, and avoid the built in build/foldr system. > > I'd start by installing the stream-fusion list library, from hackage, > which gives you the list api, and a fusion mechanism. > > To avoid the build in fusion system, you need to: With 'build in' you mean the fusion system of Prelude? > * avoid list comprehensions > * avoid .. (use Stream.enumFromTo instead) No problem. > then you can write fusion rules for your structure in terms of streams, > and they'll fuse with list operations as well. But then in order to fuse your streams with my chunky sequences I have to know, how stream-fusion fuses streams, right? Anyway, I tried to wrap Prelude lists in a newtype and thus got GHC (still 6.4.1) to invoke my rules instead of the Prelude rules. But I encountered the following problem: I define something like nonFusable x y = fusable (aux x y) where fusion rules are defined for 'fusable', but not for 'nonFusable'. I hoped that 'nonFusable' will be inlined and then 'fusable' is fused with other expressions. This does not happen. If I state the function definition also as rule, then GHC fuses eagerly. Analogously I observed that usage of ($) and (.) blocks fusion, and when I add the rules "unfold-dollar" forall f x. f $ x = f x ; "unfold-dot" forall f g. f . g = \x -> f (g x) ; then fusion takes place as expected. Am I doing something wrong? Do I have to dig into phase control? I wouldn't like that, since it seems to be too fragile. From Christian.Maeder at dfki.de Mon Jan 7 06:53:50 2008 From: Christian.Maeder at dfki.de (Christian Maeder) Date: Mon Jan 7 06:47:33 2008 Subject: [Haskell-cafe] Re: haskell package installation problem In-Reply-To: <8f4ec6fc0801031149q5b11cab5wbe655efaa4048d2f@mail.gmail.com> References: <8f4ec6fc0801031149q5b11cab5wbe655efaa4048d2f@mail.gmail.com> Message-ID: <478212CE.9040709@dfki.de> Brian Park wrote: > Hi, > > I was installing various haskell packages from hackage. > > When I was installing HaXml, I think it was complaining about > Text.PrettyPrint.HughesPJ not installed or something. (can't remember > the specific message and I can't reproduce now...) HaXml-1.13.2 needs pretty and containers as additional "build-depends" in HaXml.cabal for ghc-6.8.x (HaXml-1.13.3 should work). I don't know about http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HaXml-1.19.1 > So I installed "pretty-1.0.0.0" package as well. bad move, Cabal itself depends on (this) pretty (package). Reinstalling pretty failed and spoiled you're installation. Maybe such kind of (re-)installation should be prohibited somehow. Cheers Christian > Ever since then, when I try to install other haskell packages, I get the > following error message: > "brian@bp-desktop:~/Download/mtl-1.1.0.0$ runghc Setup.hs configure > : > /usr/local/lib/ghc-6.8.2/lib/Cabal-1.2.3.0/HSCabal-1.2.3.0.o > : unknown symbol > `prettyzm1zi0zi0zi0_TextziPrettyPrintziHughesPJ_lvl18_closure' > ghc-6.8.2: unable to load package `Cabal-1.2.3.0 '" > > Does anyone know what the problem is? > > Currently installed packages are: > ========= > /usr/local/lib/ghc-6.8.2/package.conf: > Cabal-1.2.3.0, HTTP-3001.0.4, HUnit-1.2.0.0, X11-1.4.1, > array-0.1.0.0, base-3.0.1.0, bytestring-0.9.0.1, > containers-0.1.0.1, directory-1.0.0.0, filepath-1.1.0.0, > (ghc-6.8.2), haskell98-1.0.1.0 , hpc-0.5.0.0, hxt-7.4, mtl-1.1.0.0, > network-2.1.0.0, old-locale-1.0.0.0, old-time-1.0.0.0, > packedstring-0.1.0.0, parsec-2.1.0.0, polyparse-1.1, > pretty-1.0.0.0, process-1.0.0.0, random-1.0.0.0, readline-1.0.1.0 , > rts-1.0, template-haskell-2.2.0.0, unix-2.3.0.0, xmonad-0.5, > xmonad-contrib-0.5 > ========= > > > Thank you, > > - Brian > > > ------------------------------------------------------------------------ > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From lutz at iks-jena.de Mon Jan 7 06:56:06 2008 From: lutz at iks-jena.de (Lutz Donnerhacke) Date: Mon Jan 7 06:49:52 2008 Subject: [Haskell-cafe] Show instances for error messages (Was: Refactoring status) References: <002001c84e34$569c9f30$03d5dd90$@be> <1713055262.20080103220617@gmail.com> <003501c84e43$c6df2fb0$549d8f10$@be> <001e01c84efe$5f386410$1da92c30$@be> <4781F6BA.7010109@cs.chalmers.se> Message-ID: * Henning Thielemann wrote: > happen. Paradoxical. It would be interesting if it is possible to tunnel > Show class dictionaries through to an 'error' like IO is tunneled to > 'trace'. unsafeShow :: (forall a . Show a => a) -> String From cetin.sert at gmail.com Mon Jan 7 07:56:37 2008 From: cetin.sert at gmail.com (Cetin Sert) Date: Mon Jan 7 07:50:27 2008 Subject: [Haskell-cafe] Type Mismatch Message-ID: Hi, I'm new to Haskell programming and have the following problem. ----------------------------------------------------- (|>) f g = g f data Stream a where S :: (s -> Step s a) -> s -> Stream a data Step s a = Done | Yield a s | Skip a s toStream :: [a] -> Stream a toStream ax = S step ax where step [] = Done step (a:ax) = Yield a ax fromStream :: Stream a -> [a] fromStream (S step s) = loop s where loop s = case step s of Done -> [] Skip a s' -> loop s' Yield a s' -> a : loop s' filterStream :: (a -> Bool) -> Stream a -> Stream a filterStream p (S step s) = S filter s where filter s = case step s of Done -> Done Skip a s' -> Skip a s' Yield a s' -> if p a then Yield a s' else Skip a s' mapStream :: (a -> b) -> Stream a -> Stream b mapStream f (S step s) = S map s where map s = case step s of Done -> Done Skip a s' -> Skip (f a) s' Yield a s' -> Yield (f a) s' class Streamable a where to :: a -> Stream a instance Streamable [a] where to = toStream -- ERROR: see below s f x = x |> toStream |> f |> fromStream smap x = s (mapStream x) sfilter x = s (filterStream x) (%) a b = mod a b main = do print ([0..20] |> sfilter (\x -> x % 2 == 0)) --------------------------------------------------------- Error 1 Couldn't match expected type `a' (a rigid variable) against inferred type `[a]' `a' is bound by the instance declaration at C:\Users\Sert\Lab\Haskell\HaskellApp1\HaskellApp1\src/Main.hs:63:0 Expected type: [a] -> Stream [a] Inferred type: [[a]] -> Stream [a] In the expression: toStream In the definition of `to': to = toStream C:\Users\Sert\Lab\Haskell\HaskellApp1\HaskellApp1\src\Main.hs 64 8 How can I make the types match so that I can declare lists streamable? Is there something like in-place type annotations as in ML/OCaml/F#? Best Regards, Cetin Sert corsis.de/blog From mad.one at gmail.com Mon Jan 7 08:20:05 2008 From: mad.one at gmail.com (Austin Seipp) Date: Mon Jan 7 08:14:54 2008 Subject: [Haskell-cafe] GHC's dynamic linker and Windows In-Reply-To: <000001c850b8$0b712c70$22538550$@be> References: <000001c850b8$0b712c70$22538550$@be> Message-ID: <1199711355-sup-7974@continuum> > I recently tried the latest version of HS-PLUGINS, and it gave an error on > Windows. After a bit of Googling it seemed Conal Elliot had the same > problem. I reported this problem to the author. This is also (one of) the > reason why I could not get YI running on Windows. Currently I believe Conal is working on getting the latest hs-plugins to work on windows. It was recently updated to work with ghc 6.8.x (thanks Cale & co.) but there was no release as the aim is to get it working for 6.8 on both windows and linux before making an official release (currently it seems to be linux only, as I have the latest 1.1 installed from the repo below.) The latest repo for hs-plugins for 6.8 can be found at http://code.haskell.org/~dons/code/hs-plugins I'm sure Conal and others would appreciate any patches to help move it along! > Now, according to the documentation, HS-PLUGINS seems to be mainly a handy > wrapper around GHC's dynamic linker and compiler. Suppose I would use GHC's > dynamic linker, interpreter and compiler directly (aha "GHC as a library"); > does this work on Windows, or are there known problems with these? It's a wrapper around the RTS' linker for the most part, yes. Another half of it was interface files; GHC .hi interfaces change extremely quickly inbetween even bugfix releases (and probably changes many times even between those.) This made it hard to update for newer release of GHC. Cale ported a lot of that to using the GHC API explicitly however, which should hopefully make it more resilient to newer GHC releases. GHC as a library does work on windows and it is usable. I wrote a blog post over using the API but unfortunately where it was hosted is down as of current. It does seem however google cache'd the page nicely though if it's of any interest to you: http://www.google.com/search?q=cache:DXz9SkIg0OAJ:austin.youareinferior.net/%3Fq%3Dnode/29+using+the+GHC+API+pluggable+austin&hl=en&ct=clnk&cd=1&gl=us I also wrote a library that was a small wrapper around the GHC API. The darcs repository can be found here: http://code.haskell.org/metaplug/ Note it only works on GHC 6.6.x as of right now and I've not had time to update it for 6.8. It's a sufficiently simple library though, so porting it to using 6.8 should not be hard at all (I did so on my windows box, with very few changes required.) Hope this helps! - Austin -- "It was in the days of the rains that their prayers went up, not from the fingering of knotted prayer cords or the spinning of prayer wheels, but from the great pray-machine in the monastery of Ratri, goddess of the Night." Roger Zelazny From mroth at nessie.de Mon Jan 7 09:33:51 2008 From: mroth at nessie.de (Michael Roth) Date: Mon Jan 7 09:27:34 2008 Subject: [Haskell-cafe] Problem with own written monad Message-ID: <4782384F.6000102@nessie.de> Hello list, while trying to learn the secrets of monads, I decided to write a simply monand for pure educational purpose. But it turned out that it isn't as easy as I thought... I circumnavigate quite a number of hurdles but now I reached a point where I'm at a loss. :-( The source: #! /usr/bin/env ghc data Stack a = Stack { run :: [a] -> (a, [a]) } push :: a -> Stack a push x = Stack f where f xs = ( x, x:xs ) pop :: Stack a pop = Stack f where f (x:xs) = ( x, xs ) top :: Stack a top = Stack f where f (x:xs) = ( x, x:xs ) instance Monad Stack where return x = Stack f where f xs = ( x, xs ) (>>=) stack g = Stack f where f s0 = (x2, s2) where (x1, s1) = run stack s0 (x2, s2) = run (g x1) s1 The errors: ./mymonad.hs:16:24: Couldn't match expected type `b' (a rigid variable) against inferred type `a' (a rigid variable) `b' is bound by the type signature for `>>=' at `a' is bound by the type signature for `>>=' at Expected type: [b] -> (b, [b]) Inferred type: [a] -> (b, [b]) In the first argument of `Stack', namely `f' In the expression: Stack f ./mymonad.hs:19:28: Couldn't match expected type `b' (a rigid variable) against inferred type `a' (a rigid variable) `b' is bound by the type signature for `>>=' at `a' is bound by the type signature for `>>=' at Expected type: [b] Inferred type: [a] In the second argument of `run', namely `s1' In the expression: run (g x1) s1 I think the problem is that my operator (>>=) is of type: Stack a -> (a -> Stack a) -> Stack a but should be: Stack a -> (a -> Stack b) -> Stack b But, I have simply no clue how to fix that. :-( Can anybody give my a hint? Thank you in advance. Michael Roth From rendel at rbg.informatik.tu-darmstadt.de Mon Jan 7 09:35:56 2008 From: rendel at rbg.informatik.tu-darmstadt.de (Tillmann Rendel) Date: Mon Jan 7 09:29:31 2008 Subject: [Haskell-cafe] Type Mismatch In-Reply-To: References: Message-ID: <478238CC.5070901@rbg.informatik.tu-darmstadt.de> Cetin Sert wrote: > class Streamable a where > to :: a -> Stream a The type of to looks wrong for me. a -> Stream a means to takes a single element into a stream of such elements, but you probably want to convert between different representations of streams of elements. > toStream :: [a] -> Stream a > > instance Streamable [a] where > to = toStream -- ERROR: see below Here to :: [a] -> Stream [a] and toStream :: [a] -> Stream a. These types are different, as ghc complained. Possible solutions include multi parameter type classes class Streamable s a where to :: s -> Stream a instance Streamable [a] a where to = toStream and constructor classes class Streamable s where to :: s a -> Stream a instance Streamable [] where to = toStream Tillmann From emax at cs.chalmers.se Mon Jan 7 09:56:33 2008 From: emax at cs.chalmers.se (Emil Axelsson) Date: Mon Jan 7 09:45:59 2008 Subject: [Haskell-cafe] Show instances for error messages (Was: Refactoring status) In-Reply-To: References: <002001c84e34$569c9f30$03d5dd90$@be> <1713055262.20080103220617@gmail.com> <003501c84e43$c6df2fb0$549d8f10$@be> <001e01c84efe$5f386410$1da92c30$@be> <4781F6BA.7010109@cs.chalmers.se> Message-ID: <47823DA1.8020302@cs.chalmers.se> The only possible definition of such a function is something like unsafeShow :: (forall a . Show a => a) -> String unsafeShow a = show (a :: Bool) right? And you'd also need to coerce the argument type in order to use it: putStrLn $ unsafeShow $ unsafeCoerce True Right? Then a nicer definition might be unsafeShow :: Show a => a -> b -> String unsafeShow a b = show (unsafeCoerce b `asTypeOf` a) Here is an example of how to use it to show an overloaded variable without changing the type signature: test :: Eq a => a -> IO () test a = putStrLn $ unsafeShow (undefined :: Int) a Of course, this only works safely if a is an Int: *Main> test (5 :: Int) 5 *Main> test (5 :: Double) 0 / Emil On 2008-01-07 12:56, Lutz Donnerhacke wrote: > * Henning Thielemann wrote: >> happen. Paradoxical. It would be interesting if it is possible to tunnel >> Show class dictionaries through to an 'error' like IO is tunneled to >> 'trace'. > > unsafeShow :: (forall a . Show a => a) -> String > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From rendel at rbg.informatik.tu-darmstadt.de Mon Jan 7 09:56:13 2008 From: rendel at rbg.informatik.tu-darmstadt.de (Tillmann Rendel) Date: Mon Jan 7 09:50:32 2008 Subject: [Haskell-cafe] Problem with own written monad In-Reply-To: <4782384F.6000102@nessie.de> References: <4782384F.6000102@nessie.de> Message-ID: <47823D8D.6020804@rbg.informatik.tu-darmstadt.de> Michael Roth wrote: > while trying to learn the secrets of monads, I decided to write a simply > monand for pure educational purpose. But it turned out that it isn't as > easy as I thought... I circumnavigate quite a number of hurdles but now > I reached a point where I'm at a loss. :-( > > data Stack a = Stack { run :: [a] -> (a, [a]) } This definition means that the values in the stack are always of the same type as the values returned by the monadic computation. Try something like data Stack s a = Stack { runStack :: [s] -> (a, [s]) } and instance Monad (Stack s) where ... to thread the same stack through a monadic computation with various intermediate result types, as you probably want. Tillmann From gwern0 at gmail.com Mon Jan 7 09:57:35 2008 From: gwern0 at gmail.com (gwern0@gmail.com) Date: Mon Jan 7 09:51:35 2008 Subject: [Haskell-cafe] GHC's dynamic linker and Windows In-Reply-To: <1199711355-sup-7974@continuum> References: <000001c850b8$0b712c70$22538550$@be> <1199711355-sup-7974@continuum> Message-ID: <20080107145735.GA3483@localhost> On 2008.01.07 07:20:05 -0600, Austin Seipp scribbled 2.6K characters: > > I recently tried the latest version of HS-PLUGINS, and it gave an error on > > Windows. After a bit of Googling it seemed Conal Elliot had the same > > problem. I reported this problem to the author. This is also (one of) the > > reason why I could not get YI running on Windows. > > Currently I believe Conal is working on getting the latest hs-plugins to > work on windows. It was recently updated to work with ghc 6.8.x (thanks > Cale & co.) but there was no release as the aim is to get it working for > 6.8 on both windows and linux before making an official release > (currently it seems to be linux only, as I have the latest 1.1 installed > from the repo below.) The latest repo for hs-plugins for 6.8 can be found at > > http://code.haskell.org/~dons/code/hs-plugins > > I'm sure Conal and others would appreciate any patches to help move it > along! Ah. That explains it. I'd been annoyed for some time now that hs-plugins was broken for so long with 6.8.x, but I had been pulling from . It's probably worth noting that the first Google hit for 'hs-plugins' is Don's pages, and that points to the old Darcs repo, ("Darcs repository of the latest code: darcs get --set-scripts-executable http://www.cse.unsw.edu.au/~dons/code/hs-plugins"). The second and third hits links to that page as well. Maybe the docs could be upgraded and the usual deprecation warning inserted in the old repo? -- gwern GSM Submarine E. 510 ddnp building y friends RDI JCET -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080107/f216c082/attachment-0001.bin From jules at jellybean.co.uk Mon Jan 7 09:58:46 2008 From: jules at jellybean.co.uk (Jules Bean) Date: Mon Jan 7 09:52:31 2008 Subject: [Haskell-cafe] Problem with own written monad In-Reply-To: <4782384F.6000102@nessie.de> References: <4782384F.6000102@nessie.de> Message-ID: <47823E26.2000501@jellybean.co.uk> Michael Roth wrote: > Hello list, > > while trying to learn the secrets of monads, I decided to write a simply > monand for pure educational purpose. But it turned out that it isn't as > easy as I thought... I circumnavigate quite a number of hurdles but now > I reached a point where I'm at a loss. :-( > > > The source: > > #! /usr/bin/env ghc > > data Stack a = Stack { run :: [a] -> (a, [a]) } You want: data Stack a b = Stack { run :: [a] -> (b, [a]) } All monads have the property that they can represent calculations of values of any type. Without that, they're not so useful. So your "Stack" needs two type variables : one for the kind of thing stacked, and one for what we're actually calculating at this instant. The correct types for the other functions are: > push :: a -> Stack a push :: a -> Stack a () [you could have a -> Stack a a, if you want to echo back the pushed value, but why bother? ] > pop :: Stack a pop :: Stack a a > top :: Stack a top :: Stack a a With those clues I think you will be able to write >>= and return more successfully! There are some other interesting combinators to consider, like: isolate :: Stack b x -> Stack a x -- runs the computation with an empty stack, therefore -- guaranteeing it does more pushes than pops or isolate :: Stack b x -> Stack a ([b],x) -- if you want to collect the pushes. and so on. Jules From miguelimo38 at yandex.ru Mon Jan 7 10:15:46 2008 From: miguelimo38 at yandex.ru (Miguel Mitrofanov) Date: Mon Jan 7 10:09:36 2008 Subject: [Haskell-cafe] Problem with own written monad In-Reply-To: <4782384F.6000102@nessie.de> References: <4782384F.6000102@nessie.de> Message-ID: <4628B809-C9AE-4A61-BA38-15C69572F6A1@yandex.ru> > data Stack a = Stack { run :: [a] -> (a, [a]) } [...skipped...] > But, I have simply no clue how to fix that. :-( > Can anybody give my a hint? Yes. It's simply impossible. The Stack data type can't be turned into a monad. May be you can explain what do you want to do with this "monad"? What kind of code would you write if it would be such monad? From lemming at henning-thielemann.de Mon Jan 7 10:28:24 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Mon Jan 7 10:22:20 2008 Subject: [Haskell-cafe] Problem with own written monad In-Reply-To: <4628B809-C9AE-4A61-BA38-15C69572F6A1@yandex.ru> References: <4782384F.6000102@nessie.de> <4628B809-C9AE-4A61-BA38-15C69572F6A1@yandex.ru> Message-ID: On Mon, 7 Jan 2008, Miguel Mitrofanov wrote: > > data Stack a = Stack { run :: [a] -> (a, [a]) } > > [...skipped...] > > > But, I have simply no clue how to fix that. :-( > > Can anybody give my a hint? > > Yes. It's simply impossible. The Stack data type can't be turned into > a monad. What about using the State monad? Still suitable as exercise? From bf3 at telenet.be Mon Jan 7 11:24:54 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Mon Jan 7 11:18:55 2008 Subject: [Haskell-cafe] Implicit parameters and Arrows/Yampa? In-Reply-To: <1199658931.6843.161.camel@derek-laptop> References: <001501c850b5$bfaf2b90$3f0d82b0$@be> <1199658931.6843.161.camel@derek-laptop> Message-ID: <47825256.7010907@telenet.be> Derek Elkins wrote: > Implicit parameters add an extra argument to a function conceptually. > What you need is to "add an argument" to "SF" which implicit parameters > don't know how to do since SF is just some data structure. One way to > deal with this is the way you deal with the same problem in Haskell > without implicit parameters. (I never use implicit parameters). In that > case you would use the Reader monad (transformer). Similarly, you can > use an equivalent Reader/Environment arrow transformer. > Nice, I did not know that monad yet, thanks! But can it be combined together with the arrows do/proc syntax? How would that look like? Cheers, Peter From sjanssen at cse.unl.edu Mon Jan 7 11:59:02 2008 From: sjanssen at cse.unl.edu (Spencer Janssen) Date: Mon Jan 7 11:53:01 2008 Subject: [Haskell-cafe] Concurrency questions In-Reply-To: <4780BBED.5020907@btinternet.com> References: <4780BBED.5020907@btinternet.com> Message-ID: <20080107165902.GA6008@presario> On Sun, Jan 06, 2008 at 11:30:53AM +0000, Andrew Coppin wrote: > Just a couple of things I was wondering about... > > 1. Is there some way to assign a "priority" to Haskell threads? (The > behaviour I'd like is that high priority threads always run first, and low > priority threads potentially never run at all unless there's an available > processor which is completely idle.) Not in the current system. It is not clear that thread priorities are so nice anyway (see 'priority inversion' on Wikipedia, for example). > 2. I have a situation where I have a thread generating some data and > putting it into a mutable array, and another thread trying to read that > data. Is there a way I can make the reader thread block if it tries to read > a cell that hasn't been computed yet, but not introduce too much overhead > for cells that have been filled in? I'd probably use an Array of TMVars, they should be faster than MVars when multiple threads are reading simultaneously. > 3. Would it be hard to make it so that the number of real threads (the RTS > +N flag) could be adjusted at runtime? I don't know whether it is hard, but I do know that it would be useful! Cheers, Spencer Janssen From claudiusmaximus at goto10.org Mon Jan 7 12:10:16 2008 From: claudiusmaximus at goto10.org (Claude Heiland-Allen) Date: Mon Jan 7 12:03:04 2008 Subject: [Haskell-cafe] Implicit parameters and Arrows/Yampa? In-Reply-To: <47825256.7010907@telenet.be> References: <001501c850b5$bfaf2b90$3f0d82b0$@be> <1199658931.6843.161.camel@derek-laptop> <47825256.7010907@telenet.be> Message-ID: <47825CF8.2040809@goto10.org> Peter Verswyvelen wrote: > Derek Elkins wrote: >> you can >> use an equivalent Reader/Environment arrow transformer. >> > Nice, I did not know that monad yet, thanks! > > But can it be combined together with the arrows do/proc syntax? How > would that look like? Something like this? ----8<---- module Main where import Control.Arrow import Control.Arrow.Operations import Control.Arrow.Transformer.Reader -- -- Standard list/stream arrow. -- newtype SF b c = SF { runSF :: [b] -> [c] } instance Arrow SF where arr f = SF (map f) SF f >>> SF g = SF (g . f) first (SF f) = SF (uncurry zip . (f *** id) . unzip) second (SF f) = SF (uncurry zip . (id *** f) . unzip) instance ArrowLoop SF where loop (SF f) = SF $ \as -> let (bs,cs) = unzip (f (zip as (stream cs))) in bs where stream ~(x:xs) = x:stream xs instance ArrowCircuit SF where delay x = SF (init . (x:)) -- -- Some state we want to pass around without manual plumbing. -- data AudioState = AudioState { sampleRate :: Double } runAudio state graph = proc p -> (| runReader (graph -< p) |) state -- -- Some unit generators for audio. -- wrap x = x - fromIntegral (floor x) -- phasor needs the sample rate phasor phase0 = proc hz -> do sr <- pure sampleRate <<< readState -< () rec accum <- delay (wrap phase0) -< wrap (accum + hz / sr) returnA -< accum -- osc doesn't need to know about sample rate osc phase0 = proc hz -> do phase <- phasor phase0 -< hz returnA -< cos (2 * pi * phase) -- -- Test it out. -- main = print (runSF (runAudio (AudioState{sampleRate=1000}) (osc 0)) (replicate 10 100)) ----8<---- > Cheers, > Peter Thanks, Claude -- http://claudiusmaximus.goto10.org From paul at cogito.org.uk Mon Jan 7 13:21:21 2008 From: paul at cogito.org.uk (Paul Johnson) Date: Mon Jan 7 13:15:06 2008 Subject: [Haskell-cafe] Problem with own written monad In-Reply-To: <4628B809-C9AE-4A61-BA38-15C69572F6A1@yandex.ru> References: <4782384F.6000102@nessie.de> <4628B809-C9AE-4A61-BA38-15C69572F6A1@yandex.ru> Message-ID: <47826DA1.5000401@cogito.org.uk> Miguel Mitrofanov wrote: > > Yes. It's simply impossible. The Stack data type can't be turned into > a monad. Why not? Surely this is just a variation on the theme of a state monad? Paul. From agl at imperialviolet.org Mon Jan 7 13:37:42 2008 From: agl at imperialviolet.org (Adam Langley) Date: Mon Jan 7 13:31:24 2008 Subject: [Haskell-cafe] ANN: A triple of new packages for talking to the outside world In-Reply-To: <4781B50A.2060007@serpentine.com> References: <396556a20801061554o3895ce88k87d4ecabc1860e7b@mail.gmail.com> <4781B50A.2060007@serpentine.com> Message-ID: <396556a20801071037t1b66e444u52abe1d934b7f902@mail.gmail.com> On Jan 6, 2008 9:13 PM, Bryan O'Sullivan wrote: > Ooh, nice. We could really do with an incremental version, too, which > could be spoonfed chunks of bytes, and dole out values as > deserialisation completes. > > Passing back a Left String is in some sense not much of an improvement > over calling error, as if I merely doesn't have enough bytes accumulated > yet, I can't restart parsing from the point the bytes ran out. Any > chance you'd like to hand back a continuation instead? The Left String was just a way to return an error string, otherwise a parse failure can be a little oblique. I think an incremental parser would be sufficiently different that it would be a different monad. Of course, the code duplication (again) makes me a sad panda, but avoiding that involves a lot of work on the binary package and the maintainers were uninterested last time I tried that. It would seem that there would be three possible outcomes from an incremental Get: - Failure: some bitstreams are just invalid and no amount of extra data will ever fix that - Complete [Result]: the last chunk of data has been processed. Maybe this should also include the remainder of the data? - Partial Cont [Result]: needs more data, but here's a (possibly empty) list of results so far. Applying a ByteString to the Cont from the Partial result would result in one of the same three outcomes etc. What do you think of that? It wouldn't be too hard to make up something like that using ContT if it would be useful to you. AGL -- Adam Langley agl@imperialviolet.org http://www.imperialviolet.org 650-283-9641 From derek.a.elkins at gmail.com Mon Jan 7 12:54:14 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Mon Jan 7 13:48:21 2008 Subject: [Haskell-cafe] Problem with own written monad In-Reply-To: <4628B809-C9AE-4A61-BA38-15C69572F6A1@yandex.ru> References: <4782384F.6000102@nessie.de> <4628B809-C9AE-4A61-BA38-15C69572F6A1@yandex.ru> Message-ID: <1199728455.6843.178.camel@derek-laptop> On Mon, 2008-01-07 at 18:15 +0300, Miguel Mitrofanov wrote: > > data Stack a = Stack { run :: [a] -> (a, [a]) } > > [...skipped...] > > > But, I have simply no clue how to fix that. :-( > > Can anybody give my a hint? > > Yes. It's simply impossible. The Stack data type can't be turned into > a monad. Indeed, the very first hint is that Stack isn't a functor because the type variable a occurs both positively and negatively. From derek.a.elkins at gmail.com Mon Jan 7 12:57:53 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Mon Jan 7 13:51:59 2008 Subject: [Haskell-cafe] Implicit parameters and Arrows/Yampa? In-Reply-To: <47825256.7010907@telenet.be> References: <001501c850b5$bfaf2b90$3f0d82b0$@be> <1199658931.6843.161.camel@derek-laptop> <47825256.7010907@telenet.be> Message-ID: <1199728673.6843.182.camel@derek-laptop> On Mon, 2008-01-07 at 17:24 +0100, Peter Verswyvelen wrote: > Derek Elkins wrote: > > Implicit parameters add an extra argument to a function conceptually. > > What you need is to "add an argument" to "SF" which implicit parameters > > don't know how to do since SF is just some data structure. One way to > > deal with this is the way you deal with the same problem in Haskell > > without implicit parameters. (I never use implicit parameters). In that > > case you would use the Reader monad (transformer). Similarly, you can > > use an equivalent Reader/Environment arrow transformer. > > > Nice, I did not know that monad yet, thanks! > > But can it be combined together with the arrows do/proc syntax? How > would that look like? Claude Heiland-Allen gave an example, I just want to clarify. The only reason I referred to monads is for analogy. You don't use the Reader monad or Reader monad transformer, you use an idea analogous to a monad transformer called an arrow transformer, which is what Claude does. From derek.a.elkins at gmail.com Mon Jan 7 12:59:57 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Mon Jan 7 13:54:03 2008 Subject: [Haskell-cafe] Problem with own written monad In-Reply-To: <47826DA1.5000401@cogito.org.uk> References: <4782384F.6000102@nessie.de> <4628B809-C9AE-4A61-BA38-15C69572F6A1@yandex.ru> <47826DA1.5000401@cogito.org.uk> Message-ID: <1199728797.6843.183.camel@derek-laptop> On Mon, 2008-01-07 at 18:21 +0000, Paul Johnson wrote: > Miguel Mitrofanov wrote: > > > > Yes. It's simply impossible. The Stack data type can't be turned into > > a monad. > Why not? Surely this is just a variation on the theme of a state monad? I somewhat explain in this reply: http://www.haskell.org/pipermail/haskell-cafe/2008-January/037605.html From barsoap at web.de Mon Jan 7 14:08:24 2008 From: barsoap at web.de (Achim Schneider) Date: Mon Jan 7 14:02:16 2008 Subject: [Haskell-cafe] Re: Problem with own written monad References: <4782384F.6000102@nessie.de> <4628B809-C9AE-4A61-BA38-15C69572F6A1@yandex.ru> <47826DA1.5000401@cogito.org.uk> <1199728797.6843.183.camel@derek-laptop> Message-ID: <20080107200824.7385ea6a@solaris.tower> Derek Elkins wrote: > On Mon, 2008-01-07 at 18:21 +0000, Paul Johnson wrote: > > Miguel Mitrofanov wrote: > > > > > > Yes. It's simply impossible. The Stack data type can't be turned > > > into a monad. > > Why not? Surely this is just a variation on the theme of a state > > monad? > > I somewhat explain in this reply: > http://www.haskell.org/pipermail/haskell-cafe/2008-January/037605.html > Which states that the data structure doesn't support the Monad, or that the Monad can't be implemented using that data structure. So, see, some stack data type can certainly be turned into a monad, but this Stack data type can't. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From bos at serpentine.com Mon Jan 7 14:17:08 2008 From: bos at serpentine.com (Bryan O'Sullivan) Date: Mon Jan 7 14:10:49 2008 Subject: [Haskell-cafe] ANN: A triple of new packages for talking to the outside world In-Reply-To: <396556a20801071037t1b66e444u52abe1d934b7f902@mail.gmail.com> References: <396556a20801061554o3895ce88k87d4ecabc1860e7b@mail.gmail.com> <4781B50A.2060007@serpentine.com> <396556a20801071037t1b66e444u52abe1d934b7f902@mail.gmail.com> Message-ID: <47827AB4.60608@serpentine.com> > It would seem that there would be three possible outcomes from an > incremental Get: > - Failure: some bitstreams are just invalid and no amount of extra > data will ever fix that > - Complete [Result]: the last chunk of data has been processed. > Maybe this should also include the remainder of the data? > - Partial Cont [Result]: needs more data, but here's a (possibly > empty) list of results so far. Yes, that's more or less exactly what I had in mind. References: <4782384F.6000102@nessie.de> <4628B809-C9AE-4A61-BA38-15C69572F6A1@yandex.ru> <47826DA1.5000401@cogito.org.uk> Message-ID: <93945387-E02C-4888-98C2-534144855D7D@yandex.ru> >> Yes. It's simply impossible. The Stack data type can't be turned >> into a monad. > Why not? Surely this is just a variation on the theme of a state > monad? Because it can't be turned into a functor. You can't, given a function a -> b, construct a function Stack a -> Stack b. On the contrast, you can easily construct a function State z a -> State z b. From john at repetae.net Mon Jan 7 14:51:42 2008 From: john at repetae.net (John Meacham) Date: Mon Jan 7 14:45:24 2008 Subject: [Haskell-cafe] Re: Compiler backend question In-Reply-To: <20080101184446.7500417a@solaris.tower> References: <477A1CF9.90001@telenet.be> <20080101184446.7500417a@solaris.tower> Message-ID: <20080107195142.GA27708@momenergy.repetae.net> On Tue, Jan 01, 2008 at 06:44:46PM +0100, Achim Schneider wrote: > Peter Verswyvelen wrote: > > > Another question regarding the backend: a cool feature of the > > Microsoft Visual C++ (MVC) compiler is its ability to perform "LTCG" > > (link-time-code-generation), performing whole program optimization. > > It something like this possible with Haskell / (or the GCC backend?). > > Would it be possible to feed all the generated C code of the GHC > > compiler into the MVC compiler, to generate one big MVC / LTCG > > generated executable? It would be interesting to see how much the > > whole program optimization approach (which can do analysis on the > > program as if it was a single module) would improve performance... > > > jhc does that. Or rather, it doesn't compile Haskell modules separately > but throws them together (presumably) in the first pass. It optimizes everything seperately to a level that is analogous to ghc core (which I call, oddly enough, jhc core). it then collects everything together and translates it into grin, which doesn't have an exact equivalent in ghc but is equivalent to a first order monadic strict functional language and analogous enough to the SSA intermediate form of imperative compilers that one would find it quite comfy were one used to that. I would like to move jhc to more of a 'link-time-code-generation' model though if I understand what you mean, right now jhc does a full monolithic compilation which is pretty resource intensive. I would like to switch to more of an 'incremental whole program compilation' (no, that isn't a contridiction) whereby individual files will compile to .o files, but then before the final linking a special pass will be done to generate the appropriate specialized "glue" for putting the .o files together, this should give a nice middle ground between fully monolithic and the limitations of abiding by the standard C linker. John -- John Meacham - ?repetae.net?john? From bf3 at telenet.be Mon Jan 7 14:59:30 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Mon Jan 7 14:53:10 2008 Subject: [Haskell-cafe] Implicit parameters and Arrows/Yampa? In-Reply-To: <47825CF8.2040809@goto10.org> References: <001501c850b5$bfaf2b90$3f0d82b0$@be> <1199658931.6843.161.camel@derek-laptop> <47825256.7010907@telenet.be> <47825CF8.2040809@goto10.org> Message-ID: <000001c85167$d0d54be0$727fe3a0$@be> Wow, amazing :) How long did it take you to write this little nice example? Examples like this are really welcome. It will take me a while to decipher, but that's the fun of Haskell, it's an endless learning experience! Here's a thought: I hardly know Haskell, but I can already write some code much faster and easier than I could do in C/C++ (and I've been programming 2 decades in that language, plus my colleagues tell me I'm pretty productive at it...). So I wonder what the productivity becomes when you can write code as quickly as Claude seemed to do here... Thanks, Peter PS: Also the scissors in your comment (--8<--), very original! Is this copyrighted? ;) -----Original Message----- From: Claude Heiland-Allen [mailto:claudiusmaximus@goto10.org] Something like this? ----8<---- module Main where import Control.Arrow import Control.Arrow.Operations import Control.Arrow.Transformer.Reader -- -- Standard list/stream arrow. -- newtype SF b c = SF { runSF :: [b] -> [c] } instance Arrow SF where arr f = SF (map f) SF f >>> SF g = SF (g . f) first (SF f) = SF (uncurry zip . (f *** id) . unzip) second (SF f) = SF (uncurry zip . (id *** f) . unzip) instance ArrowLoop SF where loop (SF f) = SF $ \as -> let (bs,cs) = unzip (f (zip as (stream cs))) in bs where stream ~(x:xs) = x:stream xs instance ArrowCircuit SF where delay x = SF (init . (x:)) -- -- Some state we want to pass around without manual plumbing. -- data AudioState = AudioState { sampleRate :: Double } runAudio state graph = proc p -> (| runReader (graph -< p) |) state -- -- Some unit generators for audio. -- wrap x = x - fromIntegral (floor x) -- phasor needs the sample rate phasor phase0 = proc hz -> do sr <- pure sampleRate <<< readState -< () rec accum <- delay (wrap phase0) -< wrap (accum + hz / sr) returnA -< accum -- osc doesn't need to know about sample rate osc phase0 = proc hz -> do phase <- phasor phase0 -< hz returnA -< cos (2 * pi * phase) -- -- Test it out. -- main = print (runSF (runAudio (AudioState{sampleRate=1000}) (osc 0)) (replicate 10 100)) ----8<---- > Cheers, > Peter Thanks, Claude -- http://claudiusmaximus.goto10.org From bf3 at telenet.be Mon Jan 7 15:27:17 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Mon Jan 7 15:20:56 2008 Subject: [Haskell-cafe] Re: Compiler backend question In-Reply-To: <20080107195142.GA27708@momenergy.repetae.net> References: <477A1CF9.90001@telenet.be> <20080101184446.7500417a@solaris.tower> <20080107195142.GA27708@momenergy.repetae.net> Message-ID: <000101c8516b$b2146250$163d26f0$@be> John Meacham wrote: > I would like to move jhc to more of a 'link-time-code-generation' model > though if I understand what you mean, right now jhc does a full Yes, LTCG is Microsoft's terminology. See http://msdn.microsoft.com/msdnmag/issues/02/05/Hood > monolithic compilation which is pretty resource intensive. I would like Well, M$ LTCG is also resource intensive, but it's still a lot faster than the monolothic approach would be. > to switch to more of an 'incremental whole program compilation' (no, > that isn't a contridiction) whereby individual files will compile to .o > files, but then before the final linking a special pass will be done to > generate the appropriate specialized "glue" for putting the .o files > together, this should give a nice middle ground between fully > monolithic and the limitations of abiding by the standard C linker. That would be a bit like http://llvm.org does for imperative languages? If your compiler (pretty amazing job btw) does whole program optimization, can it remove the dictionary (aka v-table in C/C++ parlance?) overhead of type classes? Because if I understand it correctly, unless one uses existential types, a dictionary can be compiled away since the type in question is known at compile time? Cheers, Peter From jon at ffconsultancy.com Mon Jan 7 15:26:34 2008 From: jon at ffconsultancy.com (Jon Harrop) Date: Mon Jan 7 15:28:22 2008 Subject: [Haskell-cafe] Re: Compiler backend question In-Reply-To: <000101c8516b$b2146250$163d26f0$@be> References: <477A1CF9.90001@telenet.be> <20080107195142.GA27708@momenergy.repetae.net> <000101c8516b$b2146250$163d26f0$@be> Message-ID: <200801072026.34449.jon@ffconsultancy.com> On Monday 07 January 2008 20:27:17 Peter Verswyvelen wrote: > If your compiler (pretty amazing job btw) does whole program optimization, > can it remove the dictionary (aka v-table in C/C++ parlance?) overhead of > type classes? Because if I understand it correctly, unless one uses > existential types, a dictionary can be compiled away since the type in > question is known at compile time? Yes. This is essentially what F# does. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?e From haskell at list.mightyreason.com Mon Jan 7 15:40:38 2008 From: haskell at list.mightyreason.com (ChrisK) Date: Mon Jan 7 15:34:37 2008 Subject: [Haskell-cafe] Re: Implicit parameters and Arrows/Yampa? In-Reply-To: <000001c85167$d0d54be0$727fe3a0$@be> References: <001501c850b5$bfaf2b90$3f0d82b0$@be> <1199658931.6843.161.camel@derek-laptop> <47825256.7010907@telenet.be> <47825CF8.2040809@goto10.org> <000001c85167$d0d54be0$727fe3a0$@be> Message-ID: <47828E46.2090606@list.mightyreason.com> Could I has one question? What is the purpose of the "stream" function in the ArrowLoop instance? Is it just to catch an unexpected [] at runtime? > ----8<---- > module Main where > > import Control.Arrow > import Control.Arrow.Operations > import Control.Arrow.Transformer.Reader > > -- > -- Standard list/stream arrow. > -- > > newtype SF b c = SF { runSF :: [b] -> [c] } > > instance Arrow SF where > arr f = SF (map f) > SF f >>> SF g = SF (g . f) > first (SF f) = SF (uncurry zip . (f *** id) . unzip) > second (SF f) = SF (uncurry zip . (id *** f) . unzip) > > instance ArrowLoop SF where > loop (SF f) = SF $ \as -> > let (bs,cs) = unzip (f (zip as (stream cs))) in bs > where stream ~(x:xs) = x:stream xs It looks like stream is (almost) an identity which would crash at runtime if it encountered a []. In particular it is equivalent to > where stream xs = head xs:stream (tail xs) > > instance ArrowCircuit SF where > delay x = SF (init . (x:)) > > > -- > -- Some state we want to pass around without manual plumbing. > -- > > data AudioState = AudioState { sampleRate :: Double } > > runAudio state graph = proc p -> (| runReader (graph -< p) |) state > > > -- > -- Some unit generators for audio. > -- > > wrap x = x - fromIntegral (floor x) > > -- phasor needs the sample rate > phasor phase0 = proc hz -> do > sr <- pure sampleRate <<< readState -< () > rec accum <- delay (wrap phase0) -< wrap (accum + hz / sr) > returnA -< accum > > -- osc doesn't need to know about sample rate > osc phase0 = proc hz -> do > phase <- phasor phase0 -< hz > returnA -< cos (2 * pi * phase) > > > -- > -- Test it out. > -- > > main = print (runSF (runAudio (AudioState{sampleRate=1000}) (osc 0)) > (replicate 10 100)) > > ----8<---- From claudiusmaximus at goto10.org Mon Jan 7 16:00:23 2008 From: claudiusmaximus at goto10.org (Claude Heiland-Allen) Date: Mon Jan 7 15:53:06 2008 Subject: [Haskell-cafe] Re: Implicit parameters and Arrows/Yampa? In-Reply-To: <47828E46.2090606@list.mightyreason.com> References: <001501c850b5$bfaf2b90$3f0d82b0$@be> <1199658931.6843.161.camel@derek-laptop> <47825256.7010907@telenet.be> <47825CF8.2040809@goto10.org> <000001c85167$d0d54be0$727fe3a0$@be> <47828E46.2090606@list.mightyreason.com> Message-ID: <478292E7.1030305@goto10.org> ChrisK wrote: > Could I has one question? What is the purpose of the "stream" function > in the ArrowLoop instance? Is it just to catch an unexpected [] at > runtime? >> instance ArrowLoop SF where >> loop (SF f) = SF $ \as -> >> let (bs,cs) = unzip (f (zip as (stream cs))) in bs >> where stream ~(x:xs) = x:stream xs > > It looks like stream is (almost) an identity which would crash at > runtime if it encountered a []. In particular it is equivalent to > > > where stream xs = head xs:stream (tail xs) Not quite that, from a blog post of mine a while back: [snip] But then the trouble arrived - I suddenly noticed that the paper was using infinite sequences, not the finite sequences I was using myself. Trying to implement an ArrowLoop as per the paper led to horrible grief: -- instance ArrowLoop SF where -- loop (SF f) = SF (loop (unzip . f . uncurry zip)) The problem is that this is far too strict - on non-empty input it caused stack overflow crashes, which isn't exactly what I wanted. I found the solution in Programming With Arrows [1] (page 17), which involves some subtlety with lazy patterns: instance ArrowLoop SF where loop (SF f) = SF $ \as -> let (bs,cs) = unzip (f (zip as (stream cs))) in bs where stream ~(x:xs) = x:stream xs [unsnip] http://www.haskell.org/arrows/biblio.html#Hug05 [1] Hope this helps, Claude -- http://claudiusmaximus.goto10.org From john at repetae.net Mon Jan 7 16:21:28 2008 From: john at repetae.net (John Meacham) Date: Mon Jan 7 16:15:12 2008 Subject: [Haskell-cafe] Re: Compiler backend question In-Reply-To: <000101c8516b$b2146250$163d26f0$@be> References: <477A1CF9.90001@telenet.be> <20080101184446.7500417a@solaris.tower> <20080107195142.GA27708@momenergy.repetae.net> <000101c8516b$b2146250$163d26f0$@be> Message-ID: <20080107212128.GB27708@momenergy.repetae.net> On Mon, Jan 07, 2008 at 09:27:17PM +0100, Peter Verswyvelen wrote: > If your compiler (pretty amazing job btw) does whole program > optimization, can it remove the dictionary (aka v-table in C/C++ > parlance?) overhead of type classes? Because if I understand it > correctly, unless one uses existential types, a dictionary can be > compiled away since the type in question is known at compile time? Both jhc and ghc can completely remove the dictionary parameter whenever the type is known at compile time because an implicit SPECIALIZATION rule is generated that gets triggered whenever an overloaded function is called on a known type. Jhc can do a bit more though when the type is not fully known at compile time. it has a fairly interesting implementation of type classes, rather than turning each type class parameter into a dictionary of functions, it passes a reification of the type itself as a single argument whenever type class arguments are present (and used). This means that the generated code looks something like (+) :: (a::*) -> a -> a -> a (+) t x y = case t of Int -> primIntAdd x y Integer -> primIntegerAdd x y ... standard optimizations then can apply to eliminating and coalescing the type scrutinizations. John -- John Meacham - ?repetae.net?john? From haskell at list.mightyreason.com Mon Jan 7 16:24:52 2008 From: haskell at list.mightyreason.com (ChrisK) Date: Mon Jan 7 16:18:42 2008 Subject: [Haskell-cafe] ANN: Build fixed for regex-base,posix,compat,pcre Message-ID: <478298A4.2030507@list.mightyreason.com> ANNOUNCEMENT: Build fixed for regex-base, regex-posix, regex-compat, regex-pcre The changes are mainly to the Cabal build files to support ghc-6.8 and ghc-6.6 simultaneously. They definitely work with cabal version 1.2.3.0 (required for regex-pcre). The regex-base, regex-posix, and regex-compat packages also seem to work with cabal-1.2.2.0 (but not regex-pcre). The darcs repositories under http://darcs.haskell.org/packages/regex-unstable/ hold the new code. I have uploaded new versions of the most popular regex-* packages to hackage: Mon Jan 7 13:18:00 PST 2008 ChrisKuklewicz regex-pcre-0.94.1 Mon Jan 7 13:05:57 PST 2008 ChrisKuklewicz regex-posix-0.93.1 Mon Jan 7 13:04:49 PST 2008 ChrisKuklewicz regex-base-0.93.1 Mon Jan 7 06:50:54 PST 2008 ChrisKuklewicz regex-compat-0.91 I would like to thank everyone who sent me updated, and particularly Olivier Boudry who sent patches. These build fixes have only been tested with ghc-6.6.1 on Mac OS X 10.5.1 (powerpc) and with ghc-6.8.2 on Linux (x86). Happy New Year, Chris Kuklewicz From andrewcoppin at btinternet.com Mon Jan 7 16:40:29 2008 From: andrewcoppin at btinternet.com (Andrew Coppin) Date: Mon Jan 7 16:34:07 2008 Subject: [Haskell-cafe] Concurrency questions In-Reply-To: <20080107165902.GA6008@presario> References: <4780BBED.5020907@btinternet.com> <20080107165902.GA6008@presario> Message-ID: <47829C4D.4@btinternet.com> Spencer Janssen wrote: > On Sun, Jan 06, 2008 at 11:30:53AM +0000, Andrew Coppin wrote: > >> Just a couple of things I was wondering about... >> >> 1. Is there some way to assign a "priority" to Haskell threads? (The >> behaviour I'd like is that high priority threads always run first, and low >> priority threads potentially never run at all unless there's an available >> processor which is completely idle.) >> > > Not in the current system. It is not clear that thread priorities are so nice > anyway (see 'priority inversion' on Wikipedia, for example). > Well, I was thinking more of using them for two things. One is for speculative work (i.e., doing work which we might need later - but don't bother unless there's cores going spare). The other is for working on entirely independent tasks - I don't see how inversion can happen when one thread is solving problem X and another is solving problem Y. But sure, it certainly adds more complexity to have priority levels. [I can also imagine situations where you might want to assign 80% CPU to one thing, and 20% CPU to the other - but that really does sound hard to implement...] >> 2. I have a situation where I have a thread generating some data and >> putting it into a mutable array, and another thread trying to read that >> data. Is there a way I can make the reader thread block if it tries to read >> a cell that hasn't been computed yet, but not introduce too much overhead >> for cells that have been filled in? >> > > I'd probably use an Array of TMVars, they should be faster than MVars when > multiple threads are reading simultaneously. > Mmm, OK. I'll try that. (I wasn't actually aware that STM is working yet...) >> 3. Would it be hard to make it so that the number of real threads (the RTS >> +N flag) could be adjusted at runtime? >> > > I don't know whether it is hard, but I do know that it would be useful! > ;-) From ben.franksen at online.de Mon Jan 7 16:38:43 2008 From: ben.franksen at online.de (Ben Franksen) Date: Mon Jan 7 16:34:16 2008 Subject: [Haskell-cafe] RE: Wikipedia on first-class object References: <2608b8a80712270110l38830795l5b9a0d05b7835ced@mail.gmail.com> <2608b8a80712270240g97b8601tc0898a5513e1b155@mail.gmail.com> <597F114C-5E60-48ED-9F7F-FF5BC3EE0F97@fastmail.fm> <1199617367.6843.7.camel@derek-laptop> <246AF129-DD30-4132-85A8-32014BA73D7C@fastmail.fm> <1199650393.6843.102.camel@derek-laptop> <108CFD7D-173D-4335-B752-7E0B4BBA98B0@fastmail.fm> <1199653689.6843.119.camel@derek-laptop> <002001c850b6$d0d9be20$728d3a60$@be> Message-ID: Peter Verswyvelen wrote: > Jerzy wrote: >> The relational syntax of Prolog is more "universal" than the functional >> notation, since you have logic variables and logical-non-determinism, and > > Isn't this just because mathematically, a function *is* a relation, but > not vice versa? A relation being just a subset of a Cartesian product of > sets, while a function being a special kind of relation for which each > element in the domain has exactly one image? So relations are inherently > much more universal than functions, but they are not that practical to > work with (for a computer and/or human?). You can as well regard a relation as a special sort of function, i.e. define relation ~ as a function A x B -> Bool by (a,b) |-> a ~ b. Cheers Ben From dons at galois.com Mon Jan 7 16:43:26 2008 From: dons at galois.com (Don Stewart) Date: Mon Jan 7 16:42:15 2008 Subject: [Haskell-cafe] Concurrency questions In-Reply-To: <47829C4D.4@btinternet.com> References: <4780BBED.5020907@btinternet.com> <20080107165902.GA6008@presario> <47829C4D.4@btinternet.com> Message-ID: <20080107214326.GF17534@scytale.galois.com> andrewcoppin: > Spencer Janssen wrote: > >On Sun, Jan 06, 2008 at 11:30:53AM +0000, Andrew Coppin wrote: > > > >>Just a couple of things I was wondering about... > >> > >>1. Is there some way to assign a "priority" to Haskell threads? (The > >>behaviour I'd like is that high priority threads always run first, and > >>low priority threads potentially never run at all unless there's an > >>available processor which is completely idle.) > >> > > > >Not in the current system. It is not clear that thread priorities are so > >nice > >anyway (see 'priority inversion' on Wikipedia, for example). > > > > Well, I was thinking more of using them for two things. One is for > speculative work (i.e., doing work which we might need later - but don't > bother unless there's cores going spare). The other is for working on > entirely independent tasks - I don't see how inversion can happen when > one thread is solving problem X and another is solving problem Y. But > sure, it certainly adds more complexity to have priority levels. > > [I can also imagine situations where you might want to assign 80% CPU to > one thing, and 20% CPU to the other - but that really does sound hard to > implement...] > > >>2. I have a situation where I have a thread generating some data and > >>putting it into a mutable array, and another thread trying to read that > >>data. Is there a way I can make the reader thread block if it tries to > >>read a cell that hasn't been computed yet, but not introduce too much > >>overhead for cells that have been filled in? > >> > > > >I'd probably use an Array of TMVars, they should be faster than MVars when > >multiple threads are reading simultaneously. > > > > Mmm, OK. I'll try that. (I wasn't actually aware that STM is working > yet...) It works, and has done so for a couple of years now. It's used in production systems. Where'd you hear otherwise? -- Don From trebla at vex.net Mon Jan 7 16:52:08 2008 From: trebla at vex.net (Albert Y. C. Lai) Date: Mon Jan 7 16:45:54 2008 Subject: [Haskell-cafe] Re: Quanta. Was: Wikipedia on first-class object In-Reply-To: <20080106225930.7ec6c56c@solaris.tower> References: <2608b8a80712270110l38830795l5b9a0d05b7835ced@mail.gmail.com> <1934333921.20071227154048@gmail.com> <47767D39.4020007@btinternet.com> <20071229184005.702ab59c@solaris.tower> <1695012808.20071229213744@gmail.com> <4683d9370712291042w21873ae3xcb0376e05b0a3326@mail.gmail.com> <1995050719.20071229215903@gmail.com> <20071229201639.22c43260@solaris.tower> <1372887653.20071229223329@gmail.com> <000001c84a57$2c7b7e00$85727a00$@be> <568741883.20071230011816@gmail.com> <871w94fugj.fsf@nmd9999.imr.no> <1199617488.6843.10.camel@derek-laptop> <87y7b2vi2e.fsf@nmd9999.imr.no> <772A83B9-7FC9-4A79-811C-4174AD89FEC0@ece.cmu.edu> <20080106225930.7ec6c56c@solaris.tower> Message-ID: <47829F08.7060606@vex.net> Achim Schneider wrote: > Erm... > > There is this story about some military (US afair) training a neural > net to detect tanks in images, I can't find the link right now. > > It worked, with amazing 100% accuracy. > > Then they threw another batch of images at the net. > > It worked, with devastating 50% accuracy. > > It turned out that in the first batch, all the pictures with tanks on > them were shot in sunny weather, all the pictures without tanks were > shot with cloudy sky. I have some similar stories to tell. I don't have references or links, but they are reproducible - in fact you have probably experienced them first-hand. A. Students were trained to do math. At first, they did well with high accuracy. Then more math was taught and tested, and they did poorly. It turned out that the first batch was algebra, where -(x+y) = -x + -y z*(x+y) = z*x + z*y and the second batch was trig, and students assumed sin(x+y) = sin(x) + sin(y) B. A friend of mine is a safe, attentive driver. But one day, the car in front of us stopped, and he almost didn't stopped, I had to remind him. It turned out that normally (by legal requirement) any car that brakes must put on red light at the back. But that day, that car, it showed no red light. From jerzy.karczmarczuk at info.unicaen.fr Mon Jan 7 17:20:14 2008 From: jerzy.karczmarczuk at info.unicaen.fr (jerzy.karczmarczuk@info.unicaen.fr) Date: Mon Jan 7 17:13:57 2008 Subject: [Haskell-cafe] Re: Quanta. Was: Wikipedia on first-class object In-Reply-To: <47829F08.7060606@vex.net> References: <47767D39.4020007@btinternet.com> <20071229184005.702ab59c@solaris.tower> <1695012808.20071229213744@gmail.com> <4683d9370712291042w21873ae3xcb0376e05b0a3326@mail.gmail.com> <1995050719.20071229215903@gmail.com> <20071229201639.22c43260@solaris.tower> <1372887653.20071229223329@gmail.com> <000001c84a57$2c7b7e00$85727a00$@be> <568741883.20071230011816@gmail.com> <871w94fugj.fsf@nmd9999.imr.no> <1199617488.6843.10.camel@derek-laptop> <87y7b2vi2e.fsf@nmd9999.imr.no> <772A83B9-7FC9-4A79-811C-4174AD89FEC0@ece.cmu.edu> <20080106225930.7ec6c56c@solaris.tower> <47829F08.7060606@vex.net> Message-ID: Albert Y. C. Lai writes: > Achim Schneider wrote: >> There is this story about some military (US afair) training a neural >> net to detect tanks in images ... > 50% accuracy. > I have some similar stories to tell.... > > A. ... students assumed > sin(x+y) = sin(x) + sin(y) > B. ... But that day, that car, it showed no red light. All this is nice to read, and make me thank Lord I am still alive, but, for goodness sake, *what do you want to convey?* No quanta, no Wikipedia, no first-class objects, no Haskell, caf? I have to fetch myself in la cuisine, and I feel lost. J.K. (an unlucky character from Kafka, as you should remember). From ben.franksen at online.de Mon Jan 7 17:23:55 2008 From: ben.franksen at online.de (Ben Franksen) Date: Mon Jan 7 17:19:28 2008 Subject: [Haskell-cafe] Re: Concurrency questions References: <4780BBED.5020907@btinternet.com> <20080107165902.GA6008@presario> Message-ID: Spencer Janssen wrote: > On Sun, Jan 06, 2008 at 11:30:53AM +0000, Andrew Coppin wrote: >> 1. Is there some way to assign a "priority" to Haskell threads? (The >> behaviour I'd like is that high priority threads always run first, and >> low priority threads potentially never run at all unless there's an >> available processor which is completely idle.) > > Not in the current system. It is not clear that thread priorities are so > nice anyway (see 'priority inversion' on Wikipedia, for example). As the wikipedia page also mentions well-known counter-measures, such as priority inheritance and priority ceilings. For real-time applications, priorities are a /must have/. Or at least, I can't see anything nicer that could replace them. Cheers Ben From barsoap at web.de Mon Jan 7 18:25:21 2008 From: barsoap at web.de (Achim Schneider) Date: Mon Jan 7 18:19:21 2008 Subject: [Haskell-cafe] Neural nets and the menu (was: something different) References: <47767D39.4020007@btinternet.com> <20071229184005.702ab59c@solaris.tower> <1695012808.20071229213744@gmail.com> <4683d9370712291042w21873ae3xcb0376e05b0a3326@mail.gmail.com> <1995050719.20071229215903@gmail.com> <20071229201639.22c43260@solaris.tower> <1372887653.20071229223329@gmail.com> <000001c84a57$2c7b7e00$85727a00$@be> <568741883.20071230011816@gmail.com> <871w94fugj.fsf@nmd9999.imr.no> <1199617488.6843.10.camel@derek-laptop> <87y7b2vi2e.fsf@nmd9999.imr.no> <772A83B9-7FC9-4A79-811C-4174AD89FEC0@ece.cmu.edu> <20080106225930.7ec6c56c@solaris.tower> <47829F08.7060606@vex.net> Message-ID: <20080108002521.66426d5c@solaris.tower> jerzy.karczmarczuk@info.unicaen.fr wrote: > Albert Y. C. Lai writes: > > > Achim Schneider wrote: > >> There is this story about some military (US afair) training a > >> neural net to detect tanks in images > ... > > 50% accuracy. > > > I have some similar stories to tell.... > > > > A. ... students assumed > > sin(x+y) = sin(x) + sin(y) > > B. ... But that day, that car, it showed no red light. > > All this is nice to read, and make me thank Lord I am still alive, > but, for goodness sake, *what do you want to convey?* > Probably that you have to come up with something more confusing and powerful than a neural net and then transfer your consciousness into it to understand yourself and how to program something like you. > No quanta, no Wikipedia, no first-class objects, no Haskell, caf? I > have to fetch myself in la cuisine, and I feel lost. > There is always a good chance to get an Espresso-Baileys in any good caf?. Or Baileys-Espresso, if you prefer. If you're lucky, you can also get mead in your coffee. I recommend any kind of sandcake with it. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From mroth at nessie.de Mon Jan 7 18:29:19 2008 From: mroth at nessie.de (Michael Roth) Date: Mon Jan 7 18:23:01 2008 Subject: [Haskell-cafe] Problem with own written monad In-Reply-To: <4628B809-C9AE-4A61-BA38-15C69572F6A1@yandex.ru> References: <4782384F.6000102@nessie.de> <4628B809-C9AE-4A61-BA38-15C69572F6A1@yandex.ru> Message-ID: <4782B5CF.9070107@nessie.de> Miguel Mitrofanov schrieb: > May be you can explain what do you want to do with this "monad"? Pure educational purpose, just "learning by doing". > What kind of code would you write if it would be such monad? Useless stuff like: s2 = do push 11 push 17 count >>= push binop (+) binop (*) pop From barsoap at web.de Mon Jan 7 18:27:42 2008 From: barsoap at web.de (Achim Schneider) Date: Mon Jan 7 18:23:43 2008 Subject: [Haskell-cafe] Re: Concurrency questions References: <4780BBED.5020907@btinternet.com> <20080107165902.GA6008@presario> Message-ID: <20080108002742.48444410@solaris.tower> Ben Franksen wrote: > Spencer Janssen wrote: > > On Sun, Jan 06, 2008 at 11:30:53AM +0000, Andrew Coppin wrote: > >> 1. Is there some way to assign a "priority" to Haskell threads? > >> (The behaviour I'd like is that high priority threads always run > >> first, and low priority threads potentially never run at all > >> unless there's an available processor which is completely idle.) > > > > Not in the current system. It is not clear that thread priorities > > are so nice anyway (see 'priority inversion' on Wikipedia, for > > example). > > As the wikipedia page also mentions well-known counter-measures, such > as priority inheritance and priority ceilings. For real-time > applications, priorities are a /must have/. Or at least, I can't see > anything nicer that could replace them. > Preemption, for hard real-time. For soft real-time, yes, SCHED_FIFO and SCHED_RR are a must. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From mroth at nessie.de Mon Jan 7 18:30:57 2008 From: mroth at nessie.de (Michael Roth) Date: Mon Jan 7 18:24:42 2008 Subject: [Haskell-cafe] Problem with own written monad In-Reply-To: <47823E26.2000501@jellybean.co.uk> References: <4782384F.6000102@nessie.de> <47823E26.2000501@jellybean.co.uk> Message-ID: <4782B631.2090904@nessie.de> Jules Bean schrieb: > data Stack a b = Stack { run :: [a] -> (b, [a]) } Thank you, that does the trick. > The correct types for the other functions are: > > push :: a -> Stack a () > pop :: Stack a a > top :: Stack a a > > With those clues I think you will be able to write >>= and return more > successfully! Yes, this was the missing link. Because I thought "Stack a a" could be abbreviated using "Stack a" I run into these problems. This was also the cause that "push" echoed back the pushed value. > There are some other interesting combinators to consider, like: > > isolate :: Stack b x -> Stack a x > -- runs the computation with an empty stack, therefore > -- guaranteeing it does more pushes than pops Did you mean: isolate :: Stack s1 a -> Stack s2 a isolate stack = Stack f where f xs = ( fst $ run stack [], xs) > and so on. Yes, I have done: push, pop, top, nop, count, clear, isolate and binop. All pretty easy, once I understand that "Stack a b" thing. From derek.a.elkins at gmail.com Mon Jan 7 17:38:37 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Mon Jan 7 18:33:12 2008 Subject: [Haskell-cafe] Re: Compiler backend question In-Reply-To: <200801072026.34449.jon@ffconsultancy.com> References: <477A1CF9.90001@telenet.be> <20080107195142.GA27708@momenergy.repetae.net> <000101c8516b$b2146250$163d26f0$@be> <200801072026.34449.jon@ffconsultancy.com> Message-ID: <1199745518.6843.199.camel@derek-laptop> On Mon, 2008-01-07 at 20:26 +0000, Jon Harrop wrote: > On Monday 07 January 2008 20:27:17 Peter Verswyvelen wrote: > > If your compiler (pretty amazing job btw) does whole program optimization, > > can it remove the dictionary (aka v-table in C/C++ parlance?) overhead of > > type classes? Because if I understand it correctly, unless one uses > > existential types, a dictionary can be compiled away since the type in > > question is known at compile time? > > Yes. This is essentially what F# does. > (This reply is aimed primarily at Peter.) Even in Haskell 98 it is not quite possible to do this. You can get rid of the vast majority of them, but the type is not always known at compile-time. There is one situation where the types depend on values. This occurs when you utilize polymorphic recursion. Polymorphic recursion is one of the things the Haskell standard wasn't conservative about. I'm not sure if any widely used language supports it besides Haskell. (Maybe Clean?) This turned out to be rather fortunate as nested data types effectively require it. As a toy example which illustrates this problem is: f :: Show a => Int -> a -> String -- type signature required f 0 x = show x f n x = f (n-1) (x,x) The dictionary to use depends on the input. There are (well, switching to Integer) an infinite number of potential types, so being able to statically resolve them would not help. Some kind of run-time witness will need to be passed around. From sjanssen at cse.unl.edu Mon Jan 7 18:42:02 2008 From: sjanssen at cse.unl.edu (Spencer Janssen) Date: Mon Jan 7 18:36:02 2008 Subject: [Haskell-cafe] Concurrency questions In-Reply-To: <47829C4D.4@btinternet.com> References: <4780BBED.5020907@btinternet.com> <20080107165902.GA6008@presario> <47829C4D.4@btinternet.com> Message-ID: <20080107234202.GA6844@presario> On Mon, Jan 07, 2008 at 09:40:29PM +0000, Andrew Coppin wrote: > Well, I was thinking more of using them for two things. One is for > speculative work (i.e., doing work which we might need later - but don't > bother unless there's cores going spare). For (pure) speculative tasks, try Control.Parallel.par. > Mmm, OK. I'll try that. (I wasn't actually aware that STM is working > yet...) STM has been available for quite awhile, as early as GHC 6.4 if memory serves. Cheers, Spencer Janssen From miguelimo38 at yandex.ru Mon Jan 7 18:42:21 2008 From: miguelimo38 at yandex.ru (Miguel Mitrofanov) Date: Mon Jan 7 18:36:16 2008 Subject: [Haskell-cafe] Problem with own written monad In-Reply-To: <4782B5CF.9070107@nessie.de> References: <4782384F.6000102@nessie.de> <4628B809-C9AE-4A61-BA38-15C69572F6A1@yandex.ru> <4782B5CF.9070107@nessie.de> Message-ID: <21D42D75-CE32-47D5-B3CC-0EE773B10C92@yandex.ru> >> What kind of code would you write if it would be such monad? > > Useless stuff like: > > s2 = do > push 11 > push 17 > count >>= push > binop (+) > binop (*) > pop Then you should use something like data Stack a = Stack {run :: [Integer] -> (a,[Integer])} From jerzy.karczmarczuk at info.unicaen.fr Mon Jan 7 19:03:49 2008 From: jerzy.karczmarczuk at info.unicaen.fr (jerzy.karczmarczuk@info.unicaen.fr) Date: Mon Jan 7 18:57:31 2008 Subject: [Haskell-cafe] Neural nets and the menu (was: something different) In-Reply-To: <20080108002521.66426d5c@solaris.tower> References: <47767D39.4020007@btinternet.com> <20071229184005.702ab59c@solaris.tower> <1695012808.20071229213744@gmail.com> <4683d9370712291042w21873ae3xcb0376e05b0a3326@mail.gmail.com> <1995050719.20071229215903@gmail.com> <20071229201639.22c43260@solaris.tower> <1372887653.20071229223329@gmail.com> <000001c84a57$2c7b7e00$85727a00$@be> <568741883.20071230011816@gmail.com> <871w94fugj.fsf@nmd9999.imr.no> <1199617488.6843.10.camel@derek-laptop> <87y7b2vi2e.fsf@nmd9999.imr.no> <772A83B9-7FC9-4A79-811C-4174AD89FEC0@ece.cmu.edu> <20080106225930.7ec6c56c@solaris.tower> <47829F08.7060606@vex.net> <20080108002521.66426d5c@solaris.tower> Message-ID: Achim Schneider writes: > jerzy.karczmarczuk@info.unicaen.fr wrote: > > ... *what do you want to convey?* >> > Probably that you have to come up with something more confusing and > powerful than a neural net and then transfer your consciousness into it > to understand yourself and how to program something like you. Oh my, really? I have to discuss this with my Master, R. Daneel Olivaw. My turn to tell an anecdote. Have you heard about the homework of Theodore Hill (mathematician)? He asked his students to flip a coin 200 times, or use some other serious random generator 200 times, and to report the result sequence. There was an option for lazy people, they could fake the sequence and produce it from the thin air, as intelligent humans could. Then he took the homeworks, scanned each for a couple of seconds, and with a remarkable accuracy selected the cheaters. How? == If you haven't hear the story, check the Web for Benford's Law (discovered by Newcomb 50 years earlier), and all the business which came with it, notably some automated ways of discovering human cheaters who try to fake *natural* data. Instructive, and despite reasonable analysis, still a bit mysterious in its essence. I find it nicer than cheaters who try to convince me that automata may fake human behaviour. Jerzy Karczmarczuk From rl at cse.unsw.edu.au Tue Jan 8 00:29:31 2008 From: rl at cse.unsw.edu.au (Roman Leshchinskiy) Date: Tue Jan 8 00:23:36 2008 Subject: Fusion vs. inlining (Was: [Haskell-cafe] Fusion of lists and chunky sequences) In-Reply-To: References: <20080103192002.GF4775@scytale.galois.com> Message-ID: <47830A3B.7040401@cse.unsw.edu.au> Henning Thielemann wrote: > > Anyway, I tried to wrap Prelude lists in a newtype and thus got GHC (still > 6.4.1) to invoke my rules instead of the Prelude rules. But I encountered > the following problem: I define something like > > nonFusable x y = fusable (aux x y) > > where fusion rules are defined for 'fusable', but not for 'nonFusable'. I > hoped that 'nonFusable' will be inlined and then 'fusable' is fused with > other expressions. This does not happen. If I state the function > definition also as rule, then GHC fuses eagerly. I suspect that fusable and/or aux are inlined into nonFusable when the latter is compiled. That's too early - you want nonFusable (with the simple definition above) to be inlined into the client code first. Adding {-# INLINE nonFusable #-} should take care of this. > Analogously I observed that usage of ($) and (.) blocks fusion, and when > I add the rules > > "unfold-dollar" forall f x. > f $ x = f x ; > > "unfold-dot" forall f g. > f . g = \x -> f (g x) ; > > then fusion takes place as expected. That shouldn't be necessary, these two ought to be inlined. Do you have a concrete example where this happens? Roman From jules at jellybean.co.uk Tue Jan 8 05:32:03 2008 From: jules at jellybean.co.uk (Jules Bean) Date: Tue Jan 8 05:25:45 2008 Subject: [Haskell-cafe] Problem with own written monad In-Reply-To: <4782B631.2090904@nessie.de> References: <4782384F.6000102@nessie.de> <47823E26.2000501@jellybean.co.uk> <4782B631.2090904@nessie.de> Message-ID: <47835123.5050707@jellybean.co.uk> Michael Roth wrote: > Did you mean: > > isolate :: Stack s1 a -> Stack s2 a > isolate stack = Stack f where f xs = ( fst $ run stack [], xs) Yes. What's slightly interesting is the way the types promise the isolation: the Stack s1 action clearly can't be consuming any of the [s2] stack, because that is the wrong type. This continues to hold even if you happen to run it with s1 == s2. Jules From bf3 at telenet.be Tue Jan 8 05:33:37 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Tue Jan 8 05:27:37 2008 Subject: [Haskell-cafe] Re: Compiler backend question In-Reply-To: <200801072026.34449.jon@ffconsultancy.com> References: <477A1CF9.90001@telenet.be> <20080107195142.GA27708@momenergy.repetae.net> <000101c8516b$b2146250$163d26f0$@be> <200801072026.34449.jon@ffconsultancy.com> Message-ID: <47835181.6000404@telenet.be> Jon Harrop wrote: > On Monday 07 January 2008 20:27:17 Peter Verswyvelen wrote: > >> If your compiler (pretty amazing job btw) does whole program optimization, >> can it remove the dictionary (aka v-table in C/C++ parlance?) overhead of >> type classes? Because if I understand it correctly, unless one uses >> existential types, a dictionary can be compiled away since the type in >> question is known at compile time? >> > > Yes. This is essentially what F# does. > Hang on. When I asked a similar question in the F# forum, it seemed that F# simply does not have type classes (but it does support .NET interfaces), and root functions are only fully polymorphic when you mark them *inline*. For example, the following will not work in the current version of F#: **let add x y = x + y let t1 = add 1 2 let t2 = add 1.0 2.0** The first usage of add forces it to work on integers, and then its type is settled once and for all. If I understood it correctly, this is because the "root polymorphic" add function can only work on specific types because it gets compiled into an object file. You can force it to work on any type on which + can be applied by forcing the function to be inline, like let inline add x y = x+y let t1 = add 1 2 let t2 = add 1.0 2.0 Then I guess the code will not be part of the object file, but it will be inserted inplace whenever it gets used (which could result in code bloat?) Can the same trick be used in GHC? Regarding Derek Elkins excellent example f :: Show a => Int -> a -> String -- type signature required f 0 x = show x f n x = f (n-1) (x,x) this indeed cannot be inlined nor optimized away, since you generally don't know the value of the first parameter at runtime. But this is a very specific case no? According to what I interpret from John Meacham's email, this case is an exception, and in many cases class type dictionary overhead gets compiled away? Thanks, Peter From jules at jellybean.co.uk Tue Jan 8 06:20:15 2008 From: jules at jellybean.co.uk (Jules Bean) Date: Tue Jan 8 06:13:56 2008 Subject: [Haskell-cafe] Re: Is there anyone out there who can translate C# generics into Haskell? In-Reply-To: <20080106111309.3f0bc240@solaris.tower> References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <1965805939.20080102232921@gmail.com> <915864007.20080103135418@gmail.com> <8627368.20080103173843@gmail.com> <1762133336.20080103215834@gmail.com> <83DE9074-6529-4B54-B2A5-D3285DC699B0@fastmail.fm> <20080106111309.3f0bc240@solaris.tower> Message-ID: <47835C6F.30900@jellybean.co.uk> Achim Schneider wrote: > things like > > > data State = State > { winSize :: IORef Size > , t :: IORef Int > , fps :: IORef Float > , showFPS :: IORef Bool > , showHelp :: IORef Bool > , grabMouse :: IORef Bool > , mousePos :: IORef (Maybe Position) > , mouseDelta :: IORef Position > , viewRot :: IORef Vec3 > , angle' :: IORef GLfloat > , ballPos :: IORef Vec2 > , ballVel :: IORef Vec2 > } Yuck! I'm not sure whether this is a real example or not, but if it's real, get rid of all those IORefs. Make State a simple type, and use (IORef State) as needed for callbacks, and hide that fact in other code. Jules From bulat.ziganshin at gmail.com Tue Jan 8 05:40:49 2008 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Tue Jan 8 06:25:56 2008 Subject: [Haskell-cafe] Implicit parameters and Arrows/Yampa? In-Reply-To: <000001c85167$d0d54be0$727fe3a0$@be> References: <001501c850b5$bfaf2b90$3f0d82b0$@be> <1199658931.6843.161.camel@derek-laptop> <47825256.7010907@telenet.be> <47825CF8.2040809@goto10.org> <000001c85167$d0d54be0$727fe3a0$@be> Message-ID: <6710342976.20080108134049@gmail.com> Hello Peter, Monday, January 7, 2008, 10:59:30 PM, you wrote: > Here's a thought: I hardly know Haskell, but I can already write > some code much faster and easier than I could do in C/C++ (and I've > been programming 2 decades in that language, plus my colleagues tell > me I'm pretty productive at it...). So I wonder what the > productivity becomes when you can write code as quickly as Claude seemed to do here... are you hear about 7-zip? it's rather popular high-ratio compressor. last two years i've developed my own archiver and outperformed 7-zip in functionality. when people ask why i don't joined 7-zip project instead (it's LGPL-licensed), i say what using C++ i will develop the same program 3x slower [1] http://freearc.sf.net -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From david.waern at gmail.com Tue Jan 8 07:28:50 2008 From: david.waern at gmail.com (David Waern) Date: Tue Jan 8 07:22:31 2008 Subject: [Haskell-cafe] ANNOUNCE: Haddock version 2.0.0.0 Message-ID: Dear Haskell community, I'm proud to announce the release of Haddock 2.0.0.0! http://www.haskell.org/haddock http://hackage.haskell.org/cgi-bin/hackage-scripts/package/haddock-2.0.0.0 Changes in version 2.0.0.0: * The GHC API is used as the front-end * Haddock now understands all syntax understood by GHC 6.8.2 * Haddock can generate documentation for some of the language extensions in GHC 6.8.2 * Format of module attributes has changed. The only way of specifiying module attributes is via a new OPTIONS_HADDOCK pragma. Example: {-# OPTIONS_HADDOCK hide, prune #-} * Haddock understands literate source files * Add a small library to read Haddock's interface files * Add a flag -B for passing the path to the GHC lib dir * Add a flag --optghc for passing options to GHC * Add a flag --ghc-version for printing the GHC version * Remove --use-package, --allow-missing-html, --ghc-pkg, in favour of only supporting --read-interface * Remove --package flag, the GHC flag -package-name can be used instead * Remove --no-implicit-prelude flag, the GHC flag -XNoImplicitPrelude can be used instead * Hoogle support temporarily removed It should be noted that this version of Haddock is not compatible with interface files from previous versions. Also, currently, when Haddock comes across a GHC language extension that it doesn't know how to render as HTML, it will bail out. If this happens to you, bug me about it, or help out by sending a patch. On the development side, Haddock has been slightly refactored for easier code navigation, and has the beginnings of a test suite. Haddock also ships with (as noted in the list of changes) a small, experimental library that can be used to read its interface files. Tools and IDE-type applications can use this library to e.g. look up the documentation for identifiers. The code repository is at http://code.haskell.org/haddock. David From tomasz.zielonka at gmail.com Tue Jan 8 09:26:41 2008 From: tomasz.zielonka at gmail.com (Tomasz Zielonka) Date: Tue Jan 8 08:20:23 2008 Subject: [Haskell-cafe] Concurrency questions In-Reply-To: <20080107165902.GA6008@presario> References: <4780BBED.5020907@btinternet.com> <20080107165902.GA6008@presario> Message-ID: <20080108142641.GB13897@lambda> On Mon, Jan 07, 2008 at 10:59:02AM -0600, Spencer Janssen wrote: > On Sun, Jan 06, 2008 at 11:30:53AM +0000, Andrew Coppin wrote: > > Just a couple of things I was wondering about... > > > > 1. Is there some way to assign a "priority" to Haskell threads? (The > > behaviour I'd like is that high priority threads always run first, and low > > priority threads potentially never run at all unless there's an available > > processor which is completely idle.) > > Not in the current system. It is not clear that thread priorities are so nice > anyway (see 'priority inversion' on Wikipedia, for example). I think using STM properly should reduce the risk of priority inversion, as long as you can replace most critical sections with transactions. AFAIU, when there are many transactions sharing some TVars, the transactions that have the biggest chance of being committed are the ones that finish first. It would still be possible for short (cheap computations and few TVar accesses), frequent low-priority transactions to cause frequent rollbacks of a long high-priority transactions, causing a priority inversion. But then, maybe it would be possible to help high-priority to finish - with STM there's much more you can do, like (transparently) rolling back the low-priority transactions. Still, it could be a bit hard to do it properly, without starving low-priority transactions. Best regards Tomasz From ahey at iee.org Tue Jan 8 09:22:17 2008 From: ahey at iee.org (Adrian Hey) Date: Tue Jan 8 09:16:00 2008 Subject: [Haskell-cafe] ANNOUNCE: Haddock version 2.0.0.0 In-Reply-To: References: Message-ID: <47838719.5020809@iee.org> Hello, I've just tried this with cabal > runghc Setup haddock --hyperlink-source --hscolour-css=..\hscolour.css and I get this error.. Setup: haddock --hyperlink-source requires Haddock version 0.8 or later This looks like a bug in cabal rather than the new Haddock to me. Can anyone think of an easy workaround? Regards -- Adrian Hey From david.waern at gmail.com Tue Jan 8 09:48:02 2008 From: david.waern at gmail.com (David Waern) Date: Tue Jan 8 09:41:44 2008 Subject: [Haskell-cafe] ANNOUNCE: Haddock version 2.0.0.0 In-Reply-To: <47838719.5020809@iee.org> References: <47838719.5020809@iee.org> Message-ID: 2008/1/8, Adrian Hey : > Hello, > > I've just tried this with cabal > > > runghc Setup haddock --hyperlink-source --hscolour-css=..\hscolour.css > > and I get this error.. > > Setup: haddock --hyperlink-source requires Haddock version 0.8 or later > > This looks like a bug in cabal rather than the new Haddock to me. > > Can anyone think of an easy workaround? Yes, you could switch to the darcs version of Cabal, where this has been fixed. I don't know if a release containing the fix has been made. David From r.kelsall at millstream.com Tue Jan 8 10:44:38 2008 From: r.kelsall at millstream.com (Richard Kelsall) Date: Tue Jan 8 10:38:18 2008 Subject: [Haskell-cafe] Please allow beginners to vocalize code. >>= :: -> &&& <- -< Message-ID: <47839A66.7080506@millstream.com> A tip for people explaining Haskell to beginners: The acts of reading and speaking are closely integrated in the brain. When I am unable to 'say' something it is much more difficult to 'read' and absorb the text. There appears to be a misconception that it somehow helps beginners to understand things if they are not told how to 'say' these strange new symbols. Certainly for me, and I would guess for most people, this idea is completely wrong. When I 'read' a new operator such as >>= I want know how to 'say' it. I don't mean that posts on Haskell-Cafe should do this, but books and articles aimed at people who haven't used Haskell before should always vocalize the symbols as soon as they are introduced. On a related note, if there isn't already, it would be nice to have a page in the wiki that gives good ways of vocalizing the operators and vocalizing them in simple code snippets. I might get round to doing this sometime, maybe just a table something like this : Operator Formal Informal -------- ------ -------- :: has type -> maps to to example f :: Int -> Int f has type Int to Int Or, to descend into trivia, a subtle distinction might be usefully made between = and == f i = 54 * i f i is 54 times i x == 27 x equals 27 Richard. From lemming at henning-thielemann.de Tue Jan 8 11:12:16 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Tue Jan 8 11:05:57 2008 Subject: [Haskell-cafe] Please allow beginners to vocalize code. >>= :: -> &&& <- -< In-Reply-To: <47839A66.7080506@millstream.com> References: <47839A66.7080506@millstream.com> Message-ID: On Tue, 8 Jan 2008, Richard Kelsall wrote: > A tip for people explaining Haskell to beginners: > > The acts of reading and speaking are closely integrated in the brain. > When I am unable to 'say' something it is much more difficult to 'read' > and absorb the text. There appears to be a misconception that it somehow > helps beginners to understand things if they are not told how to 'say' > these strange new symbols. Certainly for me, and I would guess for most > people, this idea is completely wrong. When I 'read' a new operator > such as >>= I want know how to 'say' it. '>>=' is spoken "bind" > I don't mean that posts on Haskell-Cafe should do this, but books > and articles aimed at people who haven't used Haskell before should > always vocalize the symbols as soon as they are introduced. > > On a related note, if there isn't already, it would be nice to have a > page in the wiki that gives good ways of vocalizing the operators and > vocalizing them in simple code snippets. I might get round to doing > this sometime, maybe just a table something like this : Got idea, please go ahead! I suggest categories "Style" or "Syntax". > Operator Formal Informal > -------- ------ -------- > :: has type > -> maps to to > example > f :: Int -> Int f has type Int to Int Is a symbol-by-symbol translation sensible? What about "f maps from Int to Int", "plus maps Int to a function, which maps Int to Int" From r.kelsall at millstream.com Tue Jan 8 12:14:39 2008 From: r.kelsall at millstream.com (Richard Kelsall) Date: Tue Jan 8 12:08:19 2008 Subject: [Haskell-cafe] Please allow beginners to vocalize code. >>= :: -> &&& <- -< In-Reply-To: References: <47839A66.7080506@millstream.com> Message-ID: <4783AF7F.1080308@millstream.com> Henning Thielemann wrote: > On Tue, 8 Jan 2008, Richard Kelsall wrote: ... > '>>=' is spoken "bind" > ... >> On a related note, if there isn't already, it would be nice to have a >> page in the wiki that gives good ways of vocalizing the operators and >> vocalizing them in simple code snippets. I might get round to doing >> this sometime, maybe just a table something like this : > > Got idea, please go ahead! I suggest categories "Style" or "Syntax". > > >> Operator Formal Informal >> -------- ------ -------- >> :: has type >> -> maps to to >> example >> f :: Int -> Int f has type Int to Int > > Is a symbol-by-symbol translation sensible? What about "f maps from Int to > Int", "plus maps Int to a function, which maps Int to Int" > Thank you. I've put a primitive page up here http://haskell.org/haskellwiki/Pronunciation under category syntax. Obviously it needs more work, but maybe it will act as a bit of grit in the oyster. Richard. From derek.a.elkins at gmail.com Tue Jan 8 11:43:57 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Tue Jan 8 13:02:51 2008 Subject: [Haskell-cafe] Re: Compiler backend question In-Reply-To: <47835181.6000404@telenet.be> References: <477A1CF9.90001@telenet.be> <20080107195142.GA27708@momenergy.repetae.net> <000101c8516b$b2146250$163d26f0$@be> <200801072026.34449.jon@ffconsultancy.com> <47835181.6000404@telenet.be> Message-ID: <1199810637.17810.1.camel@derek-laptop> On Tue, 2008-01-08 at 11:33 +0100, Peter Verswyvelen wrote: > Jon Harrop wrote: > > On Monday 07 January 2008 20:27:17 Peter Verswyvelen wrote: > > > >> If your compiler (pretty amazing job btw) does whole program optimization, > >> can it remove the dictionary (aka v-table in C/C++ parlance?) overhead of > >> type classes? Because if I understand it correctly, unless one uses > >> existential types, a dictionary can be compiled away since the type in > >> question is known at compile time? > >> > > > > Yes. This is essentially what F# does. > > > Hang on. > > When I asked a similar question in the F# forum, it seemed that F# > simply does not have type classes (but it does support .NET interfaces), > and root functions are only fully polymorphic when you mark them *inline*. > > For example, the following will not work in the current version of F#: > > **let add x y = x + y > let t1 = add 1 2 > let t2 = add 1.0 2.0** > > The first usage of add forces it to work on integers, and then its type > is settled once and for all. If I understood it correctly, this is > because the "root polymorphic" add function can only work on specific > types because it gets compiled into an object file. > > You can force it to work on any type on which + can be applied by > forcing the function to be inline, like > > let inline add x y = x+y > let t1 = add 1 2 > let t2 = add 1.0 2.0 > > Then I guess the code will not be part of the object file, but it will > be inserted inplace whenever it gets used (which could result in code > bloat?) > > Can the same trick be used in GHC? > > Regarding Derek Elkins excellent example > > f :: Show a => Int -> a -> String -- type signature required > f 0 x = show x > f n x = f (n-1) (x,x) > > this indeed cannot be inlined nor optimized away, since you generally > don't know the value of the first parameter at runtime. But this is a > very specific case no? According to what I interpret from John Meacham's > email, this case is an exception, and in many cases class type > dictionary overhead gets compiled away? Quoting my previous email with added emphasis, "Even in Haskell 98 it is not quite possible to do this. <>, but the type is not always known at compile-time. There is one situation where the types depend on values. This occurs when you utilize polymorphic recursion." The point of my email was that it is not possible to -completely- eliminate dictionaries (or some other run-time witness) in general. From derek.a.elkins at gmail.com Tue Jan 8 12:08:45 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Tue Jan 8 13:03:02 2008 Subject: [Haskell-cafe] Please allow beginners to vocalize code. >>= :: -> &&& <- -< In-Reply-To: <4783AF7F.1080308@millstream.com> References: <47839A66.7080506@millstream.com> <4783AF7F.1080308@millstream.com> Message-ID: <1199812125.17810.17.camel@derek-laptop> On Tue, 2008-01-08 at 17:14 +0000, Richard Kelsall wrote: > Henning Thielemann wrote: > > On Tue, 8 Jan 2008, Richard Kelsall wrote: > ... > > '>>=' is spoken "bind" > > > ... > >> On a related note, if there isn't already, it would be nice to have a > >> page in the wiki that gives good ways of vocalizing the operators and > >> vocalizing them in simple code snippets. I might get round to doing > >> this sometime, maybe just a table something like this : > > > > Got idea, please go ahead! I suggest categories "Style" or "Syntax". > > > > > >> Operator Formal Informal > >> -------- ------ -------- > >> :: has type > >> -> maps to to > >> example > >> f :: Int -> Int f has type Int to Int > > > > Is a symbol-by-symbol translation sensible? What about "f maps from Int to > > Int", "plus maps Int to a function, which maps Int to Int" > > > > Thank you. I've put a primitive page up here > > http://haskell.org/haskellwiki/Pronunciation > > under category syntax. Obviously it needs more work, but maybe it > will act as a bit of grit in the oyster. I don't why you think, "[t]here [is] a misconception that it somehow helps beginners to understand things if they are not told how to 'say' these strange new symbols." If you had said, "it doesn't help beginners to be told how to 'say' these symbols", I would have less of an issue. I don't think anyone thinks that it is helpful not to provide a reading, and in my experience, a reading is usually provided, directly or indirectly, when such things are introduced in (larger) introductions/tutorials/textbooks. However, as you've already found, some things don't seem to have meaningful readings. E.g. you list -< in the title, but the motivation of that notation has nothing to do with it having a clear "reading", but rather comes from a graphical perspective, x <- f -< y I.e. that looks like an arrow pointing left with -< the tail. That said, two readings are indirectly provided in http://www.haskell.org/arrows/sugar.html From dons at galois.com Tue Jan 8 14:28:46 2008 From: dons at galois.com (Don Stewart) Date: Tue Jan 8 14:22:27 2008 Subject: [Haskell-cafe] Re: Is there anyone out there who can translate C# generics into Haskell? In-Reply-To: <47835C6F.30900@jellybean.co.uk> References: <915864007.20080103135418@gmail.com> <8627368.20080103173843@gmail.com> <1762133336.20080103215834@gmail.com> <83DE9074-6529-4B54-B2A5-D3285DC699B0@fastmail.fm> <20080106111309.3f0bc240@solaris.tower> <47835C6F.30900@jellybean.co.uk> Message-ID: <20080108192846.GA24905@scytale.galois.com> jules: > Achim Schneider wrote: > >things like > > > > > >data State = State > > { winSize :: IORef Size > > , t :: IORef Int > > , fps :: IORef Float > > , showFPS :: IORef Bool > > , showHelp :: IORef Bool > > , grabMouse :: IORef Bool > > , mousePos :: IORef (Maybe Position) > > , mouseDelta :: IORef Position > > , viewRot :: IORef Vec3 > > , angle' :: IORef GLfloat > > , ballPos :: IORef Vec2 > > , ballVel :: IORef Vec2 > > } > > > Yuck! > > I'm not sure whether this is a real example or not, but if it's real, > get rid of all those IORefs. Make State a simple type, and use (IORef > State) as needed for callbacks, and hide that fact in other code. I agree, this is very-unHaskelly :) The State type should be a simple purely functional structured, threaded through your code via a StateT or some such. Not a bunch of pointers in IO. See xmonad for examples of this in highly effectful programs, http://code.haskell.org/xmonad/XMonad/Core.hs newtype X a = X (ReaderT XConf (StateT XState IO) a) (Carries read-only and updatable state components) -- Don From felipe.lessa at gmail.com Tue Jan 8 15:09:05 2008 From: felipe.lessa at gmail.com (Felipe Lessa) Date: Tue Jan 8 15:02:47 2008 Subject: [Haskell-cafe] Re: [Haskell] ANNOUNCE: Haddock version 2.0.0.0 In-Reply-To: References: Message-ID: On Jan 8, 2008 10:28 AM, David Waern wrote: > * Haddock now understands all syntax understood by GHC 6.8.2 Does Haddock still define __HADDOCK__? There's a lot of code that uses this flag just to hide something Haddock didn't know. -- Felipe. From barsoap at web.de Tue Jan 8 15:10:59 2008 From: barsoap at web.de (Achim Schneider) Date: Tue Jan 8 15:04:48 2008 Subject: [Haskell-cafe] Re: Is there anyone out there who can translate C# generics into Haskell? References: <915864007.20080103135418@gmail.com> <8627368.20080103173843@gmail.com> <1762133336.20080103215834@gmail.com> <83DE9074-6529-4B54-B2A5-D3285DC699B0@fastmail.fm> <20080106111309.3f0bc240@solaris.tower> <47835C6F.30900@jellybean.co.uk> <20080108192846.GA24905@scytale.galois.com> Message-ID: <20080108211059.5602ab46@solaris.tower> Don Stewart wrote: > jules: > > Achim Schneider wrote: > > >things like > > > > > > > > >data State = State > > > { winSize :: IORef Size > > > , t :: IORef Int > > > , fps :: IORef Float > > > , showFPS :: IORef Bool > > > , showHelp :: IORef Bool > > > , grabMouse :: IORef Bool > > > , mousePos :: IORef (Maybe Position) > > > , mouseDelta :: IORef Position > > > , viewRot :: IORef Vec3 > > > , angle' :: IORef GLfloat > > > , ballPos :: IORef Vec2 > > > , ballVel :: IORef Vec2 > > > } > > > > > > Yuck! > > > > I'm not sure whether this is a real example or not, but if it's > > real, get rid of all those IORefs. Make State a simple type, and > > use (IORef State) as needed for callbacks, and hide that fact in > > other code. > > I agree, this is very-unHaskelly :) > > The State type should be a simple purely functional structured, > threaded through your code via a StateT or some such. Not a bunch of > pointers in IO. > > See xmonad for examples of this in highly effectful programs, > > http://code.haskell.org/xmonad/XMonad/Core.hs > > newtype X a = X (ReaderT XConf (StateT XState IO) a) > > (Carries read-only and updatable state components) > Yes, you see, that was my first Haskell program bigger than 20 lines, there's no possibility to get the state out of the IO Monad, at least without writing a high-level interface to glut and gl, and then there's this thing that _every_ game works with input callbacks, one, global, state update function (where it doesn't _really_ matter whether you're passing and returning a state or updating a state) and one function that translates the state into some graphics representation. That said, I think it's not very Haskell-like to do something elegantly in 1000 lines when you can do it in 100 lines and still have it look nicer than C. If the update function of this particular one ever gets more complicated than idle :: State -> IdleCallback idle state = do t0 <- get $ t state t1 <- get elapsedTime t state $= t1 let td = fromIntegral t1 - fromIntegral t0 fps state $= 1/td * 1000 (bpx, bpy) <- get $ ballPos state (bvx, bvy) <- get $ ballVel state ballPos state $= (bpx + bvx*td, bpy + bvy*td) postRedisplay Nothing , I'll think of something. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From agl at imperialviolet.org Tue Jan 8 15:26:25 2008 From: agl at imperialviolet.org (Adam Langley) Date: Tue Jan 8 15:20:05 2008 Subject: [Haskell-cafe] ANN: A triple of new packages for talking to the outside world In-Reply-To: <47827AB4.60608@serpentine.com> References: <396556a20801061554o3895ce88k87d4ecabc1860e7b@mail.gmail.com> <4781B50A.2060007@serpentine.com> <396556a20801071037t1b66e444u52abe1d934b7f902@mail.gmail.com> <47827AB4.60608@serpentine.com> Message-ID: <396556a20801081226l5ebf5062p685a80c6aac6ba41@mail.gmail.com> On Jan 7, 2008 11:17 AM, Bryan O'Sullivan wrote: > > It would seem that there would be three possible outcomes from an > > incremental Get: > > - Failure: some bitstreams are just invalid and no amount of extra > > data will ever fix that > > - Complete [Result]: the last chunk of data has been processed. > > Maybe this should also include the remainder of the data? > > - Partial Cont [Result]: needs more data, but here's a (possibly > > empty) list of results so far. > > Yes, that's more or less exactly what I had in mind. Ok, see http://www.imperialviolet.org/IncrementalGet.hs Hot off the keyboard and lacking documentation and comments ;) There's a small test function at the bottom which demonstrates an infinite parser which extracts 16-bit ints from whatever you feed it. Questions: 1) Should Finished include the remainder of the ByteString (e.g. that which wasn't used by that parser) 2) I've no idea what I've done to the parse speed 3) I removed all the lookahead functions because, if the look ahead runs out of data it's not clean what should be done. We can request more with a partial result, but if the user doesn't have any more data to give there's no way, currently, to signal this and cause the lookahead to backtrack. Also, if we let the lookahead request more data via a Partial, then there's no way for the user to tell that Partial apart from one which has "real" values. But if this is useful to you, make any requests. I'll (hopefully) do them, clean it up and push a new release of binary-strict. AGL -- Adam Langley agl@imperialviolet.org http://www.imperialviolet.org 650-283-9641 From r.kelsall at millstream.com Tue Jan 8 15:36:52 2008 From: r.kelsall at millstream.com (Richard Kelsall) Date: Tue Jan 8 15:30:34 2008 Subject: [Haskell-cafe] Please allow beginners to vocalize code. >>= :: -> &&& <- -< In-Reply-To: <1199812125.17810.17.camel@derek-laptop> References: <47839A66.7080506@millstream.com> <4783AF7F.1080308@millstream.com> <1199812125.17810.17.camel@derek-laptop> Message-ID: <4783DEE4.8010203@millstream.com> Derek Elkins wrote: > I don't why you think, "[t]here [is] a misconception that it somehow > helps beginners to understand things if they are not told how to 'say' > these strange new symbols." If you had said, "it doesn't help beginners > to be told how to 'say' these symbols", I would have less of an issue. Sorry, I got a bit convoluted there. I suppose what I'm trying to say is that I struggle when I am not given direct words to attach to symbols. A word for the symbol allows me to read the program. Imagine two experienced Haskell programmers on the phone, one reading a Haskell program snippet to the other. For example Hutton first uses the => symbol on p.7 "In Haskell, every function has a type that specifies the nature of its arguments and results, which is automatically inferred from the definition of the function. For example, the function sum has the following type: Num a => [a] -> a This type states that for any type a of numbers, sum is a function that maps a list of such numbers to a single such number." This is a good description, but doesn't seem a likely way for an experienced programmer to read that statement over the phone to somebody else. I am guessing things like "For all Num a, list of a to a." "Num a implies, list of a to a." In appendix B at the back of the book I find the 'meaning' of => is 'class constraint', but again this doesn't seem a likely way of 'saying' it. Now supposing you were on the phone to a Haskell programmer and you wanted to say this f :: Int -> Int I imagine you might say "f maps Int to Int" or "function f has type Int to Int". Both symbols have been translated directly to words. Nobody would say "f, colon colon, Int, dash greater than, Int". > I don't think anyone thinks that it is helpful not to provide a reading, > and in my experience, a reading is usually provided, directly or > indirectly, when such things are introduced in (larger) > introductions/tutorials/textbooks. However, as you've already found, > some things don't seem to have meaningful readings. E.g. you list -< in > the title, but the motivation of that notation has nothing to do with it > having a clear "reading", but rather comes from a graphical perspective, > x <- f -< y > I.e. that looks like an arrow pointing left with -< the tail. That > said, two readings are indirectly provided in > http://www.haskell.org/arrows/sugar.html > From g9ks157k at acme.softbase.org Tue Jan 8 15:40:11 2008 From: g9ks157k at acme.softbase.org (Wolfgang Jeltsch) Date: Tue Jan 8 15:34:19 2008 Subject: [Haskell-cafe] Re: US Homeland Security program language security risks In-Reply-To: <7E10AC09-9888-4F92-996D-E3B45810D86C@yandex.ru> References: <5ae4f2ba0801031336x45b4c14dw34771cbc9ef0d3f4@mail.gmail.com> <20080106155400.7b733dd8@solaris.tower> <7E10AC09-9888-4F92-996D-E3B45810D86C@yandex.ru> Message-ID: <200801082140.12190.g9ks157k@acme.softbase.org> Am Sonntag, 6. Januar 2008 20:04 schrieb Miguel Mitrofanov: > > That's an interesting task: Design a non-touring complete, > > restricted language in which every expression is decidable, without > > making the language unusable for usual programming problems. > > Well, I did something like that a few years ago - it was a sort of > assembler language, allowing the programmer to, say, sort an array, > but not to calculate Akkerman function. Epigram even allows you Ackermann?s function. Best wishes, Wolfgang From frr149 at easyjob.net Tue Jan 8 16:36:38 2008 From: frr149 at easyjob.net (Fernando Rodriguez) Date: Tue Jan 8 16:30:24 2008 Subject: [Haskell-cafe] Newbie question: the need for parentheses Message-ID: Hi, I have this function that sums up a list of numbers: suma [] = 0 suma (h:t) = h + suma t However, why do I need the parenthes in the second clause? What does the compiler think I'm trying to do when I type suma [] = 0 suma h:t = h + suma t Thanks! :-) From johan.tibell at gmail.com Tue Jan 8 16:37:25 2008 From: johan.tibell at gmail.com (Johan Tibell) Date: Tue Jan 8 16:31:02 2008 Subject: [Haskell-cafe] Haskell-mode 2.4 In-Reply-To: References: Message-ID: <90889fe70801081337q5521f3e5yd49a2435d2d96ed2@mail.gmail.com> On Dec 12, 2007 5:40 AM, Stefan Monnier wrote: > * inf-haskell.el tries to find the root of the module hierarchy to determine > the root of a project (either by looking for a Cabal file or relying on > the `module' declaration line). If all works well, this will make C-c C-l > automatically switch to the root dir, so that dependencies in other > directories are automatically found. If it doesn't, complain and/or set > inferior-haskell-find-project-root to nil. First of all, thanks. My Aqua Emacs (on OS X Leopard) hangs when I send a command like C-c C-l or C-c C-t to the interpreter (I can quit the command using C-g) . Starting the interpreter and using :l from inside it works fine. This is using GHC 6.8 (and I think I also tried 6.6.) What could be the problem? I also tried to eval this but it didn't make a difference: (setq inferior-haskell-find-project-root nil) -- Johan From g9ks157k at acme.softbase.org Tue Jan 8 16:41:41 2008 From: g9ks157k at acme.softbase.org (Wolfgang Jeltsch) Date: Tue Jan 8 16:35:23 2008 Subject: [Haskell-cafe] Please allow beginners to vocalize code. >>= :: ->=?utf-8?q?=09=26=26=26?= <- -< In-Reply-To: <4783DEE4.8010203@millstream.com> References: <47839A66.7080506@millstream.com> <1199812125.17810.17.camel@derek-laptop> <4783DEE4.8010203@millstream.com> Message-ID: <200801082241.41810.g9ks157k@acme.softbase.org> Am Dienstag, 8. Januar 2008 21:36 schrieb Richard Kelsall: > Now supposing you were on the phone to a Haskell programmer and you > wanted to say this > > f :: Int -> Int > > I imagine you might say "f maps Int to Int" or "function f has type > Int to Int". Both symbols have been translated directly to words. Nobody > would say "f, colon colon, Int, dash greater than, Int". I would say: ?f double-colon Int arrow Int?. Best wishes, Wolfgang From ndmitchell at gmail.com Tue Jan 8 16:43:36 2008 From: ndmitchell at gmail.com (Neil Mitchell) Date: Tue Jan 8 16:37:14 2008 Subject: [Haskell-cafe] Newbie question: the need for parentheses In-Reply-To: References: Message-ID: <404396ef0801081343g597fd11cs5f1bd7d53995852a@mail.gmail.com> Hi > suma [] = 0 > suma (h:t) = h + suma t > > suma [] = 0 > suma h:t = h + suma t Infix operators bind less tightly than function application, so the compiler sees: (suma h) : t = h + (suma t) Hence the compiler gets confused. Thanks Neil From jules at jellybean.co.uk Tue Jan 8 16:48:01 2008 From: jules at jellybean.co.uk (Jules Bean) Date: Tue Jan 8 16:41:41 2008 Subject: [Haskell-cafe] Newbie question: the need for parentheses In-Reply-To: References: Message-ID: <4783EF91.5030807@jellybean.co.uk> Fernando Rodriguez wrote: > > Hi, > > I have this function that sums up a list of numbers: > > suma [] = 0 > suma (h:t) = h + suma t > > However, why do I need the parenthes in the second clause? What does the > compiler think I'm trying to do when I type > suma [] = 0 > suma h:t = h + suma t Definitions are parsed in very much the same way as expressions. In principle they don't need to be, but it makes the language more uniform if they are. If you wrote "suma h:t" as an expression, it would mean "(suma h) : t", because function application "binds tighter" than any infix operator. So, as a definition: suma h : t = h + suma t looks to the compiler like an attempt to redefine the operator ':', except that the left parameter is "suma h", which looks like a function application, and that's not allowed in a definition. [it also doesn't make sense because ':' is actually a constructor not any old operator. But that turns out not to be the key problem here] Note that you can define operators directly infix, e.g.: a * b = multiply a b ...and if I try to do that with something like 'suma' on the left... suma a * b = multiply a b ...I get the same error (parse error in pattern, in GHC). Hope that helps, Jules From frr149 at easyjob.net Tue Jan 8 16:48:37 2008 From: frr149 at easyjob.net (Fernando Rodriguez) Date: Tue Jan 8 16:42:30 2008 Subject: [Haskell-cafe] Displaying # of reductions after each computation in ghci? Message-ID: Hi, Is there a way to configure ghci to display the number of reuctions after each compution (as in winhugs)? Thanks! From miguelimo38 at yandex.ru Tue Jan 8 16:51:45 2008 From: miguelimo38 at yandex.ru (Miguel Mitrofanov) Date: Tue Jan 8 16:45:38 2008 Subject: [Haskell-cafe] Newbie question: the need for parentheses In-Reply-To: References: Message-ID: <0244714F-A905-43D0-A0D3-991844D3B0FE@yandex.ru> > However, why do I need the parenthes in the second clause? What > does the compiler think I'm trying to do when I type > suma [] = 0 > suma h:t = h + suma t (suma h):t = h + suma t From i.normann at iu-bremen.de Tue Jan 8 17:02:32 2008 From: i.normann at iu-bremen.de (inormann) Date: Tue Jan 8 16:56:10 2008 Subject: [Haskell-cafe] Cabal and DB packages In-Reply-To: References: Message-ID: <14700088.post@talk.nabble.com> This is how I successfully installed haskelldb-0.10 package with ghc-6.8.2 today: Assuming you have downloaded and unpacked haskelldb-0.10 from http://hackage.haskell.org/packages/archive/haskelldb/0.10/haskelldb-0.10.tar.gz you need to append in haskelldb-0.10/haskelldb.cabal pretty, old-time, directory, old-locale in line build-depends: haskell98, base, mtl and -fglasgow-exts in line ghc-options: -O2 with that it should work: runghc Setup.hs configure runghc Setup.hs build runghc Setup.hs install manu-30 wrote: > > Hello, > > I'm trying to do something that should be fairly simple, installing > some DB package so I can use MySQL or SQLite. > > However I've had troubles building HSQL, HaskellDB and Takusen before > giving up (I am using ghc 6.8.1 and Cabal-1.2.2.0). > > ------------------ > > with HSQL : > > Database/HSQL.hsc:66:7: > Could not find module `System.Time': > it is a member of package old-time-1.0.0.0, which is hidden > > so I added 'old-time' to the 'build-depends' line in the .cabal file > > but then it fails building with > > Building hsql-1.7... > [1 of 2] Compiling Database.HSQL.Types ( Database/HSQL/Types.hs, dist/ > build/Database/HSQL/Types.o ) > > Database/HSQL/Types.hs:134:18: Not in scope: type variable `forall' > > Database/HSQL/Types.hs:134:25: Not in scope: type variable `a' > > Database/HSQL/Types.hs:134:27: > Illegal operator `.' in type `forall a . (Int > -> FieldDef > -> (FieldDef -> > CString -> Int -> IO a) -> IO a)' > (Use -XTypeOperators to allow operators in types) > > etc... > > At this point, it goes over my head... > > --------------- > > What the hell, I'll use HaskellDB and FlatDB, but then I get this > message while building HaskellDB : > > src/Database/HaskellDB/HDBRec.hs:106:11: > Illegal signature in pattern: l f a > Use -XPatternSignatures to permit it > > when I add 'PatternSignatures' to the 'Extensions:' line in .cabal, > it fails configuring with : > > Setup.hs: haskelldb.cabal:8: Parse of field 'extensions' failed: > > Jeeeesus, nevermind, I'll try Takusen > > --------------- > > with Takusen : > > $ runhaskell Setup.hs configure > > Setup.hs:26:7: > Could not find module `Distribution.Program': > Use -v to see a list of the files searched for. > > I give up... > > ---------------- > > Is there any simple way to do it though ? Is there any problems with > Cabal that I need to work around ? > > Help !! > > Manu > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > -- View this message in context: http://www.nabble.com/Cabal-and-DB-packages-tp13937927p14700088.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. From stefanor at cox.net Tue Jan 8 17:11:56 2008 From: stefanor at cox.net (Stefan O'Rear) Date: Tue Jan 8 17:05:38 2008 Subject: [Haskell-cafe] Displaying # of reductions after each computation in ghci? In-Reply-To: References: Message-ID: <20080108221155.GA3393@localhost.localdomain> On Tue, Jan 08, 2008 at 09:48:37PM +0000, Fernando Rodriguez wrote: > Is there a way to configure ghci to display the number of reuctions after > each compution (as in winhugs)? No. (rambling explanation snipped awaiting further request) Stefan -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080108/fb8f0de8/attachment.bin From dons at galois.com Tue Jan 8 17:13:09 2008 From: dons at galois.com (Don Stewart) Date: Tue Jan 8 17:07:03 2008 Subject: [Haskell-cafe] Displaying # of reductions after each computation in ghci? In-Reply-To: <20080108221155.GA3393@localhost.localdomain> References: <20080108221155.GA3393@localhost.localdomain> Message-ID: <20080108221309.GB25479@scytale.galois.com> stefanor: > On Tue, Jan 08, 2008 at 09:48:37PM +0000, Fernando Rodriguez wrote: > > Is there a way to configure ghci to display the number of reuctions after > > each compution (as in winhugs)? > > No. Kind of, since you probably just want stats, not some notion of reductions: Prelude> :set +s Prelude> last [1..1000000] 1000000 (0.05 secs, 87390328 bytes) -- Don From frr149 at easyjob.net Tue Jan 8 17:25:19 2008 From: frr149 at easyjob.net (Fernando Rodriguez) Date: Tue Jan 8 17:19:09 2008 Subject: [Haskell-cafe] Currying and Partial Evaluation Message-ID: Hi, Is currying in Haskell the same thing as Partial Evaluation (http://en.wikipedia.org/wiki/Partial_evaluation)? Am I getting partial evaluation for free just by using Haskell? Thanks! From stefanor at cox.net Tue Jan 8 17:27:45 2008 From: stefanor at cox.net (Stefan O'Rear) Date: Tue Jan 8 17:21:25 2008 Subject: [Haskell-cafe] Re: Is there anyone out there who can translate C# generics into Haskell? In-Reply-To: <20080108211059.5602ab46@solaris.tower> References: <8627368.20080103173843@gmail.com> <1762133336.20080103215834@gmail.com> <83DE9074-6529-4B54-B2A5-D3285DC699B0@fastmail.fm> <20080106111309.3f0bc240@solaris.tower> <47835C6F.30900@jellybean.co.uk> <20080108192846.GA24905@scytale.galois.com> <20080108211059.5602ab46@solaris.tower> Message-ID: <20080108222745.GB3393@localhost.localdomain> On Tue, Jan 08, 2008 at 09:10:59PM +0100, Achim Schneider wrote: > Don Stewart wrote: > > > jules: > > > Achim Schneider wrote: > > > >things like > > > > > > > > > > > >data State = State > > > > { winSize :: IORef Size > > > > , t :: IORef Int > > > > , fps :: IORef Float > > > > , showFPS :: IORef Bool > > > > , showHelp :: IORef Bool > > > > , grabMouse :: IORef Bool > > > > , mousePos :: IORef (Maybe Position) > > > > , mouseDelta :: IORef Position > > > > , viewRot :: IORef Vec3 > > > > , angle' :: IORef GLfloat > > > > , ballPos :: IORef Vec2 > > > > , ballVel :: IORef Vec2 > > > > } > > > > > > > > > Yuck! > > > > > > I'm not sure whether this is a real example or not, but if it's > > > real, get rid of all those IORefs. Make State a simple type, and > > > use (IORef State) as needed for callbacks, and hide that fact in > > > other code. > > > > I agree, this is very-unHaskelly :) > > > > The State type should be a simple purely functional structured, > > threaded through your code via a StateT or some such. Not a bunch of > > pointers in IO. > > > > See xmonad for examples of this in highly effectful programs, > > > > http://code.haskell.org/xmonad/XMonad/Core.hs > > > > newtype X a = X (ReaderT XConf (StateT XState IO) a) > > > > (Carries read-only and updatable state components) > > > Yes, you see, that was my first Haskell program bigger than 20 lines, > there's no possibility to get the state out of the IO Monad, at least > without writing a high-level interface to glut and gl, and then there's > this thing that _every_ game works with input callbacks, one, global, > state update function (where it doesn't _really_ matter whether you're > passing and returning a state or updating a state) and one function > that translates the state into some graphics representation. > > That said, I think it's not very Haskell-like to do something elegantly > in 1000 lines when you can do it in 100 lines and still have it look > nicer than C. I would use IORef State. Making illegal states unrepresentable greatly helps with code prettiness; the original State allowed internal aliasing, which is quite definitely silly. I think this should be written somewhere as a general rule - when you have a mutable structure, use a reference to a record, not a record of references. Stefan -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080108/6ba5bfc6/attachment.bin From isaacdupree at charter.net Tue Jan 8 17:36:37 2008 From: isaacdupree at charter.net (Isaac Dupree) Date: Tue Jan 8 17:30:10 2008 Subject: [Haskell-cafe] Please allow beginners to vocalize code. >>= :: -> &&& <- -< In-Reply-To: <200801082241.41810.g9ks157k@acme.softbase.org> References: <47839A66.7080506@millstream.com> <1199812125.17810.17.camel@derek-laptop> <4783DEE4.8010203@millstream.com> <200801082241.41810.g9ks157k@acme.softbase.org> Message-ID: <4783FAF5.6090802@charter.net> Wolfgang Jeltsch wrote: > Am Dienstag, 8. Januar 2008 21:36 schrieb Richard Kelsall: >> Now supposing you were on the phone to a Haskell programmer and you >> wanted to say this >> >> f :: Int -> Int >> >> I imagine you might say "f maps Int to Int" or "function f has type >> Int to Int". Both symbols have been translated directly to words. Nobody >> would say "f, colon colon, Int, dash greater than, Int". > > I would say: ?f double-colon Int arrow Int?. and so we could have several columns, for exmple: symbol symbol-pronunciation meaningful-pronunc. definition-term -> arrow to function (except that it's used in lots of different places in syntax... function type, lambda, case at least) ~Isaac From frr149 at easyjob.net Tue Jan 8 17:48:14 2008 From: frr149 at easyjob.net (Fernando Rodriguez) Date: Tue Jan 8 17:42:06 2008 Subject: [Haskell-cafe] Re: Displaying # of reductions after eachcomputation in ghci? References: <20080108221155.GA3393@localhost.localdomain> Message-ID: Hello Stefan O'Rear, >> > No. > > (rambling explanation snipped awaiting further request) > > Stefan OK, I'll take the bait: why not? From ndmitchell at gmail.com Tue Jan 8 18:31:46 2008 From: ndmitchell at gmail.com (Neil Mitchell) Date: Tue Jan 8 18:25:26 2008 Subject: [Haskell-cafe] Currying and Partial Evaluation In-Reply-To: References: Message-ID: <404396ef0801081531i1c3bf1c7s12ce4aef9aab5ed2@mail.gmail.com> Hi > Is currying in Haskell the same thing as Partial Evaluation (http://en.wikipedia.org/wiki/Partial_evaluation)? No. See http://haskell.org/haskellwiki/Currying > Am I getting partial evaluation for free just by using Haskell? No. You can arrange certain things so you get some benefits, but thats a more advanced topic. Thanks Neil From barsoap at web.de Tue Jan 8 18:38:42 2008 From: barsoap at web.de (Achim Schneider) Date: Tue Jan 8 18:32:28 2008 Subject: [Haskell-cafe] Re: Is there anyone out there who can translate C# generics into Haskell? References: <8627368.20080103173843@gmail.com> <1762133336.20080103215834@gmail.com> <83DE9074-6529-4B54-B2A5-D3285DC699B0@fastmail.fm> <20080106111309.3f0bc240@solaris.tower> <47835C6F.30900@jellybean.co.uk> <20080108192846.GA24905@scytale.galois.com> <20080108211059.5602ab46@solaris.tower> <20080108222745.GB3393@localhost.localdomain> Message-ID: <20080109003842.4f23606f@solaris.tower> Stefan O'Rear wrote: > On Tue, Jan 08, 2008 at 09:10:59PM +0100, Achim Schneider wrote: > > That said, I think it's not very Haskell-like to do something > > elegantly in 1000 lines when you can do it in 100 lines and still > > have it look nicer than C. > > I would use IORef State. Making illegal states unrepresentable > greatly helps with code prettiness; the original State allowed > internal aliasing, which is quite definitely silly. > > I think this should be written somewhere as a general rule - when you > have a mutable structure, use a reference to a record, not a record of > references. > So it would be, instead of ---$<--- idle :: State -> IdleCallback idle state = do (bpx, bpy) <- get $ ballPos state (bvx, bvy) <- get $ ballVel state ballPos state $= (bpx + bvx*td, bpy + bvy*td) ---$<--- type StateRef = IORef State' idle' :: StateRef -> IdleCallback idle' st = do state <- get st let (bpx, bpy) = ballPos' state (bvx, bvy) = ballVel' state st $= state {ballPos' = (bpx+bvx, bpy+bvy)} ---$<--- or, while I'm at it ---$<--- moveBall :: State' -> State' moveBall state = state {ballPos' = (bpx+bvx, bpy+bvy)} where (bpx, bpy) = ballPos' state (bvx, bvy) = ballVel' state idle'' :: StateRef -> IdleCallback idle'' st = st $~ moveBall ---$<--- With the multiple IORef-Model, moveBall looks like this: moveBall :: Vec2 -> Vec2 -> Vec2 moveBall (bpx, bpy) (bvx,bvy) = (bpx+bvx, bpy+bvy) which is IMHO pure Haskell. On the other hand, with the one IORef-Model, the draw function could not possibly mangle any state, which would be a good thing, doing such things can result in keyboards being smashed over heads by team colleagues. I'll think about it and then let you know how to properly tackle the awkward GLpong squad. Generally, in game programming you can have so many state-related bugs that it's infeasible to detect them all statically. You also cheat much, doing stage magic instead of the real stuff, and trading off things all the time. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From barsoap at web.de Tue Jan 8 18:51:55 2008 From: barsoap at web.de (Achim Schneider) Date: Tue Jan 8 18:45:42 2008 Subject: [Haskell-cafe] Re: Currying and Partial Evaluation References: Message-ID: <20080109005155.26c6c1e0@solaris.tower> Fernando Rodriguez wrote: > > Hi, > > Is currying in Haskell the same thing as Partial Evaluation > (http://en.wikipedia.org/wiki/Partial_evaluation)? Am I getting > partial evaluation for free just by using Haskell? > No, currying is this: Prelude> let f x y = 1 + x * ( y - 3 ) Prelude> let g = f 1 Prelude> let h = f 2 Prelude> g 1 -1 Prelude> g 2 0 Prelude> h 1 -3 Prelude> h 2 -1 or, a bit more confusing and possibly enlightening, Prelude> let y f = f $ y f Prelude> :t y y :: (b -> b) -> b Prelude> let fixpoint f n = if n <= 1 then 1 else n * (f $ n - 1) Prelude> :t fixpoint fixpoint :: (Num b, Ord b) => (b -> b) -> b -> b Prelude> let fac = y fixpoint Prelude> :t fac fac :: Integer -> Integer Prelude> fac 10 3628800 Prelude> fac 100 9332621544394415268169923885626670049071596826438162146859296389521759999 3229915608941463976156518286253697920827223758251185210916864000000000000 000000000000 Note that "fixpoint 3" won't work, and that's good. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From barsoap at web.de Tue Jan 8 18:59:22 2008 From: barsoap at web.de (Achim Schneider) Date: Tue Jan 8 18:53:09 2008 Subject: [Haskell-cafe] Type System (Was: Currying and Partial Evaluation) References: <20080109005155.26c6c1e0@solaris.tower> Message-ID: <20080109005922.58f38431@solaris.tower> Achim Schneider wrote: > Prelude> let y f = f $ y f > Prelude> :t y > y :: (b -> b) -> b > Just out of curiosity: Where the heck does 'a' hide? -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From brad.larsen at gmail.com Tue Jan 8 19:03:05 2008 From: brad.larsen at gmail.com (Brad Larsen) Date: Tue Jan 8 18:56:46 2008 Subject: [Haskell-cafe] Type System (Was: Currying and Partial Evaluation) In-Reply-To: <20080109005922.58f38431@solaris.tower> References: <20080109005155.26c6c1e0@solaris.tower> <20080109005922.58f38431@solaris.tower> Message-ID: On Tue, 08 Jan 2008 18:59:22 -0500, Achim Schneider wrote: > Achim Schneider wrote: > >> Prelude> let y f = f $ y f >> Prelude> :t y >> y :: (b -> b) -> b >> > Just out of curiosity: Where the heck does 'a' hide? > Beg pardon? Are you referring to the type of y being described with 'b' instead of 'a'? Cheers, Brad Larsen From barsoap at web.de Tue Jan 8 19:07:27 2008 From: barsoap at web.de (Achim Schneider) Date: Tue Jan 8 19:01:20 2008 Subject: [Haskell-cafe] Re: Type System (Was: Currying and Partial Evaluation) References: <20080109005155.26c6c1e0@solaris.tower> <20080109005922.58f38431@solaris.tower> Message-ID: <20080109010727.4499ce98@solaris.tower> "Brad Larsen" wrote: > On Tue, 08 Jan 2008 18:59:22 -0500, Achim Schneider > wrote: > > > Achim Schneider wrote: > > > >> Prelude> let y f = f $ y f > >> Prelude> :t y > >> y :: (b -> b) -> b > >> > > Just out of curiosity: Where the heck does 'a' hide? > > > > Beg pardon? Are you referring to the type of y being described with > 'b' instead of 'a'? > Yes. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From derek.a.elkins at gmail.com Tue Jan 8 18:38:31 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Tue Jan 8 19:32:36 2008 Subject: [Haskell-cafe] Re: Currying and Partial Evaluation In-Reply-To: <20080109005155.26c6c1e0@solaris.tower> References: <20080109005155.26c6c1e0@solaris.tower> Message-ID: <1199835511.18821.1.camel@derek-laptop> On Wed, 2008-01-09 at 00:51 +0100, Achim Schneider wrote: > Fernando Rodriguez wrote: > > > > > Hi, > > > > Is currying in Haskell the same thing as Partial Evaluation > > (http://en.wikipedia.org/wiki/Partial_evaluation)? Am I getting > > partial evaluation for free just by using Haskell? > > > No, currying is this: No, it is not. This is partial application. See the wiki page Neil referenced. > > Prelude> let f x y = 1 + x * ( y - 3 ) > Prelude> let g = f 1 > Prelude> let h = f 2 > Prelude> g 1 > -1 > Prelude> g 2 > 0 > Prelude> h 1 > -3 > Prelude> h 2 > -1 > > or, a bit more confusing and possibly enlightening, > > Prelude> let y f = f $ y f > Prelude> :t y > y :: (b -> b) -> b > Prelude> let fixpoint f n = if n <= 1 then 1 else n * (f $ n - 1) > Prelude> :t fixpoint > fixpoint :: (Num b, Ord b) => (b -> b) -> b -> b > Prelude> let fac = y fixpoint > Prelude> :t fac > fac :: Integer -> Integer > Prelude> fac 10 > 3628800 > > Prelude> fac 100 > 9332621544394415268169923885626670049071596826438162146859296389521759999 > 3229915608941463976156518286253697920827223758251185210916864000000000000 > 000000000000 > > Note that "fixpoint 3" won't work, and that's good. > > From jonathanccast at fastmail.fm Tue Jan 8 21:01:53 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Tue Jan 8 20:55:40 2008 Subject: [Haskell-cafe] Re: Is there anyone out there who can translate C# generics into Haskell? In-Reply-To: <20080109003842.4f23606f@solaris.tower> References: <8627368.20080103173843@gmail.com> <1762133336.20080103215834@gmail.com> <83DE9074-6529-4B54-B2A5-D3285DC699B0@fastmail.fm> <20080106111309.3f0bc240@solaris.tower> <47835C6F.30900@jellybean.co.uk> <20080108192846.GA24905@scytale.galois.com> <20080108211059.5602ab46@solaris.tower> <20080108222745.GB3393@localhost.localdomain> <20080109003842.4f23606f@solaris.tower> Message-ID: On 8 Jan 2008, at 3:38 PM, Achim Schneider wrote: > ---$<--- > or, while I'm at it > ---$<--- > > moveBall :: State' -> State' > moveBall state = state {ballPos' = (bpx+bvx, bpy+bvy)} > where (bpx, bpy) = ballPos' state > (bvx, bvy) = ballVel' state > > idle'' :: StateRef -> IdleCallback > idle'' st = st $~ moveBall > > ---$<--- > > With the multiple IORef-Model, moveBall looks like this: > > moveBall :: Vec2 -> Vec2 -> Vec2 > moveBall (bpx, bpy) (bvx,bvy) = (bpx+bvx, bpy+bvy) You can use this with the single IORef model, using the lifting function liftMove :: (Vec2 -> Vec2 -> Vec2) -> IORef State -> IO () liftMove move r = withIORef r $ \ st -> st{ballPos = moveBall (ballPos st) (ballVel st) } liftMove and moveBall can then be maintained separately; liftMove is part of your state framework (the outer layer of your program); moveBall is part of the algorithm specification (the inner layer of your program). jcc From alfonso.acosta at gmail.com Tue Jan 8 21:32:00 2008 From: alfonso.acosta at gmail.com (Alfonso Acosta) Date: Tue Jan 8 21:25:39 2008 Subject: [Haskell-cafe] Re: Type System (Was: Currying and Partial Evaluation) In-Reply-To: <20080109010727.4499ce98@solaris.tower> References: <20080109005155.26c6c1e0@solaris.tower> <20080109005922.58f38431@solaris.tower> <20080109010727.4499ce98@solaris.tower> Message-ID: <6a7c66fc0801081832g3fe709c1vc6867486081a3027@mail.gmail.com> On Jan 9, 2008 1:07 AM, Achim Schneider wrote: > > Beg pardon? Are you referring to the type of y being described with > > 'b' instead of 'a'? > > > Yes. "(a -> a) -> a" and "(b -> b) -> b" are equivalent. For some reason ghc uses b instead of a if you are picky about it, just provide a type signature explicitly. Prelude> let {y :: (a -> a) -> a ; y f = f $ y f} Prelude> :t y y :: (a -> a) -> a From barsoap at web.de Tue Jan 8 21:37:07 2008 From: barsoap at web.de (Achim Schneider) Date: Tue Jan 8 21:31:02 2008 Subject: [Haskell-cafe] Re: Currying and Partial Evaluation References: <20080109005155.26c6c1e0@solaris.tower> <1199835511.18821.1.camel@derek-laptop> Message-ID: <20080109033707.069afa1a@solaris.tower> Derek Elkins wrote: > On Wed, 2008-01-09 at 00:51 +0100, Achim Schneider wrote: > > Fernando Rodriguez wrote: > > > > > > > > Hi, > > > > > > Is currying in Haskell the same thing as Partial Evaluation > > > (http://en.wikipedia.org/wiki/Partial_evaluation)? Am I getting > > > partial evaluation for free just by using Haskell? > > > > > No, currying is this: > > No, it is not. This is partial application. See the wiki page Neil > referenced. > Which works because of the functions being curried... of course, the usage is to "partly" apply a function, which is not possible, as all Haskell functions are, by default, curried, and thus only have one parameter, which can either be applied or not. Partial evaluation, OTOH, goes into the direction of laziness vs. eagerness: Iff the compiler sees that a thunk is only dependent on data known at compile-time, it may choose to evaluate this thunk already at compile-time, if you're lucky and the compiler isn't lazy, main = putStrLn $ show $ 1 + 2 might end up being main = putStrLn "3" in the object file. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From barsoap at web.de Tue Jan 8 21:39:30 2008 From: barsoap at web.de (Achim Schneider) Date: Tue Jan 8 21:33:43 2008 Subject: [Haskell-cafe] Re: Type System (Was: Currying and Partial Evaluation) References: <20080109005155.26c6c1e0@solaris.tower> <20080109005922.58f38431@solaris.tower> <20080109010727.4499ce98@solaris.tower> <6a7c66fc0801081832g3fe709c1vc6867486081a3027@mail.gmail.com> Message-ID: <20080109033930.0409557d@solaris.tower> "Alfonso Acosta" wrote: > On Jan 9, 2008 1:07 AM, Achim Schneider wrote: > > > Beg pardon? Are you referring to the type of y being described > > > with 'b' instead of 'a'? > > > > > Yes. > > "(a -> a) -> a" and "(b -> b) -> b" are equivalent. > > For some reason ^^^^^^^^^^^^^^^ Yes, exactly that wire which isn't obscured by the boiler plate has kindled my interest. > ghc uses b instead of a if you are picky about it, > just provide a type signature explicitly. > > Prelude> let {y :: (a -> a) -> a ; y f = f $ y f} > Prelude> :t y > y :: (a -> a) -> a -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From duncan.coutts at worc.ox.ac.uk Tue Jan 8 21:17:52 2008 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Tue Jan 8 21:43:17 2008 Subject: [Haskell-cafe] Re: Hackage web page In-Reply-To: <20080104225326.GA2044@localhost> References: <404396ef0801020830t7a6f8bc3ydf01ca829a2af778@mail.gmail.com> <20080102172004.3C121A8002@webmail223.herald.ox.ac.uk> <20080104225326.GA2044@localhost> Message-ID: <1199845072.7279.75.camel@localhost> On Fri, 2008-01-04 at 17:53 -0500, gwern0@gmail.com wrote: > On 2008.01.02 17:20:04 +0000, Duncan Coutts > scribbled 0.8K characters: > > You're quite right. We'd welcome a rewrite. You or anyone else is most welcome > > to send us a new version in .html or any other format. > > > > If there are no immediate volunteers then someone should file a bug against the > > HackageDB component in our tracker so we do not forget. > > http://hackage.haskell.org/trac/hackage > > > > Duncan > > Is there any Darcs repo for the Hackage HTML, or does it just sort of > exist by itself on the servers? Seems not, though perhaps Ross might correct me. It would indeed be an improvement. Duncan From derek.a.elkins at gmail.com Tue Jan 8 21:01:14 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Tue Jan 8 21:55:18 2008 Subject: [Haskell-cafe] Re: Currying and Partial Evaluation In-Reply-To: <20080109033707.069afa1a@solaris.tower> References: <20080109005155.26c6c1e0@solaris.tower> <1199835511.18821.1.camel@derek-laptop> <20080109033707.069afa1a@solaris.tower> Message-ID: <1199844074.18821.9.camel@derek-laptop> On Wed, 2008-01-09 at 03:37 +0100, Achim Schneider wrote: > Derek Elkins wrote: > > > On Wed, 2008-01-09 at 00:51 +0100, Achim Schneider wrote: > > > Fernando Rodriguez wrote: > > > > > > > > > > > Hi, > > > > > > > > Is currying in Haskell the same thing as Partial Evaluation > > > > (http://en.wikipedia.org/wiki/Partial_evaluation)? Am I getting > > > > partial evaluation for free just by using Haskell? > > > > > > > No, currying is this: > > > > No, it is not. This is partial application. See the wiki page Neil > > referenced. > > > Which works because of the functions being curried... and therefore partial application can't be currying. Currying is the operation of turning (a,b) -> c into a -> b -> c. Nothing more. > of course, the > usage is to "partly" apply a function, which is not possible, as all > Haskell functions are, by default, curried, and thus only have one > parameter, which can either be applied or not. Indeed. Partial application is a fuzzy term. I give a potential objective definition here: http://lambda-the-ultimate.org/node/2266#comment-33620 > > Partial evaluation, OTOH, goes into the direction of laziness vs. > eagerness: Iff the compiler sees that a thunk is only dependent on data > known at compile-time, it may choose to evaluate this thunk already at > compile-time, if you're lucky and the compiler isn't lazy, Partial evaluation has little to do with lazy v. eager evaluation. > main = putStrLn $ show $ 1 + 2 > > might end up being > > main = putStrLn "3" > > in the object file. > > From barsoap at web.de Tue Jan 8 22:32:44 2008 From: barsoap at web.de (Achim Schneider) Date: Tue Jan 8 22:26:37 2008 Subject: [Haskell-cafe] Re: Currying and Partial Evaluation References: <20080109005155.26c6c1e0@solaris.tower> <1199835511.18821.1.camel@derek-laptop> <20080109033707.069afa1a@solaris.tower> <1199844074.18821.9.camel@derek-laptop> Message-ID: <20080109043244.1daefc07@solaris.tower> Derek Elkins wrote: > On Wed, 2008-01-09 at 03:37 +0100, Achim Schneider wrote: > > Derek Elkins wrote: > > > > > On Wed, 2008-01-09 at 00:51 +0100, Achim Schneider wrote: > > > > Fernando Rodriguez wrote: > > > > > > > > > > > > > > Hi, > > > > > > > > > > Is currying in Haskell the same thing as Partial Evaluation > > > > > (http://en.wikipedia.org/wiki/Partial_evaluation)? Am I > > > > > getting partial evaluation for free just by using Haskell? > > > > > > > > > No, currying is this: > > > > > > No, it is not. This is partial application. See the wiki page > > > Neil referenced. > > > > > Which works because of the functions being curried... > > and therefore partial application can't be currying. Currying is the > operation of turning (a,b) -> c into a -> b -> c. Nothing more. > > > of course, the > > usage is to "partly" apply a function, which is not possible, as all > > Haskell functions are, by default, curried, and thus only have one > > parameter, which can either be applied or not. > > Indeed. Partial application is a fuzzy term. I give a potential > objective definition here: > http://lambda-the-ultimate.org/node/2266#comment-33620 > Yes, it seems kind of obvious that eating a chicken isn't the same as currying a chicken, but then there's a difference between eating a grilled and a curried chicken... and cooking is always more complex than eating. And you just can't have a curried chicken when there's no one around that curries them. So, currying can also be the operation of turning (define (foo x y) (+ x y)) into foo x y = x + y or, mere syntactically, foo x y = x + y into foo = \x -> \y -> x + y > > > > Partial evaluation, OTOH, goes into the direction of laziness vs. > > eagerness: Iff the compiler sees that a thunk is only dependent on > > data known at compile-time, it may choose to evaluate this thunk > > already at compile-time, if you're lucky and the compiler isn't > > lazy, > > Partial evaluation has little to do with lazy v. eager evaluation. > Well, enough for a thunk to be a reasonable metaphor for a candidate partial evaluation. The compiler is eager, so that the result is memoized before it is used... or not, but then that may not be deducible for the compiler. It's a bit like stop and go traffic. "Opportunistic evaluation" probably fits the concept better than "eager". Can we stop nit-picking, please? -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From trebla at vex.net Tue Jan 8 22:46:09 2008 From: trebla at vex.net (Albert Y. C. Lai) Date: Tue Jan 8 22:39:50 2008 Subject: [Haskell-cafe] Please allow beginners to vocalize code. >>= :: -> &&& <- -< In-Reply-To: <4783DEE4.8010203@millstream.com> References: <47839A66.7080506@millstream.com> <4783AF7F.1080308@millstream.com> <1199812125.17810.17.camel@derek-laptop> <4783DEE4.8010203@millstream.com> Message-ID: <47844381.6080105@vex.net> Richard Kelsall wrote: > Imagine > two experienced Haskell programmers on the phone, one reading a Haskell > program snippet to the other. u can txt msg XD ^^--- unworded symbol people grasp just fine. From derek.a.elkins at gmail.com Tue Jan 8 22:56:27 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Tue Jan 8 23:50:32 2008 Subject: [Haskell-cafe] Re: Currying and Partial Evaluation In-Reply-To: <20080109043244.1daefc07@solaris.tower> References: <20080109005155.26c6c1e0@solaris.tower> <1199835511.18821.1.camel@derek-laptop> <20080109033707.069afa1a@solaris.tower> <1199844074.18821.9.camel@derek-laptop> <20080109043244.1daefc07@solaris.tower> Message-ID: <1199850987.18821.15.camel@derek-laptop> On Wed, 2008-01-09 at 04:32 +0100, Achim Schneider wrote: > Derek Elkins wrote: > > > On Wed, 2008-01-09 at 03:37 +0100, Achim Schneider wrote: > > > Derek Elkins wrote: > > > > > > > On Wed, 2008-01-09 at 00:51 +0100, Achim Schneider wrote: > > > > > Fernando Rodriguez wrote: > > > > > > > > > > > > > > > > > Hi, > > > > > > > > > > > > Is currying in Haskell the same thing as Partial Evaluation > > > > > > (http://en.wikipedia.org/wiki/Partial_evaluation)? Am I > > > > > > getting partial evaluation for free just by using Haskell? > > > > > > > > > > > No, currying is this: > > > > > > > > No, it is not. This is partial application. See the wiki page > > > > Neil referenced. > > > > > > > Which works because of the functions being curried... > > > > and therefore partial application can't be currying. Currying is the > > operation of turning (a,b) -> c into a -> b -> c. Nothing more. > > > > > of course, the > > > usage is to "partly" apply a function, which is not possible, as all > > > Haskell functions are, by default, curried, and thus only have one > > > parameter, which can either be applied or not. > > > > Indeed. Partial application is a fuzzy term. I give a potential > > objective definition here: > > http://lambda-the-ultimate.org/node/2266#comment-33620 > > > Yes, it seems kind of obvious that eating a chicken isn't the same as > currying a chicken, but then there's a difference between eating > a grilled and a curried chicken... and cooking is always more complex > than eating. And you just can't have a curried chicken when there's > no one around that curries them. > > So, currying can also be the operation of turning > > (define (foo x y) (+ x y)) > > into > > foo x y = x + y > > or, mere syntactically, > > foo x y = x + y > > into > > foo = \x -> \y -> x + y > > > > > > > Partial evaluation, OTOH, goes into the direction of laziness vs. > > > eagerness: Iff the compiler sees that a thunk is only dependent on > > > data known at compile-time, it may choose to evaluate this thunk > > > already at compile-time, if you're lucky and the compiler isn't > > > lazy, > > > > Partial evaluation has little to do with lazy v. eager evaluation. > > > Well, enough for a thunk to be a reasonable metaphor for a candidate > partial evaluation. The compiler is eager, so that the result is > memoized before it is used... or not, but then that may not be > deducible for the compiler. It's a bit like stop and go traffic. > "Opportunistic evaluation" probably fits the concept better than > "eager". > > > Can we stop nit-picking, please? Can we stop using confusing, misleading or outright wrong definitions and analogies? This is how we end up with people thinking 'currying' = 'partial application' = 'partial evaluation' or 'laziness' = 'memoization' or 'monads' = 'state passing' = 'continuations' or 'type classes' = 'OO classes' From jonathanccast at fastmail.fm Wed Jan 9 00:44:45 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Wed Jan 9 00:38:40 2008 Subject: [Haskell-cafe] Re: Currying and Partial Evaluation In-Reply-To: <1199850987.18821.15.camel@derek-laptop> References: <20080109005155.26c6c1e0@solaris.tower> <1199835511.18821.1.camel@derek-laptop> <20080109033707.069afa1a@solaris.tower> <1199844074.18821.9.camel@derek-laptop> <20080109043244.1daefc07@solaris.tower> <1199850987.18821.15.camel@derek-laptop> Message-ID: On 8 Jan 2008, at 7:56 PM, Derek Elkins wrote: > Can we stop using confusing, misleading or outright wrong definitions > and analogies? What, and bring CS to a halt? jcc From derek.a.elkins at gmail.com Wed Jan 9 00:01:37 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Wed Jan 9 00:55:42 2008 Subject: [Haskell-cafe] Re: Currying and Partial Evaluation In-Reply-To: References: <20080109005155.26c6c1e0@solaris.tower> <1199835511.18821.1.camel@derek-laptop> <20080109033707.069afa1a@solaris.tower> <1199844074.18821.9.camel@derek-laptop> <20080109043244.1daefc07@solaris.tower> <1199850987.18821.15.camel@derek-laptop> Message-ID: <1199854898.18821.17.camel@derek-laptop> On Tue, 2008-01-08 at 21:44 -0800, Jonathan Cast wrote: > On 8 Jan 2008, at 7:56 PM, Derek Elkins wrote: > > Can we stop using confusing, misleading or outright wrong definitions > > and analogies? > > What, and bring CS to a halt? CS wouldn't be the only thing brought to a halt... From jonathanccast at fastmail.fm Wed Jan 9 01:13:46 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Wed Jan 9 01:07:38 2008 Subject: [Haskell-cafe] Re: Currying and Partial Evaluation In-Reply-To: <1199854898.18821.17.camel@derek-laptop> References: <20080109005155.26c6c1e0@solaris.tower> <1199835511.18821.1.camel@derek-laptop> <20080109033707.069afa1a@solaris.tower> <1199844074.18821.9.camel@derek-laptop> <20080109043244.1daefc07@solaris.tower> <1199850987.18821.15.camel@derek-laptop> <1199854898.18821.17.camel@derek-laptop> Message-ID: <6409AB31-307F-41F5-B3A0-741ABB0D2819@fastmail.fm> On 8 Jan 2008, at 9:01 PM, Derek Elkins wrote: > On Tue, 2008-01-08 at 21:44 -0800, Jonathan Cast wrote: >> On 8 Jan 2008, at 7:56 PM, Derek Elkins wrote: >>> Can we stop using confusing, misleading or outright wrong >>> definitions >>> and analogies? >> >> What, and bring CS to a halt? > > CS wouldn't be the only thing brought to a halt... Good point. We're really discussing what, the end of humanity as we know it? jcc From s.clover at gmail.com Wed Jan 9 01:21:46 2008 From: s.clover at gmail.com (Sterling Clover) Date: Wed Jan 9 01:15:26 2008 Subject: [Haskell-cafe] Re: PROPOSAL: Some more 'Applicative' combinators In-Reply-To: References: <5ab17e790801061335t59d53588s2c935067457bde0e@mail.gmail.com> <4781B685.7050500@serpentine.com> <5ab17e790801062254x41e52005n78723b5c73fa7b71@mail.gmail.com> Message-ID: <63371D3A-05D4-41A6-87AE-5E4B60481A5E@gmail.com> The more general question, which stems from a certain degree of ignorance on my part, is what uses folks have found for Alternative at all outside of parsing. --S On Jan 8, 2008, at 4:43 AM, apfelmus wrote: > Iavor Diatchki wrote: >> Bryan O'Sullivan wrote: >>> Why not make the task specificity clearer, with a separate >>> Control.Applicative.Parsing module? > > +1 > >> Now _this_ would definitely suggest that they are only good for >> parsing which would be misleading. > > Would it? I mean, I currently don't know a second use case for > them. Preferably, the names like skipMany , endBy , sepBy etc. > should still make sense in the new context. > > > Regards, > apfelmus > > _______________________________________________ > Libraries mailing list > Libraries@haskell.org > http://www.haskell.org/mailman/listinfo/libraries From bos at serpentine.com Wed Jan 9 02:57:43 2008 From: bos at serpentine.com (Bryan O'Sullivan) Date: Wed Jan 9 02:51:20 2008 Subject: [Haskell-cafe] ANN: A triple of new packages for talking to the outside world In-Reply-To: <396556a20801081226l5ebf5062p685a80c6aac6ba41@mail.gmail.com> References: <396556a20801061554o3895ce88k87d4ecabc1860e7b@mail.gmail.com> <4781B50A.2060007@serpentine.com> <396556a20801071037t1b66e444u52abe1d934b7f902@mail.gmail.com> <47827AB4.60608@serpentine.com> <396556a20801081226l5ebf5062p685a80c6aac6ba41@mail.gmail.com> Message-ID: <47847E77.8070101@serpentine.com> Adam Langley wrote: > Ok, see http://www.imperialviolet.org/IncrementalGet.hs That's excellent! This is just the sort of thing one wants if getting dribs and drabs of information instead of a steady stream. For example, I need to reconstruct TCP streams from individual packets captured off the wire, and this is a much easier mechanism to use than playing tricks with the direct-mode Get monad. > Questions: > 1) Should Finished include the remainder of the ByteString (e.g. > that which wasn't used by that parser) Yes, definitely. I had to add a runGetState to the existing Get monad so that I could recover the unparsed residual, so I'm sure it will be necessary here. > 2) I've no idea what I've done to the parse speed Getting the API right is the appropriate thing to be doing first. Afterwards, the rewrite rule ninjas can stage a night attack on performance problems. > But if this is useful to you, make any requests. I'll (hopefully) do > them, clean it up and push a new release of binary-strict. I'm lobbying for Don and company to include this stuff in the regular binary distribution. A proliferation of almost-identical packages doesn't serve the community all that well. Thanks for the nice work! I'll try to put that code to use in perhaps a few days, and let you know how the API works out in practice. References: <396556a20801061554o3895ce88k87d4ecabc1860e7b@mail.gmail.com> <4781B50A.2060007@serpentine.com> <396556a20801071037t1b66e444u52abe1d934b7f902@mail.gmail.com> <47827AB4.60608@serpentine.com> <396556a20801081226l5ebf5062p685a80c6aac6ba41@mail.gmail.com> <47847E77.8070101@serpentine.com> Message-ID: <20080109080427.GA28089@scytale.galois.com> bos: > Adam Langley wrote: > > > Ok, see http://www.imperialviolet.org/IncrementalGet.hs > > That's excellent! This is just the sort of thing one wants if getting > dribs and drabs of information instead of a steady stream. For example, > I need to reconstruct TCP streams from individual packets captured off > the wire, and this is a much easier mechanism to use than playing tricks > with the direct-mode Get monad. > > > Questions: > > 1) Should Finished include the remainder of the ByteString (e.g. > > that which wasn't used by that parser) > > Yes, definitely. I had to add a runGetState to the existing Get monad > so that I could recover the unparsed residual, so I'm sure it will be > necessary here. > > > 2) I've no idea what I've done to the parse speed > > Getting the API right is the appropriate thing to be doing first. > Afterwards, the rewrite rule ninjas can stage a night attack on > performance problems. Yeah, I'm happy to attack that problem. The key is finding a useful API that you actually can work with for real problems. This looks like a good step -- and interesting to see how you're needs differed from the original intent. > > But if this is useful to you, make any requests. I'll (hopefully) do > > them, clean it up and push a new release of binary-strict. > > I'm lobbying for Don and company to include this stuff in the regular > binary distribution. A proliferation of almost-identical packages > doesn't serve the community all that well. I'm happy to -- if people need a slightly different API, we should do what we can to support that. The goal is to make binary hacking in Haskell painless, so anything that helps that goal, is good :) -- Don From gale at sefer.org Wed Jan 9 04:06:01 2008 From: gale at sefer.org (Yitzchak Gale) Date: Wed Jan 9 03:59:38 2008 Subject: [Haskell-cafe] US Homeland Security program language security risks In-Reply-To: <1576558140.20080104021357@gmail.com> References: <5ae4f2ba0801031336x45b4c14dw34771cbc9ef0d3f4@mail.gmail.com> <1576558140.20080104021357@gmail.com> Message-ID: <2608b8a80801090106k1c5a55d1v72b54e4ff7b1f322@mail.gmail.com> Galchin Vasili wrote on Friday, January 4: >> I stumbled across this page. It seems that Haskell and other >> strongly typed functional languages like Ml/OCaml will fare much, >> much better, e.g. buffer overrun. Thoughts . .... comments. Bulat Ziganshin wrote: > for me, it looks like saying that haskell better uses CPU registers :) > the truth is that modern languages (including Java/C#) doesn't use > buffers directly. i don't have experience of their usage, but for > Haskell i had memory referencing problems only when using unsafe* > tricks Interestingly enough, a few days after this exchange, the first public report was released from a large survey funded by US Homeland Security on security of open source projects. The survey was carried out by a company called Coverity. Among the projects making top grade for security - apparently far better than most proprietary products, though complete information about that is not public - were PHP, Perl, and Python. PHP? Come on, can't we do at least as well? But right now, there is a technical impediment to the participation of Haskell: the Coverity project currently only supports projects written in C, C++, and Java. Haskell compilers are often written in Haskell. Any ideas? Perhaps Coverity's interest could be piqued if they were made aware of Haskell's emergence as an important platform in security-sensitive industries such as finance and chip design, and of the significant influence that Haskell is having on the design of all other major programming languages. The home page for the Coverity open source project is at: http://scan.coverity.com/ Some recent press coverage: http://it.slashdot.org/article.pl?sid=08/01/09/0027229 http://www.zdnet.com.au/news/security/soa/11-open-source-projects-pass-security-health-check/0,130061744,339284949,00.htm http://www.informationweek.com/story/showArticle.jhtml?articleID=205600229 -Yitz From dominic.steinitz at blueyonder.co.uk Wed Jan 9 04:26:43 2008 From: dominic.steinitz at blueyonder.co.uk (Dominic Steinitz) Date: Wed Jan 9 04:20:33 2008 Subject: [Haskell-cafe] Re: ANN: A triple of new packages for talking to the outside world References: <396556a20801061554o3895ce88k87d4ecabc1860e7b@mail.gmail.com> <4781B50A.2060007@serpentine.com> <396556a20801071037t1b66e444u52abe1d934b7f902@mail.gmail.com> <47827AB4.60608@serpentine.com> <396556a20801081226l5ebf5062p685a80c6aac6ba41@mail.gmail.com> Message-ID: Adam Langley imperialviolet.org> writes: > But if this is useful to you, make any requests. I'll (hopefully) do > them, clean it up and push a new release of binary-strict. > How difficult would it be to have a getBits functions as well as a getBytes? That would allow me drop the dependency on NewBinary in the ASN.1 package. Thanks, Dominic. From jules at jellybean.co.uk Wed Jan 9 04:50:08 2008 From: jules at jellybean.co.uk (Jules Bean) Date: Wed Jan 9 04:43:46 2008 Subject: [Haskell-cafe] Currying and Partial Evaluation In-Reply-To: References: Message-ID: <478498D0.9090000@jellybean.co.uk> Fernando Rodriguez wrote: > > Hi, > > Is currying in Haskell the same thing as Partial Evaluation > (http://en.wikipedia.org/wiki/Partial_evaluation)? Am I getting partial > evaluation for free just by using Haskell? > Thanks! I'm not sure you got a straight answer, although you provoked some discussion. Currying is the transformation which takes a function which takes multiple parameters "all at once", into a function which takes one parameter, returning a function which takes one more parameter, returning.... I.e.: uncurried function: f :: (a,b,c,d) -> e takes four parameters "all at once". In haskell it has to take them as a tuple. The corresponding curried function: f :: a -> b -> c -> d -> e Takes one parameter (of type a), and returns a function of type (b -> c -> d ->e). This takes one parameter of type b, and returns a function of type (c -> d -> e). This takes one parameter of type c and returns a function of type (d -> e). This takes one parameter of type d and returns a result of type e. So, in the end, both forms of f take four parameters and give a result of type e. The difference is that the curried form takes them "one at a time", and you can "stop partway" with only some of the parameters supplied. This process of "stopping partway" is called "partial application" (not partial evaluation), and it's a useful technique when working with higher-order functions. Convention in haskell, ML, and similar languages is to use the curried style predominantly. This is for a variety of reasons; the most practically oriented reason is simply that it makes partial application straightforward, which is a useful technique. Now for the second half of your question! Partial Evaluation is cool, but nobody has worked out a good way to get it for free. Some compilers do some kinds of partial evaluation. The "constant folding" that most C compilers do is a very simple case of partial evaluation. In principle, languages like haskell give the compiler a lot more information to determine how much partial evaluation is feasible (especially that the compiler knows which functions are pure). It remains an interesting engineering problem working out which bits to do, though. GHC does not do very much partial evaluation, although some of its optimisations (SpecConstr and some RULES pragmas) are partial-evaluation in a sense. Neil Mitchell's interesting (but as far as I know, work-in-progress) Supero project, http://www-users.cs.york.ac.uk/~ndm/supero/ , is a closely related notion of compilation. Jules From felipe.lessa at gmail.com Wed Jan 9 05:01:28 2008 From: felipe.lessa at gmail.com (Felipe Lessa) Date: Wed Jan 9 04:55:04 2008 Subject: [Haskell-cafe] Re: Type System (Was: Currying and Partial Evaluation) In-Reply-To: <20080109033930.0409557d@solaris.tower> References: <20080109005155.26c6c1e0@solaris.tower> <20080109005922.58f38431@solaris.tower> <20080109010727.4499ce98@solaris.tower> <6a7c66fc0801081832g3fe709c1vc6867486081a3027@mail.gmail.com> <20080109033930.0409557d@solaris.tower> Message-ID: On Jan 9, 2008 12:39 AM, Achim Schneider wrote: > Yes, exactly that wire which isn't obscured by the boiler plate has > kindled my interest. The name of a type variable doesn't really matter. GHC tries to preserve the names you give, otherwise it creates their own. For example, Prelude> :t \a b c d e f g -> (a,b,c,d,e,f,g) \a b c d e f g -> (a,b,c,d,e,f,g) :: t -> t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> (t, t1, t2, t3, t4, t5, t6) Welll, so why 'b'? Well, GHC didn't choose 'b' at all =) Prelude> :t let y f = f (y f) in y let y f = f (y f) in y :: (t -> t) -> t but Prelude> :t let y f = f $ y f in y let y f = f $ y f in y :: (b -> b) -> b because Prelude> :t ($) ($) :: (a -> b) -> a -> b In another exemple, Prelude> :t \a b c d e f g -> (id a,b,c,d,e,f,g) \a b c d e f g -> (id a,b,c,d,e,f,g) :: a -> t -> t1 -> t2 -> t3 -> t4 -> t5 -> (a, t, t1, t2, t3, t4, t5) Prelude> :t \a b c d e f g -> (a,b,c,d,id e,f,g) \a b c d e f g -> (a,b,c,d,id e,f,g) :: t -> t1 -> t2 -> t3 -> a -> t4 -> t5 -> (t, t1, t2, t3, a, t4, t5) Prelude> :t \a b c d e f g -> (a,b,id c,d,id e,f,g) \a b c d e f g -> (a,b,id c,d,id e,f,g) :: t -> t1 -> a -> t2 -> a1 -> t3 -> t4 -> (t, t1, a, t2, a1, t3, t4) -- Felipe. From frr149 at easyjob.net Wed Jan 9 05:03:18 2008 From: frr149 at easyjob.net (Fernando Rodriguez) Date: Wed Jan 9 04:57:05 2008 Subject: [Haskell-cafe] Re: Currying and Partial Evaluation References: <478498D0.9090000@jellybean.co.uk> Message-ID: Hello Jules, > I'm not sure you got a straight answer, although you provoked some > discussion. Thanks for your answer, now everything is much clearer. From apfelmus at quantentunnel.de Wed Jan 9 05:26:47 2008 From: apfelmus at quantentunnel.de (apfelmus) Date: Wed Jan 9 05:23:39 2008 Subject: [Haskell-cafe] Re: PROPOSAL: Some more 'Applicative' combinators In-Reply-To: <63371D3A-05D4-41A6-87AE-5E4B60481A5E@gmail.com> References: <5ab17e790801061335t59d53588s2c935067457bde0e@mail.gmail.com> <4781B685.7050500@serpentine.com> <5ab17e790801062254x41e52005n78723b5c73fa7b71@mail.gmail.com> <63371D3A-05D4-41A6-87AE-5E4B60481A5E@gmail.com> Message-ID: Sterling Clover wrote: > The more general question, which stems from a certain degree of > ignorance on my part, is what uses folks have found for Alternative at > all outside of parsing. Alternative is the generalization of MonadPlus, so empty and <|> are useful for lists and Maybe at least. But I'm not sure whether many :: Alternative f => f a -> f [a] and friends have any uses outside of parsing. Regards, apfelmus From barsoap at web.de Wed Jan 9 05:47:25 2008 From: barsoap at web.de (Achim Schneider) Date: Wed Jan 9 05:41:09 2008 Subject: [Haskell-cafe] Re: Currying and Partial Evaluation References: <20080109005155.26c6c1e0@solaris.tower> <1199835511.18821.1.camel@derek-laptop> <20080109033707.069afa1a@solaris.tower> <1199844074.18821.9.camel@derek-laptop> <20080109043244.1daefc07@solaris.tower> <1199850987.18821.15.camel@derek-laptop> Message-ID: <20080109114725.12ff6853@solaris.tower> Derek Elkins wrote: > Can we stop using confusing, misleading or outright wrong definitions > and analogies? > No, we can't, ever, that's plain impossible. And will never stop to use enlightening, inspiring or vastly approximate or aggregate definitions and analogies, and I won't stop laughing about my mistakes. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From lemming at henning-thielemann.de Wed Jan 9 06:11:49 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Wed Jan 9 06:05:51 2008 Subject: Fusion vs. inlining (Was: [Haskell-cafe] Fusion of lists and chunky sequences) In-Reply-To: <47830A3B.7040401@cse.unsw.edu.au> References: <20080103192002.GF4775@scytale.galois.com> <47830A3B.7040401@cse.unsw.edu.au> Message-ID: On Tue, 8 Jan 2008, Roman Leshchinskiy wrote: > Henning Thielemann wrote: > > > > Anyway, I tried to wrap Prelude lists in a newtype and thus got GHC (still > > 6.4.1) to invoke my rules instead of the Prelude rules. But I encountered > > the following problem: I define something like > > > > nonFusable x y = fusable (aux x y) > > > > where fusion rules are defined for 'fusable', but not for 'nonFusable'. I > > hoped that 'nonFusable' will be inlined and then 'fusable' is fused with > > other expressions. This does not happen. If I state the function > > definition also as rule, then GHC fuses eagerly. > > I suspect that fusable and/or aux are inlined into nonFusable when the > latter is compiled. That's too early - you want nonFusable (with the > simple definition above) to be inlined into the client code first. Adding > > {-# INLINE nonFusable #-} > > should take care of this. I forget to mention, that I already declared {-# INLINE nonFusable #-} As you guessed, it seems that 'fusable' was inlined and thus was no longer available for fusion. So I set INLINE for nonFusable and NOINLINE for fusable. Now I see the foldr/build counter decreases in the simplifier statistics, where the counter for my custom rules increases. > > Analogously I observed that usage of ($) and (.) blocks fusion, and when > > I add the rules > > > > "unfold-dollar" forall f x. > > f $ x = f x ; > > > > "unfold-dot" forall f g. > > f . g = \x -> f (g x) ; > > > > then fusion takes place as expected. > > That shouldn't be necessary, these two ought to be inlined. Do you have > a concrete example where this happens? When I constructed a small example I encountered the behaviour you mentioned. However there are still several cases where I expected that fusion took place but it didn't. Maybe I can track them down to very simple cases. Since the functions on the chunky structure can be faster than the list functions by a factor of 30, I'm very keen on getting the list functions eliminated completely. From frr149 at easyjob.net Wed Jan 9 06:52:55 2008 From: frr149 at easyjob.net (Fernando Rodriguez) Date: Wed Jan 9 06:46:47 2008 Subject: [Haskell-cafe] Trouble with indentation Message-ID: Hi, I'm trying to write a function that finds out the week day using the Zeller congruence (http://en.wikipedia.org/wiki/Zeller's_congruence). However, ghc complains about: parse error on input `=' at the "if m <= 2 then " line. I believe this is some sort of layout error. Can someone point out what I am doing wrong? Here's the code: data DiaSemana = Lunes | Martes | Miercoles | Jueves | Viernes | Sabado | Domingo deriving (Show, Eq, Ord, Enum) diaDeSemana d m a = toEnum num :: DiaSemana where num = zeller x y z zeller x y z = (700 + (26 * x - 2) `div` 10 + d + y + y `div` 4 + z `div` 4 - 2 * z) `mod` 7 if m <= 2 then x = m + 10 y = (a - 1) `mod` 100 z = (a-1) 'div' 100 else x = m - 2 y = a `mod` 100 z = a `div` 100 From simonmarhaskell at gmail.com Wed Jan 9 07:03:24 2008 From: simonmarhaskell at gmail.com (Simon Marlow) Date: Wed Jan 9 06:57:05 2008 Subject: [Haskell-cafe] Re: [Haskell] ANNOUNCE: Haddock version 2.0.0.0 In-Reply-To: References: Message-ID: <4784B80C.1070004@gmail.com> Felipe Lessa wrote: > On Jan 8, 2008 10:28 AM, David Waern wrote: >> * Haddock now understands all syntax understood by GHC 6.8.2 > > Does Haddock still define __HADDOCK__? There's a lot of code that uses > this flag just to hide something Haddock didn't know. Haddock itself never defined __HADDOCK__, because it didn't do the CPP preprocessing itself. Cabal adds __HADDOCK__ itself when preprocessing files for passing to Haddock. When used with Haddock version 2, Cabal no longer defines __HADDOCK__ when preprocessing. Haddock 2 can do the preprocessing itself, because it is processing the Haskell files using the GHC API. In this case, if you want __HADDOCK__ defined, you have to add it explicitly with --optghc -D__HADDOCK__. The easiest way to use Haddock 2 is via Cabal, which will automatically add the appropriate options for your package, including the right -B option which Haddock now needs in order that the GHC API can find its package database. Cheers, Simon From ithika at gmail.com Wed Jan 9 07:07:44 2008 From: ithika at gmail.com (Dougal Stanton) Date: Wed Jan 9 07:01:22 2008 Subject: [Haskell-cafe] Trouble with indentation In-Reply-To: References: Message-ID: <2d3641330801090407k51793e32td5be50849d141c7b@mail.gmail.com> On 09/01/2008, Fernando Rodriguez wrote: > > However, ghc complains about: parse error on input `=' at the "if m <= 2 > then " line. I believe this is some sort of layout error. Can someone point > out what I am doing wrong? Assuming the layout didn't get munged during the email process, the problem is that the 'if' can't go there. You need to have 'sth = if ...' not 'if cond then sth = ' > diaDeSemana d m a = toEnum num :: DiaSemana > where > num = zeller x y z > zeller x y z = (700 + (26 * x - 2) `div` 10 > + d + y + y `div` 4 + z `div` 4 - 2 * z) > `mod` 7 > if m <= 2 then > x = m + 10 > y = (a - 1) `mod` 100 > z = (a-1) 'div' 100 > else > x = m - 2 > y = a `mod` 100 > z = a `div` 100 Maybe try: > (x,y,z) = if m <= 2 > then (m+10, (a-1)`mod`100, (a-1)`div`100) > else (m-2 , a`mod`100, a`div`100) I haven't tested this though.... -- Dougal Stanton dougal@dougalstanton.net // http://www.dougalstanton.net From jules at jellybean.co.uk Wed Jan 9 07:13:23 2008 From: jules at jellybean.co.uk (Jules Bean) Date: Wed Jan 9 07:07:00 2008 Subject: [Haskell-cafe] Trouble with indentation In-Reply-To: References: Message-ID: <4784BA63.2060009@jellybean.co.uk> Fernando Rodriguez wrote: > > Hi, > > I'm trying to write a function that finds out the week day using the > Zeller congruence (http://en.wikipedia.org/wiki/Zeller's_congruence). > > However, ghc complains about: parse error on input `=' at the "if m <= 2 > then " line. I believe this is some sort of layout error. Can someone > point out what I am doing wrong? > > Here's the code: > > data DiaSemana = Lunes | Martes | Miercoles | Jueves | Viernes > | Sabado | Domingo deriving (Show, Eq, Ord, Enum) > diaDeSemana d m a = toEnum num :: DiaSemana > where > num = zeller x y z > zeller x y z = (700 + (26 * x - 2) `div` 10 > + d + y + y `div` 4 + z `div` 4 - 2 * z) > `mod` 7 > if m <= 2 then x = m > + 10 > y = (a - 1) `mod` 100 > z = (a-1) 'div' 100 > else x = m - 2 > y = a `mod` 100 > z = a `div` 100 That looks like it's been mangled a bit by your mail program or mine, but anyway: This is not a layout problem. The problem here is simply that you can't put "ifs" around chunks of definitions. "if" is an expression level concept, not a definition-level one. You could try: diaDeSemana d m a = toEnum num :: DiaSemana where num = zeller x y z zeller x y z = (700 + (26 * x - 2) `div` 10 + d + y + y `div` 4 + z `div` 4 - 2 * z) `mod` 7 x | m <= 2 = m + 10 | otherwise = m - 2 y | m <= 2 = (a - 1) `mod` 100 | otherwise = a `mod` 100 z | m <= 2 = (a-1) 'div' 100 | otherwise = a `div` 100 or, to avoid the ugly duplication of the m <= 2 constraint, we can use an if in an expresson like this: diaDeSemana d m a = toEnum num :: DiaSemana where num = zeller x y z zeller x y z = (700 + (26 * x - 2) `div` 10 + d + y + y `div` 4 + z `div` 4 - 2 * z) `mod` 7 (x,y,z) = if m <=2 then (m+10,(a-1)`mod`100,(a-1)`div`100) else (m-2,a`mod`100,a`div`100) ... or, replacing the if with guards again ... diaDeSemana d m a = toEnum num :: DiaSemana where num = zeller x y z zeller x y z = (700 + (26 * x - 2) `div` 10 + d + y + y `div` 4 + z `div` 4 - 2 * z) `mod` 7 (x,y,z) | m <=2 = (m+10,(a-1)`mod`100,(a-1)`div`100) | otherwise = (m-2 ,a `mod`100,a `div`100) Jules From jules at jellybean.co.uk Wed Jan 9 07:25:14 2008 From: jules at jellybean.co.uk (Jules Bean) Date: Wed Jan 9 07:18:52 2008 Subject: [Haskell-cafe] Re: Is there anyone out there who can translate C# generics into Haskell? In-Reply-To: <20080108211059.5602ab46@solaris.tower> References: <915864007.20080103135418@gmail.com> <8627368.20080103173843@gmail.com> <1762133336.20080103215834@gmail.com> <83DE9074-6529-4B54-B2A5-D3285DC699B0@fastmail.fm> <20080106111309.3f0bc240@solaris.tower> <47835C6F.30900@jellybean.co.uk> <20080108192846.GA24905@scytale.galois.com> <20080108211059.5602ab46@solaris.tower> Message-ID: <4784BD2A.4010903@jellybean.co.uk> Achim Schneider wrote: > Yes, you see, that was my first Haskell program bigger than 20 lines, > there's no possibility to get the state out of the IO Monad, at least > without writing a high-level interface to glut and gl, and then there's > this thing that _every_ game works with input callbacks, one, global, > state update function (where it doesn't _really_ matter whether you're > passing and returning a state or updating a state) and one function > that translates the state into some graphics representation. Understood. My objection was not about having an IORef somewhere (you need it to thread via the callback), but about making each component an IORef when one big IORef makes more sense. It makes plenty of sense to try to write precise type signatures, including not having IO in the type of functions which don't do IO. For ramblings about the annoyance of having to use IORefs to thread your custom monad state through callbacks, take a look at http://www.haskell.org/pipermail/haskell-cafe/2007-July/028501.html which sketches a typeclass "solution" Jules From a.d.clark at ed.ac.uk Wed Jan 9 08:18:52 2008 From: a.d.clark at ed.ac.uk (allan) Date: Wed Jan 9 08:14:53 2008 Subject: [Haskell-cafe] Data.Binary and serialising doubles in IEEE format Message-ID: <4784C9BC.2010101@ed.ac.uk> Dear all I have what I think should be a relatively simple problem: I have a C program which reads in data from a binary file, it is a specific format so it knows that there are 3 integers followed by three doubles or whatever. So I'm trying to serialise the data from within a Haskell program and write it out to a file such that the C program can read this. I've gotten the integers to work no problem but I'm having difficulty with the doubles. My method is to use the Data.Binary library to write the data out as a bytestring and then simply write this out to disk. The problem is that the instance of Binary for Double does not serialise the data in the format which is expected by the C program (standard IEEE format using fread and a cast). Now there was a thread on (essentially) this very same topic on haskell-cafe back in April, see: http://www.haskell.org/pipermail/haskell-cafe/2007-April/024596.html There was some discussion about the 'right' thing to do and that the library intended to be split into two separate portions; one for users that wish to serialise their own data and have it readable by the same haskell program, and those that wish to communicate with programs written in other languages. From the above thread: > Perhaps we just don't care about ARM or other arches where GHC runs that > do not use IEEE formats, I don't know. If that were the case we'd say > something like: > > instance Binary Double where > put d = assert (isIEEE (undefined :: Double)) $ do > write (poke d) Now for my specific problem I'd be happy if I could write a function: putDouble :: Double -> Put and so obviously I tried: putDouble :: Double -> Put putDouble d = assert (isIEEE (undefined :: Double)) $ do write (poke d) However I seem to be stuck at this point, where does the 'write' function come from? Essentially then, is there anyone that can write my 'putDouble' function or give some hint as to how I might do it. For the moment assume that I'm not really concerned with portability across platforms at least for the time being (I certainly don't think that the C program I'm attempting to communicate with is particularly portable anyway). kind regards allan From duncan.coutts at worc.ox.ac.uk Wed Jan 9 08:32:58 2008 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Wed Jan 9 08:34:11 2008 Subject: [Haskell-cafe] Re: ANN: A triple of new packages for talking to the outside world In-Reply-To: References: <396556a20801061554o3895ce88k87d4ecabc1860e7b@mail.gmail.com> <4781B50A.2060007@serpentine.com> <396556a20801071037t1b66e444u52abe1d934b7f902@mail.gmail.com> <47827AB4.60608@serpentine.com> <396556a20801081226l5ebf5062p685a80c6aac6ba41@mail.gmail.com> Message-ID: <1199885578.7279.119.camel@localhost> On Wed, 2008-01-09 at 09:26 +0000, Dominic Steinitz wrote: > Adam Langley imperialviolet.org> writes: > > > But if this is useful to you, make any requests. I'll (hopefully) do > > them, clean it up and push a new release of binary-strict. > > > How difficult would it be to have a getBits functions as well as a getBytes? > That would allow me drop the dependency on NewBinary in the ASN.1 package. The difficulty is in deciding what the api should be. Does it give you a real bitstream or only a byte aligned one? If I ask for 3 bits then 15 bytes what does it do? Does it assume I meant 3 bits, then pad to the next byte boundary and get 15 bytes, or does it mean get 15 bytes but at this 3 bit shift offset? Duncan From shenyute at gmail.com Wed Jan 9 09:40:55 2008 From: shenyute at gmail.com (Yu-Teh Shen) Date: Wed Jan 9 09:34:34 2008 Subject: [Haskell-cafe] Why purely in haskell? Message-ID: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> I got question about why haskell insist to be a purely FL. I mean is there any feature which is only support by pure? I mean maybe the program is much easier to prove? Or maybe we can cache some value for laziness. Could anyone give me some more information about why haskell needs to be pure. Thanks a lot. Shen, Yu-Teh From ndmitchell at gmail.com Wed Jan 9 09:55:53 2008 From: ndmitchell at gmail.com (Neil Mitchell) Date: Wed Jan 9 09:49:28 2008 Subject: [Haskell-cafe] Why purely in haskell? In-Reply-To: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> Message-ID: <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> Hi Shen, > I got question about why haskell insist to be a purely FL. I mean is > there any feature which is only support by pure? Laziness. It is very difficult to have a lazy language which is not pure. Laziness and purity together help with equational reasoning, compiler transformations, less obscure bugs, better compositionality etc. Thanks Neil From barsoap at web.de Wed Jan 9 09:57:39 2008 From: barsoap at web.de (Achim Schneider) Date: Wed Jan 9 09:51:22 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> Message-ID: <20080109155739.6b83cf13@solaris.tower> "Yu-Teh Shen" wrote: > I got question about why haskell insist to be a purely FL. I mean is > there any feature which is only support by pure? > I mean maybe the program is much easier to prove? Or maybe we can > cache some value for laziness. > Could anyone give me some more information about why haskell needs to > be pure. > To give a short answer: Because if pureness would be abandoned for easy implementation of feature X, features Y and Z would become completely awkward. The pureness is an ideological design decision basing on the assumption that pureness is ideal to ensure whole-system consistency. Most important is referential transparency, its lack of spooky side-effects and thus making global memoization of evaluation results feasible. In fact, the most obvious point really seems to be that getChar :: Char cant' be cached, though its type implies it, while getChar :: IO Char enshures that only the _action_ of getting a char can be cached, not the char itself. (and asking why and how the IO type does that opens a big can of worms) It's along the lines of "a value is an unary, static function that returns a value" vs. "an input function is an unary, dynamic function that returns a value" and the proper handling of the terms "static" and "dynamic" in every possible case. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From ithika at gmail.com Wed Jan 9 10:06:55 2008 From: ithika at gmail.com (Dougal Stanton) Date: Wed Jan 9 10:00:32 2008 Subject: [Haskell-cafe] Why purely in haskell? In-Reply-To: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> Message-ID: <2d3641330801090706m4ed9a927l282bb840a7dfcb7f@mail.gmail.com> On 09/01/2008, Yu-Teh Shen wrote: > I got question about why haskell insist to be a purely FL. I mean is > there any feature which is only support by pure? Have a look at the ueber-retrospective on Haskell, fifty-five pages of all the history and motivation one could possibly want. It's interesting reading, I promise! ;-) D. -- Dougal Stanton dougal@dougalstanton.net // http://www.dougalstanton.net From dominic.steinitz at blueyonder.co.uk Wed Jan 9 10:10:07 2008 From: dominic.steinitz at blueyonder.co.uk (Dominic Steinitz) Date: Wed Jan 9 10:03:51 2008 Subject: [Haskell-cafe] Re: ANN: A triple of new packages for talking tothe outside world References: <396556a20801061554o3895ce88k87d4ecabc1860e7b@mail.gmail.com> <4781B50A.2060007@serpentine.com> <396556a20801071037t1b66e444u52abe1d934b7f902@mail.gmail.com> <47827AB4.60608@serpentine.com> <396556a20801081226l5ebf5062p685a80c6aac6ba41@mail.gmail.com> <1199885578.7279.119.camel@localhost> Message-ID: Duncan Coutts worc.ox.ac.uk> writes: > > > On Wed, 2008-01-09 at 09:26 +0000, Dominic Steinitz wrote: > > Adam Langley imperialviolet.org> writes: > > > > > But if this is useful to you, make any requests. I'll (hopefully) do > > > them, clean it up and push a new release of binary-strict. > > > > > How difficult would it be to have a getBits functions as well as a getBytes? > > That would allow me drop the dependency on NewBinary in the ASN.1 package. > > The difficulty is in deciding what the api should be. Does it give you a > real bitstream or only a byte aligned one? If I ask for 3 bits then 15 > bytes what does it do? Does it assume I meant 3 bits, then pad to the > next byte boundary and get 15 bytes, or does it mean get 15 bytes but at > this 3 bit shift offset? > > Duncan > I'd suggest an aligned and unaligned api. So the aligned api would get 3 bits and the 15 bytes would start from the next byte boundary. The unaligned api would get 3 bits and the 15 bytes (=15 x 8 bits) would finish still with an offset of 3. Dominic. From moonlite at dtek.chalmers.se Wed Jan 9 10:17:54 2008 From: moonlite at dtek.chalmers.se (Mattias Bengtsson) Date: Wed Jan 9 10:11:35 2008 Subject: [Haskell-cafe] Why purely in haskell? In-Reply-To: <2d3641330801090706m4ed9a927l282bb840a7dfcb7f@mail.gmail.com> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <2d3641330801090706m4ed9a927l282bb840a7dfcb7f@mail.gmail.com> Message-ID: <1199891874.6707.56.camel@mben-desktop> On Wed, 2008-01-09 at 15:06 +0000, Dougal Stanton wrote: > Have a look at the ueber-retrospective on Haskell, fifty-five pages of > all the history and motivation one could possibly want. > > > > It's interesting reading, I promise! ;-) I actually think it was a really interesting read when i read it a year ago or so! :) From frr149 at easyjob.net Wed Jan 9 10:32:38 2008 From: frr149 at easyjob.net (Fernando Rodriguez) Date: Wed Jan 9 10:26:28 2008 Subject: [Haskell-cafe] Silly question: accessing a slot in a data type Message-ID: Hi, I'm writing a very simple address book. I defined the follwoing types for Contact and AddressBook: type Name= String type PhoneNumber= Integer data Contact = Contact {name :: Name, phone:: PhoneNumber} deriving Show -- The addressBook is a lista of Contacts data AddressBook= AddressBook [Contact] deriving Show -- Create a test one ag = Agenda [Contact "BillG" 618965332, Contact "Linus" 5897458] I wan't to write a function to search for a given phone by name and return a Maybe PhoneNumber. I know how to do this recursively on a "raw" list, but how do I access the list inside AddressBook? Also, how do I represent an AddressBook with an empty list and one with data on its list for my pattern matching? Thanks! From barsoap at web.de Wed Jan 9 10:36:01 2008 From: barsoap at web.de (Achim Schneider) Date: Wed Jan 9 10:29:44 2008 Subject: [Haskell-cafe] Re: Silly question: accessing a slot in a data type References: Message-ID: <20080109163601.69226633@solaris.tower> Fernando Rodriguez wrote: > > Hi, > > I'm writing a very simple address book. I defined the follwoing types > for Contact and AddressBook: > > type Name= String > type PhoneNumber= Integer > > data Contact = Contact {name :: Name, phone:: PhoneNumber} deriving > Show > > -- The addressBook is a lista of Contacts > data AddressBook= AddressBook [Contact] deriving Show > > -- Create a test one > ag = Agenda [Contact "BillG" 618965332, Contact "Linus" 5897458] > > I wan't to write a function to search for a given phone by name and > return a Maybe PhoneNumber. I know how to do this recursively on a > "raw" list, but how do I access the list inside AddressBook? Also, > how do I represent an AddressBook with an empty list and one with > data on its list for my pattern matching? > > Thanks! like this: manglePhone contact = contact { phone = ( 1 + phone contact ) } -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From barsoap at web.de Wed Jan 9 10:39:14 2008 From: barsoap at web.de (Achim Schneider) Date: Wed Jan 9 10:33:38 2008 Subject: [Haskell-cafe] Re: Silly question: accessing a slot in a data type References: Message-ID: <20080109163914.49cc6693@solaris.tower> Fernando Rodriguez wrote: > > Hi, > > I'm writing a very simple address book. I defined the follwoing types > for Contact and AddressBook: > > type Name= String > type PhoneNumber= Integer > > data Contact = Contact {name :: Name, phone:: PhoneNumber} deriving > Show > > -- The addressBook is a lista of Contacts > data AddressBook= AddressBook [Contact] deriving Show > > -- Create a test one > ag = Agenda [Contact "BillG" 618965332, Contact "Linus" 5897458] > > I wan't to write a function to search for a given phone by name and > return a Maybe PhoneNumber. I know how to do this recursively on a > "raw" list, but how do I access the list inside AddressBook? Also, > how do I represent an AddressBook with an empty list and one with > data on its list for my pattern matching? > > Thanks! Sorry, I meant to write something along the lines of bookHead :: AddressBook -> Contact bookHead (AddressBook (c:cs)) = c which isn't really useful. I think you want to say type AdressBook = [Contact] instead. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From bos at serpentine.com Wed Jan 9 10:41:41 2008 From: bos at serpentine.com (Bryan O'Sullivan) Date: Wed Jan 9 10:35:16 2008 Subject: [Haskell-cafe] US Homeland Security program language security risks In-Reply-To: <2608b8a80801090106k1c5a55d1v72b54e4ff7b1f322@mail.gmail.com> References: <5ae4f2ba0801031336x45b4c14dw34771cbc9ef0d3f4@mail.gmail.com> <1576558140.20080104021357@gmail.com> <2608b8a80801090106k1c5a55d1v72b54e4ff7b1f322@mail.gmail.com> Message-ID: <4784EB35.1040208@serpentine.com> Yitzchak Gale wrote: > Perhaps Coverity's interest could be > piqued if they were made aware of Haskell's emergence > as an important platform in security-sensitive > industries such as finance and chip design, and of > the significant influence that Haskell is having on the > design of all other major programming languages. During one of Simon PJ's tutorials at OSCON last year, a Coverity engineer was in the audience. He told us afterwards that he downloaded the GHC source and gave a try at analysing it while Simon talked. He didn't get far, of course; their software wasn't built for the tricks that -fvia-C plays. But they have at least one person who was that interested. However, it would cost several million dollars to produce a tool as slick as Coverity's for Haskell (Prevent is really very impressive). That would rival Coverity's R&D expenditure to date; they're a small company. I'd have a hard time believing that any such investment could be recouped through commercial sales within the next decade. References: <4784B80C.1070004@gmail.com> Message-ID: Now I see. Thanks David and Simon for the clarifications! =) -- Felipe. From bf3 at telenet.be Wed Jan 9 11:07:46 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Wed Jan 9 11:01:44 2008 Subject: [Haskell-cafe] GHC 6.8.2 as a library on Windows and GHCi Message-ID: <4784F152.5050101@telenet.be> I while I ago I sent an email regarding hs-plugins not working on windows. I now tried to directly use GHC API, but I also failed. The following program (which might be buggy, I copy/pasted from various sources) import DynFlags import GHC main = defaultErrorHandler defaultDynFlags $ do session <- newSession (Just "d:/app/ghc-6.8.2") flags <- getSessionDynFlags session (flags, _) <- parseDynamicFlags flags [] GHC.defaultCleanupHandler flags $ do setSessionDynFlags session flags{ hscTarget=HscInterpreted } prelude <- findModule session (mkModuleName "Prelude") Nothing setContext session [] [prelude] runStmt session "let n = 2 + 2" RunToCompletion -- n is bound runStmt session "n" RunToCompletion -- 4 is printed (note "it" is bound) gives the following error when run from GHCi *Main> :load "l:/test.hs" [1 of 1] Compiling Main ( l:/test.hs, interpreted ) Ok, modules loaded: Main. *Main> main GHCi runtime linker: fatal error: I found a duplicate definition for symbol _forkOS_entry whilst processing object file d:/app/ghc-6.8.2/lib\base-3.0.1.0/HSbase-3.0.1.0.o This could be caused by: * Loading two different object files which export the same symbol * Specifying the same object file twice on the GHCi command line * An incorrect `package.conf' entry, causing some object to be loaded twice. GHCi cannot safely continue in this situation. Exiting now. Sorry. Process haskell finished Is my code incorrect, or is this a (known?) bug in GHC 6.8.2 on Windows? I haven't tried the Linux version yet. NOTE: The program *does* run fine when compiling via GHC --make. Thanks, Peter -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080109/744f9a88/attachment.htm From gwern0 at gmail.com Wed Jan 9 11:23:58 2008 From: gwern0 at gmail.com (gwern0@gmail.com) Date: Wed Jan 9 11:19:12 2008 Subject: [Haskell-cafe] GHC 6.8.2 as a library on Windows and GHCi In-Reply-To: <4784F152.5050101@telenet.be> References: <4784F152.5050101@telenet.be> Message-ID: <20080109162358.GA19064@localhost> On 2008.01.09 17:07:46 +0100, Peter Verswyvelen scribbled 4.7K characters: > I while I ago I sent an email regarding hs-plugins not working on windows. > > I now tried to directly use GHC API, but I also failed. > > The following program (which might be buggy, I copy/pasted from various > sources) > > import DynFlags > import GHC > > main = defaultErrorHandler defaultDynFlags $ do > session <- newSession (Just "d:/app/ghc-6.8.2") > flags <- getSessionDynFlags session > (flags, _) <- parseDynamicFlags flags [] > GHC.defaultCleanupHandler flags $ do > setSessionDynFlags session flags{ hscTarget=HscInterpreted } > prelude <- findModule session (mkModuleName "Prelude") Nothing > setContext session [] [prelude] > runStmt session "let n = 2 + 2" RunToCompletion -- n is bound > runStmt session "n" RunToCompletion -- 4 is printed (note > "it" is bound) > > gives the following error when run from GHCi > *Main> :load "l:/test.hs" > [1 of 1] Compiling Main ( l:/test.hs, interpreted ) > Ok, modules loaded: Main. > *Main> main > > GHCi runtime linker: fatal error: I found a duplicate definition for > symbol > _forkOS_entry > whilst processing object file > d:/app/ghc-6.8.2/lib\base-3.0.1.0/HSbase-3.0.1.0.o > This could be caused by: > * Loading two different object files which export the same symbol > * Specifying the same object file twice on the GHCi command line > * An incorrect `package.conf' entry, causing some object to be > loaded twice. > GHCi cannot safely continue in this situation. Exiting now. Sorry. > > Process haskell finished > > Is my code incorrect, or is this a (known?) bug in GHC 6.8.2 on Windows? I > haven't tried the Linux version yet. > > NOTE: The program *does* run fine when compiling via GHC --make. > > Thanks, > Peter I think your installation is just buggy. I ran it here, and it compiles fine (although it doesn't run, as Linux obviously has "d:/app/ghc-6.8.2") and runs, printing "4" if I replace the string with "/usr/lib/ghc-6.8.2". Could it be that your GHCi is not the 6.8.2 one, or your path incorrect? -- gwern & b AHPCRC Playboy Dolch += SG530 Karimov CNCIS beef -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080109/1c425db5/attachment.bin From isaacdupree at charter.net Wed Jan 9 11:29:46 2008 From: isaacdupree at charter.net (Isaac Dupree) Date: Wed Jan 9 11:23:31 2008 Subject: [Haskell-cafe] US Homeland Security program language security risks In-Reply-To: <4784EB35.1040208@serpentine.com> References: <5ae4f2ba0801031336x45b4c14dw34771cbc9ef0d3f4@mail.gmail.com> <1576558140.20080104021357@gmail.com> <2608b8a80801090106k1c5a55d1v72b54e4ff7b1f322@mail.gmail.com> <4784EB35.1040208@serpentine.com> Message-ID: <4784F67A.1060806@charter.net> Bryan O'Sullivan wrote: > Yitzchak Gale wrote: > >> Perhaps Coverity's interest could be >> piqued if they were made aware of Haskell's emergence >> as an important platform in security-sensitive >> industries such as finance and chip design, and of >> the significant influence that Haskell is having on the >> design of all other major programming languages. > > During one of Simon PJ's tutorials at OSCON last year, a Coverity > engineer was in the audience. He told us afterwards that he downloaded > the GHC source and gave a try at analysing it while Simon talked. He > didn't get far, of course; their software wasn't built for the tricks > that -fvia-C plays. But they have at least one person who was that > interested. unregisterised, it should be standard C without tricks, though still nothing like ordinary C and therefore possibly not analyzable ~Isaac From bf3 at telenet.be Wed Jan 9 11:58:04 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Wed Jan 9 11:52:03 2008 Subject: [Haskell-cafe] GHC 6.8.2 as a library on Windows and GHCi In-Reply-To: <20080109162358.GA19064@localhost> References: <4784F152.5050101@telenet.be> <20080109162358.GA19064@localhost> Message-ID: <4784FD1C.1020007@telenet.be> gwern0@gmail.com wrote: > I think your installation is just buggy. I ran it here, and it compiles fine (although it doesn't run, as Linux obviously has "d:/app/ghc-6.8.2") and runs, printing "4" if I replace the string with "/usr/lib/ghc-6.8.2". Could it be that your GHCi is not the 6.8.2 one, or your path incorrect? > Interesting... But I don't see what could be wrong with my installation. I just downloaded and installed the binary installer from the Internet. I did have to expose the package ghc before GHCi could compile my code. I also just tried a clean install of GHC-6.8.2 on a brand new Windows XP SP2 system (that never had any GHC nor GCC nor MINGW installed before), but that also gives the same error. So I guess it runs fine on Linux (as you tested), but not on Windows? Thanks, Peter From cetin.sert at gmail.com Wed Jan 9 12:17:13 2008 From: cetin.sert at gmail.com (Cetin Sert) Date: Wed Jan 9 12:11:14 2008 Subject: [Haskell-cafe] Problems with Unicode Symbols as Infix Function Names in Propositional Calculus Haskell DSL Message-ID: I want to design a DSL in Haskell for propositional calculus. But instead of using natural language names for functions like or, and, implies etc. I want to use Unicode symbols as infix functions ?, ?, ?, ?, ? But I keep getting error messages from the GHC parser. Is there a way to make GHC parse my source files correctly? If it is not possible yet, please consider this as a ?feature request?. Best Regards, Cetin Sert INF 521, 4-6-2 69120 Heidelberg Germany http://www.corsis.de -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080109/92ebb756/attachment.htm From dons at galois.com Wed Jan 9 12:24:17 2008 From: dons at galois.com (Don Stewart) Date: Wed Jan 9 12:18:01 2008 Subject: [Haskell-cafe] Problems with Unicode Symbols as Infix Function Names in Propositional Calculus Haskell DSL In-Reply-To: References: Message-ID: <20080109172417.GA29140@scytale.galois.com> cetin.sert: > I want to design a DSL in Haskell for propositional calculus. But instead > of using natural language names for functions like or, and, implies etc. I > want to use Unicode symbols as infix functions NOT, *, *, ->, <-> But I > keep getting error messages from the GHC parser. Is there a way to make > GHC parse my source files correctly? If it is not possible yet, please > consider this as a "feature request". > > > The "survey of Haskell unicode support" might have some advice, http://blog.kfish.org/2007/10/survey-haskell-unicode-support.html See also -XUnicodeSyntax for enabling unicode keywords for -> <- forall et al. This is turning into an FAQ, so clarifying the unicode support in the GHC user's guide would be a good result. -- Don From felipe.lessa at gmail.com Wed Jan 9 12:24:30 2008 From: felipe.lessa at gmail.com (Felipe Lessa) Date: Wed Jan 9 12:18:09 2008 Subject: [Haskell-cafe] Problems with Unicode Symbols as Infix Function Names in Propositional Calculus Haskell DSL In-Reply-To: References: Message-ID: On Jan 9, 2008 3:17 PM, Cetin Sert wrote: > I want to design a DSL in Haskell for propositional calculus. But instead of > using natural language names for functions like or, and, implies etc. I want > to use Unicode symbols as infix functions ?, ?, ?, ?, ? I guess you can't do anything for ?, as it is a prefix function. But for the others, what is wrong with e.g. (\/), (/\), (-->) and (<->)? You could write things like 'a /\ b --> c'. -- Felipe. From tora at zonetora.co.uk Wed Jan 9 12:33:59 2008 From: tora at zonetora.co.uk (Tristan Allwood) Date: Wed Jan 9 12:27:36 2008 Subject: [Haskell-cafe] Problems with Unicode Symbols as Infix Function Names in Propositional Calculus Haskell DSL In-Reply-To: References: Message-ID: <20080109173359.GA32610@doc.ic.ac.uk> Hi, Attached works fine for me (ghc 6.8.2) You'll have trouble with ? though, as ghc steals that symbol for type signature declarations. A ghc expert could probably shed more light; Cheers, Tris GHCi also doesn't (at least for me) print symbol names correctly, but that's a different issue. >ghci Bloop.hs GHCi, version 6.8.2: http://www.haskell.org/ghc/ :? for help Loading package base ... linking ... done. [1 of 1] Compiling Main ( Bloop.hs, interpreted ) Ok, modules loaded: Main. *Main> :browse (?) :: Bool -> Bool (? :: Bool -> Bool -> Bool (? :: Bool -> Bool -> Bool (?) :: Bool -> Bool -> Bool *Main> False ? True True On Wed, Jan 09, 2008 at 06:17:13PM +0100, Cetin Sert wrote: > I want to design a DSL in Haskell for propositional calculus. But instead of using natural language names for functions like or, and, implies etc. I want to use Unicode symbols as infix functions ?, ?, ?, ?, ? But I keep getting error messages from the GHC parser. Is there a way to make GHC parse my source files correctly? If it is not possible yet, please consider this as a ?feature request?. > > > > Best Regards, > > Cetin Sert > > INF 521, 4-6-2 > > 69120 Heidelberg > > Germany > > > > http://www.corsis.de > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe -- Tristan Allwood PhD Student Department of Computing Imperial College London -------------- next part -------------- A non-text attachment was scrubbed... Name: Bloop.hs Type: text/x-haskell Size: 207 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080109/5756709a/Bloop.bin From cetin.sert at gmail.com Wed Jan 9 12:34:53 2008 From: cetin.sert at gmail.com (Cetin Sert) Date: Wed Jan 9 12:28:55 2008 Subject: [Haskell-cafe] Problems with Unicode Symbols as Infix Function Names in Propositional Calculus Haskell DSL In-Reply-To: <20080109172417.GA29140@scytale.galois.com> References: <20080109172417.GA29140@scytale.galois.com> Message-ID: Neither appending "{-# OPTIONS_GHC -fglasgow-exts -xunicodesyntax #-}" at the beginning of a .hs source file in Visual Haskell nor setting the ghc options from the project properties seems to solve the problem. I keep getting "Error 1 lexical error (UTF-8 decoding error) C:\Users\Sert\Lab\Haskell\HaskellApp1\HaskellApp1\src\Explogic.hs Line 25 Column 2 " in the IDE. Maybe this is Visual Haskell-specific o_O!? -- not (?) :: P a => a -> Bool (?) a | g a = False | otherwise = True Best Regards, Cetin Sert -----Original Message----- From: Don Stewart [mailto:dons@galois.com] Sent: Mittwoch, 9. Januar 2008 18:24 To: Cetin Sert Cc: Haskell-Cafe@haskell.org Subject: Re: [Haskell-cafe] Problems with Unicode Symbols as Infix Function Names in Propositional Calculus Haskell DSL cetin.sert: > I want to design a DSL in Haskell for propositional calculus. But instead > of using natural language names for functions like or, and, implies etc. I > want to use Unicode symbols as infix functions NOT, *, *, ->, <-> But I > keep getting error messages from the GHC parser. Is there a way to make > GHC parse my source files correctly? If it is not possible yet, please > consider this as a "feature request". > > > The "survey of Haskell unicode support" might have some advice, http://blog.kfish.org/2007/10/survey-haskell-unicode-support.html See also -XUnicodeSyntax for enabling unicode keywords for -> <- forall et al. This is turning into an FAQ, so clarifying the unicode support in the GHC user's guide would be a good result. -- Don From derek.a.elkins at gmail.com Wed Jan 9 11:43:41 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Wed Jan 9 12:37:44 2008 Subject: [Haskell-cafe] Why purely in haskell? In-Reply-To: <2d3641330801090706m4ed9a927l282bb840a7dfcb7f@mail.gmail.com> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <2d3641330801090706m4ed9a927l282bb840a7dfcb7f@mail.gmail.com> Message-ID: <1199897022.18821.24.camel@derek-laptop> On Wed, 2008-01-09 at 15:06 +0000, Dougal Stanton wrote: > On 09/01/2008, Yu-Teh Shen wrote: > > I got question about why haskell insist to be a purely FL. I mean is > > there any feature which is only support by pure? > > Have a look at the ueber-retrospective on Haskell, fifty-five pages of > all the history and motivation one could possibly want. > > > > It's interesting reading, I promise! ;-) A shorter and lighter and and also interesting and entertaining read is: http://research.microsoft.com/~simonpj/Papers/haskell-retrospective/index.htm While the reason Haskell was pure was to support laziness, at this point though it's safe to say Haskell "insists" on being pure no more than water "insists" on being wet. From miguelimo38 at yandex.ru Wed Jan 9 13:05:32 2008 From: miguelimo38 at yandex.ru (Miguel Mitrofanov) Date: Wed Jan 9 12:59:29 2008 Subject: [Haskell-cafe] Silly question: accessing a slot in a data type In-Reply-To: References: Message-ID: <8F84D3B2-6F89-43D8-8D7B-7D301AAE7F42@yandex.ru> > Also, how do I represent an AddressBook with an empty list and one > with data on its list for my pattern matching? phoneLookup (AddressBook []) = Nothing From frr149 at easyjob.net Wed Jan 9 13:15:33 2008 From: frr149 at easyjob.net (Fernando Rodriguez) Date: Wed Jan 9 13:09:18 2008 Subject: [Haskell-cafe] Trouble with function with two clauses Message-ID: Hi, I have the following type and function: data ConsCell a = Nil | Cons a (ConsCell a) deriving Show head' Nil = Nothing head' (Cons a _) = Just a Works fine, however, what's wrong with the following function? head'' | Nil = Nothing | Cons a _ = Just a Thanks! From frr149 at easyjob.net Wed Jan 9 13:18:14 2008 From: frr149 at easyjob.net (Fernando Rodriguez) Date: Wed Jan 9 13:13:40 2008 Subject: [Haskell-cafe] Re: Silly question: accessing a slot in a data type References: <8F84D3B2-6F89-43D8-8D7B-7D301AAE7F42@yandex.ru> Message-ID: Hello Miguel, >> Also, how do I represent an AddressBook with an empty list and one >> with data on its list for my pattern matching? >> > phoneLookup (AddressBook []) = Nothing Thanks. From blancolioni at gmail.com Wed Jan 9 13:42:20 2008 From: blancolioni at gmail.com (Fraser Wilson) Date: Wed Jan 9 13:35:54 2008 Subject: [Haskell-cafe] Trouble with function with two clauses In-Reply-To: References: Message-ID: In head'', what is being compared to Nil? The guards of a function are a series of Boolean expressions; but in your example they are of type ConsCell a. The difference is that in a pattern, the structure of the argument is matched; in a guard, an arbitrary expression is evaluated. I have always found the Haskell report instructive in these cases; particularly the transformations into the core language -- in this case see section 4.4.3.2 (http://haskell.org/onlinereport/decls.html#sect4.4.3.2); this should make it clear why head'' is not valid Haskell. cheers, Fraser. Guards are really a series of Boolean equations, and the first that evaluates to true On Jan 9, 2008 7:15 PM, Fernando Rodriguez < frr149@easyjob.net> wrote: > > Hi, > > I have the following type and function: > > data ConsCell a = Nil | Cons a (ConsCell a) deriving Show > head' Nil = Nothing > head' (Cons a _) = Just a > > Works fine, however, what's wrong with the following function? > > head'' > | Nil = Nothing > | Cons a _ = Just a > > Thanks! > > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080109/0bf535fb/attachment.htm From rendel at rbg.informatik.tu-darmstadt.de Wed Jan 9 13:44:42 2008 From: rendel at rbg.informatik.tu-darmstadt.de (Tillmann Rendel) Date: Wed Jan 9 13:38:37 2008 Subject: [Haskell-cafe] Trouble with function with two clauses In-Reply-To: References: Message-ID: <4785161A.5090506@rbg.informatik.tu-darmstadt.de> Fernando Rodriguez wrote: > data ConsCell a = Nil | Cons a (ConsCell a) deriving Show > head' Nil = Nothing > head' (Cons a _) = Just a > > Works fine, however, what's wrong with the following function? > > head'' | Nil = Nothing > | Cons a _ = Just a You cannot use | as a general shortcut in function definitions as you try here. The stroke is instead used to express different branches selected by boolean expressions: headIfNotZero Nil = Nothing headIfNotZero (Cons a) | a == 0 = Nothing | otherwise = Just a In this definition, (a == 0) and (otherwise) are boolean expressions. GHCi, version 6.8.1: http://www.haskell.org/ghc/ :? for help Loading package base ... linking ... done. Prelude> otherwise True But in your definition of head'', Nil and (Cons a) are Patterns, not boolean expressions, so it doesnt work out. If you don't like to write out the name of the function you want to define over and over again, you can use an explicit case statement: head''' x = case x of Nil -> Nothing Cons a _ -> Just a This is sometimes easier to read, but in this case, I would use your head' definition. Tillmann From gwern0 at gmail.com Wed Jan 9 13:47:33 2008 From: gwern0 at gmail.com (gwern0@gmail.com) Date: Wed Jan 9 13:42:14 2008 Subject: [Haskell-cafe] Trouble with function with two clauses In-Reply-To: References: Message-ID: <20080109184733.GA23140@localhost> On 2008.01.09 18:15:33 +0000, Fernando Rodriguez scribbled 0.3K characters: > > Hi, > > I have the following type and function: > > data ConsCell a = Nil | Cons a (ConsCell a) deriving Show > head' Nil = Nothing > head' (Cons a _) = Just a > > Works fine, however, what's wrong with the following function? > > head'' | Nil = Nothing > | Cons a _ = Just a > > Thanks! Couple of things. Your head'' is trying to use pattern-matching, but guards (which are what you are actually using) require a Bool expression on the left hand side; guards just desugar into if-then-else clauses. In this case it'd look something like > head'' a = if Nil then Nothing else if Cons a _ then Just a else ??? This doesn't make sense. Nil is just Nil, it's not in Bool; the if can't do anything with that. Similarly, Cons a _ is just ConsCell and in the Show typeclass; it too is not Bool. If we turn it into pattern-matching: > head'' Nil = Nothing > head'' Cons a _ = Just a But this still doesn't work - one definition takes a single argument, and the other 3; Nil (1), vs [Cons, a, _] (3). So: head'' Nil = Nothing head'' (Cons a _) = Just a Parentheses force the Cons to be seen as a single argument. So I guess your final product would look like this, which is pretty much what you start out with. > data ConsCell a = Nil | Cons a (ConsCell a) deriving Show > > head' :: ConsCell a -> Maybe a > head' Nil = Nothing > head' (Cons a _) = Just a -- gwern Hackers Emerson EO SAS Majic CANSLO rail ABC CFD RSOC -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080109/f11d1d00/attachment.bin From sethg at ropine.com Wed Jan 9 13:59:35 2008 From: sethg at ropine.com (Seth Gordon) Date: Wed Jan 9 13:53:14 2008 Subject: [Haskell-cafe] Re: US Homeland Security program language security risks In-Reply-To: <200801061619.31146.daniel.is.fischer@web.de> References: <5ae4f2ba0801031336x45b4c14dw34771cbc9ef0d3f4@mail.gmail.com> <200801061538.58319.daniel.is.fischer@web.de> <20080106155400.7b733dd8@solaris.tower> <200801061619.31146.daniel.is.fischer@web.de> Message-ID: <47851997.6010201@ropine.com> Daniel Fischer wrote: > Am Sonntag, 6. Januar 2008 15:54 schrieb Achim Schneider: >> That's an interesting task: Design a non-touring complete, >> restricted language in which every expression is decidable, without >> making the language unusable for usual programming problems. > > I'm not a logician, but didn't G?del prove that you couldn't express the > (full) arithmetic of natural numbers in such a language? What if you restricted yourself to the arithmetic of natural numbers modulo 2^64? From lemming at henning-thielemann.de Wed Jan 9 14:49:18 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Wed Jan 9 14:42:55 2008 Subject: [Haskell-cafe] Trouble with function with two clauses In-Reply-To: References: Message-ID: On Wed, 9 Jan 2008, Fernando Rodriguez wrote: > I have the following type and function: > > data ConsCell a = Nil | Cons a (ConsCell a) deriving Show > head' Nil = Nothing > head' (Cons a _) = Just a > > Works fine, however, what's wrong with the following function? > > head'' > | Nil = Nothing > | Cons a _ = Just a Maybe you want head''' x = case x of Nil -> Nothing Cons a _ -> Just a From babo.online at gmail.com Wed Jan 9 15:45:08 2008 From: babo.online at gmail.com (Attila Babo) Date: Wed Jan 9 15:38:43 2008 Subject: [Haskell-cafe] GHC 6.8.2 as a library on Windows and GHCi In-Reply-To: <4784FD1C.1020007@telenet.be> References: <4784F152.5050101@telenet.be> <20080109162358.GA19064@localhost> <4784FD1C.1020007@telenet.be> Message-ID: <597c69660801091245tccd91bfid1b5f7b98d66d7c3@mail.gmail.com> Using ghci your code is fine under Linux, but fails on Windows, even with a daily snapshot from today. It's OK when compiling with ghc on both platforms. From bf3 at telenet.be Wed Jan 9 15:50:35 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Wed Jan 9 15:44:33 2008 Subject: [Haskell-cafe] Why purely in haskell? In-Reply-To: <1199897022.18821.24.camel@derek-laptop> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <2d3641330801090706m4ed9a927l282bb840a7dfcb7f@mail.gmail.com> <1199897022.18821.24.camel@derek-laptop> Message-ID: <4785339B.7050308@telenet.be> Derek Elkins wrote: > A shorter and lighter and and also interesting and entertaining read is: > http://research.microsoft.com/~simonpj/Papers/haskell-retrospective/index.htm Just read it, quoting: `Tony Hoare?s comment: ?I fear that Haskell is doomed to succeed?` LOL! Very good stuff If Haskell wasn't pure, I would not spent so much time trying to bend my over-imperative mind to it. I had it with impure languages, way to tricky. Those languages were nice when I was young & reckless :) But I'm amazed that impure (albeit strong) languages like LISP and Scheme are still used for projects... I mean, in Scheme you can "set!" the addition operator to become a multiplication operator at runtime, modifying global behavior... Now that's a side effect, C/C++ is nothing compared to that! So I guess that with such great power comes great responsibility? Peter From barsoap at web.de Wed Jan 9 15:56:25 2008 From: barsoap at web.de (Achim Schneider) Date: Wed Jan 9 15:50:18 2008 Subject: [Haskell-cafe] Re: GHC 6.8.2 as a library on Windows and GHCi References: <4784F152.5050101@telenet.be> <20080109162358.GA19064@localhost> <4784FD1C.1020007@telenet.be> <597c69660801091245tccd91bfid1b5f7b98d66d7c3@mail.gmail.com> Message-ID: <20080109215625.38f22d10@solaris.tower> "Attila Babo" wrote: > Using ghci your code is fine under Linux, but fails on Windows, even > with a daily snapshot from today. It's OK when compiling with ghc on > both platforms. > I think it is time for peter to become acquainted with the readline package and write a custom repl. Or just copy half of ghci into a module and call it. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From mad.one at gmail.com Wed Jan 9 16:13:48 2008 From: mad.one at gmail.com (Austin Seipp) Date: Wed Jan 9 16:08:47 2008 Subject: [Haskell-cafe] GHC 6.8.2 as a library on Windows and GHCi In-Reply-To: <4784F152.5050101@telenet.be> References: <4784F152.5050101@telenet.be> Message-ID: <1199912018-sup-7263@continuum> Excerpts from Peter Verswyvelen's message of Wed Jan 09 10:07:46 -0600 2008: > Is my code incorrect, or is this a (known?) bug in GHC 6.8.2 on Windows? > I haven't tried the Linux version yet. The same thing happens on my Windows XP box as it does with yours. On both windows and my linux box, ghc --make works fine, and on linux with ghci, it works fine but not on windows (and fails with the exact same error.) Just from a general idea I would say that the reason would be related to the linker loading base twice: once when ghci itself is started, and the second time when you actually call into the ghc api; setSessionDynFlags will give your session knowledge of all installed packages, so when you're actually executing code using runStmt it may reload the object file into an address space where it already resides. GHCi only has one symbol table in its address space, so loading twice will naturally cause clashes. This seems slightly related to the fact that, you can't do similar with hs-plugins as it directly interfaces with the runtime linker and therefore you must always compile your apps that use hs-plugins rather than loading them into ghci. Why this would only occur on Windows and not linux though, I have no idea. It seems a bug report is well in order. I'm probably just talking nonsense though; I guess you'll just have to make due with ghc --make! Sorry I couldn't further help, you may get more info by asking a ghc guru. - Austin -- "It was in the days of the rains that their prayers went up, not from the fingering of knotted prayer cords or the spinning of prayer wheels, but from the great pray-machine in the monastery of Ratri, goddess of the Night." Roger Zelazny From anton at appsolutions.com Wed Jan 9 16:18:36 2008 From: anton at appsolutions.com (Anton van Straaten) Date: Wed Jan 9 16:11:29 2008 Subject: [Haskell-cafe] Why purely in haskell? In-Reply-To: <4785339B.7050308@telenet.be> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <2d3641330801090706m4ed9a927l282bb840a7dfcb7f@mail.gmail.com> <1199897022.18821.24.camel@derek-laptop> <4785339B.7050308@telenet.be> Message-ID: <47853A2C.2060508@appsolutions.com> Peter Verswyvelen wrote: > But I'm amazed that impure (albeit strong) languages like LISP and > Scheme are still used for projects... I mean, in Scheme you can "set!" > the addition operator to become a multiplication operator at runtime, > modifying global behavior... Now that's a side effect, C/C++ is nothing > compared to that! So I guess that with such great power comes great > responsibility? Scheme and Lisp typically constrain this feature in various ways, ranging from compiler options and declarations to, more recently, features of a module system. For example, in R6RS Scheme, variables and syntax imported via the module system cannot be mutated, so the denotation of a name (including names like "+") can be statically determined. OTOH, the freedom to change things on the fly can be nice to have, and if used with "great responsibility" (mainly an understanding of what's safe to do and what isn't), the downside can be vanishingly small. Anton From apfelmus at quantentunnel.de Wed Jan 9 16:18:17 2008 From: apfelmus at quantentunnel.de (apfelmus) Date: Wed Jan 9 16:12:08 2008 Subject: [Haskell-cafe] Re: Difference lists and ShowS In-Reply-To: <477D60F6.5090408@vex.net> References: <20080103105916.7d562d17@solaris.tower> <20080103120847.13725ce6@solaris.tower> <477CD9E0.6060604@charter.net> <20080103154115.28a84ce3@solaris.tower> <477D60F6.5090408@vex.net> Message-ID: Albert Y. C. Lai wrote: > apfelmus wrote: >> I don't know a formalism for easy reasoning about time in a lazy >> language. Anyone any pointers? Note that the problem is already >> present for difference lists in strict languages. > > http://homepages.inf.ed.ac.uk/wadler/topics/strictness-analysis.html > > especially "strictness analysis aids time analysis". Ah, of course, thanks. Together with D. Sands. Complexity Analysis for a Lazy Higher-Order Language. http://citeseer.ist.psu.edu/291589.html for the higher-order case, a satisfactory analysis can be put together. The formalism is basically as follows: for a function f, let f^T denote the time needed to execute it to weak normal form given that it's arguments are already in weak normal form. Weak normal form = full normal form for algebraic values and lambda-abstraction for functions = what you'd expect in a strict language. Plain values = nullary functions. For instance (++)^T [] ys = 1 + ys^T = 1 (++)^T (x:xs) ys = 1 + (x:(xs ++ ys))^T = 1 + (++)^T xs ys + xs^T + ys^T -- (:) is free = 1 + (++)^T xs ys ==> (++)^T xs ys = O(length xs) Substituting a function application by the function body is counted as 1 time step, that's where the 1 + comes from. For difference lists, we have (.)^T f g = O(1) since it immediately returns the lambda-abstraction \x -> f(g x) . Now, we missed something important about difference lists namely the function toList f = f [] that turns a difference list into an ordinary list and this function is O(n). In contrast, The "pendant" for ordinary lists, i.e. the identity function, is only O(1). Why is it O(n)? Well, (.) itself may be O(1) but it constructs a function that needs lots of time to run. In particular (f . g)^T [] = ((\x->f (g x))[])^T = 1 + (f (g []))^T = 1 + f^T (g []) + (g [])^T = 1 + f^T (g []) + g^T [] So, to analyze higher-order functions, we simply have to keep track of the "size" of the returned functions (more precisely, Sands uses "cost-closures"). The above reduces to (f . g)^T [] = 1 + f^T [] + g^T [] Since our difference lists don't care of what they are prepended to f^T xs = f^T [] Cheating a bit with the notation, we can write toList^T (f . g) = 1 + toList^T f + toList^T g This means that a difference list build out of n elements by m applications of (.) will take O(n + m) time. This is the same as O(m) because m >= n , our lists are concatenations of singletons. That's not O(n) as anticipated, but it's alright: a concatenation of m empty lists is empty but clearly takes O(m) time, so the number of concatenations matters. Since difference lists offer such a good concatenation, why not replace ordinary lists entirely? Well, the problem is that we have another function that should run fast, namely head . For ordinary lists, head^T xs = O(1) but for difference lists, we have (head . toList)^T f = O(m) which is >= O(n) in the worst case, lazy evaluation notwithstanding. How to analyze lazy evaluation? Wadler's approach is to add an extra argument to every expression which says how much of the expression is to be evaluated. This extra information can be encoded via projections. But I think it's sufficient here to let (head expr)^T symbolize the time to reduce expr to weak head normal form. For example, (head . toList)^T (f . g) = 1 + (head . toList)^T f assuming that f is nonempty. But due to the 1 + , any left-nested composition like head . toList $ (((a . b) . c) . d) . e still needs O(m) time. So, difference lists are no "eierlegende wollmilchsau" either. Regards, apfelmus From dons at galois.com Wed Jan 9 16:21:04 2008 From: dons at galois.com (Don Stewart) Date: Wed Jan 9 16:14:48 2008 Subject: [Haskell-cafe] Why purely in haskell? In-Reply-To: <47853A2C.2060508@appsolutions.com> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <2d3641330801090706m4ed9a927l282bb840a7dfcb7f@mail.gmail.com> <1199897022.18821.24.camel@derek-laptop> <4785339B.7050308@telenet.be> <47853A2C.2060508@appsolutions.com> Message-ID: <20080109212104.GD29472@scytale.galois.com> anton: > OTOH, the freedom to change things on the fly can be nice to have, and > if used with "great responsibility" (mainly an understanding of what's > safe to do and what isn't), the downside can be vanishingly small. It can be small, unless you need to have any kind of static assurance (say for high assurance software, or for new kinds of optimisations, or if you want to reorder code in the compiler for parallelism). Then the downside to arbitrary, untracked effects in the system is huge. -- Don From g9ks157k at acme.softbase.org Wed Jan 9 16:23:05 2008 From: g9ks157k at acme.softbase.org (Wolfgang Jeltsch) Date: Wed Jan 9 16:16:44 2008 Subject: [Haskell-cafe] Problems with Unicode Symbols as Infix Function Names in Propositional Calculus Haskell DSL In-Reply-To: References: <20080109172417.GA29140@scytale.galois.com> Message-ID: <200801092223.06129.g9ks157k@acme.softbase.org> Am Mittwoch, 9. Januar 2008 18:34 schrieb Cetin Sert: > Neither appending "{-# OPTIONS_GHC -fglasgow-exts -xunicodesyntax #-}" First, I think, you have to use -XUnicodeSyntax (as Don said), and not -xunicodesyntax. Second, -XUnicodeSyntax only enables alternative notation for certain built-in syntax (as Don said). Unicode for operators is a different matter. I?d think, it should work out of the box and wonder a bit why it doesn?t. > [?] Best wishes, Wolfgang From g9ks157k at acme.softbase.org Wed Jan 9 16:29:28 2008 From: g9ks157k at acme.softbase.org (Wolfgang Jeltsch) Date: Wed Jan 9 16:23:06 2008 Subject: [Haskell-cafe] Problems with Unicode Symbols as Infix Function Names in Propositional Calculus Haskell DSL In-Reply-To: References: Message-ID: <200801092229.29048.g9ks157k@acme.softbase.org> Am Mittwoch, 9. Januar 2008 18:24 schrieb Felipe Lessa: > [?] > But for the others, what is wrong with e.g. (\/), (/\), (-->) and (<->)? These are not the true symbols. They look ugly compared to the real ones. Nice typography is a great thing! > You could write things like 'a /\ b --> c'. With Cetin?s approach you could write things like ?a ? b ? c?. Doesn?t this look a lot better? :-) Best wishes, Wolfgang From bf3 at telenet.be Wed Jan 9 16:30:22 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Wed Jan 9 16:23:54 2008 Subject: [Haskell-cafe] Re: GHC 6.8.2 as a library on Windows and GHCi In-Reply-To: <20080109215625.38f22d10@solaris.tower> References: <4784F152.5050101@telenet.be> <20080109162358.GA19064@localhost> <4784FD1C.1020007@telenet.be> <597c69660801091245tccd91bfid1b5f7b98d66d7c3@mail.gmail.com> <20080109215625.38f22d10@solaris.tower> Message-ID: <007601c85306$d784e860$868eb920$@be> > I think it is time for peter to become acquainted with the readline > package and write a custom repl. No no, I already did that, a long time ago, in 68000 assembly :) > Or just copy half of ghci into a module and call it. I'm just interested in seeing if the interpreter/compiler/linker infrastructure can be used as a library on both Linux/Windows/OSX, and for creating plugins at runtime. When using Microsoft's C#/.NET I used that a lot. On that platform it is very easy to generate code on the fly, call the C# compiler, emit code, load code, creating "plugins". But Microsoft.NET does not support Haskell :( F# is a good step forward, but it's not lazy, and I am. From anton at appsolutions.com Wed Jan 9 16:59:18 2008 From: anton at appsolutions.com (Anton van Straaten) Date: Wed Jan 9 16:52:15 2008 Subject: [Haskell-cafe] Why purely in haskell? In-Reply-To: <20080109212104.GD29472@scytale.galois.com> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <2d3641330801090706m4ed9a927l282bb840a7dfcb7f@mail.gmail.com> <1199897022.18821.24.camel@derek-laptop> <4785339B.7050308@telenet.be> <47853A2C.2060508@appsolutions.com> <20080109212104.GD29472@scytale.galois.com> Message-ID: <478543B6.4040907@appsolutions.com> Don Stewart wrote: > anton: >> OTOH, the freedom to change things on the fly can be nice to have, and >> if used with "great responsibility" (mainly an understanding of what's >> safe to do and what isn't), the downside can be vanishingly small. > > It can be small, unless you need to have any kind of static assurance > (say for high assurance software, or for new kinds of optimisations, or > if you want to reorder code in the compiler for parallelism). > > Then the downside to arbitrary, untracked effects in the system is huge. Oh dear - I'm going to have to rethink the paper I was working on, provisionally titled "In defense of arbitrary untracked effects in high assurance software." ;) But by "can be vanishingly small", I definitely meant something like "in cases where it's technically and economically appropriate". Anton From daveroundy at gmail.com Wed Jan 9 17:15:18 2008 From: daveroundy at gmail.com (David Roundy) Date: Wed Jan 9 17:08:54 2008 Subject: [Haskell-cafe] Why purely in haskell? In-Reply-To: <20080109212104.GD29472@scytale.galois.com> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <2d3641330801090706m4ed9a927l282bb840a7dfcb7f@mail.gmail.com> <1199897022.18821.24.camel@derek-laptop> <4785339B.7050308@telenet.be> <47853A2C.2060508@appsolutions.com> <20080109212104.GD29472@scytale.galois.com> Message-ID: <117f2cc80801091415x643bec1cmf09931d4d16d59e5@mail.gmail.com> On Jan 9, 2008 4:21 PM, Don Stewart wrote: > anton: > > OTOH, the freedom to change things on the fly can be nice to have, and > > if used with "great responsibility" (mainly an understanding of what's > > safe to do and what isn't), the downside can be vanishingly small. > > It can be small, unless you need to have any kind of static assurance > (say for high assurance software, or for new kinds of optimisations, or > if you want to reorder code in the compiler for parallelism). > > Then the downside to arbitrary, untracked effects in the system is huge. I just want to point out that unsafePerformIO is at the core of the (safe) bytestring library. As SPJ et al pointed out, this is crucial functionality, and is only unsafe if unsafely used. (Yes, it's unsafe, but you can write a safe module with a purely safe interface that uses unsafePerformIO in its core.) David From daveroundy at gmail.com Wed Jan 9 17:25:28 2008 From: daveroundy at gmail.com (David Roundy) Date: Wed Jan 9 17:19:04 2008 Subject: [Haskell-cafe] Re: ANN: A triple of new packages for talking tothe outside world In-Reply-To: References: <396556a20801061554o3895ce88k87d4ecabc1860e7b@mail.gmail.com> <4781B50A.2060007@serpentine.com> <396556a20801071037t1b66e444u52abe1d934b7f902@mail.gmail.com> <47827AB4.60608@serpentine.com> <396556a20801081226l5ebf5062p685a80c6aac6ba41@mail.gmail.com> <1199885578.7279.119.camel@localhost> Message-ID: <117f2cc80801091425l41b73ea3uddda3d91ba9405e7@mail.gmail.com> On Jan 9, 2008 10:10 AM, Dominic Steinitz wrote: > Duncan Coutts worc.ox.ac.uk> writes: > > The difficulty is in deciding what the api should be. Does it give you a > > real bitstream or only a byte aligned one? If I ask for 3 bits then 15 > > bytes what does it do? Does it assume I meant 3 bits, then pad to the > > next byte boundary and get 15 bytes, or does it mean get 15 bytes but at > > this 3 bit shift offset? > > I'd suggest an aligned and unaligned api. > > So the aligned api would get 3 bits and the 15 bytes would start from the next > byte boundary. > > The unaligned api would get 3 bits and the 15 bytes (=15 x 8 bits) would finish > still with an offset of 3. Do you mean we'd have an unalignedGetBytes as well as getBytes (which would remain aligned)? That would make sense, but it would seem a bit heavy to duplicate all of the binary API. David From lemming at henning-thielemann.de Wed Jan 9 17:42:30 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Wed Jan 9 17:36:06 2008 Subject: [Haskell-cafe] Why purely in haskell? In-Reply-To: <117f2cc80801091415x643bec1cmf09931d4d16d59e5@mail.gmail.com> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <2d3641330801090706m4ed9a927l282bb840a7dfcb7f@mail.gmail.com> <1199897022.18821.24.camel@derek-laptop> <4785339B.7050308@telenet.be> <47853A2C.2060508@appsolutions.com> <20080109212104.GD29472@scytale.galois.com> <117f2cc80801091415x643bec1cmf09931d4d16d59e5@mail.gmail.com> Message-ID: On Wed, 9 Jan 2008, David Roundy wrote: > On Jan 9, 2008 4:21 PM, Don Stewart wrote: > > anton: > > > OTOH, the freedom to change things on the fly can be nice to have, and > > > if used with "great responsibility" (mainly an understanding of what's > > > safe to do and what isn't), the downside can be vanishingly small. > > > > It can be small, unless you need to have any kind of static assurance > > (say for high assurance software, or for new kinds of optimisations, or > > if you want to reorder code in the compiler for parallelism). > > > > Then the downside to arbitrary, untracked effects in the system is huge. > > I just want to point out that unsafePerformIO is at the core of the > (safe) bytestring library. As SPJ et al pointed out, this is crucial > functionality, and is only unsafe if unsafely used. Indeed, there are hacks and they are some times necessary. The good thing about Haskell is, that hacks look like hacks. In Modula-3 modules using hacks must be explicitly marked as UNSAFE. See http://www.cs.purdue.edu/homes/hosking/m3/reference/unsafe.html Maybe this is also an option for Haskell? Wouldn't this also simplify http://www.haskell.org/haskellwiki/Safely_running_untrusted_Haskell_code ? From barsoap at web.de Wed Jan 9 17:43:52 2008 From: barsoap at web.de (Achim Schneider) Date: Wed Jan 9 17:37:43 2008 Subject: [Haskell-cafe] Re: ANN: A triple of new packages for talking tothe outside world References: <396556a20801061554o3895ce88k87d4ecabc1860e7b@mail.gmail.com> <4781B50A.2060007@serpentine.com> <396556a20801071037t1b66e444u52abe1d934b7f902@mail.gmail.com> <47827AB4.60608@serpentine.com> <396556a20801081226l5ebf5062p685a80c6aac6ba41@mail.gmail.com> <1199885578.7279.119.camel@localhost> <117f2cc80801091425l41b73ea3uddda3d91ba9405e7@mail.gmail.com> Message-ID: <20080109234352.3ee84d4a@solaris.tower> "David Roundy" wrote: > On Jan 9, 2008 10:10 AM, Dominic Steinitz > wrote: > > Duncan Coutts worc.ox.ac.uk> writes: > > > The difficulty is in deciding what the api should be. Does it > > > give you a real bitstream or only a byte aligned one? If I ask > > > for 3 bits then 15 bytes what does it do? Does it assume I meant > > > 3 bits, then pad to the next byte boundary and get 15 bytes, or > > > does it mean get 15 bytes but at this 3 bit shift offset? > > > > I'd suggest an aligned and unaligned api. > > > > So the aligned api would get 3 bits and the 15 bytes would start > > from the next byte boundary. > > > > The unaligned api would get 3 bits and the 15 bytes (=15 x 8 bits) > > would finish still with an offset of 3. > > Do you mean we'd have an unalignedGetBytes as well as getBytes (which > would remain aligned)? That would make sense, but it would seem a bit > heavy to duplicate all of the binary API. > getBytes per default unaligned and additionally snapToNextByte? -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From stefanor at cox.net Wed Jan 9 17:48:55 2008 From: stefanor at cox.net (Stefan O'Rear) Date: Wed Jan 9 17:42:31 2008 Subject: [Haskell-cafe] Problems with Unicode Symbols as Infix Function Names in Propositional Calculus Haskell DSL In-Reply-To: <200801092223.06129.g9ks157k@acme.softbase.org> References: <20080109172417.GA29140@scytale.galois.com> <200801092223.06129.g9ks157k@acme.softbase.org> Message-ID: <20080109224855.GA3589@localhost.localdomain> On Wed, Jan 09, 2008 at 10:23:05PM +0100, Wolfgang Jeltsch wrote: > Am Mittwoch, 9. Januar 2008 18:34 schrieb Cetin Sert: > > Neither appending "{-# OPTIONS_GHC -fglasgow-exts -xunicodesyntax #-}" > > First, I think, you have to use -XUnicodeSyntax (as Don said), and > not -xunicodesyntax. Second, -XUnicodeSyntax only enables alternative > notation for certain built-in syntax (as Don said). > > Unicode for operators is a different matter. I?d think, it should work out of > the box and wonder a bit why it doesn?t. The give-away is that GHC gave a "UTF-8 decoding error". This says that Cetin is using a different encoding, presumably (due to his mention of Visual Haskell, ergo Windows) UTF-16. Stefan -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080109/bcbcc3ce/attachment.bin From dons at galois.com Wed Jan 9 18:20:28 2008 From: dons at galois.com (Don Stewart) Date: Wed Jan 9 18:14:14 2008 Subject: [Haskell-cafe] Why purely in haskell? In-Reply-To: <478543B6.4040907@appsolutions.com> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <2d3641330801090706m4ed9a927l282bb840a7dfcb7f@mail.gmail.com> <1199897022.18821.24.camel@derek-laptop> <4785339B.7050308@telenet.be> <47853A2C.2060508@appsolutions.com> <20080109212104.GD29472@scytale.galois.com> <478543B6.4040907@appsolutions.com> Message-ID: <20080109232028.GA4910@scytale.galois.com> anton: > Don Stewart wrote: > >anton: > >>OTOH, the freedom to change things on the fly can be nice to have, and > >>if used with "great responsibility" (mainly an understanding of what's > >>safe to do and what isn't), the downside can be vanishingly small. > > > >It can be small, unless you need to have any kind of static assurance > >(say for high assurance software, or for new kinds of optimisations, or > >if you want to reorder code in the compiler for parallelism). > > > >Then the downside to arbitrary, untracked effects in the system is huge. > > Oh dear - I'm going to have to rethink the paper I was working on, > provisionally titled "In defense of arbitrary untracked effects in high > assurance software." ;) That would be an awesome paper :) -- Don From vigalchin at gmail.com Wed Jan 9 19:21:50 2008 From: vigalchin at gmail.com (Galchin Vasili) Date: Wed Jan 9 19:15:24 2008 Subject: [Haskell-cafe] Tim Sweeney (the gamer) Message-ID: <5ae4f2ba0801091621t5580361dv6fc5663f0c54c0ca@mail.gmail.com> Hello, I have been reading with great interested Tim Sweeney's slides on the Next Generation Programming Language. Does anybody know his email address? Kind regards, Vasili -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080109/bb1f155c/attachment.htm From trevion at gmail.com Wed Jan 9 19:39:26 2008 From: trevion at gmail.com (J. Garrett Morris) Date: Wed Jan 9 19:33:01 2008 Subject: [Haskell-cafe] Tim Sweeney (the gamer) In-Reply-To: <5ae4f2ba0801091621t5580361dv6fc5663f0c54c0ca@mail.gmail.com> References: <5ae4f2ba0801091621t5580361dv6fc5663f0c54c0ca@mail.gmail.com> Message-ID: <6cf91caa0801091639u33d668a0yc39de6a46618a7c2@mail.gmail.com> I imagine you can get in touch with him through Epic (www.epicgames.com) if you can't find another way to contact him. /g On Jan 9, 2008 4:21 PM, Galchin Vasili wrote: > Hello, > > I have been reading with great interested Tim Sweeney's slides on the > Next Generation Programming Language. Does anybody know his email address? > > Kind regards, Vasili > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > -- The man who'd introduced them didn't much like either of them, though he acted as if he did, anxious as he was to preserve good relations at all times. One never knew, after all, now did one now did one now did one. From graham.fawcett at gmail.com Wed Jan 9 19:46:53 2008 From: graham.fawcett at gmail.com (Graham Fawcett) Date: Wed Jan 9 19:40:29 2008 Subject: [Haskell-cafe] Why purely in haskell? In-Reply-To: <20080109232028.GA4910@scytale.galois.com> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <2d3641330801090706m4ed9a927l282bb840a7dfcb7f@mail.gmail.com> <1199897022.18821.24.camel@derek-laptop> <4785339B.7050308@telenet.be> <47853A2C.2060508@appsolutions.com> <20080109212104.GD29472@scytale.galois.com> <478543B6.4040907@appsolutions.com> <20080109232028.GA4910@scytale.galois.com> Message-ID: On Jan 9, 2008 6:20 PM, Don Stewart wrote: > anton: > > Oh dear - I'm going to have to rethink the paper I was working on, > > provisionally titled "In defense of arbitrary untracked effects in high > > assurance software." ;) > > That would be an awesome paper :) Hear, hear! Anton, if you're looking for a co-author, and you're willing to tackle the high-assurance parts, I have years of experience with arbitrary untracked effects. ;-) Graham From droundy at darcs.net Wed Jan 9 20:01:34 2008 From: droundy at darcs.net (David Roundy) Date: Wed Jan 9 19:55:09 2008 Subject: [Haskell-cafe] Re: ANN: A triple of new packages for talking tothe outside world In-Reply-To: <20080109234352.3ee84d4a@solaris.tower> References: <396556a20801061554o3895ce88k87d4ecabc1860e7b@mail.gmail.com> <4781B50A.2060007@serpentine.com> <396556a20801071037t1b66e444u52abe1d934b7f902@mail.gmail.com> <47827AB4.60608@serpentine.com> <396556a20801081226l5ebf5062p685a80c6aac6ba41@mail.gmail.com> <1199885578.7279.119.camel@localhost> <117f2cc80801091425l41b73ea3uddda3d91ba9405e7@mail.gmail.com> <20080109234352.3ee84d4a@solaris.tower> Message-ID: <20080110010123.GF18915@darcs.net> On Wed, Jan 09, 2008 at 11:43:52PM +0100, Achim Schneider wrote: > "David Roundy" wrote: > > > On Jan 9, 2008 10:10 AM, Dominic Steinitz > > wrote: > > > Duncan Coutts worc.ox.ac.uk> writes: > > > > The difficulty is in deciding what the api should be. Does it > > > > give you a real bitstream or only a byte aligned one? If I ask > > > > for 3 bits then 15 bytes what does it do? Does it assume I meant > > > > 3 bits, then pad to the next byte boundary and get 15 bytes, or > > > > does it mean get 15 bytes but at this 3 bit shift offset? > > > > > > I'd suggest an aligned and unaligned api. > > > > > > So the aligned api would get 3 bits and the 15 bytes would start > > > from the next byte boundary. > > > > > > The unaligned api would get 3 bits and the 15 bytes (=15 x 8 bits) > > > would finish still with an offset of 3. > > > > Do you mean we'd have an unalignedGetBytes as well as getBytes (which > > would remain aligned)? That would make sense, but it would seem a bit > > heavy to duplicate all of the binary API. > > > getBytes per default unaligned and additionally snapToNextByte? But I can't imagine an implementation in which this change wouldn't slow down getBytes for the normal case. Perhaps the slowdown would be small, but it seems unwise to enforce that slowness at the API level, when we've already got a perfectly good API for fast binary IO. Maybe there's some type hackery you could do to avoid a speed penalty, but that's a lot to add for a somewhat dubious benefit. Note that you could get a similar effect with getBytes always aligned, and an additional function shiftToByte which takes the remainder of the input and bitshifts everything so that the current read pointer is on a byte boundary. Obviously this would be an O(N) operation (where N is the remainder of the input), which could certainly be a problem. Another option, I suppose, would be to introduce a type class for bytewise-reading monads. That'd be a type hack, but not such a bad one. Then you could have the efficient implementation, and one that allows bitwise reading, and there could also be a function that allows bitwise parsing of a chunk of a byte-aligned data. -- David Roundy Department of Physics Oregon State University From agl at imperialviolet.org Wed Jan 9 20:23:02 2008 From: agl at imperialviolet.org (Adam Langley) Date: Wed Jan 9 20:16:38 2008 Subject: [Haskell-cafe] Data.Binary and serialising doubles in IEEE format In-Reply-To: <4784C9BC.2010101@ed.ac.uk> References: <4784C9BC.2010101@ed.ac.uk> Message-ID: <396556a20801091723t12731105lc4f2a484a3157aae@mail.gmail.com> On Jan 9, 2008 5:18 AM, allan wrote: > Essentially then, is there anyone that can write my 'putDouble' function > or give some hint as to how I might do it. > For the moment assume that I'm not really concerned with portability > across platforms at least for the time being (I certainly don't think > that the C program I'm attempting to communicate with is particularly > portable anyway). > I happen to have the reverse functions lying around which might be some help in doing this. They aren't terribly beautiful, but they'll take an IEEE double or float from a Bytestring and return the value + the remaining ByteString. (They aren't very well tested, but they have been found to mostly work). ddouble :: BS.ByteString -> (Double, BS.ByteString) ddouble bytes = (encodeFloat fraction $ fromIntegral exp, rest) where fraction = sign * fromIntegral ((n .&. 0xfffffffffffff) .|. (if rawExp > 0 then 0x10000000000000 else 0)) sign = if n `shiftR` 63 == 0 then 1 else -1 exp = rawExp - (1023 + 52) rawExp = (n `shiftR` 52) .&. 0x7ff (b, rest) = BS.splitAt 8 bytes n :: Word64 n = foldl1 (.|.) $ map (\(s, v) -> (fromIntegral v) `shiftL` s) $ zip [0,8..56] $ BS.unpack b dfloat :: BS.ByteString -> (Float, BS.ByteString) dfloat bytes = (encodeFloat fraction $ fromIntegral exp, rest) where fraction = sign * fromIntegral ((n .&. 0x7fffff) .|. (if rawExp > 0 then 0x800000 else 0)) sign = if n `shiftR` 31 == 0 then 1 else -1 exp = rawExp - (127 + 23) rawExp = (n `shiftR` 23) .&. 0xff (b, rest) = BS.splitAt 4 bytes n :: Word32 n = foldl1 (.|.) $ map (\(s, v) -> (fromIntegral v) `shiftL` s) $ zip [0, 8, 16, 24] $ BS.unpack b AGL -- Adam Langley agl@imperialviolet.org http://www.imperialviolet.org 650-283-9641 From agl at imperialviolet.org Wed Jan 9 20:25:56 2008 From: agl at imperialviolet.org (Adam Langley) Date: Wed Jan 9 20:19:32 2008 Subject: [Haskell-cafe] Re: ANN: A triple of new packages for talking tothe outside world In-Reply-To: <20080110010123.GF18915@darcs.net> References: <396556a20801061554o3895ce88k87d4ecabc1860e7b@mail.gmail.com> <396556a20801071037t1b66e444u52abe1d934b7f902@mail.gmail.com> <47827AB4.60608@serpentine.com> <396556a20801081226l5ebf5062p685a80c6aac6ba41@mail.gmail.com> <1199885578.7279.119.camel@localhost> <117f2cc80801091425l41b73ea3uddda3d91ba9405e7@mail.gmail.com> <20080109234352.3ee84d4a@solaris.tower> <20080110010123.GF18915@darcs.net> Message-ID: <396556a20801091725p4a2dbf8aw3117a568b807c195@mail.gmail.com> On Jan 9, 2008 5:01 PM, David Roundy wrote: > But I can't imagine an implementation in which this change wouldn't slow > down getBytes for the normal case. Perhaps the slowdown would be small, > but it seems unwise to enforce that slowness at the API level, when we've > already got a perfectly good API for fast binary IO. Maybe there's some > type hackery you could do to avoid a speed penalty, but that's a lot to add > for a somewhat dubious benefit. I believe that it would be an additional if statement in the fast path at least. How about a BitGet monad which get be run in the Get monad? > test :: Get () > test = do > runBitGet 2 (do > getBitField 2) So the first argument to runBitGet is the number of bytes to parse for bit fields and then functions in BitGet can extract bit-length ints etc. Anyone like that idea? AGL -- Adam Langley agl@imperialviolet.org http://www.imperialviolet.org 650-283-9641 From lennart at augustsson.net Wed Jan 9 20:40:39 2008 From: lennart at augustsson.net (Lennart Augustsson) Date: Wed Jan 9 20:34:14 2008 Subject: [Haskell-cafe] Re: Displaying # of reductions after eachcomputation in ghci? In-Reply-To: References: <20080108221155.GA3393@localhost.localdomain> Message-ID: What is a reduction anyway? On Jan 8, 2008 2:48 PM, Fernando Rodriguez wrote: > Hello Stefan O'Rear, > > >> > > No. > > > > (rambling explanation snipped awaiting further request) > > > > Stefan > > OK, I'll take the bait: why not? > > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080109/a9a0f858/attachment.htm From barsoap at web.de Wed Jan 9 20:40:35 2008 From: barsoap at web.de (Achim Schneider) Date: Wed Jan 9 20:34:20 2008 Subject: [Haskell-cafe] Re: ANN: A triple of new packages for talking tothe outside world References: <396556a20801061554o3895ce88k87d4ecabc1860e7b@mail.gmail.com> <4781B50A.2060007@serpentine.com> <396556a20801071037t1b66e444u52abe1d934b7f902@mail.gmail.com> <47827AB4.60608@serpentine.com> <396556a20801081226l5ebf5062p685a80c6aac6ba41@mail.gmail.com> <1199885578.7279.119.camel@localhost> <117f2cc80801091425l41b73ea3uddda3d91ba9405e7@mail.gmail.com> <20080109234352.3ee84d4a@solaris.tower> <20080110010123.GF18915@darcs.net> Message-ID: <20080110024035.712d44c5@solaris.tower> David Roundy wrote: > [ something that every C programmer dreams of ] > I'm not going to answer, I'd be just vapour-waring around. But, yes, any-alignment any-granularity reads can be done in O(1), with 1 ranging from case to case from one instruction to a few shifts and &'s, plus some constant cost to choose the appropriate function based on current alignment, which could be set by things like snapToByte, snapToWord, snapToInt128, getBit, getBits , getByte, GetWhatever and one state var to change the "advance mode" from request-sized to constant-sized. As I said, I'm vapour-waring. But then it's a swiss army knife. With many general- and special-purpose functions. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From barsoap at web.de Wed Jan 9 20:48:47 2008 From: barsoap at web.de (Achim Schneider) Date: Wed Jan 9 20:42:29 2008 Subject: [Haskell-cafe] Re: Displaying # of reductions after eachcomputation in ghci? References: <20080108221155.GA3393@localhost.localdomain> Message-ID: <20080110024847.67031abf@solaris.tower> "Lennart Augustsson" wrote: > What is a reduction anyway? > () -> o -> . -> -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From andre at digirati.com.br Wed Jan 9 22:57:09 2008 From: andre at digirati.com.br (Andre Nathan) Date: Wed Jan 9 22:49:48 2008 Subject: [Haskell-cafe] Comments and suggestions on code Message-ID: <1199937429.8936.33.camel@homesick> Hello I've just found time to finish writing my first "real world" program, so I thought I'd post it here and ask for insight on general issues such as if there's anything that isn't done "the Haskell way", or if there's something that could be done more efficiently. The code is at the bottom of this message and also at http://hpaste.org/4893. I realize it's a bit long, so if anyone could just skim through it and see if there's anything really ugly or stupid and point it out, it would be of great help :) Just to make it easier to follow the code, its idea is simple: - Build a process tree by reading entries from /proc (represented as a map); - Compare each child of the init process against a whitelist (which comes from a configuration file); - For each child not in the whitelist, send it a KILL signal. The idea here is to run this on webservers and try to catch bad customers who try to run daemons from their accounts, the typical script kiddie stuff. Anyway, there's one specific question I'd like to ask. I'm using "StateT PsTree IO" to keep program state (the process tree). IO is necessary because all information is read from /proc files. Now consider the following function: appendChild :: Pid -> Pid -> StateT PsTree IO Bool appendChild ppid pid = do tree <- get let PsInfo psData children = mapLookup ppid tree put $ Map.insert ppid (PsInfo psData (pid:children)) tree return True It changes the program state by modifying a process tree entry, but it does no I/O at all. The return type is there basically to match the return type of the function which calls it (insertParent), which calls functions that do I/O. Is there anyway to avoid the "IO" in appendChild's signature (other than making it a pure function by passing the process tree as a parameter and returning a modified map)? I would also like to try ways to improve efficiency, maybe trying a hash table instead of a map for the state, and also using bytestrings. I guess I could try making it parallel, since each child of init can be checked independently. Anyway, this is already longer than I thought it would be (I hope I'm not abusing too much :) The code follows. Thanks in advance for any comments or suggestions. Andre module Main where import qualified Data.Map as Map import Directory import Control.Monad.State import Maybe import System.Environment import System.IO import System.Posix.Files import System.Posix.Signals import System.Posix.Unistd import System.Posix.User import Text.Printf import Text.Regex import Text.Regex.Posix type Pid = FilePath type Uid = String type PsData = Map.Map String String type PsChildren = [Pid] type KillFunction = PsTree -> Pid -> IO () data PsInfo = PsInfo PsData PsChildren type PsTree = Map.Map Pid PsInfo type Whitelist = Map.Map FilePath String mapLookup :: (Ord a) => a -> Map.Map a b -> b mapLookup k = fromJust . Map.lookup k -- Process Tree construction parentPid :: PsInfo -> Pid parentPid (PsInfo psData _) = mapLookup "PPid" psData getProcInfo :: String -> PsData -> PsData getProcInfo line psData = do case line =~~ "^([A-Za-z]+):[[:space:]]+(.*)$" of Nothing -> psData Just ([_, key, value]:_) -> Map.insert key value psData getIds :: String -> PsData -> (String, String) getIds id psData = (rId, eId) where (rId:eId:_) = words (mapLookup id psData) processData :: String -> PsData processData procData = addIds psData where psData = foldr getProcInfo Map.empty (lines procData) addIds psData = Map.union psData (idMap psData) idMap psData = Map.fromList [("RUid", rUid), ("EUid", eUid), ("RGid", rGid), ("EGid", eGid)] (rUid, eUid) = getIds "Uid" psData (rGid, eGid) = getIds "Gid" psData readLink :: String -> IO String readLink link = catch (readSymbolicLink link) (\e -> return "?") procInfo :: Pid -> IO PsInfo procInfo pid = do let dir = "/proc/" ++ pid ++ "/" procData <- readFile $ dir ++ "status" exe <- readLink $ dir ++ "exe" cwd <- readLink $ dir ++ "cwd" cmd <- readFile $ dir ++ "cmdline" let cmd' = subRegex (mkRegex "[^a-zA-z[:space:]\\/\\.-]") cmd " " info = processData procData adminInfo = Map.fromList [("Exe", exe), ("Cwd", cwd), ("Cmd", cmd')] return $ PsInfo (Map.union info adminInfo) [] addProc :: Pid -> StateT PsTree IO PsInfo addProc pid = do info <- lift $ procInfo pid modify (Map.insert pid info) return info appendChild :: Pid -> Pid -> StateT PsTree IO Bool appendChild ppid pid = do tree <- get let PsInfo psData children = mapLookup ppid tree put $ Map.insert ppid (PsInfo psData (pid:children)) tree return True insertParent :: Pid -> Pid -> StateT PsTree IO Bool insertParent ppid pid = do tree <- get if Map.member ppid tree then appendChild ppid pid else do built <- insertInTree ppid if built then appendChild ppid pid else return False insertPid :: Pid -> StateT PsTree IO Bool insertPid "1" = do info <- addProc "1" return True insertPid pid = do info <- addProc pid let ppid = parentPid info if ppid == "0" then return False else insertParent ppid pid insertInTree :: Pid -> StateT PsTree IO Bool insertInTree pid = do tree <- get if Map.member pid tree then return True else insertPid pid buildTree :: FilePath -> StateT PsTree IO Bool buildTree entry | entry =~ "^[0-9]+$" = insertInTree entry | otherwise = return False createTree :: IO PsTree createTree = do entries <- getDirectoryContents "/proc" execStateT (mapM_ buildTree entries) Map.empty -- Process Tree pretty-printing treeStr :: PsTree -> PsChildren -> Int -> String -> String treeStr tree children level str = foldr append str children where append pid s = treeStr tree children' (level + 1) newstr where PsInfo _ children' = mapLookup pid tree pad = take (4 * level) [' ', ' ' ..] newstr = s ++ "\n" ++ pad ++ pid printTree :: PsTree -> Pid -> IO () printTree tree pid = putStrLn (treeStr tree children 1 pid) where PsInfo _ children = mapLookup pid tree -- Process killing tryToKill :: PsTree -> KillFunction -> Pid -> Uid -> Uid -> Bool -> IO Bool tryToKill tree killFun pid "0" allowedUid killed = do -- The process may be starting, give it a second chance. sleep 10 -- conservative value. let PsInfo psData _ = mapLookup pid tree if allowedUid /= mapLookup "EUid" psData then killFun tree pid >> return True else return (killed || False) tryToKill tree killFun pid _ _ _ = killFun tree pid >> return True buildWhitelist :: String -> Whitelist -> Whitelist buildWhitelist line whitelist = do case line =~~ "^[ \t]*([^: \t]+)[ \t]*:[ \t]*([^ \t]+)[ \t]*$" of Nothing -> error "Invalid configuration file" Just ([_, exe, user]:_) -> Map.insert exe user whitelist readWhiteList :: FilePath -> IO Whitelist readWhiteList file = do contents <- readFile file return $ foldr buildWhitelist Map.empty (lines contents) allowedUidForExecutable :: Whitelist -> FilePath -> IO Uid allowedUidForExecutable whitelist exe = do case Map.lookup exe whitelist of Nothing -> return "0" Just user -> do entry <- getUserEntryForName user return $ show (userID entry) processBastard :: PsTree -> Whitelist -> KillFunction -> Bool -> Pid -> IO Bool processBastard tree whitelist killFun killed pid = do let PsInfo psData _ = mapLookup pid tree euid = mapLookup "EUid" psData exe = mapLookup "Exe" psData allowedUid <- allowedUidForExecutable whitelist exe if euid /= allowedUid then tryToKill tree killFun pid euid allowedUid killed else return killed withEachBastard :: PsTree -> Whitelist -> KillFunction -> IO Bool withEachBastard tree whitelist killFun = foldM (processBastard tree whitelist killFun) False children where (PsInfo _ children) = mapLookup "1" tree printWarnings :: Pid -> PsData -> IO () printWarnings pid psData = do let exe = mapLookup "Exe" psData let cmd = mapLookup "Cmd" psData let cwd = mapLookup "Cwd" psData let ppid = mapLookup "PPid" psData let euid = mapLookup "EUid" psData let ruid = mapLookup "RUid" psData let egid = mapLookup "EGid" psData if ruid /= euid then hPrintf stderr "PID %s: RUID=%s, EUID=%s\n" pid ruid euid else return () hPrintf stderr "Killing proc %s (%s, UID=%s, GID=%s), child of %s\n" pid exe euid egid ppid hPrintf stderr " Process command line: %s\n" cmd hPrintf stderr " Process working directory: %s\n" cwd killTree :: KillFunction killTree tree pid = do let PsInfo psData children = mapLookup pid tree printWarnings pid psData signalProcess sigKILL (read pid) mapM_ (killTree tree) children killBastards :: PsTree -> Whitelist -> Int -> IO () killBastards tree whitelist n = do runAgain <- withEachBastard tree whitelist killTree if runAgain && n > 1 then do sleep 2 killBastards tree whitelist (n - 1) else return () -- Configuration printConfig :: KillFunction printConfig tree pid = do let PsInfo psData _ = mapLookup pid tree exe = mapLookup "Exe" psData euid = mapLookup "EUid" psData entry <- getUserEntryForID (read euid) putStrLn $ exe ++ ": " ++ (userName entry) -- main helpers config :: PsTree -> IO () config tree = do withEachBastard tree Map.empty printConfig return () pstree :: PsTree -> IO () pstree tree = do printTree tree "1" -- In newer kernels, process 2 is kthreadd, which is not a child -- of init. let info = mapLookup "2" tree if parentPid info /= "1" then printTree tree "2" else return () kill :: PsTree -> IO () kill tree = do whitelist <- readWhiteList "killbastards.conf" killBastards tree whitelist 5 main :: IO () main = do args <- getArgs tree <- createTree case args of ["config"] -> config tree ["pstree"] -> pstree tree [] -> kill tree From jonathanccast at fastmail.fm Thu Jan 10 00:32:10 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Thu Jan 10 00:25:55 2008 Subject: [Haskell-cafe] Comments and suggestions on code In-Reply-To: <1199937429.8936.33.camel@homesick> References: <1199937429.8936.33.camel@homesick> Message-ID: <6C68D342-F1B3-4333-8D7E-83E21E1FDB57@fastmail.fm> On 9 Jan 2008, at 7:57 PM, Andre Nathan wrote: > Hello > > I've just found time to finish writing my first "real world" > program, so > I thought I'd post it here and ask for insight on general issues > such as > if there's anything that isn't done "the Haskell way", or if there's > something that could be done more efficiently. > > The code is at the bottom of this message and also at > http://hpaste.org/4893. I realize it's a bit long, so if anyone could > just skim through it and see if there's anything really ugly or stupid > and point it out, it would be of great help :) > > Just to make it easier to follow the code, its idea is simple: > > - Build a process tree by reading entries from /proc (represented as a > map); > - Compare each child of the init process against a whitelist (which > comes from a configuration file); > - For each child not in the whitelist, send it a KILL signal. > > The idea here is to run this on webservers and try to catch bad > customers who try to run daemons from their accounts, the typical > script > kiddie stuff. > > Anyway, there's one specific question I'd like to ask. I'm using > "StateT > PsTree IO" to keep program state (the process tree). IO is necessary > because all information is read from /proc files. Now consider the > following function: > > appendChild :: Pid -> Pid -> StateT PsTree IO Bool > appendChild ppid pid = do > tree <- get > let PsInfo psData children = mapLookup ppid tree > put $ Map.insert ppid (PsInfo psData (pid:children)) tree > return True A return type of Bool suggests the code might fail; a constant function should have return type (). > > It changes the program state by modifying a process tree entry, but it > does no I/O at all. The return type is there basically to match the > return type of the function which calls it (insertParent), which calls > functions that do I/O. Is there anyway to avoid the "IO" in > appendChild's signature (other than making it a pure function by > passing > the process tree as a parameter and returning a modified map)? This is the best solution, as well as the most idiomatic. It's really simple, too: appendChild :: Pid -> Pid -> PsTree -> PsTree appendChild ppid pid tree = Map.insert ppid (PsInfo psData (pid:children)) tree where PsInfo psData children = mapLookup ppid tree Which is two lines shorter than your version, and IMHO just as clear; or, even better appendChild ppid pid = Map.alter (fmap $ \ (PsInfo psData children) -> PsInfo psData (pid:children)) ppid which is a one-liner. Alternatively, you could keep the definition, but change the type to appendChild :: Monad m => Pid -> Pid -> StateT PsTree m Bool or appendChild :: MonadState m PsTree => Pid -> Pid -> m Bool although this is likely to be less efficient. > I would also like to try ways to improve efficiency, maybe trying a > hash > table instead of a map for the state, and also using bytestrings. I > guess I could try making it parallel, since each child of init can be > checked independently. > > Anyway, this is already longer than I thought it would be (I hope I'm > not abusing too much :) An actual coding question, abuse? We should be so lucky. > The code follows. Thanks in advance for any > comments or suggestions. > > Andre > > > module Main where > > import qualified Data.Map as Map Also import Data.Map (Map) (Map.Map looks kind of silly). > import Directory > import Control.Monad.State > import Maybe > import System.Environment > import System.IO > import System.Posix.Files > import System.Posix.Signals > import System.Posix.Unistd > import System.Posix.User > import Text.Printf > import Text.Regex > import Text.Regex.Posix > > type Pid = FilePath > type Uid = String > > type PsData = Map.Map String String > type PsChildren = [Pid] > type KillFunction = PsTree -> Pid -> IO () > data PsInfo = PsInfo PsData PsChildren This sequence is better written data PsInfo = PsInfo{ psData :: Map String String, psChildren :: [Pid] } If find myself using typedefs relatively infrequently in Haskell. > type PsTree = Map.Map Pid PsInfo > > type Whitelist = Map.Map FilePath String > > mapLookup :: (Ord a) => a -> Map.Map a b -> b > mapLookup k = fromJust . Map.lookup k > > -- Process Tree construction > > parentPid :: PsInfo -> Pid > parentPid (PsInfo psData _) = mapLookup "PPid" psData > > getProcInfo :: String -> PsData -> PsData > getProcInfo line psData = do > case line =~~ "^([A-Za-z]+):[[:space:]]+(.*)$" of > Nothing -> psData > Just ([_, key, value]:_) -> Map.insert key value psData > getIds :: String -> PsData -> (String, String) > getIds id psData = (rId, eId) > where (rId:eId:_) = words (mapLookup id psData) > > processData :: String -> PsData > processData procData = addIds psData > where psData = foldr getProcInfo Map.empty (lines procData) > addIds psData = Map.union psData (idMap psData) > idMap psData = Map.fromList [("RUid", rUid), ("EUid", eUid), > ("RGid", rGid), ("EGid", eGid)] > (rUid, eUid) = getIds "Uid" psData > (rGid, eGid) = getIds "Gid" psData > > readLink :: String -> IO String > readLink link = catch (readSymbolicLink link) (\e -> return "?") > > procInfo :: Pid -> IO PsInfo > procInfo pid = do > let dir = "/proc/" ++ pid ++ "/" > procData <- readFile $ dir ++ "status" > exe <- readLink $ dir ++ "exe" > cwd <- readLink $ dir ++ "cwd" > cmd <- readFile $ dir ++ "cmdline" > let cmd' = subRegex (mkRegex "[^a-zA-z[:space:]\\/\\.-]") cmd " " > info = processData procData > adminInfo = Map.fromList [("Exe", exe), ("Cwd", cwd), > ("Cmd", cmd')] > return $ PsInfo (Map.union info adminInfo) [] > > addProc :: Pid -> StateT PsTree IO PsInfo > addProc pid = do > info <- lift $ procInfo pid > modify (Map.insert pid info) > return info > > appendChild :: Pid -> Pid -> StateT PsTree IO Bool > appendChild ppid pid = do > tree <- get > let PsInfo psData children = mapLookup ppid tree > put $ Map.insert ppid (PsInfo psData (pid:children)) tree > return True As above, or appendChild ppid pid = Map.alter (fmap $ \ st -> st {children = pid : children st}) ppid with the record syntax. > > insertParent :: Pid -> Pid -> StateT PsTree IO Bool > insertParent ppid pid = do > tree <- get > if Map.member ppid tree > then appendChild ppid pid modify (appendChild ppid pid) > else do > built <- insertInTree ppid > if built > then appendChild ppid pid > else return False > > insertPid :: Pid -> StateT PsTree IO Bool > insertPid "1" = do > info <- addProc "1" > return True > insertPid pid = do > info <- addProc pid > let ppid = parentPid info > if ppid == "0" then return False else insertParent ppid pid > > insertInTree :: Pid -> StateT PsTree IO Bool > insertInTree pid = do > tree <- get > if Map.member pid tree then return True else insertPid pid > > buildTree :: FilePath -> StateT PsTree IO Bool > buildTree entry | entry =~ "^[0-9]+$" = insertInTree entry > | otherwise = return False This function is fairly complicated, simply because of the number of separate definitions involved; I would be looking for opportunities to inline definitions here, so it's clearer what the definitions are. (Also, I would try to build a single, self-recursive function at the top level, put the call to procInfo there, and make everything else pure). > > createTree :: IO PsTree > createTree = do > entries <- getDirectoryContents "/proc" > execStateT (mapM_ buildTree entries) Map.empty > > -- Process Tree pretty-printing > > treeStr :: PsTree -> PsChildren -> Int -> String -> String > treeStr tree children level str = foldr append str children > where append pid s = treeStr tree children' (level + 1) newstr > where PsInfo _ children' = mapLookup pid tree > pad = take (4 * level) [' ', ' ' ..] > newstr = s ++ "\n" ++ pad ++ pid > > printTree :: PsTree -> Pid -> IO () > printTree tree pid = putStrLn (treeStr tree children 1 pid) > where PsInfo _ children = mapLookup pid tree > > -- Process killing > > tryToKill :: PsTree -> KillFunction -> Pid -> Uid -> Uid -> Bool -> > IO Bool > tryToKill tree killFun pid "0" allowedUid killed = do > -- The process may be starting, give it a second chance. > sleep 10 -- conservative value. > let PsInfo psData _ = mapLookup pid tree > if allowedUid /= mapLookup "EUid" psData > then killFun tree pid >> return True > else return (killed || False) > tryToKill tree killFun pid _ _ _ = killFun tree pid >> return True > > buildWhitelist :: String -> Whitelist -> Whitelist > buildWhitelist line whitelist = do > case line =~~ "^[ \t]*([^: \t]+)[ \t]*:[ \t]*([^ \t]+)[ \t]*$" of > Nothing -> error "Invalid configuration file" > Just ([_, exe, user]:_) -> Map.insert exe user whitelist > > readWhiteList :: FilePath -> IO Whitelist > readWhiteList file = do > contents <- readFile file > return $ foldr buildWhitelist Map.empty (lines contents) > > allowedUidForExecutable :: Whitelist -> FilePath -> IO Uid > allowedUidForExecutable whitelist exe = do > case Map.lookup exe whitelist of > Nothing -> return "0" > Just user -> do > entry <- getUserEntryForName user > return $ show (userID entry) > > processBastard :: PsTree -> Whitelist -> KillFunction -> Bool -> > Pid -> IO Bool > processBastard tree whitelist killFun killed pid = do > let PsInfo psData _ = mapLookup pid tree > euid = mapLookup "EUid" psData > exe = mapLookup "Exe" psData > allowedUid <- allowedUidForExecutable whitelist exe > if euid /= allowedUid > then tryToKill tree killFun pid euid allowedUid killed > else return killed > > withEachBastard :: PsTree -> Whitelist -> KillFunction -> IO Bool > withEachBastard tree whitelist killFun = > foldM (processBastard tree whitelist killFun) False children > where (PsInfo _ children) = mapLookup "1" tree > > printWarnings :: Pid -> PsData -> IO () > printWarnings pid psData = do > let exe = mapLookup "Exe" psData > let cmd = mapLookup "Cmd" psData > let cwd = mapLookup "Cwd" psData > let ppid = mapLookup "PPid" psData > let euid = mapLookup "EUid" psData > let ruid = mapLookup "RUid" psData > let egid = mapLookup "EGid" psData > if ruid /= euid > then hPrintf stderr "PID %s: RUID=%s, EUID=%s\n" pid ruid euid > else return () > hPrintf stderr "Killing proc %s (%s, UID=%s, GID=%s), child of %s\n" > pid exe euid egid ppid > hPrintf stderr " Process command line: %s\n" cmd > hPrintf stderr " Process working directory: %s\n" cwd > > killTree :: KillFunction > killTree tree pid = do > let PsInfo psData children = mapLookup pid tree > printWarnings pid psData > signalProcess sigKILL (read pid) > mapM_ (killTree tree) children > > killBastards :: PsTree -> Whitelist -> Int -> IO () > killBastards tree whitelist n = do > runAgain <- withEachBastard tree whitelist killTree > if runAgain && n > 1 > then do > sleep 2 > killBastards tree whitelist (n - 1) > else > return () > > -- Configuration > > printConfig :: KillFunction > printConfig tree pid = do > let PsInfo psData _ = mapLookup pid tree > exe = mapLookup "Exe" psData > euid = mapLookup "EUid" psData > entry <- getUserEntryForID (read euid) > putStrLn $ exe ++ ": " ++ (userName entry) I wouldn't call this a KillFunction; in fact, I would probably just inline the definition of KillFunction throughout. An expression that has to be decoded is better than a name that is misleading. > > -- main helpers > > config :: PsTree -> IO () > config tree = do > withEachBastard tree Map.empty printConfig > return () > > pstree :: PsTree -> IO () > pstree tree = do > printTree tree "1" > -- In newer kernels, process 2 is kthreadd, which is not a child > -- of init. > let info = mapLookup "2" tree > if parentPid info /= "1" then printTree tree "2" else return () > > kill :: PsTree -> IO () > kill tree = do > whitelist <- readWhiteList "killbastards.conf" > killBastards tree whitelist 5 > > main :: IO () > main = do > args <- getArgs > tree <- createTree > case args of > ["config"] -> config tree > ["pstree"] -> pstree tree > [] -> kill tree > From emax at cs.chalmers.se Thu Jan 10 01:19:43 2008 From: emax at cs.chalmers.se (Emil Axelsson) Date: Thu Jan 10 01:09:00 2008 Subject: [Haskell-cafe] Show instances for error messages (Was: Refactoring status) In-Reply-To: References: <002001c84e34$569c9f30$03d5dd90$@be> <1713055262.20080103220617@gmail.com> <003501c84e43$c6df2fb0$549d8f10$@be> <001e01c84efe$5f386410$1da92c30$@be> <4781F6BA.7010109@cs.chalmers.se> Message-ID: <4785B8FF.1090103@cs.chalmers.se> I think partial type signatures http://hackage.haskell.org/trac/haskell-prime/wiki/PartialTypeAnnotations would allow that kind of "tunneling". Is there any ongoing work on that? / Emil Henning Thielemann skrev: > On Mon, 7 Jan 2008, Emil Axelsson wrote: > >> One approach to programming in Haskell, which I use all the time, is to write >> the type signature before the function body. This means that if I'm trying to do >> something strange, I will often be warned by the type checker even before I've >> written the strange code. >> >> But I've also been bitten by the problem of having to change a lot of type >> signatures just because I want to e.g. show an overloaded variable. > > ... which is especially annoying if you need the Show instance for an > 'error'. Since 'error' denotes a programming error it should never be > evaluated and thus the Show instance is only for cases which must not > happen. Paradoxical. It would be interesting if it is possible to tunnel > Show class dictionaries through to an 'error' like IO is tunneled to > 'trace'. > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From cetin.sert at gmail.com Thu Jan 10 02:02:43 2008 From: cetin.sert at gmail.com (Cetin Sert) Date: Thu Jan 10 01:56:46 2008 Subject: [Haskell-cafe] Problems with Unicode Symbols as Infix Function Names in Propositional Calculus Haskell DSL In-Reply-To: <20080109224855.GA3589@localhost.localdomain> References: <20080109172417.GA29140@scytale.galois.com> <200801092223.06129.g9ks157k@acme.softbase.org> <20080109224855.GA3589@localhost.localdomain> Message-ID: I'm making sure that my project files are all saved in UTF-8: I'm not newbie enough to miss something like that. I suspect something between Visual Studio and the background GHC instance that feeds it with syntax highlighting and environment information (like a list of functions that are accessible or inferred type infos etc..) might be causing a miscommunication with regards to the file encodings. I also tried writing -XUnicodeSyntax. I'll try to use some other editor and directly call the compiler to see if it works. Thanks for all your support ^_^ Best Regards, Cetin Sert http://www.corsis.de -----Original Message----- From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Stefan O'Rear Sent: Mittwoch, 9. Januar 2008 23:49 To: Wolfgang Jeltsch Cc: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] Problems with Unicode Symbols as Infix Function Names in Propositional Calculus Haskell DSL On Wed, Jan 09, 2008 at 10:23:05PM +0100, Wolfgang Jeltsch wrote: > Am Mittwoch, 9. Januar 2008 18:34 schrieb Cetin Sert: > > Neither appending "{-# OPTIONS_GHC -fglasgow-exts -xunicodesyntax #-}" > > First, I think, you have to use -XUnicodeSyntax (as Don said), and not > -xunicodesyntax. Second, -XUnicodeSyntax only enables alternative > notation for certain built-in syntax (as Don said). > > Unicode for operators is a different matter. I?d think, it should > work out of the box and wonder a bit why it doesn?t. The give-away is that GHC gave a "UTF-8 decoding error". This says that Cetin is using a different encoding, presumably (due to his mention of Visual Haskell, ergo Windows) UTF-16. Stefan From alfonso.acosta at gmail.com Thu Jan 10 02:15:25 2008 From: alfonso.acosta at gmail.com (Alfonso Acosta) Date: Thu Jan 10 02:08:57 2008 Subject: [Haskell-cafe] ANNOUNCE: Haddock version 2.0.0.0 In-Reply-To: References: Message-ID: <6a7c66fc0801092315k103123afmfeee3c7d7db67df9@mail.gmail.com> On Jan 8, 2008 1:28 PM, David Waern wrote: > Dear Haskell community, > > I'm proud to announce the release of Haddock 2.0.0.0! Great! I already tested a dracs spanshot before the release and seemed to work well with TH code. Any idea about when will hackage adopt this version to generate its documentation? From paul at cogito.org.uk Thu Jan 10 02:27:35 2008 From: paul at cogito.org.uk (Paul Johnson) Date: Thu Jan 10 02:21:12 2008 Subject: [Haskell-cafe] Problem with own written monad In-Reply-To: <4782B631.2090904@nessie.de> References: <4782384F.6000102@nessie.de> <47823E26.2000501@jellybean.co.uk> <4782B631.2090904@nessie.de> Message-ID: <4785C8E7.70501@cogito.org.uk> Michael Roth wrote: > Yes, I have done: push, pop, top, nop, count, clear, isolate and binop. > All pretty easy, once I understand that "Stack a b" thing. > Now you are ready to write your monad tutorial. This is a standard rite of passage (or should that be "write a passage") for new Haskell programmers. Paul. From mmitar at gmail.com Thu Jan 10 03:22:03 2008 From: mmitar at gmail.com (Mitar) Date: Thu Jan 10 03:15:36 2008 Subject: [Haskell-cafe] 0/0 > 1 == False Message-ID: Hi! Why is 0/0 (which is NaN) > 1 == False and at the same time 0/0 < 1 == False. This means that 0/0 == 1? No, because also 0/0 == 1 == False. I understand that proper mathematical behavior would be that as 0/0 is mathematically undefined that 0/0 cannot be even compared to 1. There is probably an implementation reason behind it, but do we really want such "hidden" behavior? Would not it be better to throw some kind of an error? Mitar From cristi at ot.onrc.ro Thu Jan 10 03:45:58 2008 From: cristi at ot.onrc.ro (Cristian Baboi) Date: Thu Jan 10 03:39:59 2008 Subject: [Haskell-cafe] 0/0 > 1 == False In-Reply-To: References: Message-ID: On Thu, 10 Jan 2008 10:22:03 +0200, Mitar wrote: > Hi! > > Why is 0/0 (which is NaN) > 1 == False and at the same time 0/0 < 1 == > False. This means that 0/0 == 1? No, because also 0/0 == 1 == False. > > I understand that proper mathematical behavior would be that as 0/0 is > mathematically undefined that 0/0 cannot be even compared to 1. > > There is probably an implementation reason behind it, but do we really > want such "hidden" behavior? Would not it be better to throw some kind > of an error? > > > Mitar I think it's a bug. Here is why: let f = (\x -> x/0) in f 0 == f 0 Referential transparency say that f 0 must equal to f 0, but in this case it is not. :-) ________ Information from NOD32 ________ This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com From benja.fallenstein at gmail.com Thu Jan 10 03:48:51 2008 From: benja.fallenstein at gmail.com (Benja Fallenstein) Date: Thu Jan 10 03:42:26 2008 Subject: [Haskell-cafe] 0/0 > 1 == False In-Reply-To: References: Message-ID: Hi Mitar, On Jan 10, 2008 9:22 AM, Mitar wrote: > I understand that proper mathematical behavior would be that as 0/0 is > mathematically undefined that 0/0 cannot be even compared to 1. My understanding is that common mathematical practice is that comparing an undefined value to anything (including itself) always yields false; "x /= x" is sometimes used to formalize "x is undefined." If you have access to JSTOR, this article contains an overview of different fields' perspectives on dealing with undefinedness: http://links.jstor.org/sici?sici=0022-4812(199009)55%3A3%3C1269%3AAPFVOC%3E2.0.CO%3B2-T - Benja From cristi at ot.onrc.ro Thu Jan 10 04:07:15 2008 From: cristi at ot.onrc.ro (Cristian Baboi) Date: Thu Jan 10 04:01:07 2008 Subject: [Haskell-cafe] 0/0 > 1 == False In-Reply-To: References: Message-ID: On Thu, 10 Jan 2008 10:48:51 +0200, Benja Fallenstein wrote: > Hi Mitar, > > On Jan 10, 2008 9:22 AM, Mitar wrote: >> I understand that proper mathematical behavior would be that as 0/0 is >> mathematically undefined that 0/0 cannot be even compared to 1. > > My understanding is that common mathematical practice is that > comparing an undefined value to anything (including itself) always > yields false; "x /= x" is sometimes used to formalize "x is > undefined." Why let a = a in a /= a is not False ? ________ Information from NOD32 ________ This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com From ketil+haskell at ii.uib.no Thu Jan 10 04:13:05 2008 From: ketil+haskell at ii.uib.no (Ketil Malde) Date: Thu Jan 10 04:06:50 2008 Subject: [Haskell-cafe] 0/0 > 1 == False In-Reply-To: (Cristian Baboi's message of "Thu\, 10 Jan 2008 10\:45\:58 +0200") References: Message-ID: <87bq7u6o2m.fsf@nmd9999.imr.no> "Cristian Baboi" writes: > I think it's a bug. > Here is why: > > let f = (\x -> x/0) in f 0 == f 0 > > Referential transparency say that f 0 must equal to f 0, but in this > case it is not. :-) I think you are wrong. Referential transparency says that you can replace any occurence of 'f 0' with another expression of the same value, it does not say anything about the behaviour of (==). -k -- If I haven't seen further, it is by standing in the footprints of giants From cristi at ot.onrc.ro Thu Jan 10 04:13:32 2008 From: cristi at ot.onrc.ro (Cristian Baboi) Date: Thu Jan 10 04:07:41 2008 Subject: [Haskell-cafe] 0/0 > 1 == False In-Reply-To: References: Message-ID: On Thu, 10 Jan 2008 10:48:51 +0200, Benja Fallenstein wrote: > Hi Mitar, > > On Jan 10, 2008 9:22 AM, Mitar wrote: >> I understand that proper mathematical behavior would be that as 0/0 is >> mathematically undefined that 0/0 cannot be even compared to 1. > > My understanding is that common mathematical practice is that > comparing an undefined value to anything (including itself) always > yields false; "x /= x" is sometimes used to formalize "x is > undefined." How about this: f 1 = 1 f 2 = 2 > f 3 /= f 3 ________ Information from NOD32 ________ This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com From gale at sefer.org Thu Jan 10 04:17:18 2008 From: gale at sefer.org (Yitzchak Gale) Date: Thu Jan 10 04:10:53 2008 Subject: [Haskell-cafe] 0/0 > 1 == False In-Reply-To: References: Message-ID: <2608b8a80801100117wda28551ida0166f548147aac@mail.gmail.com> Mitar wrote: > > Why is 0/0 (which is NaN) > 1 == False and at the same time 0/0 < 1 == > > False. This means that 0/0 == 1? No, because also 0/0 == 1 == False. > > I understand that proper mathematical behavior would be that as 0/0 is > > mathematically undefined that 0/0 cannot be even compared to 1. > > There is probably an implementation reason behind it, but do we really > > want such "hidden" behavior? Would not it be better to throw some kind > > of an error? Like nearly all programming languages, Haskell implements the standard IEEE behavior for floating point numbers. That leads to some mathematical infelicities that are especially irking to us in Haskell, but the consensus was that it is best to follow the standard. That is why NaN==NaN, NaNNan are all False, The special case of 1/0 is less clear, though. One might decide that it should be an error rather than NaN, as some languages have. Cristian Baboi wrote: > I think it's a bug. > Here is why: > > let f = (\x -> x/0) in f 0 == f 0 > > Referential transparency say that f 0 must equal to f 0, but in this case > it is not. :-) This does not violate referential transparency. f 0 is always the same value. (==) is a function like any other; in this case, it does not satisfy the mathematical laws we would like it to in order to conform to standard floating point behavior. From cristi at ot.onrc.ro Thu Jan 10 04:18:20 2008 From: cristi at ot.onrc.ro (Cristian Baboi) Date: Thu Jan 10 04:12:20 2008 Subject: [Haskell-cafe] 0/0 > 1 == False In-Reply-To: <87bq7u6o2m.fsf@nmd9999.imr.no> References: <87bq7u6o2m.fsf@nmd9999.imr.no> Message-ID: and there is no such thing as "the same bottom" right ? On Thu, 10 Jan 2008 11:13:05 +0200, Ketil Malde wrote: > "Cristian Baboi" writes: > >> I think it's a bug. >> Here is why: >> >> let f = (\x -> x/0) in f 0 == f 0 >> >> Referential transparency say that f 0 must equal to f 0, but in this >> case it is not. :-) > > I think you are wrong. Referential transparency says that you can > replace any occurence of 'f 0' with another expression of the same > value, it does not say anything about the behaviour of (==). > > -k ________ Information from NOD32 ________ This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com From gale at sefer.org Thu Jan 10 04:23:51 2008 From: gale at sefer.org (Yitzchak Gale) Date: Thu Jan 10 04:17:25 2008 Subject: [Haskell-cafe] 0/0 > 1 == False In-Reply-To: References: <87bq7u6o2m.fsf@nmd9999.imr.no> Message-ID: <2608b8a80801100123j253a530dmfe295da0ec77628@mail.gmail.com> Cristian Baboi wrote: > and there is no such thing as "the same bottom" right ? Yes and no. Semantically, every bottom is the same. However, the Haskell Report makes bottom an explicit exceptional case. Compilers are allowed to do whatever they want with bottoms, including different results for different bottoms. There isn't any choice, really. In order to behave the same for every bottom, you would first have to solve the Halting Problem. Or hang forever on every bottom, which I don't think you would want. Regards, Yitz From cristi at ot.onrc.ro Thu Jan 10 04:28:58 2008 From: cristi at ot.onrc.ro (Cristian Baboi) Date: Thu Jan 10 04:22:39 2008 Subject: [Haskell-cafe] 0/0 > 1 == False In-Reply-To: <2608b8a80801100123j253a530dmfe295da0ec77628@mail.gmail.com> References: <87bq7u6o2m.fsf@nmd9999.imr.no> <2608b8a80801100123j253a530dmfe295da0ec77628@mail.gmail.com> Message-ID: On Thu, 10 Jan 2008 11:23:51 +0200, Yitzchak Gale wrote: > Cristian Baboi wrote: >> and there is no such thing as "the same bottom" right ? > Yes and no. Semantically, Yes and No is bottom ? ________ Information from NOD32 ________ This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com From jules at jellybean.co.uk Thu Jan 10 05:02:42 2008 From: jules at jellybean.co.uk (Jules Bean) Date: Thu Jan 10 04:56:22 2008 Subject: [Haskell-cafe] 0/0 > 1 == False In-Reply-To: <2608b8a80801100117wda28551ida0166f548147aac@mail.gmail.com> References: <2608b8a80801100117wda28551ida0166f548147aac@mail.gmail.com> Message-ID: <4785ED42.6070006@jellybean.co.uk> Yitzchak Gale wrote: > Mitar wrote: >>> Why is 0/0 (which is NaN) > 1 == False and at the same time 0/0 < 1 == >>> False. This means that 0/0 == 1? No, because also 0/0 == 1 == False. >>> I understand that proper mathematical behavior would be that as 0/0 is >>> mathematically undefined that 0/0 cannot be even compared to 1. >>> There is probably an implementation reason behind it, but do we really >>> want such "hidden" behavior? Would not it be better to throw some kind >>> of an error? > > Like nearly all programming languages, Haskell implements > the standard IEEE behavior for floating point numbers. > That leads to some mathematical infelicities that are > especially irking to us in Haskell, but the consensus was > that it is best to follow the standard. Nitpick: I think the haskell standard doesn't force you to implement IEEE floating point. Rather the haskell standard, for efficiency, permits you to reuse the "native" floating point of your host system. Since most of us are using haskell on top of IEEE C libraries / FPUs, most of us have IEEE floating point behaviour. Practically speaking, if you want different semantics from what the bare metal gives you, you have to wrap all kinds of things which would otherwise be directly compiled to opcodes, which robs you of any chance of getting the good performance you would hope for. Jules From gale at sefer.org Thu Jan 10 05:13:50 2008 From: gale at sefer.org (Yitzchak Gale) Date: Thu Jan 10 05:07:23 2008 Subject: [Haskell-cafe] 0/0 > 1 == False In-Reply-To: References: <87bq7u6o2m.fsf@nmd9999.imr.no> <2608b8a80801100123j253a530dmfe295da0ec77628@mail.gmail.com> Message-ID: <2608b8a80801100213l7e05c613rb095445a89251b25@mail.gmail.com> Cristian Baboi wrote: >>> and there is no such thing as "the same bottom" right ? I wrote: >> Yes and no. > Semantically, Yes and No is bottom ? Yes and no. -Yitz From gale at sefer.org Thu Jan 10 05:17:53 2008 From: gale at sefer.org (Yitzchak Gale) Date: Thu Jan 10 05:11:26 2008 Subject: [Haskell-cafe] 0/0 > 1 == False In-Reply-To: References: <87bq7u6o2m.fsf@nmd9999.imr.no> <2608b8a80801100123j253a530dmfe295da0ec77628@mail.gmail.com> Message-ID: <2608b8a80801100217i61af7fb0p962aef44a266e9e5@mail.gmail.com> Cristian Baboi wrote: > I think this should be put this way: > Bottom is a part of the semantic domain which is not Haskell. Rather, something outside Haskell that describes what Haskell programs mean. Yes. > In the semantic domain there is one bottom. > In Haskell there are many expressions that represent bottom. > One cannot test those for equality. Yes. > The result of a Haskell function applied to some arguments cannot be > bottom. I think you mean that they cannot be bottom if you want to compare them for equality. Yes. -Yitz From gale at sefer.org Thu Jan 10 05:22:48 2008 From: gale at sefer.org (Yitzchak Gale) Date: Thu Jan 10 05:16:22 2008 Subject: [Haskell-cafe] 0/0 > 1 == False In-Reply-To: <4785ED42.6070006@jellybean.co.uk> References: <2608b8a80801100117wda28551ida0166f548147aac@mail.gmail.com> <4785ED42.6070006@jellybean.co.uk> Message-ID: <2608b8a80801100222q275808b8vb833af30ca9fb897@mail.gmail.com> I wrote: >> Like nearly all programming languages, Haskell implements >> the standard IEEE behavior for floating point numbers. >> That leads to some mathematical infelicities that are >> especially irking to us in Haskell, but the consensus was >> that it is best to follow the standard. Jules Bean wrote: > Nitpick: > I think the haskell standard doesn't force you to implement IEEE > floating point. Not a nitpick. I should have written "Haskell compilers implement", not "Haskell implements". Thanks for the correction, and for the additional illumination. -Yitz From johan.tibell at gmail.com Thu Jan 10 05:29:41 2008 From: johan.tibell at gmail.com (Johan Tibell) Date: Thu Jan 10 05:23:15 2008 Subject: [Haskell-cafe] viewing HS files in Firefox In-Reply-To: <4727747B.7040902@millstream.com> References: <4723C03A.6080909@charter.net> <47272376.3020302@jellybean.co.uk> <4727747B.7040902@millstream.com> Message-ID: <90889fe70801100229y50178012ib404db0d4eec5ce3@mail.gmail.com> Adding the following to my lighttpd config (on Ubuntu Feisty) solves the problem from the server side: #### external configuration files ## mimetype mapping # change mime type for haskell source files so they get displayed # inside the browser include_shell "/usr/share/lighttpd/create-mime.assign.pl" mimetype.assign += ( ".hs" => "text/plain", ".lhs" => "text/plain" ) -- Johan From ketil+haskell at ii.uib.no Thu Jan 10 05:37:32 2008 From: ketil+haskell at ii.uib.no (Ketil Malde) Date: Thu Jan 10 05:31:14 2008 Subject: [Haskell-cafe] 0/0 > 1 == False In-Reply-To: <2608b8a80801100217i61af7fb0p962aef44a266e9e5@mail.gmail.com> (Yitzchak Gale's message of "Thu\, 10 Jan 2008 12\:17\:53 +0200") References: <87bq7u6o2m.fsf@nmd9999.imr.no> <2608b8a80801100123j253a530dmfe295da0ec77628@mail.gmail.com> <2608b8a80801100217i61af7fb0p962aef44a266e9e5@mail.gmail.com> Message-ID: <87sl1655lf.fsf@nmd9999.imr.no> "Yitzchak Gale" writes: >> In the semantic domain there is one bottom. >> In Haskell there are many expressions that represent bottom. >> One cannot test those for equality. If we are being pedantic, I can define data Foo = Foo instance Eq Foo where _ == _ = True (undefined :: Foo) == Foo --> True >> The result of a Haskell function applied to some arguments cannot be >> bottom. This function is bottom for any argument: f x = undefined > I think you mean that they cannot be bottom if you want > to compare them for equality. Yes. See above. What is the precise term for describing this? Structural equality? On the other hand, some bottoms are exceptions, you may be able to catch them and do something useful with them after all, no? How does that fit in? -k -- If I haven't seen further, it is by standing in the footprints of giants From lemming at henning-thielemann.de Thu Jan 10 05:41:44 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Thu Jan 10 05:35:17 2008 Subject: [Haskell-cafe] 0/0 > 1 == False In-Reply-To: <87sl1655lf.fsf@nmd9999.imr.no> References: <87bq7u6o2m.fsf@nmd9999.imr.no> <2608b8a80801100123j253a530dmfe295da0ec77628@mail.gmail.com> <2608b8a80801100217i61af7fb0p962aef44a266e9e5@mail.gmail.com> <87sl1655lf.fsf@nmd9999.imr.no> Message-ID: On Thu, 10 Jan 2008, Ketil Malde wrote: > > I think you mean that they cannot be bottom if you want > > to compare them for equality. Yes. > > See above. What is the precise term for describing this? Structural > equality? > > On the other hand, some bottoms are exceptions, you may be able to > catch them and do something useful with them after all, no? How does > that fit in? Catching errors is a hack: http://www.haskell.org/haskellwiki/Error http://www.haskell.org/haskellwiki/Exception From nickrolfe at gmail.com Thu Jan 10 05:56:10 2008 From: nickrolfe at gmail.com (Nick Rolfe) Date: Thu Jan 10 05:49:44 2008 Subject: [Haskell-cafe] Tim Sweeney (the gamer) In-Reply-To: <5ae4f2ba0801091621t5580361dv6fc5663f0c54c0ca@mail.gmail.com> References: <5ae4f2ba0801091621t5580361dv6fc5663f0c54c0ca@mail.gmail.com> Message-ID: <9313e97c0801100256r404973fdm9f781a2e8b90cd44@mail.gmail.com> On 10/01/2008, Galchin Vasili wrote: > Hello, > > I have been reading with great interested Tim Sweeney's slides on the > Next Generation Programming Language. Does anybody know his email address? Vasili is referring to these slides, which will probably interest many people on this list: http://morpheus.cs.ucdavis.edu/papers/sweeny.pdf He refers to Haskell and its strengths (and some of its weaknesses) quite a bit. For those who don't know him, Tim Sweeney is the main programmer behind Epic Games's popular Unreal Engine. When he talks, many game developers will listen. Perhaps more importantly, anything he does will affect a large number of game developers. Apologies if this has been posted before. From asviraspossible at gmail.com Thu Jan 10 06:47:13 2008 From: asviraspossible at gmail.com (Victor Nazarov) Date: Thu Jan 10 06:40:48 2008 Subject: [Haskell-cafe] Displaying steps in my interpreter Message-ID: Hello, I have little practice in Haskell. And I look forward for suggestions on how to improve the code. Code is not working: some definitions are missed. The goal of the code is to implement the evaluator for untyped lambda-calculus. The main problem is how to display each step of reduction? More detailed questions follows in the end of the code. Terms of lambda-calculus is the following data-type: > > data (Binder bndr) => > Term bndr = > Var bndr > | Lam bndr (Term bndr) > | App (Term bndr) (Term bndr) > Binder class is used to generate new unique binders and to compare binders > > class (Eq bndr) => Binder bndr > where {- ... -} > Next we'll define the evaluator. Evaluator returns the WHNF for each well-formed term, or _|_ if there is no WHNF Straight forward version: whnf :: Term bndr -> Term bndr whnf = reduce [] where reduce (a:as) (Lam b i) = reduce as $ subst b a i reduce as (App f a) = reduce (a:as) f reduce as term = foldl term App as But our goal is to perform only one step of reduction. And to display term after each reduction We refactor the original definition to perform this: > > whnfGen :: (Maybe String -> Bool) -> Term bndr -> Term bndr > whnfGen isFinal = runSteps isFinal $ reduce' [] > > where reduce' (a:as) (Lam b i) = markStep "beta" >> reduce as $ subst b a i > reduce' as (App f a) = reduce (a:as) f > reduce' as term = unwind as term > > reduce as term = > do final <- checkFinal > if final > then unwind as term > else reduce' as term > > unwind as term = return $ foldl term App as > Steps is the monad: > > newtype Steps mark a = > Steps { unSteps :: StateT (Maybe mark) (Reader (Maybe mark -> Bool)) a } > > instance Monad (Steps mark) > where (Steps a) >>= f = Steps $ a >>= \x -> unSteps (f x) > return a = Steps $ return a > > runSteps :: (Maybe mark -> Bool) -> Steps a -> (Maybe mark, a) > runSteps isFinal act = runReader (runStateT (unSteps act) Nothing) isFinal > > checkFinal :: Steps mark Bool > checkFinal = > do st <- Steps $ get > isFinal <- Steps $ lift $ ask > return $ isFinal st > > markStep :: mark -> Steps mark () > markStep = Steps . put . Just > Normal whnf can be written as follows: > > whnf = whnfGen (const False) > To print the reduction steps we can use the following code > > printReductions t = > do t' <- whnfGen isJust t > print t' > printReductions t' > Is there any better ways to implement printReductions? Is there a way to abstract out this steps pattern? For example if I want to show the process of converting lambda-terms to combinatory logic terms (I, K, S basis). I'll have to implement the same pattern. I can reuse Steps monad, but, I'll have to use markStep, checkFinal and special version of recursion. Is there a way to abstract this? Is there a more effective way to perform this? In printReductions I have to rescan the syntax tree over and over again to find the redex. Is there a way to save the position in the tree, to print the tree and then to resume from saved position? Thanx for reading this :) -- vir http://vir.comtv.ru/ From barsoap at web.de Thu Jan 10 06:51:49 2008 From: barsoap at web.de (Achim Schneider) Date: Thu Jan 10 06:45:34 2008 Subject: [Haskell-cafe] Re: Tim Sweeney (the gamer) References: <5ae4f2ba0801091621t5580361dv6fc5663f0c54c0ca@mail.gmail.com> <9313e97c0801100256r404973fdm9f781a2e8b90cd44@mail.gmail.com> Message-ID: <20080110125149.0f5dd989@solaris.tower> "Nick Rolfe" wrote: > http://morpheus.cs.ucdavis.edu/papers/sweeny.pdf > > He refers to Haskell and its strengths (and some of its weaknesses) > quite a bit. > > For those who don't know him, Tim Sweeney is the main programmer > behind Epic Games's popular Unreal Engine. When he talks, many game > developers will listen. > We will dream, most likely. > Perhaps more importantly, anything he does > will affect a large number of game developers. > Dreaming of pointy-haired bosses listening to him, that is. That said, he made the slides before the advent of the GHC API, which is the dream of anyone being worried about scripting performance... not to mention that it greatly reduces the edit/compile/test cycle once in place. Bytestring fusion wasn't in sight, too, afair... or spj worrying about pipeline stalls, to single out a single thing. All this is quite important in an industry where you test whether it's faster to properly generate the index numbers or rely on Java exceptions when you want to randomly index 3x3 portions of an NxM map where the indexed portion reduces to 2x3 or 2x2 in rare cases. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From sebastian.sylvan at gmail.com Thu Jan 10 07:15:10 2008 From: sebastian.sylvan at gmail.com (Sebastian Sylvan) Date: Thu Jan 10 07:08:44 2008 Subject: [Haskell-cafe] Re: Tim Sweeney (the gamer) In-Reply-To: <20080110125149.0f5dd989@solaris.tower> References: <5ae4f2ba0801091621t5580361dv6fc5663f0c54c0ca@mail.gmail.com> <9313e97c0801100256r404973fdm9f781a2e8b90cd44@mail.gmail.com> <20080110125149.0f5dd989@solaris.tower> Message-ID: <3d96ac180801100415x54bba49l2bc53553a5b2483d@mail.gmail.com> On Jan 10, 2008 11:51 AM, Achim Schneider wrote: > "Nick Rolfe" wrote: > > > http://morpheus.cs.ucdavis.edu/papers/sweeny.pdf > > > > He refers to Haskell and its strengths (and some of its weaknesses) > > quite a bit. > > > > For those who don't know him, Tim Sweeney is the main programmer > > behind Epic Games's popular Unreal Engine. When he talks, many game > > developers will listen. > > > We will dream, most likely. > > > Perhaps more importantly, anything he does > > will affect a large number of game developers. > > > Dreaming of pointy-haired bosses listening to him, that is. > I think he meant in the sense that the unreal engine has *lots* of licensees. If UnrealScript 4 is a Haskell-like language with lenient evaluation and limited dependent typing, etc., then that's what a large number of game developers will use in their day-to-day work. -- Sebastian Sylvan +44(0)7857-300802 UIN: 44640862 From barsoap at web.de Thu Jan 10 07:41:42 2008 From: barsoap at web.de (Achim Schneider) Date: Thu Jan 10 07:35:31 2008 Subject: [Haskell-cafe] Re: Tim Sweeney (the gamer) References: <5ae4f2ba0801091621t5580361dv6fc5663f0c54c0ca@mail.gmail.com> <9313e97c0801100256r404973fdm9f781a2e8b90cd44@mail.gmail.com> <20080110125149.0f5dd989@solaris.tower> <3d96ac180801100415x54bba49l2bc53553a5b2483d@mail.gmail.com> Message-ID: <20080110134142.3db7479e@solaris.tower> "Sebastian Sylvan" wrote: > > > For those who don't know him, Tim Sweeney is the main programmer > > > behind Epic Games's popular Unreal Engine. When he talks, many > > > game developers will listen. > > > > > We will dream, most likely. > > > > > Perhaps more importantly, anything he does > > > will affect a large number of game developers. > > > > > Dreaming of pointy-haired bosses listening to him, that is. > > > > I think he meant in the sense that the unreal engine has *lots* of > licensees. If UnrealScript 4 is a Haskell-like language with lenient > evaluation and limited dependent typing, etc., then that's what a > large number of game developers will use in their day-to-day work. > Er, yes. Some gameplay programmers will, and also some level designers, seen 3d-wise, that most likely means gfx guys, who would generally rather work with some warm, fuzzy, graphical switch->event thingy. The rest is still afaict left with C++ which gets linked into the engine. You make less bugs with that language? Fucking learn to write C++! I don't know how the UE is priced, but with the $10.000 that the cheapest id engine cost as I looked it up you can develop a whole game... CrystalSpace is sufficient for nearly everything one could want to do, except maybe ahead-of-the-art graphic demos pushed into markets by million-euro advertisement and game-mag-bribing budgets. I don't think you would get even close to 1000 people who use UnrealScript to earn their living. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From david.waern at gmail.com Thu Jan 10 07:55:38 2008 From: david.waern at gmail.com (David Waern) Date: Thu Jan 10 07:49:11 2008 Subject: [Haskell-cafe] ANNOUNCE: Haddock version 2.0.0.0 In-Reply-To: <6a7c66fc0801092315k103123afmfeee3c7d7db67df9@mail.gmail.com> References: <6a7c66fc0801092315k103123afmfeee3c7d7db67df9@mail.gmail.com> Message-ID: 2008/1/10, Alfonso Acosta : > On Jan 8, 2008 1:28 PM, David Waern wrote: > > Dear Haskell community, > > > > I'm proud to announce the release of Haddock 2.0.0.0! > > Great! I already tested a dracs spanshot before the release and seemed > to work well with TH code. > > Any idea about when will hackage adopt this version to generate its > documentation? Hmm, I'm not sure since I'm not involved in Hackage, but I can't think of anything that would stop Hackage from adopting it right away. David From jules at jellybean.co.uk Thu Jan 10 07:55:41 2008 From: jules at jellybean.co.uk (Jules Bean) Date: Thu Jan 10 07:49:19 2008 Subject: [Haskell-cafe] viewing HS files in Firefox In-Reply-To: <90889fe70801100229y50178012ib404db0d4eec5ce3@mail.gmail.com> References: <4723C03A.6080909@charter.net> <47272376.3020302@jellybean.co.uk> <4727747B.7040902@millstream.com> <90889fe70801100229y50178012ib404db0d4eec5ce3@mail.gmail.com> Message-ID: <478615CD.1040205@jellybean.co.uk> Johan Tibell wrote: > Adding the following to my lighttpd config (on Ubuntu Feisty) solves > the problem from the server side: > > #### external configuration files > ## mimetype mapping > > # change mime type for haskell source files so they get displayed > # inside the browser > include_shell "/usr/share/lighttpd/create-mime.assign.pl" > mimetype.assign += ( ".hs" => "text/plain", > ".lhs" => "text/plain" ) Fortunately the new haddock uses hscolour, so HS files are served as (colourised!) HTML and the problem is no longer a problem, for me. Jules From sebastian.sylvan at gmail.com Thu Jan 10 07:57:01 2008 From: sebastian.sylvan at gmail.com (Sebastian Sylvan) Date: Thu Jan 10 07:50:34 2008 Subject: [Haskell-cafe] Re: Tim Sweeney (the gamer) In-Reply-To: <20080110134142.3db7479e@solaris.tower> References: <5ae4f2ba0801091621t5580361dv6fc5663f0c54c0ca@mail.gmail.com> <9313e97c0801100256r404973fdm9f781a2e8b90cd44@mail.gmail.com> <20080110125149.0f5dd989@solaris.tower> <3d96ac180801100415x54bba49l2bc53553a5b2483d@mail.gmail.com> <20080110134142.3db7479e@solaris.tower> Message-ID: <3d96ac180801100457v16e5a17ah75c88a2bb555815e@mail.gmail.com> On Jan 10, 2008 12:41 PM, Achim Schneider wrote: > "Sebastian Sylvan" wrote: > > > > > For those who don't know him, Tim Sweeney is the main programmer > > > > behind Epic Games's popular Unreal Engine. When he talks, many > > > > game developers will listen. > > > > > > > We will dream, most likely. > > > > > > > Perhaps more importantly, anything he does > > > > will affect a large number of game developers. > > > > > > > Dreaming of pointy-haired bosses listening to him, that is. > > > > > > > I think he meant in the sense that the unreal engine has *lots* of > > licensees. If UnrealScript 4 is a Haskell-like language with lenient > > evaluation and limited dependent typing, etc., then that's what a > > large number of game developers will use in their day-to-day work. > > > Er, yes. Some gameplay programmers will, and also some level designers, > seen 3d-wise, that most likely means gfx guys, who would generally > rather work with some warm, fuzzy, graphical switch->event thingy. The > rest is still afaict left with C++ which gets linked into the engine. I would assume that if they did go this route of developing their own language, they would probably put a much larger part of the code-base in this new language, but this is all hypothetical. > > You make less bugs with that language? Fucking learn to write C++! Excuse me? > > I don't think you would get even close to 1000 people who use > UnrealScript to earn their living. > You don't need more than that. All you need to do is prove that it works, and other similar languages will have an easier time. If you get a couple of AAA titles using a purely functional language for >50% of the code, then the resistance towards switching languages will likely diminish. -- Sebastian Sylvan +44(0)7857-300802 UIN: 44640862 From Nicholls.Mark at mtvne.com Thu Jan 10 08:03:06 2008 From: Nicholls.Mark at mtvne.com (Nicholls, Mark) Date: Thu Jan 10 07:56:41 2008 Subject: [Haskell-cafe] confusion about 'instance'.... In-Reply-To: <002c01c84e00$76b74d30$6425e790$@be> References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <004a01c84d7e$556a3160$003e9420$@vers@telenet.be> <002c01c84e00$76b74d30$6425e790$@be> Message-ID: Should be straight forward....simplest example is... class A a data D = D1 instance A D fine.....D is declared to be a member of type class A.... what about..... class A a type T = (forall x.Num x=>x) instance A T error!... " Illegal polymorphic or qualified type: forall x. (Num x) => x In the instance declaration for `A T'" I am simply trying to state that all members of typeclass Num are of typeclass A.... Doesn't like it. Does this mean that instance only operates on 'atomic' (for want of a better word) types? -----Original Message----- From: Peter Verswyvelen [mailto:peter.vers@telenet.be] On Behalf Of Peter Verswyvelen Sent: 03 January 2008 12:02 To: Nicholls, Mark Cc: haskell-cafe@haskell.org Subject: RE: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? Hi Mark, >> "foo1 :: Int -> obj -> String" > Yep...I think that's what I'd do....though I would have done... > "foo1 :: obj -> Int -> String" > Does that matter? Well, it's a good habit in Haskell to move the "most important" parameter to the end of the argument list. See e.g. http://www.haskell.org/haskellwiki/Parameter_order. > OK but I was going to go onto > Interface IX where A : IX {} > and > Interface IX where A : B {} No, I would not know how to that in Haskell using type classes. It seems Haskell does not allow cycles in type class definitions. But as I'm new, this does not mean it's not possible. It's more important to know *what* you are trying to do, than to give a solution in a different language, since OO and FP are kind of orthogonal languages. > Where I cannot see a way to do the above in Haskell at all....as > interfaces effectively operator on type classes not types....which seems > inherently more powerful Yeah, kind of makes sense. I liked interfaces in C# a lot, but when I started doing everything with interfaces, I found the lack of support for "mixins" or "default implementations" problematic. This ended up in a lot of copy/paste or encapsulating the implementations into a static class with plain functions, a mess. > But if these could be done in Haskell the see what could be made of > stuff like....which is obviously problematic in C# it obviously doesn't > work....but potentially does make 'sense'. > Interface IX : A {} Ah! That's one of the bigger restrictions in C# yes! C++ can do that; ATL uses it a lot, and I also like that approach. You can emulate "mixins" with that, and still stay in the single inheritance paradigm. In Haskell you don't do that at all of course, since you avoid thinking about "objects and inheritance" in the first place. OO is strange. They offer you the nice concept of inheritance, and then the guidelines tell you: "don't use too many levels of inheritance"... Although I've build huge projects using OO, it always felt a bit like unsafe hacking. I don't really have that feeling with Haskell, but that could also be because I'm too new to the language ;-) > I'm looking at Haskell because of the formality of it's type > system....but I'm actually not convinced it is as powerful as an OO > one....i.e. OO ones operatate principally (in Haskell speak) on "type > classes" not "types" Maybe you are right, I don't know, my theoritical skills are not high enough to answer that. Haskell just "feels" better to me, although the lack of a friendly productive IDE and large standard framework remains a bit of a burden. Good luck, Peter -----Original Message----- From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Nicholls, Mark Sent: Wednesday, January 02, 2008 5:41 PM To: haskell-cafe@haskell.org Subject: [Haskell-cafe] Is there anyone out there who can translate C# generics into Haskell? I'm trying to translate some standard C# constucts into Haskell... some of this seems easy.... Specifically 1) Interface IX { } 2) Interface IX { } 3) Interface IX Where A : IY { } 4) Interface IX : IZ Where A : IY { } I can take a punt at the first 2....but then it all falls apart _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe From lrpalmer at gmail.com Thu Jan 10 08:14:07 2008 From: lrpalmer at gmail.com (Luke Palmer) Date: Thu Jan 10 08:07:39 2008 Subject: [Haskell-cafe] confusion about 'instance'.... In-Reply-To: References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <002c01c84e00$76b74d30$6425e790$@be> Message-ID: <7ca3f0160801100514l43003d25g59c799498ba6a221@mail.gmail.com> On Jan 10, 2008 1:03 PM, Nicholls, Mark wrote: > Should be straight forward....simplest example is... > > class A a > > data D = D1 > > instance A D > > fine.....D is declared to be a member of type class A.... > > what about..... > > class A a > > type T = (forall x.Num x=>x) > > instance A T > > error!... > > " Illegal polymorphic or qualified type: forall x. (Num x) => x > In the instance declaration for `A T'" > > I am simply trying to state that all members of typeclass Num are of > typeclass A.... Ahh, you want: instance Num a => A a Sorry to lead you on, but that actually is not legal (and -fallow-undecidable-instances will make it legal, but you don't want that, because instances of this particular form are very likely to lead to an infinite loop). Adding supertypes like this is not possible in Haskell. I really want it to be, but alas... Luke > Doesn't like it. > > Does this mean that instance only operates on 'atomic' (for want of a > better word) types? > > > -----Original Message----- > From: Peter Verswyvelen [mailto:peter.vers@telenet.be] On Behalf Of > Peter Verswyvelen > Sent: 03 January 2008 12:02 > To: Nicholls, Mark > Cc: haskell-cafe@haskell.org > Subject: RE: [Haskell-cafe] Is there anyone out there who can translate > C# generics into Haskell? > > Hi Mark, > > >> "foo1 :: Int -> obj -> String" > > Yep...I think that's what I'd do....though I would have done... > > "foo1 :: obj -> Int -> String" > > Does that matter? > > Well, it's a good habit in Haskell to move the "most important" > parameter to > the end of the argument list. See e.g. > http://www.haskell.org/haskellwiki/Parameter_order. > > > OK but I was going to go onto > > Interface IX where A : IX {} > > and > > Interface IX where A : B {} > > No, I would not know how to that in Haskell using type classes. It seems > Haskell does not allow cycles in type class definitions. But as I'm new, > this does not mean it's not possible. It's more important to know *what* > you > are trying to do, than to give a solution in a different language, since > OO > and FP are kind of orthogonal languages. > > > Where I cannot see a way to do the above in Haskell at all....as > > interfaces effectively operator on type classes not types....which > seems > > inherently more powerful > > Yeah, kind of makes sense. I liked interfaces in C# a lot, but when I > started doing everything with interfaces, I found the lack of support > for > "mixins" or "default implementations" problematic. This ended up in a > lot of > copy/paste or encapsulating the implementations into a static class with > plain functions, a mess. > > > But if these could be done in Haskell the see what could be made of > > stuff like....which is obviously problematic in C# it obviously > doesn't > > work....but potentially does make 'sense'. > > Interface IX : A {} > > Ah! That's one of the bigger restrictions in C# yes! C++ can do that; > ATL > uses it a lot, and I also like that approach. You can emulate "mixins" > with > that, and still stay in the single inheritance paradigm. In Haskell you > don't do that at all of course, since you avoid thinking about "objects > and > inheritance" in the first place. > > OO is strange. They offer you the nice concept of inheritance, and then > the > guidelines tell you: "don't use too many levels of inheritance"... > Although > I've build huge projects using OO, it always felt a bit like unsafe > hacking. > I don't really have that feeling with Haskell, but that could also be > because I'm too new to the language ;-) > > > I'm looking at Haskell because of the formality of it's type > > system....but I'm actually not convinced it is as powerful as an OO > > one....i.e. OO ones operatate principally (in Haskell speak) on "type > > classes" not "types" > > Maybe you are right, I don't know, my theoritical skills are not high > enough > to answer that. Haskell just "feels" better to me, although the lack of > a > friendly productive IDE and large standard framework remains a bit of a > burden. > > Good luck, > Peter > > -----Original Message----- > From: haskell-cafe-bounces@haskell.org > [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Nicholls, Mark > Sent: Wednesday, January 02, 2008 5:41 PM > To: haskell-cafe@haskell.org > Subject: [Haskell-cafe] Is there anyone out there who can translate C# > generics into Haskell? > > I'm trying to translate some standard C# constucts into Haskell... some > of this seems easy.... > > Specifically > > 1) > > Interface IX > { > } > > 2) > > Interface IX > { > } > > 3) > > Interface IX > Where A : IY > { > } > > 4) > > Interface IX : IZ > Where A : IY > { > } > > > I can take a punt at the first 2....but then it all falls apart > _______________________________________________ > 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 > From Nicholls.Mark at mtvne.com Thu Jan 10 08:25:20 2008 From: Nicholls.Mark at mtvne.com (Nicholls, Mark) Date: Thu Jan 10 08:20:54 2008 Subject: [Haskell-cafe] confusion about 'instance'.... In-Reply-To: <7ca3f0160801100514l43003d25g59c799498ba6a221@mail.gmail.com> References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <002c01c84e00$76b74d30$6425e790$@be> <7ca3f0160801100514l43003d25g59c799498ba6a221@mail.gmail.com> Message-ID: Thanks for your response, I think you helped me on one of my previous abberations. Hmmm....this all slightly does my head in....on one hand we have types....then type classes (which appear to be a relation defined on types)....then existential types...which now appear not to be treated quite in the same way as 'normal' types....and in this instance the syntax even seems to change....does "instance Num a => A a" Mean the same thing as "instance A (forall a.Num a=>a)" seems like a weird questions, as you're saying my version doesn't mean anything....but does it mean that "forall types 'a', if 'a' is a member of the class Num, then 'a' is a member of class 'A'".... and secondly in what way can this construct lead to "undecidable instances" What are the instances, and what about them is undecidable....seems pretty decidable to me? What is the ramifications of turning this option on? -----Original Message----- From: Luke Palmer [mailto:lrpalmer@gmail.com] Sent: 10 January 2008 13:14 To: Nicholls, Mark Cc: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] confusion about 'instance'.... On Jan 10, 2008 1:03 PM, Nicholls, Mark wrote: > Should be straight forward....simplest example is... > > class A a > > data D = D1 > > instance A D > > fine.....D is declared to be a member of type class A.... > > what about..... > > class A a > > type T = (forall x.Num x=>x) > > instance A T > > error!... > > " Illegal polymorphic or qualified type: forall x. (Num x) => x > In the instance declaration for `A T'" > > I am simply trying to state that all members of typeclass Num are of > typeclass A.... Ahh, you want: instance Num a => A a Sorry to lead you on, but that actually is not legal (and -fallow-undecidable-instances will make it legal, but you don't want that, because instances of this particular form are very likely to lead to an infinite loop). Adding supertypes like this is not possible in Haskell. I really want it to be, but alas... Luke > Doesn't like it. > > Does this mean that instance only operates on 'atomic' (for want of a > better word) types? > > > -----Original Message----- > From: Peter Verswyvelen [mailto:peter.vers@telenet.be] On Behalf Of > Peter Verswyvelen > Sent: 03 January 2008 12:02 > To: Nicholls, Mark > Cc: haskell-cafe@haskell.org > Subject: RE: [Haskell-cafe] Is there anyone out there who can translate > C# generics into Haskell? > > Hi Mark, > > >> "foo1 :: Int -> obj -> String" > > Yep...I think that's what I'd do....though I would have done... > > "foo1 :: obj -> Int -> String" > > Does that matter? > > Well, it's a good habit in Haskell to move the "most important" > parameter to > the end of the argument list. See e.g. > http://www.haskell.org/haskellwiki/Parameter_order. > > > OK but I was going to go onto > > Interface IX where A : IX {} > > and > > Interface IX where A : B {} > > No, I would not know how to that in Haskell using type classes. It seems > Haskell does not allow cycles in type class definitions. But as I'm new, > this does not mean it's not possible. It's more important to know *what* > you > are trying to do, than to give a solution in a different language, since > OO > and FP are kind of orthogonal languages. > > > Where I cannot see a way to do the above in Haskell at all....as > > interfaces effectively operator on type classes not types....which > seems > > inherently more powerful > > Yeah, kind of makes sense. I liked interfaces in C# a lot, but when I > started doing everything with interfaces, I found the lack of support > for > "mixins" or "default implementations" problematic. This ended up in a > lot of > copy/paste or encapsulating the implementations into a static class with > plain functions, a mess. > > > But if these could be done in Haskell the see what could be made of > > stuff like....which is obviously problematic in C# it obviously > doesn't > > work....but potentially does make 'sense'. > > Interface IX : A {} > > Ah! That's one of the bigger restrictions in C# yes! C++ can do that; > ATL > uses it a lot, and I also like that approach. You can emulate "mixins" > with > that, and still stay in the single inheritance paradigm. In Haskell you > don't do that at all of course, since you avoid thinking about "objects > and > inheritance" in the first place. > > OO is strange. They offer you the nice concept of inheritance, and then > the > guidelines tell you: "don't use too many levels of inheritance"... > Although > I've build huge projects using OO, it always felt a bit like unsafe > hacking. > I don't really have that feeling with Haskell, but that could also be > because I'm too new to the language ;-) > > > I'm looking at Haskell because of the formality of it's type > > system....but I'm actually not convinced it is as powerful as an OO > > one....i.e. OO ones operatate principally (in Haskell speak) on "type > > classes" not "types" > > Maybe you are right, I don't know, my theoritical skills are not high > enough > to answer that. Haskell just "feels" better to me, although the lack of > a > friendly productive IDE and large standard framework remains a bit of a > burden. > > Good luck, > Peter > > -----Original Message----- > From: haskell-cafe-bounces@haskell.org > [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Nicholls, Mark > Sent: Wednesday, January 02, 2008 5:41 PM > To: haskell-cafe@haskell.org > Subject: [Haskell-cafe] Is there anyone out there who can translate C# > generics into Haskell? > > I'm trying to translate some standard C# constucts into Haskell... some > of this seems easy.... > > Specifically > > 1) > > Interface IX > { > } > > 2) > > Interface IX > { > } > > 3) > > Interface IX > Where A : IY > { > } > > 4) > > Interface IX : IZ > Where A : IY > { > } > > > I can take a punt at the first 2....but then it all falls apart > _______________________________________________ > 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 > From miguelimo38 at yandex.ru Thu Jan 10 08:30:18 2008 From: miguelimo38 at yandex.ru (Miguel Mitrofanov) Date: Thu Jan 10 08:23:57 2008 Subject: [Haskell-cafe] confusion about 'instance'.... In-Reply-To: 1630000000230271475 References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <004a01c84d7e$556a3160$003e9420$@vers@telenet.be> <002c01c84e00$76b74d30$6425e790$@be> 1630000000230271475 Message-ID: <533531199971818@webmail10.yandex.ru> > class A a > type T = (forall x.Num x=>x) > instance A T "type" declares a synonym, like #define in C - but working only on types. So, essentially, you wrote instance A (forall x.Num x => x) which is not very Haskelly. > I am simply trying to state that all members of typeclass Num are of > typeclass A.... You can't do that. But, if there would not be any other instances of A, then you don't need it at all, you can just use Num class. And if there are some, for example data D = D instance A D then it can happen (well, it's unlikely, but possible) that you or some other developer working on your code would declare instance Num D where ... After that, you would have two instances of A for the type D, one defined explicitly and one derived from the Num instance. That's not a problem for this empty class, but if class A is not empty, say class A x where a :: x then the compiler would be unable to decide which instance (and which "a") to choose. So allowing that leads to non-obvious bugs. However, if you trust yourself enough, you can do what you want to in this way: {-# OPTIONS_GHC -fglasgow-exts -fallow-undecidable-instances #-} class A a instance Num a => A a From bulat.ziganshin at gmail.com Thu Jan 10 08:36:21 2008 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Jan 10 08:30:32 2008 Subject: [Haskell-cafe] confusion about 'instance'.... In-Reply-To: References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <002c01c84e00$76b74d30$6425e790$@be> <7ca3f0160801100514l43003d25g59c799498ba6a221@mail.gmail.com> Message-ID: <1903939160.20080110163621@gmail.com> Hello Mark, Thursday, January 10, 2008, 4:25:20 PM, you wrote: "instance Num a =>> A a" > Mean the same thing as > "instance A (forall a.Num a=>a)" programmers going from OOP world always forget that classes in Haskell doesn't the same as classes in C++. *implementation* of this instance require to pass dictionary of Num class along with type. now imagine the following code: f :: A a => a -> a f cannot use your instance because it doesn't receive Num dictionary of type `a`. it is unlike OOP situation where every object carries the generic VMT which includes methods for every class/interface that object supports as usual, i suggest you to study http://haskell.org/haskellwiki/OOP_vs_type_classes first and especially two papers mentioned in References there -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From Nicholls.Mark at mtvne.com Thu Jan 10 08:49:18 2008 From: Nicholls.Mark at mtvne.com (Nicholls, Mark) Date: Thu Jan 10 08:42:51 2008 Subject: [Haskell-cafe] confusion about 'instance'.... In-Reply-To: <533531199971818@webmail10.yandex.ru> References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <004a01c84d7e$556a3160$003e9420$@vers@telenet.be> <002c01c84e00$76b74d30$6425e790$@be> 1630000000230271475 <533531199971818@webmail10.yandex.ru> Message-ID: > > class A a > > type T = (forall x.Num x=>x) > > instance A T > > "type" declares a synonym, like #define in C - but working only on types. > So, essentially, you wrote Yep that's fine.. > > instance A (forall x.Num x => x) > Yep > > which is not very Haskelly. > Hmmm... > > > > I am simply trying to state that all members of typeclass Num are of > > > typeclass A.... > > > You can't do that. Because it wont let me...or because it makes no sense? > But, if there would not be any other instances of A, > then you don't need it at all, you can just use Num class. And if there > are some, for example Ok but there may be....I'm just trying to get my head around Haskells type system.... > > data D = D > > instance A D > > Yep. D is a member of A > > then it can happen (well, it's unlikely, but possible) that you or some > other developer working on your code would declare > > instance Num D where ... > D is a member of Num (and I'm assuming that we've got....All Nums are also members of A....which is fine...so far). So...Num x implies A x.... So...D is a member of A.... Fine. > > > After that, you would have two instances of A for the type D, one defined > explicitly and one derived from the Num instance. I would have 2 declarations that D is a member of A....both consistent. > That's not a problem for > this empty class, but if class A is not empty, say > > > > class A x where a :: x > > > > then the compiler would be unable to decide which instance (and which "a") > to choose. So allowing that leads to non-obvious bugs. > This slightly bamboozles me..... I only have 1 type. If I say "my name is mark" twice, it doesn't mean I belong to set of objects called Mark twice.... which makes me think that type classes are not simple relations on types after all....they appear to be relations on declarations of types being members of a class. So in my example...there exists two instances of me claiming my name is Mark. > > > However, if you trust yourself enough, you can do what you want to in this > way: > > > > {-# OPTIONS_GHC -fglasgow-exts -fallow-undecidable-instances #-} > > class A a > > instance Num a => A a Hmmm...OK... It all seems a little odd.... From barsoap at web.de Thu Jan 10 08:49:23 2008 From: barsoap at web.de (Achim Schneider) Date: Thu Jan 10 08:43:05 2008 Subject: [Haskell-cafe] Re: Tim Sweeney (the gamer) References: <5ae4f2ba0801091621t5580361dv6fc5663f0c54c0ca@mail.gmail.com> <9313e97c0801100256r404973fdm9f781a2e8b90cd44@mail.gmail.com> <20080110125149.0f5dd989@solaris.tower> <3d96ac180801100415x54bba49l2bc53553a5b2483d@mail.gmail.com> <20080110134142.3db7479e@solaris.tower> <3d96ac180801100457v16e5a17ah75c88a2bb555815e@mail.gmail.com> Message-ID: <20080110144923.2db79eba@solaris.tower> "Sebastian Sylvan" wrote: > > > > You make less bugs with that language? Fucking learn to write C++! > > Excuse me? > A probable exclamation of a pointy-haired boss, that is. What I wanted to say is that if you tell such a guy that you'll make less bugs in language X, he would assume that you can't program properly at all or in the language you're supposed to be programming in. As much as I agree with your idealism, the most rigorous proof of the earth being a sphere orbiting the sun could not convince people of the fact that the earth isn't a planar disk, and actual awareness on how the sun "rises" and the sun "sets" is rare even in these days where people accept the fact. Paradigm changes might only take a generation in a scientific community, but it takes close to eons in a society, as its members aren't nearly as involved in the scientific progress, and are (that's a guess now) equally likely to resist a new paradigm as the scientists themselves. The surest thing to make people switch is to make them not aware of it, i.e. make things look exactly like in C, with incremental updates of the same variable and everything, while still retaining a purely functional semantic under the hood. I guess that's why success has to be avoided at all cost. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From niko.korhonen at gmail.com Thu Jan 10 08:51:05 2008 From: niko.korhonen at gmail.com (Niko Korhonen) Date: Thu Jan 10 08:44:45 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> Message-ID: Neil Mitchell wrote: > Laziness and purity together help with equational reasoning, compiler > transformations, less obscure bugs, better compositionality etc. Although it could be argued that laziness is the cause of some very obscure bugs... Niko From barsoap at web.de Thu Jan 10 08:54:41 2008 From: barsoap at web.de (Achim Schneider) Date: Thu Jan 10 08:48:29 2008 Subject: [Haskell-cafe] Re: Tim Sweeney (the gamer) References: <5ae4f2ba0801091621t5580361dv6fc5663f0c54c0ca@mail.gmail.com> <9313e97c0801100256r404973fdm9f781a2e8b90cd44@mail.gmail.com> <20080110125149.0f5dd989@solaris.tower> <3d96ac180801100415x54bba49l2bc53553a5b2483d@mail.gmail.com> <20080110134142.3db7479e@solaris.tower> <3d96ac180801100457v16e5a17ah75c88a2bb555815e@mail.gmail.com> <20080110144923.2db79eba@solaris.tower> Message-ID: <20080110145441.79a6d62c@solaris.tower> Achim Schneider wrote: > The surest thing to make people switch is to make them not aware of > it, i.e. make things look exactly like in C, with incremental updates > of the same variable and everything, while still retaining a purely > functional semantic under the hood. > > I guess that's why success has to be avoided at all cost. > But, still, I bet people would like to see Warning: Statements without effect: "c <- return 1 >>= increment >> return 2" ^^^^^^^^ *** ^^^ || when they write c = 1 ++c c = 2 -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From lrpalmer at gmail.com Thu Jan 10 08:58:33 2008 From: lrpalmer at gmail.com (Luke Palmer) Date: Thu Jan 10 08:52:06 2008 Subject: [Haskell-cafe] confusion about 'instance'.... In-Reply-To: References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <002c01c84e00$76b74d30$6425e790$@be> <7ca3f0160801100514l43003d25g59c799498ba6a221@mail.gmail.com> Message-ID: <7ca3f0160801100558j26003bbcr72853800518cde69@mail.gmail.com> On Jan 10, 2008 1:25 PM, Nicholls, Mark wrote: > Thanks for your response, I think you helped me on one of my previous > abberations. > > Hmmm....this all slightly does my head in....on one hand we have > types....then type classes (which appear to be a relation defined on > types)....then existential types...which now appear not to be treated > quite in the same way as 'normal' types....and in this instance the > syntax even seems to change....does > > "instance Num a => A a" > > Mean the same thing as > > "instance A (forall a.Num a=>a)" Uh... that second one is pretty much nonsensical to me. I could imagine it meaning the type (forall a.Num a => a) itself is an instance of A, but not specializations of it (like Int). But without an identity in the type system, the meaning of that would be convoluted. It's kind of off topic, but just for the interested, here are two similar, legal constructions: Existential: newtype Numeric = forall a. Num a => Numeric a Universal: newtype Numeric' = Numeric' (forall a. Num a => a) Both of which are easily declared to be instances of Num. They're not what you want though, because Haskell doesn't support what you want :-(. Anyway, if you have a value of type Numeric, you know it contains some value of a Num type, but you don't know what type exactly (and you can never find out). If you have a value of type Numeric', then you can produce a value of any Num type you please (i.e. the value is built out of only operations in the Num class, nothing more specific). But that was a digression; ignore at your leisure (now that you've already read it :-). > and secondly in what way can this construct lead to "undecidable > instances" Okay, read: instance A a => B b (where a and be might be more complex expressions) not as "b is an instance of B whenever a is an instance of A", but rather as "b is an instance of B, and using it as such adds a constraint of A a". Let's look at a slightly more complex (and contrived) example: class Foo a where foo :: a -> a instance (Foo [a]) => Foo a where foo x = head $ foo [x] Then when checking the type of the expression foo (0::Int), we'd have to check if Foo Int, Foo [Int], Foo [[Int]], Foo [[[Int]]], ad infinitum. > What are the instances, and what about them is undecidable....seems > pretty decidable to me? > > What is the ramifications of turning this option on? Theoretically, compile time fails to guarantee to ever finish. Practically, ghc will give you a very-difficult-to-reason-about message when constraint checking stack overflows. Luke From lrpalmer at gmail.com Thu Jan 10 09:00:57 2008 From: lrpalmer at gmail.com (Luke Palmer) Date: Thu Jan 10 08:54:29 2008 Subject: [Haskell-cafe] confusion about 'instance'.... In-Reply-To: <1903939160.20080110163621@gmail.com> References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <002c01c84e00$76b74d30$6425e790$@be> <7ca3f0160801100514l43003d25g59c799498ba6a221@mail.gmail.com> <1903939160.20080110163621@gmail.com> Message-ID: <7ca3f0160801100600g2616f212lf6d2948a6514ad80@mail.gmail.com> On Jan 10, 2008 1:36 PM, Bulat Ziganshin wrote: > Hello Mark, > > Thursday, January 10, 2008, 4:25:20 PM, you wrote: > > "instance Num a => A a" > > > Mean the same thing as > > > "instance A (forall a.Num a=>a)" > > programmers going from OOP world always forget that classes in Haskell > doesn't the same as classes in C++. *implementation* of this instance > require to pass dictionary of Num class along with type. now imagine > the following code: > > f :: A a => a -> a > > f cannot use your instance because it doesn't receive Num dictionary > of type `a`. it is unlike OOP situation where every object carries the > generic VMT which includes methods for every class/interface that > object supports I'm not sure that's a good argument. It doesn't need a Num dictionary, it only needs an A dictionary. That's what it says. You only need a Num dictionary in order to construct an A dictionary, which seems perfectly reasonable. Luke From Nicholls.Mark at mtvne.com Thu Jan 10 09:04:20 2008 From: Nicholls.Mark at mtvne.com (Nicholls, Mark) Date: Thu Jan 10 08:57:55 2008 Subject: [Haskell-cafe] confusion about 'instance'.... In-Reply-To: <1903939160.20080110163621@gmail.com> References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <002c01c84e00$76b74d30$6425e790$@be> <7ca3f0160801100514l43003d25g59c799498ba6a221@mail.gmail.com> <1903939160.20080110163621@gmail.com> Message-ID: > -----Original Message----- > From: Bulat Ziganshin [mailto:bulat.ziganshin@gmail.com] > Sent: 10 January 2008 13:36 > To: Nicholls, Mark > Cc: Luke Palmer; haskell-cafe@haskell.org > Subject: Re[2]: [Haskell-cafe] confusion about 'instance'.... > > Hello Mark, > > Thursday, January 10, 2008, 4:25:20 PM, you wrote: > > "instance Num a =>> A a" > > > Mean the same thing as > > > "instance A (forall a.Num a=>a)" > > programmers going from OOP world always forget that classes in Haskell > doesn't the same as classes in C++. *implementation* of this instance > require to pass dictionary of Num class along with type. now imagine > the following code: My confusion is not between OO classes and Haskell classes, but exactly are the members of a Haskell type class...I'd naively believed them to be types (like it says on the packet!)...but now I'm not so sure. > > f :: A a => a -> a > > f cannot use your instance because it doesn't receive Num dictionary > of type `a`. it is unlike OOP situation where every object carries the > generic VMT which includes methods for every class/interface that > object supports > > as usual, i suggest you to study > http://haskell.org/haskellwiki/OOP_vs_type_classes > first and especially two papers mentioned in References there I have done....learning is not an atomic operation....i.e. I can only believe what I understand...academic papers are especially beyond me at this point. I can translate OO into mathematical logic pretty easily, I was trying to do the same thing (informally of course) with Haskell....but things are not quite what they appear....not because of some OO hang up (which I probably have many)...but because of what "type class" actually means. So you may be right, I think I need to understand more about the sematics of Haskell...I was hoping to stay (initially) ignorant. I will try the postscript doc and see if it makes any sense. > > -- > Best regards, > Bulat mailto:Bulat.Ziganshin@gmail.com From lrpalmer at gmail.com Thu Jan 10 09:11:59 2008 From: lrpalmer at gmail.com (Luke Palmer) Date: Thu Jan 10 09:05:31 2008 Subject: [Haskell-cafe] confusion about 'instance'.... In-Reply-To: References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <002c01c84e00$76b74d30$6425e790$@be> <7ca3f0160801100514l43003d25g59c799498ba6a221@mail.gmail.com> <1903939160.20080110163621@gmail.com> Message-ID: <7ca3f0160801100611h3c4c03b5lb317e6e34721a53f@mail.gmail.com> On Jan 10, 2008 2:04 PM, Nicholls, Mark wrote: > I can translate OO into mathematical logic pretty easily, I was trying > to do the same thing (informally of course) with Haskell....but things > are not quite what they appear....not because of some OO hang up (which > I probably have many)...but because of what "type class" actually means. But you can think of a type class as a set of types! The problem is that if we allow certain kinds of instances (such as the Foo instance I gave earlier) then the set is allowed to be non-recursive (only recursively enumerable), so determining whether a particular type is a member of it would be undecidable. Luke From jerzy.karczmarczuk at info.unicaen.fr Thu Jan 10 09:15:46 2008 From: jerzy.karczmarczuk at info.unicaen.fr (jerzy.karczmarczuk@info.unicaen.fr) Date: Thu Jan 10 09:09:23 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> Message-ID: Niko Korhonen writes: ... > Although it could be argued that laziness is the cause of some very > obscure bugs... > Niko Example, PLEASE. Jerzy Karczmarczuk From jules at jellybean.co.uk Thu Jan 10 09:17:14 2008 From: jules at jellybean.co.uk (Jules Bean) Date: Thu Jan 10 09:10:48 2008 Subject: [Haskell-cafe] confusion about 'instance'.... In-Reply-To: References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <002c01c84e00$76b74d30$6425e790$@be> <7ca3f0160801100514l43003d25g59c799498ba6a221@mail.gmail.com> Message-ID: <478628EA.4010707@jellybean.co.uk> Nicholls, Mark wrote: > Thanks for your response, I think you helped me on one of my previous > abberations. > > Hmmm....this all slightly does my head in....on one hand we have > types....then type classes (which appear to be a relation defined on > types)....then existential types...which now appear not to be treated > quite in the same way as 'normal' types....and in this instance the > syntax even seems to change....does > > "instance Num a => A a" This means: Given any type "a". Any type at all. Yes, ANY type "a", we accept that it might be an instance of A, and we add a "Num" context to the current inference. So, supposing: f :: (A a) => a -> b and we're trying to type check: f x We first try to unify x's type with the type variable "a", which is easy. Then we impose the constraint "A a". At some later stage we will try to resolve this constraint. When we try to resolve it, we find that all types "a" are instances of A, but you have to add a Num constraint. So we add the Num constraint. This behaviour is not what everyone wants, but it is a consequence of they type classes are specified. GHC lets you turn off this behaviour somewhat with overlapping and undecidable instances but that's not really an ideal solution either. The ideal solution to this precise case is probably just to make the Num class a superclass of A. That seems to do what you want. Jules From jules at jellybean.co.uk Thu Jan 10 09:22:06 2008 From: jules at jellybean.co.uk (Jules Bean) Date: Thu Jan 10 09:15:41 2008 Subject: [Haskell-cafe] confusion about 'instance'.... In-Reply-To: References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <002c01c84e00$76b74d30$6425e790$@be> <7ca3f0160801100514l43003d25g59c799498ba6a221@mail.gmail.com> <1903939160.20080110163621@gmail.com> Message-ID: <47862A0E.6040409@jellybean.co.uk> Nicholls, Mark wrote: > > My confusion is not between OO classes and Haskell classes, but exactly > are the members of a Haskell type class...I'd naively believed them to > be types (like it says on the packet!)...but now I'm not so sure. > Which packet? Classes are not types. Classes are groups of types. Sets of types. Classifications of types. For any type, you can ask the quesiton "is this type a member of this class, or not?" Without wishing to split hairs too finely, I find it a useful intuition not to consider the class context "part of the type" somehow. So, when you see this: (Num a, Eq b) => a -> b -> a Rather than thinking of that whole thing as a type, it helps to think of the part on the right of the => as the 'actual type' and the part on the left of the => as "some extra constraints on the type". So you might say this has the type "a -> b -> a", providing that a is a Num and b is an Eq. Jules From Nicholls.Mark at mtvne.com Thu Jan 10 09:28:32 2008 From: Nicholls.Mark at mtvne.com (Nicholls, Mark) Date: Thu Jan 10 09:22:06 2008 Subject: [Haskell-cafe] confusion about 'instance'.... In-Reply-To: <7ca3f0160801100558j26003bbcr72853800518cde69@mail.gmail.com> References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <002c01c84e00$76b74d30$6425e790$@be> <7ca3f0160801100514l43003d25g59c799498ba6a221@mail.gmail.com> <7ca3f0160801100558j26003bbcr72853800518cde69@mail.gmail.com> Message-ID: > > Thanks for your response, I think you helped me on one of my previous > > abberations. > > > > Hmmm....this all slightly does my head in....on one hand we have > > types....then type classes (which appear to be a relation defined on > > types)....then existential types...which now appear not to be treated > > quite in the same way as 'normal' types....and in this instance the > > syntax even seems to change....does > > > > "instance Num a => A a" > > > > Mean the same thing as > > > > "instance A (forall a.Num a=>a)" > > Uh... that second one is pretty much nonsensical to me. I could imagine > it > meaning the type (forall a.Num a => a) itself is an instance of A, but not > specializations of it (like Int). But without an identity in the type > system, > the meaning of that would be convoluted. It's kind of off topic, but just > for the interested, here are two similar, legal constructions: ok > > Existential: > newtype Numeric = forall a. Num a => Numeric a > My compiler doesn't like this...." A newtype constructor cannot have an existential context," > Universal: > newtype Numeric' = Numeric' (forall a. Num a => a) Not so sure I understand the difference here..... > > Both of which are easily declared to be instances of Num. They're not > what > you want though, because Haskell doesn't support what you want :-(. > Anyway, > if you have a value of type Numeric, you know it contains some value of a > Num type, but you don't know what type exactly (and you can never find > out). > If you have a value of type Numeric', then you can produce a value of any > Num > type you please (i.e. the value is built out of only operations in the Num > class, nothing more specific). > > But that was a digression; ignore at your leisure (now that you've already > read it :-). Makes little sense to me...."Numeric" looks reasonable...I think... "Numeric'"...seems weird....and I'm not sure I understood the explanation. > > > and secondly in what way can this construct lead to "undecidable > > instances" > > Okay, read: > > instance A a => B b > > (where a and be might be more complex expressions) not as "b is an > instance of > B whenever a is an instance of A", but rather as "b is an instance of B, > and > using it as such adds a constraint of A a". Let's look at a slightly more > complex (and contrived) example: > > class Foo a where > foo :: a -> a > > instance (Foo [a]) => Foo a where > foo x = head $ foo [x] > > Then when checking the type of the expression foo (0::Int), we'd have to > check if Foo Int, Foo [Int], Foo [[Int]], Foo [[[Int]]], ad infinitum. Ooo blimey....that sort of makes sense. > > > What are the instances, and what about them is undecidable....seems > > pretty decidable to me? > > > > What is the ramifications of turning this option on? > > Theoretically, compile time fails to guarantee to ever finish. > Practically, > ghc will give you a very-difficult-to-reason-about message when constraint > checking stack overflows. > > Luke From simonmarhaskell at gmail.com Thu Jan 10 09:31:13 2008 From: simonmarhaskell at gmail.com (Simon Marlow) Date: Thu Jan 10 09:24:49 2008 Subject: [Haskell-cafe] Re: [Haskell] Problems with Unicode Symbols as Infix Function Names in Propositional Calculus Haskell DSL In-Reply-To: References: Message-ID: <47862C31.5040403@gmail.com> Cetin Sert wrote: > I want to design a DSL in Haskell for propositional calculus. But > instead of using natural language names for functions like or, and, > implies etc. I want to use Unicode symbols as infix functions ?, ?, ?, > ?, ? But I keep getting error messages from the GHC parser. Is there a > way to make GHC parse my source files correctly? If it is not possible > yet, please consider this as a ?feature request?. GHC supports unicode source files encoded using UTF-8 by default. It should be possible to use many unicode symbols for infix symbols. Note that when -XUnicodeSyntax is on, certain symbols have special meanings (e.g. ? means ->). Without more information I can't tell exactly what problem you're encountering. If you supply the source code you're trying to compile, we might be able to help. Also, note that glasgow-haskell-users@haskell.org is a better forum for GHC-specific issues. Cheers, Simon From johan.tibell at gmail.com Thu Jan 10 09:32:37 2008 From: johan.tibell at gmail.com (Johan Tibell) Date: Thu Jan 10 09:26:12 2008 Subject: [Haskell-cafe] viewing HS files in Firefox In-Reply-To: <478615CD.1040205@jellybean.co.uk> References: <4723C03A.6080909@charter.net> <47272376.3020302@jellybean.co.uk> <4727747B.7040902@millstream.com> <90889fe70801100229y50178012ib404db0d4eec5ce3@mail.gmail.com> <478615CD.1040205@jellybean.co.uk> Message-ID: <90889fe70801100632p11adcde4h9c07c0ae6ad0117e@mail.gmail.com> On Jan 10, 2008 1:55 PM, Jules Bean wrote: > > Johan Tibell wrote: > > Adding the following to my lighttpd config (on Ubuntu Feisty) solves > > the problem from the server side: > > > > #### external configuration files > > ## mimetype mapping > > > > # change mime type for haskell source files so they get displayed > > # inside the browser > > include_shell "/usr/share/lighttpd/create-mime.assign.pl" > > mimetype.assign += ( ".hs" => "text/plain", > > ".lhs" => "text/plain" ) > > Fortunately the new haddock uses hscolour, so HS files are served as > (colourised!) HTML and the problem is no longer a problem, for me. > > Jules > My problem is when viewing plain darcs repositories (like mine on darcs.johantibell.com which I recently fixed with the above mime type hack.) -- Johan From Nicholls.Mark at mtvne.com Thu Jan 10 09:33:52 2008 From: Nicholls.Mark at mtvne.com (Nicholls, Mark) Date: Thu Jan 10 09:27:26 2008 Subject: [Haskell-cafe] confusion about 'instance'.... In-Reply-To: <7ca3f0160801100611h3c4c03b5lb317e6e34721a53f@mail.gmail.com> References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <002c01c84e00$76b74d30$6425e790$@be> <7ca3f0160801100514l43003d25g59c799498ba6a221@mail.gmail.com> <1903939160.20080110163621@gmail.com> <7ca3f0160801100611h3c4c03b5lb317e6e34721a53f@mail.gmail.com> Message-ID: Someone said something about having 2 instances of the type in the typeclass.....maybe I misinterpreted it. > -----Original Message----- > From: Luke Palmer [mailto:lrpalmer@gmail.com] > Sent: 10 January 2008 14:12 > To: Nicholls, Mark > Cc: Bulat Ziganshin; haskell-cafe@haskell.org > Subject: Re: Re[2]: [Haskell-cafe] confusion about 'instance'.... > > On Jan 10, 2008 2:04 PM, Nicholls, Mark wrote: > > I can translate OO into mathematical logic pretty easily, I was trying > > to do the same thing (informally of course) with Haskell....but things > > are not quite what they appear....not because of some OO hang up (which > > I probably have many)...but because of what "type class" actually means. > > But you can think of a type class as a set of types! The problem is that > if we allow certain kinds of instances (such as the Foo instance I gave > earlier) then the set is allowed to be non-recursive (only recursively > enumerable), so determining whether a particular type is a member of it > would be undecidable. > > Luke From Nicholls.Mark at mtvne.com Thu Jan 10 09:41:13 2008 From: Nicholls.Mark at mtvne.com (Nicholls, Mark) Date: Thu Jan 10 09:34:49 2008 Subject: [Haskell-cafe] confusion about 'instance'.... In-Reply-To: <47862A0E.6040409@jellybean.co.uk> References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <002c01c84e00$76b74d30$6425e790$@be> <7ca3f0160801100514l43003d25g59c799498ba6a221@mail.gmail.com> <1903939160.20080110163621@gmail.com> <47862A0E.6040409@jellybean.co.uk> Message-ID: > -----Original Message----- > From: Jules Bean [mailto:jules@jellybean.co.uk] > Sent: 10 January 2008 14:22 > To: Nicholls, Mark > Cc: Bulat Ziganshin; haskell-cafe@haskell.org > Subject: Re: [Haskell-cafe] confusion about 'instance'.... > > Nicholls, Mark wrote: > > > > My confusion is not between OO classes and Haskell classes, but exactly > > are the members of a Haskell type class...I'd naively believed them to > > be types (like it says on the packet!)...but now I'm not so sure. > > > > > Which packet? The packet labelled "type class"....you're from .co.uk....you should understand my English idioms. :-) > > Classes are not types. Yep. > > Classes are groups of types. Sets of types. Classifications of types. I had them down as an n-ary relation on types....someone's said something somewhere that's made me question that...but I think I misinterpreted them....so I may default back to n-ary relation. > > For any type, you can ask the quesiton "is this type a member of this > class, or not?" yep > > Without wishing to split hairs too finely, I find it a useful intuition > not to consider the class context "part of the type" somehow. > > So, when you see this: > > (Num a, Eq b) => a -> b -> a > > Rather than thinking of that whole thing as a type, it helps to think of > the part on the right of the => as the 'actual type' and the part on the > left of the => as "some extra constraints on the type". Hmmm...I'm not sure that helps....it may just make me more confused. > > So you might say this has the type "a -> b -> a", providing that a is a > Num and b is an Eq. > > Jules From mroth at nessie.de Thu Jan 10 10:01:54 2008 From: mroth at nessie.de (Michael Roth) Date: Thu Jan 10 09:55:28 2008 Subject: [Haskell-cafe] Field updates in a state monad Message-ID: <47863362.3000408@nessie.de> Hello list, still playing with monads and states, I have the following question: Given: import Control.Monad.State.Lazy data MyData = MyData { content :: String } foobar :: State MyData String foobar = do gets content Ok, that looks nice and tidy. But: foobar2 :: State MyData () foobar2 = do modify $ \x -> x { content = "hello haskell"} ...looks not so nice. Exists there a way to write this cleaner without writing countless "set_xyz" helper functions? Michael From monnier at iro.umontreal.ca Thu Jan 10 10:07:25 2008 From: monnier at iro.umontreal.ca (Stefan Monnier) Date: Thu Jan 10 10:01:14 2008 Subject: [Haskell-cafe] Re: viewing HS files in Firefox References: <4723C03A.6080909@charter.net> <47272376.3020302@jellybean.co.uk> <4727747B.7040902@millstream.com> <90889fe70801100229y50178012ib404db0d4eec5ce3@mail.gmail.com> <478615CD.1040205@jellybean.co.uk> <90889fe70801100632p11adcde4h9c07c0ae6ad0117e@mail.gmail.com> Message-ID: > My problem is when viewing plain darcs repositories (like mine on > darcs.johantibell.com which I recently fixed with the above mime type > hack.) Please complain to your browser('s authors): most browsers only provide *one* way to view a given mime-type, which is stupid. It's not specific to .hs files. They could at least provide a way to override the provided mime-type, so you can say "display this application/octet-stream file as a text/plain". Similarly they should allow you to choose (via a context-menu, for example) to open a pdf file in the pdf plugin or in a separate application. Stefan From lutz at iks-jena.de Thu Jan 10 10:16:21 2008 From: lutz at iks-jena.de (Lutz Donnerhacke) Date: Thu Jan 10 10:09:57 2008 Subject: [Haskell-cafe] Field updates in a state monad References: <47863362.3000408@nessie.de> Message-ID: * Michael Roth wrote: > Exists there a way to write this cleaner without writing countless > "set_xyz" helper functions? The syntactic sugar for record modifications is simply that: sugar. You might write your own modifier functions: set_bla x y = x { bla = y } From barsoap at web.de Thu Jan 10 10:36:30 2008 From: barsoap at web.de (Achim Schneider) Date: Thu Jan 10 10:30:11 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> Message-ID: <20080110163630.056dc3e2@solaris.tower> jerzy.karczmarczuk@info.unicaen.fr wrote: > Niko Korhonen writes: > > ... > > Although it could be argued that laziness is the cause of some very > > obscure bugs... > > Niko > > Example, PLEASE. > [1..] == [1..] , for assumed operational semantics of ones own axiomatic semantics. Bugs are only a misunderstanding away. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From rendel at rbg.informatik.tu-darmstadt.de Thu Jan 10 10:45:00 2008 From: rendel at rbg.informatik.tu-darmstadt.de (Tillmann Rendel) Date: Thu Jan 10 10:38:48 2008 Subject: [Haskell-cafe] confusion about 'instance'.... In-Reply-To: References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <004a01c84d7e$556a3160$003e9420$@vers@telenet.be> <002c01c84e00$76b74d30$6425e790$@be> 1630000000230271475 <533531199971818@webmail10.yandex.ru> Message-ID: <47863D7C.1090506@rbg.informatik.tu-darmstadt.de> Nicholls, Mark wrote: > I only have 1 type. > > If I say "my name is mark" twice, it doesn't mean I belong to set of > objects called Mark twice.... Typeclasses define not only sets of types, but a common interface for these types, too. An analogy would be to say: I have a name, and it is Marc. I have a name, and it is John. From a "set of things" perspective, there is no problem: you belong to the set of people having a name. But what name should I actually use when I want to adress you? Tillmann From barsoap at web.de Thu Jan 10 10:45:27 2008 From: barsoap at web.de (Achim Schneider) Date: Thu Jan 10 10:39:16 2008 Subject: [Haskell-cafe] Re: viewing HS files in Firefox References: <4723C03A.6080909@charter.net> <47272376.3020302@jellybean.co.uk> <4727747B.7040902@millstream.com> <90889fe70801100229y50178012ib404db0d4eec5ce3@mail.gmail.com> <478615CD.1040205@jellybean.co.uk> <90889fe70801100632p11adcde4h9c07c0ae6ad0117e@mail.gmail.com> Message-ID: <20080110164527.1cc04263@solaris.tower> Stefan Monnier wrote: > > My problem is when viewing plain darcs repositories (like mine on > > darcs.johantibell.com which I recently fixed with the above mime > > type hack.) > > Please complain to your browser('s authors): most browsers only > provide *one* way to view a given mime-type, which is stupid. It's > not specific to .hs files. > > They could at least provide a way to override the provided mime-type, > so you can say "display this application/octet-stream file as > a text/plain". Similarly they should allow you to choose (via > a context-menu, for example) to open a pdf file in the pdf plugin or > in a separate application. > Konqueror offers: - mime default actions - opening path/index.html if pointed to path/ or path when operating locally - for any hyperlink: - save link as - copy link address - open with <-- - preview with <-- ...as it does offer copy, move, open with and preview with for any file in directory mode. Kpdf and likewise also nicely integrate their own buttons into the toolbar, replacing the khtmlpart zoom ones and so on. Vastly underestimated this thing is. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From daniel.yokomizo at gmail.com Thu Jan 10 10:47:17 2008 From: daniel.yokomizo at gmail.com (Daniel Yokomizo) Date: Thu Jan 10 10:40:50 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <20080110163630.056dc3e2@solaris.tower> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower> Message-ID: On Jan 10, 2008 3:36 PM, Achim Schneider wrote: > jerzy.karczmarczuk@info.unicaen.fr wrote: > > > Niko Korhonen writes: > > > > ... > > > Although it could be argued that laziness is the cause of some very > > > obscure bugs... > > > Niko > > > > Example, PLEASE. > > > [1..] == [1..] > > , for assumed operational semantics of ones own axiomatic semantics. > Bugs are only a misunderstanding away. It has nothing to do with laziness, but with using an algebraic function (==) with a codata structure (stream). If Haskell kept laziness but enforced separation of data and codata such code wouldn't compile. Lazy lists or streams never are a problem, but you can't (generically) fold codata. > -- > (c) this sig last receiving data processing entity. Inspect headers for > past copyright information. All rights reserved. Unauthorised copying, > hiring, renting, public performance and/or broadcasting of this > signature prohibited. Best regards, Daniel Yokomizo From barsoap at web.de Thu Jan 10 10:55:30 2008 From: barsoap at web.de (Achim Schneider) Date: Thu Jan 10 10:49:12 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower> Message-ID: <20080110165530.3948df88@solaris.tower> "Daniel Yokomizo" wrote: > On Jan 10, 2008 3:36 PM, Achim Schneider wrote: > > jerzy.karczmarczuk@info.unicaen.fr wrote: > > > > > Niko Korhonen writes: > > > > > > ... > > > > Although it could be argued that laziness is the cause of some > > > > very obscure bugs... > > > > Niko > > > > > > Example, PLEASE. > > > > > [1..] == [1..] > > > > , for assumed operational semantics of ones own axiomatic semantics. > > Bugs are only a misunderstanding away. > > It has nothing to do with laziness, but with using an algebraic > function (==) with a codata structure (stream). If Haskell kept > laziness but enforced separation of data and codata such code wouldn't > compile. Lazy lists or streams never are a problem, but you can't > (generically) fold codata. > Exactly. Denotationally it hasn't, but axiomatically it has. Because it looks like mathematical terms one can easily get lost in believing it reduces like mathematics, too. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From lemming at henning-thielemann.de Thu Jan 10 10:57:44 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Thu Jan 10 10:51:34 2008 Subject: [Haskell-cafe] confusion about 'instance'.... In-Reply-To: References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <002c01c84e00$76b74d30$6425e790$@be> <7ca3f0160801100514l43003d25g59c799498ba6a221@mail.gmail.com> <7ca3f0160801100558j26003bbcr72853800518cde69@mail.gmail.com> Message-ID: On Thu, 10 Jan 2008, Nicholls, Mark wrote: > > Existential: > > newtype Numeric = forall a. Num a => Numeric a > > > > My compiler doesn't like this...." A newtype constructor cannot have an > existential context," > > > Universal: > > newtype Numeric' = Numeric' (forall a. Num a => a) > > Not so sure I understand the difference here..... Looks like http://www.haskell.org/haskellwiki/Generic_number_type From daveroundy at gmail.com Thu Jan 10 10:59:40 2008 From: daveroundy at gmail.com (David Roundy) Date: Thu Jan 10 10:53:13 2008 Subject: [Haskell-cafe] Why purely in haskell? In-Reply-To: References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <2d3641330801090706m4ed9a927l282bb840a7dfcb7f@mail.gmail.com> <1199897022.18821.24.camel@derek-laptop> <4785339B.7050308@telenet.be> <47853A2C.2060508@appsolutions.com> <20080109212104.GD29472@scytale.galois.com> <117f2cc80801091415x643bec1cmf09931d4d16d59e5@mail.gmail.com> Message-ID: <117f2cc80801100759o23af9f8dtdbaff6ca8213171a@mail.gmail.com> On Jan 9, 2008 5:42 PM, Henning Thielemann wrote: > > I just want to point out that unsafePerformIO is at the core of the > > (safe) bytestring library. As SPJ et al pointed out, this is crucial > > functionality, and is only unsafe if unsafely used. > > Indeed, there are hacks and they are some times necessary. The good thing > about Haskell is, that hacks look like hacks. > > In Modula-3 modules using hacks must be explicitly marked as UNSAFE. See > http://www.cs.purdue.edu/homes/hosking/m3/reference/unsafe.html > Maybe this is also an option for Haskell? I don't think this is a good idea. It comes down to a question of whether you think it should be allowed for Haskell code to be used to write core Haskell libraries in a first-class manner. Perhaps you think libraries should always be in C in order to avoid the use of unsafePerformIO, but I prefer to allow them to be written in Haskell. But then, I don't see unsafePerformIO as inherently a hack. It's the only possible way that certain useful abstractions can be impelemented--at least, that's understanding. I'd be curious as to how much of the Prelude would be marked unsafe if you had your wish... David From jules at jellybean.co.uk Thu Jan 10 11:05:11 2008 From: jules at jellybean.co.uk (Jules Bean) Date: Thu Jan 10 10:58:47 2008 Subject: [Haskell-cafe] confusion about 'instance'.... In-Reply-To: References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <002c01c84e00$76b74d30$6425e790$@be> <7ca3f0160801100514l43003d25g59c799498ba6a221@mail.gmail.com> <1903939160.20080110163621@gmail.com> <47862A0E.6040409@jellybean.co.uk> Message-ID: <47864237.2080206@jellybean.co.uk> Nicholls, Mark wrote: >> Classes are groups of types. Sets of types. Classifications of types. > > I had them down as an n-ary relation on types....someone's said > something somewhere that's made me question that...but I think I > misinterpreted them....so I may default back to n-ary relation. Yes, and 1-ary relations are sets. And haskell98 only supports unary type classes, and all our discussion so far had been about unary type classes. But, since you mention it, yes MPTCs are n-ary relations. Jules From daveroundy at gmail.com Thu Jan 10 11:11:47 2008 From: daveroundy at gmail.com (David Roundy) Date: Thu Jan 10 11:05:22 2008 Subject: [Haskell-cafe] Re: ANN: A triple of new packages for talking tothe outside world In-Reply-To: <396556a20801091725p4a2dbf8aw3117a568b807c195@mail.gmail.com> References: <396556a20801061554o3895ce88k87d4ecabc1860e7b@mail.gmail.com> <47827AB4.60608@serpentine.com> <396556a20801081226l5ebf5062p685a80c6aac6ba41@mail.gmail.com> <1199885578.7279.119.camel@localhost> <117f2cc80801091425l41b73ea3uddda3d91ba9405e7@mail.gmail.com> <20080109234352.3ee84d4a@solaris.tower> <20080110010123.GF18915@darcs.net> <396556a20801091725p4a2dbf8aw3117a568b807c195@mail.gmail.com> Message-ID: <117f2cc80801100811p65d34fefl3a49c75948160493@mail.gmail.com> On Jan 9, 2008 8:25 PM, Adam Langley wrote: > I believe that it would be an additional if statement in the fast path at least. > > How about a BitGet monad which get be run in the Get monad? ... > Anyone like that idea? Sounds good to me. But then, I don't use Data.Binary (due to the lack of floating point support), so I'm not sure my opinion is all that relevant. David From stefan at cs.uu.nl Thu Jan 10 12:12:46 2008 From: stefan at cs.uu.nl (Stefan Holdermans) Date: Thu Jan 10 12:06:30 2008 Subject: [Haskell-cafe] Why purely in haskell? In-Reply-To: <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> Message-ID: <83F69307-DBDA-4AE9-B2CA-1AF3C057C6CC@cs.uu.nl> Neil wrote: > Laziness. It is very difficult to have a lazy language which is not > pure. Exactly. > Laziness and purity together help with equational reasoning, compiler > transformations, less obscure bugs, better compositionality etc. Related, but nevertheless a shameless plug: Jurriaan Hage and myself did some thinking about this lately and put some stuff on paper that I presented two days ago at PEPM [1]. Here's a quote, taken from the introduction: "Functional programming languages can be classified along several axes: we can distinguish between pure and impure langauges as well as between langauges with strict and nonstrict semantics. In practice, not all combinations make sense. Nonstrict languages better be pure, because reasoning about unrestricted side-effects becomes more complicated when the order of evaluation gets less predictable." "Purity has some clear advantages. For example, it enables equational reasoning and it opens the road to memoization, common subexpression elimination, and parallel evaluation strategies. The driving force that enables these opportunities is referential transparency: in a pure language, each of a program's terms can, at any time, be replaced by its value without changing the meaning of the program as a whole." Cheers, Stefan ----- [1] Jurriaan Hage and Stefan Holdermans. Heap recycling for lazy languages. In John Hatcliff, Robert Gl?ck, and Oege de Moor, editors, _Proceedings of the 2008 ACM SIGPLAN Symposium on Partial Evaluation and Semantics-Based Program Manipulation_, PEPM'08, San Francisco, California, USA, January 7--8, 2008, pages 189--197. ACM Press, 2008. http://doi.acm.org/10.1145/1328408.1328436 . From jerzy.karczmarczuk at info.unicaen.fr Thu Jan 10 12:13:03 2008 From: jerzy.karczmarczuk at info.unicaen.fr (jerzy.karczmarczuk@info.unicaen.fr) Date: Thu Jan 10 12:06:39 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <20080110163630.056dc3e2@solaris.tower> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower> Message-ID: Achim Schneider answers my question to somebody else (Niko Korhonen): >> > Although it could be argued that laziness is the cause of some very >> > obscure bugs... >> > Niko >> >> Example, PLEASE. >> > [1..] == [1..] Whatever you may say more, this is neither obscure nor a bug. I still wait for a relevant example. But I don't insist too much... Jerzy Karczmarczuk From johan.tibell at gmail.com Thu Jan 10 12:32:40 2008 From: johan.tibell at gmail.com (Johan Tibell) Date: Thu Jan 10 12:26:13 2008 Subject: [Haskell-cafe] Haskell-mode 2.4 In-Reply-To: <90889fe70801081337q5521f3e5yd49a2435d2d96ed2@mail.gmail.com> References: <90889fe70801081337q5521f3e5yd49a2435d2d96ed2@mail.gmail.com> Message-ID: <90889fe70801100932m15c1e08ey90c7a04578a35d54@mail.gmail.com> > First of all, thanks. My Aqua Emacs (on OS X Leopard) hangs when I > send a command like C-c C-l or C-c C-t to the interpreter (I can quit > the command using C-g) . Starting the interpreter and using :l from > inside it works fine. This is using GHC 6.8 (and I think I also tried > 6.6.) What could be the problem? > > I also tried to eval this but it didn't make a difference: > > (setq inferior-haskell-find-project-root nil) It looks like this is a problem with 6.8.2 as haskell-mode-2.3 has the same problem? Seems like the commands being sent to the haskell process never reaches it. From rendel at rbg.informatik.tu-darmstadt.de Thu Jan 10 12:38:07 2008 From: rendel at rbg.informatik.tu-darmstadt.de (Tillmann Rendel) Date: Thu Jan 10 12:31:54 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> Message-ID: <478657FF.2060509@rbg.informatik.tu-darmstadt.de> jerzy.karczmarczuk@info.unicaen.fr wrote: >> Although it could be argued that laziness is the cause of some very >> obscure bugs... Niko > > Example, PLEASE. Prelude> sum [1..1000000] *** Exception: stack overflow Prelude> Data.List.foldl' (+) 0 [1..1000000] 500000500000 Tillmann From apfelmus at quantentunnel.de Thu Jan 10 12:39:28 2008 From: apfelmus at quantentunnel.de (apfelmus) Date: Thu Jan 10 12:33:14 2008 Subject: [Haskell-cafe] Re: Displaying steps in my interpreter In-Reply-To: References: Message-ID: Victor Nazarov wrote: > The goal of the code is to implement the evaluator for untyped lambda-calculus. > The main problem is how to display each step of reduction? More > detailed questions follows in the end of the code. > > Terms of lambda-calculus is the following data-type: >> data (Binder bndr) => >> Term bndr = >> Var bndr >> | Lam bndr (Term bndr) >> | App (Term bndr) (Term bndr) >> > > Next we'll define the evaluator. Evaluator returns the WHNF for each > well-formed term, or _|_ if there is no WHNF > > Straight forward version: > > whnf :: Term bndr -> Term bndr > whnf = reduce [] > where reduce (a:as) (Lam b i) = reduce as $ subst b a i > reduce as (App f a) = reduce (a:as) f > reduce as term = foldl term App as > > But our goal is to perform only one step of reduction. And to display term > after each reduction > Is there a more effective way to perform this? In printReductions I have > to rescan the syntax tree over and over again to find the redex. Is there a > way to save the position in the tree, to print the tree and then to resume > from saved position? Yes, there is: you can use a zipper http://en.wikibooks.org/wiki/Haskell/Zippers Here's how: data Branch v = AppL (Term v) | AppR (Term v) | Lamb v type Context v = [Branch v] type Zipper v = (Context v, Term v) whnf :: Term v -> Term v whnf t = whnf' ([],t) where whnf' (AppL e':cxt, Lam x e) = whnf' (cxt , subst x e' e) whnf' (cxt , App f e) = whnf' (AppL e:cxt, f) whnf' z = unwind z unwind :: Zipper v -> Term v unwind ([] , t) = t unwind (AppL e:cxt, f) = unwind (cxt, App f e) unwind (AppR f:cxt, e) = unwind (cxt, App f e) unwind (Lamb x:cxt, e) = unwind (cxt, Lam x e) Note how this whnf and your whnf are pretty much exactly the same. In fact, your stack of pending applications (the as in reduce' as ) is already a zipper. The only difference here is that we are no longer limited to only walk down the left spine and can now implement other reduction strategies like nf or wnf too. Concerning the problem of printing intermediate steps, I don't quite understand your approach. I'd simply use a Writer monad to keep track of intermediate terms import Control.Monad.Writer -- use a difference list or something for better performance type Trace v = [Zipper v] whnf :: Term v -> Writer (Trace v) (Term v) whnf t = whnf' ([],t) where whnf' (AppL e':cxt, Lam x e) = tell (cxt, App (Lam x e) e') >> whnf' (cxt , subst x e' e) whnf' (cxt , App f e) = whnf' (AppL e:cxt, f) whnf' z = return $ unwind z The definition of whnf is basically left unchanged, except that a redex is recorded via tell whenever a beta-reduction is about to be performed. The recorded terms can be printed afterwards printTrace :: Writer (Trace v) (Term v) -> IO () printTrace w = let (t, ts) = runWriter t ts putStrLn . unlines . map show $ ts Note that "zipped" terms are recorded, i.e. the redex enclosed in its context and you can even highlight the redex while printing. Last but not least, there is a nice introductory paper about the many possible reduction strategies for lambda calculus http://www.itu.dk/people/sestoft/papers/sestoft-lamreduce.pdf Regards, apfelmus From barsoap at web.de Thu Jan 10 12:56:59 2008 From: barsoap at web.de (Achim Schneider) Date: Thu Jan 10 12:50:43 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower> Message-ID: <20080110185659.4d7117ff@solaris.tower> jerzy.karczmarczuk@info.unicaen.fr wrote: > Achim Schneider answers my question to somebody else (Niko Korhonen): > > >> > Although it could be argued that laziness is the cause of some > >> > very obscure bugs... > >> > Niko > >> > >> Example, PLEASE. > >> > > [1..] == [1..] > > Whatever you may say more, this is neither obscure nor a bug. I still > wait for a relevant example. But I don't insist too much... > It's not an example of a bug, but of a cause. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From chaddai.fouche at gmail.com Thu Jan 10 13:10:10 2008 From: chaddai.fouche at gmail.com (=?ISO-8859-1?Q?Chadda=EF_Fouch=E9?=) Date: Thu Jan 10 13:03:43 2008 Subject: [Haskell-cafe] Field updates in a state monad In-Reply-To: References: <47863362.3000408@nessie.de> Message-ID: 2008/1/10, Lutz Donnerhacke : > * Michael Roth wrote: > > Exists there a way to write this cleaner without writing countless > > "set_xyz" helper functions? > > The syntactic sugar for record modifications is simply that: sugar. > You might write your own modifier functions: > set_bla x y = x { bla = y } That seems to be exactly what Michael search to avoid. And I don't see any way to do that with the haskell records. Some extension of records may have first-class label though. A pretty interesting alternative could be HList, it has first-class label and a bunch of other good stuff. I never used it though, so I don't know how it affects the performances, if someone could give his experience with it ? -- Jeda? From dons at galois.com Thu Jan 10 13:10:21 2008 From: dons at galois.com (Don Stewart) Date: Thu Jan 10 13:03:57 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <478657FF.2060509@rbg.informatik.tu-darmstadt.de> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> <478657FF.2060509@rbg.informatik.tu-darmstadt.de> Message-ID: <20080110181021.GA17771@scytale.galois.com> rendel: > jerzy.karczmarczuk@info.unicaen.fr wrote: > >>Although it could be argued that laziness is the cause of some very > >>obscure bugs... Niko > > > >Example, PLEASE. > > Prelude> sum [1..1000000] > *** Exception: stack overflow > > Prelude> Data.List.foldl' (+) 0 [1..1000000] > 500000500000 See, http://hackage.haskell.org/trac/ghc/ticket/1997 Strictness for for atomic numeric types is inconsitently applied across the base library. Fixing the inconsitencies would let fix a range of similar issues. Note the strictness analyser handles this in compiled code, but doesn't run in ghci. -- Don From andre at digirati.com.br Thu Jan 10 13:21:28 2008 From: andre at digirati.com.br (Andre Nathan) Date: Thu Jan 10 13:14:06 2008 Subject: [Haskell-cafe] Comments and suggestions on code In-Reply-To: <6C68D342-F1B3-4333-8D7E-83E21E1FDB57@fastmail.fm> References: <1199937429.8936.33.camel@homesick> <6C68D342-F1B3-4333-8D7E-83E21E1FDB57@fastmail.fm> Message-ID: <1199989288.5309.12.camel@homesick> Hi Jonathan On Wed, 2008-01-09 at 21:32 -0800, Jonathan Cast wrote: > An actual coding question, abuse? We should be so lucky. :) Your comments are much appreciated. > This function is fairly complicated, simply because of the number of > separate definitions involved; I would be looking for opportunities > to inline definitions here, so it's clearer what the definitions > are. (Also, I would try to build a single, self-recursive function > at the top level, put the call to procInfo there, and make everything > else pure). I rewrote insertInTree like below. Now it is the only function that has a StateT return type, and I also got rid of addProc, insertPid and insertParent :) insertInTree :: Pid -> StateT PsTree IO () insertInTree pid = do tree <- get if Map.member pid tree then return () else do info <- lift $ procInfo pid modify (Map.insert pid info) let ppid = parentPid info if ppid /= "0" then do insertInTree ppid modify (appendChild ppid pid) else return () I also rewrote createTree like this: createTree :: IO PsTree createTree = do entries <- getDirectoryContents "/proc" let procs = filter (=~ "^[0-9]+$") entries execStateT (mapM_ insertInTree procs) Map.empty Is that a bad way to do it? If haskell wasn't lazy this would be 3 O(n) operations, and I could write it using readDirStream to process all entries in one pass. I'm not sure if that's really necessary when laziness is present though. Thanks a lot for the other comments. I'll look into using a record for PsInfo now. Best, Andre From jerzy.karczmarczuk at info.unicaen.fr Thu Jan 10 13:34:31 2008 From: jerzy.karczmarczuk at info.unicaen.fr (jerzy.karczmarczuk@info.unicaen.fr) Date: Thu Jan 10 13:28:03 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <20080110185659.4d7117ff@solaris.tower> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower> <20080110185659.4d7117ff@solaris.tower> Message-ID: Achim Schneider: > jerzy.karczmarczuk asks what's wrong with: >> > [1..] == [1..] >> >> Whatever you may say more, this is neither obscure nor a bug. I still >> wait for a relevant example. But I don't insist too much... >> > It's not an example of a bug, but of a cause. A cause of WHAT?? This is a perfect, nice, runaway computation, which agrees with all dogmas of my religion. Now, if somebody says that the fact that some people find it difficult to grasp the essence of laziness, and THIS is a source of bugs, I may believe. But not the laziness itself. (For some people the (==) operator seems to be a permanent source of bugs.) The difference between fold and stricter fold' won't convince me either. People who want to use laziness must simply read the documentation... On the other hand, what Don Stewart pointed out, the inconsistency between enumFrom and enumFromTo, and the difference of behaviours when one passes from Int to Integer, now, this is another story, worrying a little... Thanks. Perhaps another example is more relevant, the tradeoffs space-time in the "optimized" version of the powerset generator... Jerzy Karczmarczuk From dons at galois.com Thu Jan 10 13:45:21 2008 From: dons at galois.com (Don Stewart) Date: Thu Jan 10 13:38:57 2008 Subject: [Haskell-cafe] Re: ANN: A triple of new packages for talking tothe outside world In-Reply-To: <396556a20801091725p4a2dbf8aw3117a568b807c195@mail.gmail.com> References: <396556a20801071037t1b66e444u52abe1d934b7f902@mail.gmail.com> <47827AB4.60608@serpentine.com> <396556a20801081226l5ebf5062p685a80c6aac6ba41@mail.gmail.com> <1199885578.7279.119.camel@localhost> <117f2cc80801091425l41b73ea3uddda3d91ba9405e7@mail.gmail.com> <20080109234352.3ee84d4a@solaris.tower> <20080110010123.GF18915@darcs.net> <396556a20801091725p4a2dbf8aw3117a568b807c195@mail.gmail.com> Message-ID: <20080110184521.GA17906@scytale.galois.com> agl: > On Jan 9, 2008 5:01 PM, David Roundy wrote: > > But I can't imagine an implementation in which this change wouldn't slow > > down getBytes for the normal case. Perhaps the slowdown would be small, > > but it seems unwise to enforce that slowness at the API level, when we've > > already got a perfectly good API for fast binary IO. Maybe there's some > > type hackery you could do to avoid a speed penalty, but that's a lot to add > > for a somewhat dubious benefit. > > I believe that it would be an additional if statement in the fast path at least. > > How about a BitGet monad which get be run in the Get monad? > > > test :: Get () > > test = do > > runBitGet 2 (do > > getBitField 2) > > So the first argument to runBitGet is the number of bytes to parse for > bit fields and then functions in BitGet can extract bit-length ints > etc. > > Anyone like that idea? That's pretty much what we envisaged as the approach to take. Monad transformers adding some bit-buffer state over Get/Put. -- Don From miguelimo38 at yandex.ru Thu Jan 10 13:59:37 2008 From: miguelimo38 at yandex.ru (Miguel Mitrofanov) Date: Thu Jan 10 13:53:30 2008 Subject: [Haskell-cafe] confusion about 'instance'.... In-Reply-To: References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <004a01c84d7e$556a3160$003e9420$@vers@telenet.be> <002c01c84e00$76b74d30$6425e790$@be> 1630000000230271475 <533531199971818@webmail10.yandex.ru> Message-ID: <37591B19-9567-4365-8DFA-08D167ECF307@yandex.ru> > If I say "my name is mark" twice, it doesn't mean I belong to set of > objects called Mark twice.... Yes, but instance declaration doesn't only state that some type belongs to some class. It also provides some operations on this type. From sebastian.sylvan at gmail.com Thu Jan 10 14:00:05 2008 From: sebastian.sylvan at gmail.com (Sebastian Sylvan) Date: Thu Jan 10 13:53:46 2008 Subject: [Haskell-cafe] Re: Tim Sweeney (the gamer) In-Reply-To: <20080110144923.2db79eba@solaris.tower> References: <5ae4f2ba0801091621t5580361dv6fc5663f0c54c0ca@mail.gmail.com> <9313e97c0801100256r404973fdm9f781a2e8b90cd44@mail.gmail.com> <20080110125149.0f5dd989@solaris.tower> <3d96ac180801100415x54bba49l2bc53553a5b2483d@mail.gmail.com> <20080110134142.3db7479e@solaris.tower> <3d96ac180801100457v16e5a17ah75c88a2bb555815e@mail.gmail.com> <20080110144923.2db79eba@solaris.tower> Message-ID: <3d96ac180801101100q5efc3781i6048ed344c40be28@mail.gmail.com> On Jan 10, 2008 1:49 PM, Achim Schneider wrote: > "Sebastian Sylvan" wrote: > > > > > > > You make less bugs with that language? Fucking learn to write C++! > > > > Excuse me? > > > A probable exclamation of a pointy-haired boss, that is. What I wanted > to say is that if you tell such a guy that you'll make less bugs in > language X, he would assume that you can't program properly at all or > in the language you're supposed to be programming in. > Maybe I'm just lucky, but if we are still talking about the games industry I don't think this fits my experience of bosses. Games compete very much on performance, and we basically rewrite almost all of our code over a few years or so anyway (though not all at once). I think that means the games industry is very well suited to be at the forefront of adopting new technology, but there would have to be a fairly disruptive change in order for someone to say, for example, "right, let's rewrite all our runtime code in Haskell". Concurrency does seem pretty disruptive. -- Sebastian Sylvan +44(0)7857-300802 UIN: 44640862 From vigalchin at gmail.com Thu Jan 10 14:12:40 2008 From: vigalchin at gmail.com (Galchin Vasili) Date: Thu Jan 10 14:06:12 2008 Subject: [Haskell-cafe] GHC API? Message-ID: <5ae4f2ba0801101112l5b489ba6xdf51e75ae6fbef22@mail.gmail.com> Hello, I am reading http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/API. Is the GHC API a means of reflection Haskell? Or to put more simply what is its intent? Thanks, Vasili -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080110/d831c9e5/attachment.htm From dons at galois.com Thu Jan 10 14:16:40 2008 From: dons at galois.com (Don Stewart) Date: Thu Jan 10 14:10:14 2008 Subject: [Haskell-cafe] GHC API? In-Reply-To: <5ae4f2ba0801101112l5b489ba6xdf51e75ae6fbef22@mail.gmail.com> References: <5ae4f2ba0801101112l5b489ba6xdf51e75ae6fbef22@mail.gmail.com> Message-ID: <20080110191640.GA18003@scytale.galois.com> vigalchin: > Hello, > > I am reading > [1]http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/API. Is > the GHC API a means of reflection Haskell? Or to put more simply what is > its intent? > It can be used for reflection, since it exposes the interpreter at runtime. I think the original intent was a reusable code base of Haskell compiler/interpreter/type checker code, supporting all Haskell + GHC extensions, callable from Haskell, making language research, and new Haskell tools easier. -- Don From vigalchin at gmail.com Thu Jan 10 14:22:05 2008 From: vigalchin at gmail.com (Galchin Vasili) Date: Thu Jan 10 14:15:38 2008 Subject: [Haskell-cafe] The reason why I want Tim Sweeney's email address .. Message-ID: <5ae4f2ba0801101122l7b61f601p59b45dbe9ec928df@mail.gmail.com> Hello, http://www.coverity.com/html/library.php ....*Ensuring Code Quality in Multi-threaded Applications* ** *This "white paper" touches on Haskell's STM but also issues that Sweeney brought up in his slides(parallel programming in huge multi-cores and why the current thread-based paradigm is woefully inadequate. I already sent to Simon Peyton-Jones and Simon Marlowe.* ** *Regards, Vasili* -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080110/011c002a/attachment.htm From briqueabraque at yahoo.com Thu Jan 10 14:22:02 2008 From: briqueabraque at yahoo.com (=?windows-1252?Q?Maur=ED=ADcio?=) Date: Thu Jan 10 14:15:46 2008 Subject: [Haskell-cafe] Not to load Prelude Message-ID: Hi, Is it possible not to load Prelude module when compiling a Haskell module? Or instruct ghc to ?unload? it? Thanks, Maur?cio From droundy at darcs.net Thu Jan 10 14:23:04 2008 From: droundy at darcs.net (David Roundy) Date: Thu Jan 10 14:16:37 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <20080110181021.GA17771@scytale.galois.com> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> <478657FF.2060509@rbg.informatik.tu-darmstadt.de> <20080110181021.GA17771@scytale.galois.com> Message-ID: <20080110192302.GJ28763@darcs.net> On Thu, Jan 10, 2008 at 10:10:21AM -0800, Don Stewart wrote: > rendel: > > jerzy.karczmarczuk@info.unicaen.fr wrote: > > >>Although it could be argued that laziness is the cause of some very > > >>obscure bugs... Niko > > > > > >Example, PLEASE. > > > > Prelude> sum [1..1000000] > > *** Exception: stack overflow > > > > Prelude> Data.List.foldl' (+) 0 [1..1000000] > > 500000500000 > > See, > http://hackage.haskell.org/trac/ghc/ticket/1997 > > Strictness for for atomic numeric types is inconsitently applied > across the base library. Fixing the inconsitencies would let > fix a range of similar issues. Having followed this discussion, I agree with your analysis, but also think that rendel has chosen a good example of a pretty obscure bug caused by laziness in code written by folks who are actually decent Haskell programmers. It's unfortunate that there's no way to include strictness behavior in function types (at least that I'm aware of), so one has to rely on possibly-undocumented (and certainly never checked by a compiler) strictness behavior of many functions in order to write truly correct code. I wish there were a nice way around this issue (but can't really even imagine one). -- David Roundy Department of Physics Oregon State University From allbery at ece.cmu.edu Thu Jan 10 14:29:35 2008 From: allbery at ece.cmu.edu (Brandon S. Allbery KF8NH) Date: Thu Jan 10 14:23:08 2008 Subject: [Haskell-cafe] Not to load Prelude In-Reply-To: References: Message-ID: <024E30F4-69FE-4B67-80CA-0D753DA323B4@ece.cmu.edu> On Jan 10, 2008, at 14:22 , Maur? cio wrote: > Is it possible not to load Prelude module > when compiling a Haskell module? Or instruct > ghc to ?unload? it? -fno-implicit-prelude -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH From ari.rahikkala at gmail.com Thu Jan 10 14:31:31 2008 From: ari.rahikkala at gmail.com (Ari Rahikkala) Date: Thu Jan 10 14:25:06 2008 Subject: [Haskell-cafe] Not to load Prelude In-Reply-To: References: Message-ID: Sorry for the double message, Mauricio. It's the first time I ever posted to haskell-cafe - figures I'd click on "reply" and not "reply to all"... On Jan 10, 2008 9:22 PM, Maur??cio wrote: > Hi, > > Is it possible not to load Prelude module > when compiling a Haskell module? Or instruct > ghc to "unload" it? > > Thanks, > Maur?cio > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -XNoImplicitPrelude.does this in 6.8.x. In earlier versions (and apparently in 6.8 too), it's -fno-implicit-prelude. From clifford.beshers at gmail.com Thu Jan 10 14:31:38 2008 From: clifford.beshers at gmail.com (Clifford Beshers) Date: Thu Jan 10 14:25:13 2008 Subject: [Haskell-cafe] Not to load Prelude In-Reply-To: References: Message-ID: <6841b9520801101131v71399e9ah6d00d990ac7c5f4e@mail.gmail.com> Use: import Prelude () On Jan 10, 2008 11:22 AM, Maur??cio wrote: > Hi, > > Is it possible not to load Prelude module > when compiling a Haskell module? Or instruct > ghc to "unload" it? > > Thanks, > Maur?cio > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080110/fd0c7fb1/attachment.htm From jeremy.shaw at linspireinc.com Thu Jan 10 14:33:08 2008 From: jeremy.shaw at linspireinc.com (Jeremy Shaw) Date: Thu Jan 10 14:25:30 2008 Subject: [Haskell-cafe] Not to load Prelude In-Reply-To: References: Message-ID: At Thu, 10 Jan 2008 17:22:02 -0200, Maur??cio wrote: > > Hi, > > Is it possible not to load Prelude module > when compiling a Haskell module? Or instruct > ghc to ?unload? it? You can either do: import Prelude() or compile with the -fno-implicit-prelude flag, or add {-# LANGUAGE NoImplicitPrelude #-} to the top of the module. NoImplicitPrelude is more aggressive than 'import Prelude()'. You will have to look elsewhere for a better explanation of the difference. j. From jerzy.karczmarczuk at info.unicaen.fr Thu Jan 10 14:35:30 2008 From: jerzy.karczmarczuk at info.unicaen.fr (jerzy.karczmarczuk@info.unicaen.fr) Date: Thu Jan 10 14:29:03 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <20080110192302.GJ28763@darcs.net> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> <478657FF.2060509@rbg.informatik.tu-darmstadt.de> <20080110181021.GA17771@scytale.galois.com> <20080110192302.GJ28763@darcs.net> Message-ID: David Roundy writes: > It's unfortunate that there's no way to include strictness > behavior in function types (at least that I'm aware of), so one has to rely > on possibly-undocumented (and certainly never checked by a compiler) > strictness behavior of many functions in order to write truly correct > code. > > I wish there were a nice way around this issue (but can't really even > imagine one). I wonder not how to get around, but WHY we can't help the strictness analyser in a way Clean permits, say: add :: !Integer -> !Integer -> Integer I thought it could be done without any serious revolution within the compiler, but perhaps I am too na?ve (which in general is true...) Jerzy Karczmarczuk From barsoap at web.de Thu Jan 10 14:39:22 2008 From: barsoap at web.de (Achim Schneider) Date: Thu Jan 10 14:33:00 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower> <20080110185659.4d7117ff@solaris.tower> Message-ID: <20080110203922.0c4deb87@solaris.tower> jerzy.karczmarczuk@info.unicaen.fr wrote: > Achim Schneider: > > > jerzy.karczmarczuk asks what's wrong with: > >> > [1..] == [1..] > >> > >> Whatever you may say more, this is neither obscure nor a bug. I > >> still wait for a relevant example. But I don't insist too much... > >> > > It's not an example of a bug, but of a cause. > > A cause of WHAT?? This is a perfect, nice, runaway computation, which ^^^^^^^ > agrees with all dogmas of my religion. ^^^^^ The essence of laziness is to do the least work necessary to cause the desired effect, which is to see that the set of natural numbers equals the set of natural numbers, which, axiomatically, is always computable in O(1) by equality by identity. The essence of non-strictness, though, is another kind of story. Like a golem plowing half of the country until you remember that you placed him a bit absent-mindedly into your backyard and said "plow", that still won't plow mountains. The essence of strictness is easy, though: get stuck on a stone, fall over and continue moving until you break. And people just think axiomatically and then translate their understanding more or less blindly into code, even if they can't name the axiom(s). Or, as I already mentioned: | , for assumed operational semantics of ones own axiomatic semantics. | Bugs are only a misunderstanding away. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From barsoap at web.de Thu Jan 10 14:43:56 2008 From: barsoap at web.de (Achim Schneider) Date: Thu Jan 10 14:38:35 2008 Subject: [Haskell-cafe] Re: Tim Sweeney (the gamer) References: <5ae4f2ba0801091621t5580361dv6fc5663f0c54c0ca@mail.gmail.com> <9313e97c0801100256r404973fdm9f781a2e8b90cd44@mail.gmail.com> <20080110125149.0f5dd989@solaris.tower> <3d96ac180801100415x54bba49l2bc53553a5b2483d@mail.gmail.com> <20080110134142.3db7479e@solaris.tower> <3d96ac180801100457v16e5a17ah75c88a2bb555815e@mail.gmail.com> <20080110144923.2db79eba@solaris.tower> <3d96ac180801101100q5efc3781i6048ed344c40be28@mail.gmail.com> Message-ID: <20080110204356.361e5cb0@solaris.tower> "Sebastian Sylvan" wrote: > Concurrency > does seem pretty disruptive. > Yes, the thought of using par on a dual quad-core makes me salivate. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From dons at galois.com Thu Jan 10 14:51:37 2008 From: dons at galois.com (Don Stewart) Date: Thu Jan 10 14:45:13 2008 Subject: [Haskell-cafe] Re: Tim Sweeney (the gamer) In-Reply-To: <20080110204356.361e5cb0@solaris.tower> References: <5ae4f2ba0801091621t5580361dv6fc5663f0c54c0ca@mail.gmail.com> <9313e97c0801100256r404973fdm9f781a2e8b90cd44@mail.gmail.com> <20080110125149.0f5dd989@solaris.tower> <3d96ac180801100415x54bba49l2bc53553a5b2483d@mail.gmail.com> <20080110134142.3db7479e@solaris.tower> <3d96ac180801100457v16e5a17ah75c88a2bb555815e@mail.gmail.com> <20080110144923.2db79eba@solaris.tower> <3d96ac180801101100q5efc3781i6048ed344c40be28@mail.gmail.com> <20080110204356.361e5cb0@solaris.tower> Message-ID: <20080110195137.GB18003@scytale.galois.com> barsoap: > "Sebastian Sylvan" wrote: > > > Concurrency > > does seem pretty disruptive. > > > Yes, the thought of using par on a dual quad-core makes me salivate. Haskell is (in a very small part) driving sales of multicore boxes -- I've met half a dozen people who nominated Haskell's multicore support as a deciding reason to explicit get a multi-core box. Maybe we need to get some kickbacks from the hardware vendors, for helping their sales :) Intel, AMD, Nvidia -- are you guys listening?? In return, we can improve the parallelism support further. --Don From lemming at henning-thielemann.de Thu Jan 10 14:56:26 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Thu Jan 10 14:49:58 2008 Subject: [Haskell-cafe] Why purely in haskell? In-Reply-To: <117f2cc80801100759o23af9f8dtdbaff6ca8213171a@mail.gmail.com> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <2d3641330801090706m4ed9a927l282bb840a7dfcb7f@mail.gmail.com> <1199897022.18821.24.camel@derek-laptop> <4785339B.7050308@telenet.be> <47853A2C.2060508@appsolutions.com> <20080109212104.GD29472@scytale.galois.com> <117f2cc80801091415x643bec1cmf09931d4d16d59e5@mail.gmail.com> <117f2cc80801100759o23af9f8dtdbaff6ca8213171a@mail.gmail.com> Message-ID: On Thu, 10 Jan 2008, David Roundy wrote: > On Jan 9, 2008 5:42 PM, Henning Thielemann > > > In Modula-3 modules using hacks must be explicitly marked as UNSAFE. See > > http://www.cs.purdue.edu/homes/hosking/m3/reference/unsafe.html > > Maybe this is also an option for Haskell? > > I don't think this is a good idea. It comes down to a question of > whether you think it should be allowed for Haskell code to be used to > write core Haskell libraries in a first-class manner. Perhaps you > think libraries should always be in C in order to avoid the use of > unsafePerformIO, but I prefer to allow them to be written in Haskell. The Modula-3 designers acknowledged that there are things that should not be done, but must be done, illustrated by the quotation: "There are some cases that no law can be framed to cover." That is, marking a module as UNSAFE does not discourage their usage, but it swaps the burden of proof: For a safe module the compiler guarantees that nasty things can't happen, for an unsafe module the programmer must provide this warranty. If your program seg-faults you only have to scan the UNSAFE modules. For running untrusted Haskell code, this means, that if someone sends Haskell code to you (maybe as solution of an exercise) that is labelled 'safe' and uses no IO or a restricted IO wrapper type, then some especially nasty things can't happen - however the according Wiki page lists even more problems. From barsoap at web.de Thu Jan 10 14:57:07 2008 From: barsoap at web.de (Achim Schneider) Date: Thu Jan 10 14:50:53 2008 Subject: [Haskell-cafe] Re: Tim Sweeney (the gamer) References: <5ae4f2ba0801091621t5580361dv6fc5663f0c54c0ca@mail.gmail.com> <9313e97c0801100256r404973fdm9f781a2e8b90cd44@mail.gmail.com> <20080110125149.0f5dd989@solaris.tower> <3d96ac180801100415x54bba49l2bc53553a5b2483d@mail.gmail.com> <20080110134142.3db7479e@solaris.tower> <3d96ac180801100457v16e5a17ah75c88a2bb555815e@mail.gmail.com> <20080110144923.2db79eba@solaris.tower> <3d96ac180801101100q5efc3781i6048ed344c40be28@mail.gmail.com> <20080110204356.361e5cb0@solaris.tower> <20080110195137.GB18003@scytale.galois.com> Message-ID: <20080110205707.73639010@solaris.tower> Don Stewart wrote: > In return, we can improve the parallelism support further. > Now don't make me think of using par on a beowolf cluster of ps3's. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From ketil+haskell at ii.uib.no Thu Jan 10 15:06:37 2008 From: ketil+haskell at ii.uib.no (Ketil Malde) Date: Thu Jan 10 15:00:19 2008 Subject: [Haskell-cafe] Why purely in haskell? In-Reply-To: <117f2cc80801100759o23af9f8dtdbaff6ca8213171a@mail.gmail.com> (David Roundy's message of "Thu\, 10 Jan 2008 10\:59\:40 -0500") References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <2d3641330801090706m4ed9a927l282bb840a7dfcb7f@mail.gmail.com> <1199897022.18821.24.camel@derek-laptop> <4785339B.7050308@telenet.be> <47853A2C.2060508@appsolutions.com> <20080109212104.GD29472@scytale.galois.com> <117f2cc80801091415x643bec1cmf09931d4d16d59e5@mail.gmail.com> <117f2cc80801100759o23af9f8dtdbaff6ca8213171a@mail.gmail.com> Message-ID: <87zlvdsawi.fsf@nmd9999.imr.no> "David Roundy" writes: >> > I just want to point out that unsafePerformIO is at the core of the >> > (safe) bytestring library. As SPJ et al pointed out, this is crucial >> > functionality, and is only unsafe if unsafely used. >> In Modula-3 modules using hacks must be explicitly marked as UNSAFE. See >> http://www.cs.purdue.edu/homes/hosking/m3/reference/unsafe.html >> Maybe this is also an option for Haskell? > I don't think this is a good idea. I think the point is (should be) to mark functions unsafe when they may be unsafe to /use/, and not when they just make use of potentially unsafe functionality. It is perfectly reasonable to write safe (pure) code that uses unsafe ones. You just have to trust the author to get it right. > I'd be curious as to how much of the Prelude would be marked unsafe > if you had your wish... All of it? In the end it is all passed to GCC (or generates assembly), which is inherently "unsafe". :-) -k -- If I haven't seen further, it is by standing in the footprints of giants From sebastian.sylvan at gmail.com Thu Jan 10 15:10:57 2008 From: sebastian.sylvan at gmail.com (Sebastian Sylvan) Date: Thu Jan 10 15:04:29 2008 Subject: [Haskell-cafe] Why purely in haskell? In-Reply-To: <87zlvdsawi.fsf@nmd9999.imr.no> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <2d3641330801090706m4ed9a927l282bb840a7dfcb7f@mail.gmail.com> <1199897022.18821.24.camel@derek-laptop> <4785339B.7050308@telenet.be> <47853A2C.2060508@appsolutions.com> <20080109212104.GD29472@scytale.galois.com> <117f2cc80801091415x643bec1cmf09931d4d16d59e5@mail.gmail.com> <117f2cc80801100759o23af9f8dtdbaff6ca8213171a@mail.gmail.com> <87zlvdsawi.fsf@nmd9999.imr.no> Message-ID: <3d96ac180801101210p616db74ah9dcc4be8167cf3ba@mail.gmail.com> On Jan 10, 2008 8:06 PM, Ketil Malde wrote: > "David Roundy" writes: > > >> > I just want to point out that unsafePerformIO is at the core of the > >> > (safe) bytestring library. As SPJ et al pointed out, this is crucial > >> > functionality, and is only unsafe if unsafely used. > > >> In Modula-3 modules using hacks must be explicitly marked as UNSAFE. See > >> http://www.cs.purdue.edu/homes/hosking/m3/reference/unsafe.html > >> Maybe this is also an option for Haskell? > > > I don't think this is a good idea. > > I think the point is (should be) to mark functions unsafe when they > may be unsafe to /use/, I think using the IO monad for this works well... -- Sebastian Sylvan +44(0)7857-300802 UIN: 44640862 From droundy at darcs.net Thu Jan 10 15:12:23 2008 From: droundy at darcs.net (David Roundy) Date: Thu Jan 10 15:05:55 2008 Subject: [Haskell-cafe] Why purely in haskell? In-Reply-To: <3d96ac180801101210p616db74ah9dcc4be8167cf3ba@mail.gmail.com> References: <2d3641330801090706m4ed9a927l282bb840a7dfcb7f@mail.gmail.com> <1199897022.18821.24.camel@derek-laptop> <4785339B.7050308@telenet.be> <47853A2C.2060508@appsolutions.com> <20080109212104.GD29472@scytale.galois.com> <117f2cc80801091415x643bec1cmf09931d4d16d59e5@mail.gmail.com> <117f2cc80801100759o23af9f8dtdbaff6ca8213171a@mail.gmail.com> <87zlvdsawi.fsf@nmd9999.imr.no> <3d96ac180801101210p616db74ah9dcc4be8167cf3ba@mail.gmail.com> Message-ID: <20080110201222.GN28763@darcs.net> On Thu, Jan 10, 2008 at 08:10:57PM +0000, Sebastian Sylvan wrote: > On Jan 10, 2008 8:06 PM, Ketil Malde wrote: > > "David Roundy" writes: > > > > >> > I just want to point out that unsafePerformIO is at the core of the > > >> > (safe) bytestring library. As SPJ et al pointed out, this is crucial > > >> > functionality, and is only unsafe if unsafely used. > > > > >> In Modula-3 modules using hacks must be explicitly marked as UNSAFE. See > > >> http://www.cs.purdue.edu/homes/hosking/m3/reference/unsafe.html > > >> Maybe this is also an option for Haskell? > > > > > I don't think this is a good idea. > > > > I think the point is (should be) to mark functions unsafe when they > > may be unsafe to /use/, > > I think using the IO monad for this works well... Would you suggest moving head and tail into the IO monad? -- David Roundy Department of Physics Oregon State University From john at repetae.net Thu Jan 10 15:16:13 2008 From: john at repetae.net (John Meacham) Date: Thu Jan 10 15:09:49 2008 Subject: [Haskell-cafe] 0/0 > 1 == False In-Reply-To: <2608b8a80801100117wda28551ida0166f548147aac@mail.gmail.com> References: <2608b8a80801100117wda28551ida0166f548147aac@mail.gmail.com> Message-ID: <20080110201613.GA30239@momenergy.repetae.net> On Thu, Jan 10, 2008 at 11:17:18AM +0200, Yitzchak Gale wrote: > The special case of 1/0 is less clear, though. One might > decide that it should be an error rather than NaN, as some > languages have. It is neither, 1/0 = Infinity -1/0 = -Infinity At least on IEEE style floating point systems. (this isn't mandated by the haskell standard though I believe) John -- John Meacham - ?repetae.net?john? From john at repetae.net Thu Jan 10 15:23:22 2008 From: john at repetae.net (John Meacham) Date: Thu Jan 10 15:16:56 2008 Subject: [Haskell-cafe] Re: viewing HS files in Firefox In-Reply-To: References: <4723C03A.6080909@charter.net> <47272376.3020302@jellybean.co.uk> <4727747B.7040902@millstream.com> <90889fe70801100229y50178012ib404db0d4eec5ce3@mail.gmail.com> <478615CD.1040205@jellybean.co.uk> <90889fe70801100632p11adcde4h9c07c0ae6ad0117e@mail.gmail.com> Message-ID: <20080110202322.GB30239@momenergy.repetae.net> On Thu, Jan 10, 2008 at 10:07:25AM -0500, Stefan Monnier wrote: > > My problem is when viewing plain darcs repositories (like mine on > > darcs.johantibell.com which I recently fixed with the above mime type > > hack.) > > Please complain to your browser('s authors): most browsers only provide > *one* way to view a given mime-type, which is stupid. It's not specific > to .hs files. This extension allows this in firefox. it gives you an 'open in browser as' option that lets you view links in a variety of ways rather than being forced to download it. http://www.spasche.net/mozilla/ John -- John Meacham - ?repetae.net?john? From barsoap at web.de Thu Jan 10 15:24:34 2008 From: barsoap at web.de (Achim Schneider) Date: Thu Jan 10 15:18:25 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False References: <2608b8a80801100117wda28551ida0166f548147aac@mail.gmail.com> <20080110201613.GA30239@momenergy.repetae.net> Message-ID: <20080110212434.07e18eb8@solaris.tower> John Meacham wrote: > On Thu, Jan 10, 2008 at 11:17:18AM +0200, Yitzchak Gale wrote: > > The special case of 1/0 is less clear, though. One might > > decide that it should be an error rather than NaN, as some > > languages have. > > It is neither, > > 1/0 = Infinity > -1/0 = -Infinity > Just out of curiosity: 1/-0 = -Infinity? -1/-0 = Infinity? If you don't have two separate values for nothing, one approaching from negativeness and one from positiveness, defining the result to be infinite instead of NaN makes no sense IMHO. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From sebastian.sylvan at gmail.com Thu Jan 10 15:26:42 2008 From: sebastian.sylvan at gmail.com (Sebastian Sylvan) Date: Thu Jan 10 15:20:16 2008 Subject: [Haskell-cafe] Why purely in haskell? In-Reply-To: <20080110201222.GN28763@darcs.net> References: <2d3641330801090706m4ed9a927l282bb840a7dfcb7f@mail.gmail.com> <4785339B.7050308@telenet.be> <47853A2C.2060508@appsolutions.com> <20080109212104.GD29472@scytale.galois.com> <117f2cc80801091415x643bec1cmf09931d4d16d59e5@mail.gmail.com> <117f2cc80801100759o23af9f8dtdbaff6ca8213171a@mail.gmail.com> <87zlvdsawi.fsf@nmd9999.imr.no> <3d96ac180801101210p616db74ah9dcc4be8167cf3ba@mail.gmail.com> <20080110201222.GN28763@darcs.net> Message-ID: <3d96ac180801101226v5af06e80i4e271488e96195f2@mail.gmail.com> On Jan 10, 2008 8:12 PM, David Roundy wrote: > > On Thu, Jan 10, 2008 at 08:10:57PM +0000, Sebastian Sylvan wrote: > > On Jan 10, 2008 8:06 PM, Ketil Malde wrote: > > > "David Roundy" writes: > > > > > > >> > I just want to point out that unsafePerformIO is at the core of the > > > >> > (safe) bytestring library. As SPJ et al pointed out, this is crucial > > > >> > functionality, and is only unsafe if unsafely used. > > > > > > >> In Modula-3 modules using hacks must be explicitly marked as UNSAFE. See > > > >> http://www.cs.purdue.edu/homes/hosking/m3/reference/unsafe.html > > > >> Maybe this is also an option for Haskell? > > > > > > > I don't think this is a good idea. > > > > > > I think the point is (should be) to mark functions unsafe when they > > > may be unsafe to /use/, > > > > I think using the IO monad for this works well... > > Would you suggest moving head and tail into the IO monad? They're not really unsafe, though, they just have the potential to fail (from which you can recover). Unsafe to me mean "may reformat your harddrive, kill your dog, and break up with your girlfriend". They really should return a Maybe type, but I recognize that this would be inconvenient (so would having e.g. integer division returning Maybe). > -- > David Roundy > Department of Physics > Oregon State University > _______________________________________________ > > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- Sebastian Sylvan +44(0)7857-300802 UIN: 44640862 From droundy at darcs.net Thu Jan 10 15:27:25 2008 From: droundy at darcs.net (David Roundy) Date: Thu Jan 10 15:20:58 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False In-Reply-To: <20080110212434.07e18eb8@solaris.tower> References: <2608b8a80801100117wda28551ida0166f548147aac@mail.gmail.com> <20080110201613.GA30239@momenergy.repetae.net> <20080110212434.07e18eb8@solaris.tower> Message-ID: <20080110202724.GO28763@darcs.net> On Thu, Jan 10, 2008 at 09:24:34PM +0100, Achim Schneider wrote: > John Meacham wrote: > > On Thu, Jan 10, 2008 at 11:17:18AM +0200, Yitzchak Gale wrote: > > > The special case of 1/0 is less clear, though. One might > > > decide that it should be an error rather than NaN, as some > > > languages have. > > > > It is neither, > > > > 1/0 = Infinity > > -1/0 = -Infinity > > Just out of curiosity: > > 1/-0 = -Infinity? > -1/-0 = Infinity? Yes. (You could have tried this for yourself, you know... but I suppose haskell-cafe isn't a bad interactive Haskell interpreter, perhaps more user friendly than ghci.) -- David Roundy Department of Physics Oregon State University From ketil+haskell at ii.uib.no Thu Jan 10 15:27:27 2008 From: ketil+haskell at ii.uib.no (Ketil Malde) Date: Thu Jan 10 15:21:10 2008 Subject: [Haskell-cafe] Re: Tim Sweeney (the gamer) In-Reply-To: <3d96ac180801101100q5efc3781i6048ed344c40be28@mail.gmail.com> (Sebastian Sylvan's message of "Thu\, 10 Jan 2008 19\:00\:05 +0000") References: <5ae4f2ba0801091621t5580361dv6fc5663f0c54c0ca@mail.gmail.com> <9313e97c0801100256r404973fdm9f781a2e8b90cd44@mail.gmail.com> <20080110125149.0f5dd989@solaris.tower> <3d96ac180801100415x54bba49l2bc53553a5b2483d@mail.gmail.com> <20080110134142.3db7479e@solaris.tower> <3d96ac180801100457v16e5a17ah75c88a2bb555815e@mail.gmail.com> <20080110144923.2db79eba@solaris.tower> <3d96ac180801101100q5efc3781i6048ed344c40be28@mail.gmail.com> Message-ID: <87ve61s9xs.fsf@nmd9999.imr.no> "Sebastian Sylvan" writes: > Maybe I'm just lucky, but if we are still talking about the games > industry I don't think this fits my experience of bosses. Games > compete very much on performance, and we basically rewrite almost all > of our code over a few years or so anyway Another thing is that having the next big game means an incredible amount of money - more than a Hollywood blockbuster, according to popular rumor. Many companies may be willing to take a risk on promising but immature technology in the hope that it will give them the advantage they need to deliver the next Halo (or whatever). Very competitive industry, large money involved, lots of software rewritten or developed from scratch. Sounds ideal. Any boss who insists on doing things the way they've always done it won't last long. -k -- If I haven't seen further, it is by standing in the footprints of giants From barsoap at web.de Thu Jan 10 15:37:51 2008 From: barsoap at web.de (Achim Schneider) Date: Thu Jan 10 15:31:37 2008 Subject: [Haskell-cafe] Re: Tim Sweeney (the gamer) References: <5ae4f2ba0801091621t5580361dv6fc5663f0c54c0ca@mail.gmail.com> <9313e97c0801100256r404973fdm9f781a2e8b90cd44@mail.gmail.com> <20080110125149.0f5dd989@solaris.tower> <3d96ac180801100415x54bba49l2bc53553a5b2483d@mail.gmail.com> <20080110134142.3db7479e@solaris.tower> <3d96ac180801100457v16e5a17ah75c88a2bb555815e@mail.gmail.com> <20080110144923.2db79eba@solaris.tower> <3d96ac180801101100q5efc3781i6048ed344c40be28@mail.gmail.com> <87ve61s9xs.fsf@nmd9999.imr.no> Message-ID: <20080110213751.48e11d83@solaris.tower> Ketil Malde wrote: > "Sebastian Sylvan" writes: > > > Maybe I'm just lucky, but if we are still talking about the games > > industry I don't think this fits my experience of bosses. Games > > compete very much on performance, and we basically rewrite almost > > all of our code over a few years or so anyway > > Another thing is that having the next big game means an incredible > amount of money - more than a Hollywood blockbuster, according to > popular rumor. Many companies may be willing to take a risk on > promising but immature technology in the hope that it will give them > the advantage they need to deliver the next Halo (or whatever). > > Very competitive industry, large money involved, lots of software > rewritten or developed from scratch. Sounds ideal. Any boss who > insists on doing things the way they've always done it won't last > long. > Just to set things straight: You can make more money selling mind trainers and party games like Nintendo does, or selling games with slideshow complexity but much visible flesh for handsets... at least here in Germany that's the much bigger portion of the industry. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From lemming at henning-thielemann.de Thu Jan 10 15:40:03 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Thu Jan 10 15:33:34 2008 Subject: [Haskell-cafe] Not to load Prelude In-Reply-To: References: Message-ID: On Thu, 10 Jan 2008, [windows-1252] Maur??cio wrote: > Hi, > > Is it possible not to load Prelude module > when compiling a Haskell module? Or instruct > ghc to ?unload? it? You can either import Prelude () but some things like 'fromInteger' as used for number literals are still present. You can write the pragma {-# OPTIONS -fno-implicit-prelude #-} at the top of your module to get completely rid of the Prelude. From barsoap at web.de Thu Jan 10 15:41:53 2008 From: barsoap at web.de (Achim Schneider) Date: Thu Jan 10 15:38:42 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False References: <2608b8a80801100117wda28551ida0166f548147aac@mail.gmail.com> <20080110201613.GA30239@momenergy.repetae.net> <20080110212434.07e18eb8@solaris.tower> <20080110202724.GO28763@darcs.net> Message-ID: <20080110214153.46ad3395@solaris.tower> David Roundy wrote: > On Thu, Jan 10, 2008 at 09:24:34PM +0100, Achim Schneider wrote: > > John Meacham wrote: > > > On Thu, Jan 10, 2008 at 11:17:18AM +0200, Yitzchak Gale wrote: > > > > The special case of 1/0 is less clear, though. One might > > > > decide that it should be an error rather than NaN, as some > > > > languages have. > > > > > > It is neither, > > > > > > 1/0 = Infinity > > > -1/0 = -Infinity > > > > Just out of curiosity: > > > > 1/-0 = -Infinity? > > -1/-0 = Infinity? > > Yes. (You could have tried this for yourself, you know... but I > suppose haskell-cafe isn't a bad interactive Haskell interpreter, > perhaps more user friendly than ghci.) > Prelude> 1 `div` 0 *** Exception: divide by zero That's it. One just shouldn't just extrapolate and think you didn't mean GHC but IEEE... -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From droundy at darcs.net Thu Jan 10 15:52:20 2008 From: droundy at darcs.net (David Roundy) Date: Thu Jan 10 15:45:52 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False In-Reply-To: <20080110214153.46ad3395@solaris.tower> References: <2608b8a80801100117wda28551ida0166f548147aac@mail.gmail.com> <20080110201613.GA30239@momenergy.repetae.net> <20080110212434.07e18eb8@solaris.tower> <20080110202724.GO28763@darcs.net> <20080110214153.46ad3395@solaris.tower> Message-ID: <20080110205220.GR28763@darcs.net> On Thu, Jan 10, 2008 at 09:41:53PM +0100, Achim Schneider wrote: > David Roundy wrote: > > On Thu, Jan 10, 2008 at 09:24:34PM +0100, Achim Schneider wrote: > > > John Meacham wrote: > > > > 1/0 = Infinity > > > > -1/0 = -Infinity > > > > > > Just out of curiosity: > > > > > > 1/-0 = -Infinity? > > > -1/-0 = Infinity? > > > > Yes. (You could have tried this for yourself, you know... but I > > suppose haskell-cafe isn't a bad interactive Haskell interpreter, > > perhaps more user friendly than ghci.) > > Prelude> 1 `div` 0 > *** Exception: divide by zero > > That's it. One just shouldn't just extrapolate and think you didn't mean > GHC but IEEE... Prelude> 1/(-0) -Infinity You need to use the / operator, if you want to do floating-point division. -- David Roundy Department of Physics Oregon State University From barsoap at web.de Thu Jan 10 16:04:08 2008 From: barsoap at web.de (Achim Schneider) Date: Thu Jan 10 15:57:51 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False References: <2608b8a80801100117wda28551ida0166f548147aac@mail.gmail.com> <20080110201613.GA30239@momenergy.repetae.net> <20080110212434.07e18eb8@solaris.tower> <20080110202724.GO28763@darcs.net> <20080110214153.46ad3395@solaris.tower> <20080110205220.GR28763@darcs.net> Message-ID: <20080110220408.47186b19@solaris.tower> David Roundy wrote: > On Thu, Jan 10, 2008 at 09:41:53PM +0100, Achim Schneider wrote: > > David Roundy wrote: > > > On Thu, Jan 10, 2008 at 09:24:34PM +0100, Achim Schneider wrote: > > > > John Meacham wrote: > > > > > 1/0 = Infinity > > > > > -1/0 = -Infinity > > > > > > > > Just out of curiosity: > > > > > > > > 1/-0 = -Infinity? > > > > -1/-0 = Infinity? > > > > > > Yes. (You could have tried this for yourself, you know... but I > > > suppose haskell-cafe isn't a bad interactive Haskell interpreter, > > > perhaps more user friendly than ghci.) > > > > Prelude> 1 `div` 0 > > *** Exception: divide by zero > > > > That's it. One just shouldn't just extrapolate and think you didn't > > mean GHC but IEEE... > > Prelude> 1/(-0) > -Infinity > > You need to use the / operator, if you want to do floating-point > division. > Yes, exactly, integers don't have +-0 and +-infinity... only (obviously) a kind of nan. It's just that with the stuff I do I know I have some logical problem in my formulas when I get any special floating point value anywhere, and using --excess-precision can only make the numbers more precise. Said differently: I don't know a thing about floats or numerics. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From lemming at henning-thielemann.de Thu Jan 10 16:04:43 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Thu Jan 10 15:58:17 2008 Subject: [Haskell-cafe] Re: Difference lists and ShowS In-Reply-To: References: <20080103105916.7d562d17@solaris.tower> <20080103120847.13725ce6@solaris.tower> <477CD9E0.6060604@charter.net> <20080103154115.28a84ce3@solaris.tower> <477D60F6.5090408@vex.net> Message-ID: On Wed, 9 Jan 2008, apfelmus wrote: > So, difference lists are no "eierlegende wollmilchsau" either. LEO's forum suggests 'swiss army knife' as translation. :-) From barsoap at web.de Thu Jan 10 16:16:04 2008 From: barsoap at web.de (Achim Schneider) Date: Thu Jan 10 16:09:48 2008 Subject: [Haskell-cafe] Re: Difference lists and ShowS References: <20080103105916.7d562d17@solaris.tower> <20080103120847.13725ce6@solaris.tower> <477CD9E0.6060604@charter.net> <20080103154115.28a84ce3@solaris.tower> <477D60F6.5090408@vex.net> Message-ID: <20080110221604.7a06a8c7@solaris.tower> Henning Thielemann wrote: > > On Wed, 9 Jan 2008, apfelmus wrote: > > > So, difference lists are no "eierlegende wollmilchsau" either. > > LEO's forum suggests 'swiss army knife' as translation. :-) > But you really need one with 5 differently-sized blades plus three spezialized carving blades, an USB stick, microscope, 13 kinds of torx, imbus etc drivers each, a tv set (analogue/digital) with unfoldable touchscreen, at least 3-band GSM and WiFi connectivity, hydraulic car jack and chain saw to award it with the term egg-laying woolmilkpig. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From apfelmus at quantentunnel.de Thu Jan 10 16:35:24 2008 From: apfelmus at quantentunnel.de (apfelmus) Date: Thu Jan 10 16:29:12 2008 Subject: [Haskell-cafe] Re: Difference lists and ShowS In-Reply-To: <20080110221604.7a06a8c7@solaris.tower> References: <20080103105916.7d562d17@solaris.tower> <20080103120847.13725ce6@solaris.tower> <477CD9E0.6060604@charter.net> <20080103154115.28a84ce3@solaris.tower> <477D60F6.5090408@vex.net> <20080110221604.7a06a8c7@solaris.tower> Message-ID: Achim Schneider wrote: > Henning Thielemann wrote: > >> apfelmus wrote: >> >>> So, difference lists are no "eierlegende wollmilchsau" either. > >> LEO's forum suggests 'swiss army knife' as translation. :-) >> > But you really need one with 5 differently-sized blades plus three > spezialized carving blades, an USB stick, microscope, 13 kinds of torx, > imbus etc drivers each, a tv set (analogue/digital) with unfoldable > touchscreen, at least 3-band GSM and WiFi connectivity, hydraulic car > jack and chain saw to award it with the term egg-laying woolmilkpig. But even such knives still can't lay eggs :( Regards, apfelmus From ajb at spamcop.net Thu Jan 10 17:47:31 2008 From: ajb at spamcop.net (ajb@spamcop.net) Date: Thu Jan 10 17:41:03 2008 Subject: [Haskell-cafe] Re: Difference lists and ShowS In-Reply-To: <20080110221604.7a06a8c7@solaris.tower> References: <20080103105916.7d562d17@solaris.tower> <20080103120847.13725ce6@solaris.tower> <477CD9E0.6060604@charter.net> <20080103154115.28a84ce3@solaris.tower> <477D60F6.5090408@vex.net> <20080110221604.7a06a8c7@solaris.tower> Message-ID: <20080110174731.ow3jw8g9kc8o4swo@webmail.spamcop.net> G'day all. Quoting Achim Schneider : > But you really need one with 5 differently-sized blades plus three > spezialized carving blades, an USB stick, microscope, 13 kinds of torx, > imbus etc drivers each, a tv set (analogue/digital) with unfoldable > touchscreen, at least 3-band GSM and WiFi connectivity, hydraulic car > jack and chain saw to award it with the term egg-laying woolmilkpig. So a better translation into British engineering language might be "Heath Robinson"? Cheers, Andrew Bromage From lrpalmer at gmail.com Thu Jan 10 17:54:55 2008 From: lrpalmer at gmail.com (Luke Palmer) Date: Thu Jan 10 17:48:27 2008 Subject: [Haskell-cafe] \_ -> not equivalent to const $ Message-ID: <7ca3f0160801101454g27267cd4qdbe3b93300b30a56@mail.gmail.com> In attempting to devise a variant of cycle which did not keep its argument alive (for the purpose of cycle [1::Int..]), I came across this peculiar behavior: import Debug.Trace cycle' :: (a -> [b]) -> [b] cycle' xs = xs undefined ++ cycle' xs > take 20 $ cycle' (const $ 1:2:3:4:trace "x" 5:[]) [1,2,3,4,x 5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5] Nuts. Oh, but wait: > take 20 $ cycle' (\_ -> 1:2:3:4:trace "x" 5:[]) [1,2,3,4,x 5,1,2,3,4,x 5,1,2,3,4,x 5,1,2,3,4,x 5] Hey, it worked! Can someone explain what the heck is going on here? Luke From rendel at rbg.informatik.tu-darmstadt.de Thu Jan 10 18:05:42 2008 From: rendel at rbg.informatik.tu-darmstadt.de (Tillmann Rendel) Date: Thu Jan 10 17:59:07 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <20080110203922.0c4deb87@solaris.tower> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower> <20080110185659.4d7117ff@solaris.tower> <20080110203922.0c4deb87@solaris.tower> Message-ID: <4786A4C6.9080905@rbg.informatik.tu-darmstadt.de> Achim Schneider wrote: > [1..] == [1..] > > [some discussion about the nontermination of this expression] > > The essence of laziness is to do the least work necessary to cause the > desired effect, which is to see that the set of natural numbers equals > the set of natural numbers, which, axiomatically, is always > computable in O(1) by equality by identity. This would make sense if Haskell had inbuild equality and (==) where part of the formal semantics of Haskell, wich it isn't. (==) is a library function like every other library function. How could the language or a system implementing the language decide wether this or any other library function returns True without actually running it? Haskell is a programming language, not a theorem prover. Tillmann From monnier at iro.umontreal.ca Thu Jan 10 18:05:48 2008 From: monnier at iro.umontreal.ca (Stefan Monnier) Date: Thu Jan 10 17:59:27 2008 Subject: [Haskell-cafe] Haskell-mode 2.4 In-Reply-To: <90889fe70801100932m15c1e08ey90c7a04578a35d54@mail.gmail.com> (Johan Tibell's message of "Thu, 10 Jan 2008 18:32:40 +0100") References: <90889fe70801081337q5521f3e5yd49a2435d2d96ed2@mail.gmail.com> <90889fe70801100932m15c1e08ey90c7a04578a35d54@mail.gmail.com> Message-ID: >> First of all, thanks. My Aqua Emacs (on OS X Leopard) hangs when I >> send a command like C-c C-l or C-c C-t to the interpreter (I can quit >> the command using C-g) . Starting the interpreter and using :l from >> inside it works fine. This is using GHC 6.8 (and I think I also tried >> 6.6.) What could be the problem? >> >> I also tried to eval this but it didn't make a difference: >> >> (setq inferior-haskell-find-project-root nil) > It looks like this is a problem with 6.8.2 as haskell-mode-2.3 has the > same problem? Seems like the commands being sent to the haskell > process never reaches it. Try can you try to look into the nature of the hang? Is Emacs completely frozen? Does C-g get you back to something usable? If so, can you set Options => Enter Debugger on Quit, then reproduce the problem than hit C-g and show me the backtrace? If not, can you run Emacs under a debugger and give me a backtrace of when Emacs is frozen? Stefan From felipe.lessa at gmail.com Thu Jan 10 18:11:46 2008 From: felipe.lessa at gmail.com (Felipe Lessa) Date: Thu Jan 10 18:05:18 2008 Subject: [Haskell-cafe] \_ -> not equivalent to const $ In-Reply-To: <7ca3f0160801101454g27267cd4qdbe3b93300b30a56@mail.gmail.com> References: <7ca3f0160801101454g27267cd4qdbe3b93300b30a56@mail.gmail.com> Message-ID: On Jan 10, 2008 8:54 PM, Luke Palmer wrote: > Can someone explain what the heck is going on here? AFAICT, nothing is wrong. You see, both returned the very same values. What you saw was in fact the problem with unsafePerformIO and friends, as they may be executed lots of times *or not*. The compiler is free to behave in those two ways for the code with const or with the lambda. But referential transparency wasn't broken at all =). It seems const retained the value, while the lambda didn't. An optimization might transform one into the other if the compiler sees fit. -- Felipe. From lrpalmer at gmail.com Thu Jan 10 18:14:52 2008 From: lrpalmer at gmail.com (Luke Palmer) Date: Thu Jan 10 18:08:23 2008 Subject: [Haskell-cafe] \_ -> not equivalent to const $ In-Reply-To: References: <7ca3f0160801101454g27267cd4qdbe3b93300b30a56@mail.gmail.com> Message-ID: <7ca3f0160801101514x49b00e9pe912db2ab5b9b6df@mail.gmail.com> On Jan 10, 2008 11:11 PM, Felipe Lessa wrote: > On Jan 10, 2008 8:54 PM, Luke Palmer wrote: > > Can someone explain what the heck is going on here? > > AFAICT, nothing is wrong. You see, both returned the very same values. > What you saw was in fact the problem with unsafePerformIO and friends, > as they may be executed lots of times *or not*. The compiler is free > to behave in those two ways for the code with const or with the > lambda. But referential transparency wasn't broken at all =). Of course. I'm trying to write a variant of cycle that will be efficient with memory for my purposes, so the Haskell 98 standard, which says nothing about memory usage, doesn't really interest me. I'm more interested in what is going on in ghc (6.8.1) in this case, if it has a simple explanation. And of course am interested if there are any better ways to write such a function. Luke From asviraspossible at gmail.com Thu Jan 10 18:15:49 2008 From: asviraspossible at gmail.com (Victor Nazarov) Date: Thu Jan 10 18:09:24 2008 Subject: [Haskell-cafe] \_ -> not equivalent to const $ In-Reply-To: References: <7ca3f0160801101454g27267cd4qdbe3b93300b30a56@mail.gmail.com> Message-ID: On Jan 11, 2008 2:11 AM, Felipe Lessa wrote: > On Jan 10, 2008 8:54 PM, Luke Palmer wrote: > > Can someone explain what the heck is going on here? > > AFAICT, nothing is wrong. You see, both returned the very same values. [snip] > But referential transparency wasn't broken at all =). > Referential transparency wasn't broken, but I wonder what was the compiler, and what were it's options. -- vir http://vir.comtv.ru/ From lrpalmer at gmail.com Thu Jan 10 18:20:36 2008 From: lrpalmer at gmail.com (Luke Palmer) Date: Thu Jan 10 18:14:08 2008 Subject: [Haskell-cafe] \_ -> not equivalent to const $ In-Reply-To: References: <7ca3f0160801101454g27267cd4qdbe3b93300b30a56@mail.gmail.com> Message-ID: <7ca3f0160801101520r3c93737ak4dcf1a125828de69@mail.gmail.com> On Jan 10, 2008 11:15 PM, Victor Nazarov wrote: > On Jan 11, 2008 2:11 AM, Felipe Lessa wrote: > > On Jan 10, 2008 8:54 PM, Luke Palmer wrote: > > > Can someone explain what the heck is going on here? > > > > AFAICT, nothing is wrong. You see, both returned the very same values. > [snip] > > But referential transparency wasn't broken at all =). > > > Referential transparency wasn't broken, but I wonder what was the > compiler, and what were it's options. Ahh, it was ghc 6.8.1, without any optimization. If I turn on optimization, the behavior goes away, and they both behave like the const version. Darn. Luke > -- > vir > http://vir.comtv.ru/ > From felipe.lessa at gmail.com Thu Jan 10 18:28:00 2008 From: felipe.lessa at gmail.com (Felipe Lessa) Date: Thu Jan 10 18:21:32 2008 Subject: [Haskell-cafe] \_ -> not equivalent to const $ In-Reply-To: <7ca3f0160801101520r3c93737ak4dcf1a125828de69@mail.gmail.com> References: <7ca3f0160801101454g27267cd4qdbe3b93300b30a56@mail.gmail.com> <7ca3f0160801101520r3c93737ak4dcf1a125828de69@mail.gmail.com> Message-ID: On Jan 10, 2008 9:20 PM, Luke Palmer wrote: > Ahh, it was ghc 6.8.1, without any optimization. If I turn on optimization, > the behavior goes away, and they both behave like the const version. That was what I suggested on the last line of my previous e-mail. As const is in Prelude, which probably was compiled with optimizations, it would explain the difference. -- Felipe. From asviraspossible at gmail.com Thu Jan 10 18:33:54 2008 From: asviraspossible at gmail.com (Victor Nazarov) Date: Thu Jan 10 18:27:27 2008 Subject: [Haskell-cafe] \_ -> not equivalent to const $ In-Reply-To: References: <7ca3f0160801101454g27267cd4qdbe3b93300b30a56@mail.gmail.com> <7ca3f0160801101520r3c93737ak4dcf1a125828de69@mail.gmail.com> Message-ID: On Jan 11, 2008 2:28 AM, Felipe Lessa wrote: > On Jan 10, 2008 9:20 PM, Luke Palmer wrote: > > Ahh, it was ghc 6.8.1, without any optimization. If I turn on optimization, > > the behavior goes away, and they both behave like the const version. > > That was what I suggested on the last line of my previous e-mail. As > const is in Prelude, which probably was compiled with optimizations, > it would explain the difference. Optimization of const doesn't affect this program behavior. -- vir http://vir.comtv.ru/ From barsoap at web.de Thu Jan 10 19:00:04 2008 From: barsoap at web.de (Achim Schneider) Date: Thu Jan 10 18:53:51 2008 Subject: [Haskell-cafe] Re: Difference lists and ShowS References: <20080103105916.7d562d17@solaris.tower> <20080103120847.13725ce6@solaris.tower> <477CD9E0.6060604@charter.net> <20080103154115.28a84ce3@solaris.tower> <477D60F6.5090408@vex.net> <20080110221604.7a06a8c7@solaris.tower> <20080110174731.ow3jw8g9kc8o4swo@webmail.spamcop.net> Message-ID: <20080111010004.4fa208bc@solaris.tower> ajb@spamcop.net wrote: > G'day all. > > Quoting Achim Schneider : > > > But you really need one with 5 differently-sized blades plus three > > spezialized carving blades, an USB stick, microscope, 13 kinds of > > torx, imbus etc drivers each, a tv set (analogue/digital) with > > unfoldable touchscreen, at least 3-band GSM and WiFi connectivity, > > hydraulic car jack and chain saw to award it with the term > > egg-laying woolmilkpig. > > So a better translation into British engineering language might be > "Heath Robinson"? > Not really. To give you the perfect cs example, take a look at emacs: eight megabytes and continuous swapping, a whole OS with any app and library you could ever dream of, but not one decent editor. See, on the one hand that beast is every farmer's dream, but then you can't butcher the pig 'cos you want to have its milk, wool and eggs.. http://catb.org/jargon/html/C/creeping-featuritis.html is the associated plague. Outlook reminds me of it, too: I spend half a paid hour configuring it, changing everything, from default message format to quote behaviour and similar. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From ajb at spamcop.net Thu Jan 10 19:09:36 2008 From: ajb at spamcop.net (ajb@spamcop.net) Date: Thu Jan 10 19:03:07 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower> <20080110185659.4d7117ff@solaris.tower> Message-ID: <20080110190936.97et3kihyskwkoco@webmail.spamcop.net> G'day all. Quoting jerzy.karczmarczuk@info.unicaen.fr: > Perhaps another example is more relevant, the tradeoffs > space-time in the > "optimized" version of the powerset generator... Yeah, I was going to bring up that topic. I've been lazy programming for 15 or so years, and the only "bugs" that I can think of are: 1. Indirect "black holes" that are not expressible in a strict language. You generally have to be doing something bizarre for this to occur, and it doesn't take too long before you can accurately predict when they constitute a likely risk. 2. Space leaks. This is the one thing that really bites hard, because a space leak is a global property of a lazy program, and hence can't be reasoned about locally. Cheers, Andrew Bromage From barsoap at web.de Thu Jan 10 19:12:02 2008 From: barsoap at web.de (Achim Schneider) Date: Thu Jan 10 19:05:40 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower> <20080110185659.4d7117ff@solaris.tower> <20080110203922.0c4deb87@solaris.tower> <4786A4C6.9080905@rbg.informatik.tu-darmstadt.de> Message-ID: <20080111011202.6354e435@solaris.tower> Tillmann Rendel wrote: > Achim Schneider wrote: > > [1..] == [1..] > > > > [some discussion about the nontermination of this expression] > > > > The essence of laziness is to do the least work necessary to cause > > the desired effect, which is to see that the set of natural numbers > > equals the set of natural numbers, which, axiomatically, is always > > computable in O(1) by equality by identity. > > This would make sense if Haskell had inbuild equality and (==) where > part of the formal semantics of Haskell, wich it isn't. (==) is a > library function like every other library function. How could the > language or a system implementing the language decide wether this or > any other library function returns True without actually running it? > The list instance for Eq might eg. know something about the structure of the lists and be smart enough not to get caught in the recursion of x = 1:1:x and y = 1:1:1:y so it could successfully compare x == y to True in six compares. > Haskell is a programming language, not a theorem prover. > Yes I know. That's why I wrote axiomatic and operational semantics, not denotational; I didn't want to start a bar fight. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From lrpalmer at gmail.com Thu Jan 10 19:12:33 2008 From: lrpalmer at gmail.com (Luke Palmer) Date: Thu Jan 10 19:06:05 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <20080110190936.97et3kihyskwkoco@webmail.spamcop.net> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower> <20080110185659.4d7117ff@solaris.tower> <20080110190936.97et3kihyskwkoco@webmail.spamcop.net> Message-ID: <7ca3f0160801101612x3a1365d2h4f6e7f49433fc969@mail.gmail.com> On Jan 11, 2008 12:09 AM, wrote: > > 1. Indirect "black holes" that are not expressible in a strict > language. You generally have to be doing something bizarre for this > to occur, and it doesn't take too long before you can accurately > predict when they constitute a likely risk. What do you mean by "black hole" here? Luke From briqueabraque at yahoo.com Thu Jan 10 19:16:27 2008 From: briqueabraque at yahoo.com (=?UTF-8?B?TWF1csOtwq1jaW8=?=) Date: Thu Jan 10 19:10:07 2008 Subject: [Haskell-cafe] Re: Not to load Prelude In-Reply-To: References: Message-ID: >> Hi, >> >> Is it possible not to load Prelude (...) >(...) NoImplicitPrelude is more aggressive > than 'import Prelude()'. You will have to > look elsewhere for a better explanation of > the difference. I tried google and ghc homepage, but could not find ?elsewhere? :) Can you give me a link or somewhere to start from? Thanks, Maur?cio From scook0 at gmail.com Thu Jan 10 19:26:52 2008 From: scook0 at gmail.com (Stuart Cook) Date: Thu Jan 10 19:20:24 2008 Subject: [Haskell-cafe] Field updates in a state monad In-Reply-To: <47863362.3000408@nessie.de> References: <47863362.3000408@nessie.de> Message-ID: <49b351060801101626j66c35a97m5b7dedcf1213808d@mail.gmail.com> On Jan 11, 2008 2:01 AM, Michael Roth wrote: > Hello list, > Exists there a way to write this cleaner without writing countless > "set_xyz" helper functions? The "set_xyz" methods have to be written, but that doesn't mean *you* have to write them. You can use Template Haskell to automatically derive setter functions for you. Writing the TH derivations is a little fiddly, but luckily others have already encountered the same problem. These blog posts can point you to a few implementations: http://luqui.org/blog/archives/2007/08/05/haskell-state-accessors-second-attempt-composability/ (http://tinyurl.com/2ve2zw) http://twan.home.fmf.nl/blog/haskell/overloading-functional-references.details (http://tinyurl.com/2ustba) In particular, take a look at Luke's code, because it also contains helper functions for combining these getters and setters with MonadState. Stuart From ajb at spamcop.net Thu Jan 10 19:28:26 2008 From: ajb at spamcop.net (ajb@spamcop.net) Date: Thu Jan 10 19:21:57 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <7ca3f0160801101612x3a1365d2h4f6e7f49433fc969@mail.gmail.com> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower> <20080110185659.4d7117ff@solaris.tower> <20080110190936.97et3kihyskwkoco@webmail.spamcop.net> <7ca3f0160801101612x3a1365d2h4f6e7f49433fc969@mail.gmail.com> Message-ID: <20080110192826.vnj4iv0r280080sw@webmail.spamcop.net> G'day all. Quoting Luke Palmer : > What do you mean by "black hole" here? A "black hole" is what happens when evalation of something recursively depends on its own evaluation in such a way that no useful work can be done. An example is: let omega = omega + 1 in omega In previous GHCs, that triggered am error which used the phrase "black hole". Now, I think it just consumes the heap and/or stack. On my 2005-era Hugs, it causes a seg fault. Most examples of black holes aren't so blatant. In all cases, they are genuine bugs in the program (i.e. the program is incorrect), but programs containing bugs like this are not even expressible in a strict language. So I claim this is a class of (admittedly rare) bug that is only a problem because of laziness. Cheers, Andrew Bromage From allbery at ece.cmu.edu Thu Jan 10 19:33:58 2008 From: allbery at ece.cmu.edu (Brandon S. Allbery KF8NH) Date: Thu Jan 10 19:27:32 2008 Subject: [Haskell-cafe] Re: Not to load Prelude In-Reply-To: References: Message-ID: On Jan 10, 2008, at 19:16 , Maur? cio wrote: > >> Hi, > >> > >> Is it possible not to load Prelude (...) > > >(...) NoImplicitPrelude is more aggressive > > than 'import Prelude()'. You will have to > > look elsewhere for a better explanation of > > the difference. > > I tried google and ghc homepage, but could > not find ?elsewhere? :) Can you give me a > link or somewhere to start from? You'll find it in a careful reading of the Haskell98 Report: certain syntactical constructs are rewritten into calls to Prelude functions. Most notably: a bare untyped integral number is rewritten as (fromIntegral num) (so its type will be (Num a => a)), and [n..m] list generation syntax is rewritten into calls to enumFrom ([n..]), enumFromTo ([n..m]), enumFromThen ([n,o..]), enumFromThenTo ([n,o..m]). (There are some such for which even -fno-implicit-prelude isn't enough; I think these are documented in the "bugs" section of the GHC manual.) -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH From jerzy.karczmarczuk at info.unicaen.fr Thu Jan 10 19:57:54 2008 From: jerzy.karczmarczuk at info.unicaen.fr (jerzy.karczmarczuk@info.unicaen.fr) Date: Thu Jan 10 19:51:25 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <20080110192826.vnj4iv0r280080sw@webmail.spamcop.net> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower> <20080110185659.4d7117ff@solaris.tower> <20080110190936.97et3kihyskwkoco@webmail.spamcop.net> <7ca3f0160801101612x3a1365d2h4f6e7f49433fc969@mail.gmail.com> <20080110192826.vnj4iv0r280080sw@webmail.spamcop.net> Message-ID: ajb@spamcop.net writes: > A "black hole" is what happens when evalation of something recursively > depends on its own evaluation in such a way that no useful work can be > done. An example is: > > let omega = omega + 1 in omega > > In previous GHCs, that triggered am error which used the phrase "black > hole". Now, I think it just consumes the heap and/or stack. On my > 2005-era Hugs, it causes a seg fault. Strange, because blackohes are visible by the runtime. Clean should say: "Warning, cycle in spine detected", and stop. Jerzy Karczmarczuk PS. Perhaps Simon decided to think more literally about the black hole as it is in the theory of relativity? You know, when you descend a probe into it, and look from a faraway, safe distance, it takes an infinite amount of time for the probe to reach the event horizon... From duncan.coutts at worc.ox.ac.uk Thu Jan 10 20:42:26 2008 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Thu Jan 10 20:35:59 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <20080111011202.6354e435@solaris.tower> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower> <20080110185659.4d7117ff@solaris.tower> <20080110203922.0c4deb87@solaris.tower> <4786A4C6.9080905@rbg.informatik.tu-darmstadt.de> <20080111011202.6354e435@solaris.tower> Message-ID: <1200015747.7279.192.camel@localhost> On Fri, 2008-01-11 at 01:12 +0100, Achim Schneider wrote: > Tillmann Rendel wrote: > > > Achim Schneider wrote: > > > [1..] == [1..] > > > > > > [some discussion about the nontermination of this expression] > > > > > > The essence of laziness is to do the least work necessary to cause > > > the desired effect, which is to see that the set of natural numbers > > > equals the set of natural numbers, which, axiomatically, is always > > > computable in O(1) by equality by identity. > > > > This would make sense if Haskell had inbuild equality and (==) where > > part of the formal semantics of Haskell, wich it isn't. (==) is a > > library function like every other library function. How could the > > language or a system implementing the language decide wether this or > > any other library function returns True without actually running it? > > > The list instance for Eq might eg. know something about the structure > of the lists and be smart enough not to get caught in the recursion of x > = 1:1:x and y = 1:1:1:y so it could successfully compare x == y to > True in six compares. So let's imagine: ones = 1 : ones ones' = repeat 1 where repeat n = n : repeat n So you're suggesting that: ones == ones = True but ones' == ones' = _|_ Well if that were the case then it is distinguishing two equal values and hence breaking referential transparency. We can fairly trivially prove that ones and ones' are equal so == is not allowed to distinguish them. Fortunately it is impossible to write == above, at least using primitives within the language. Duncan From johan.tibell at gmail.com Thu Jan 10 22:45:45 2008 From: johan.tibell at gmail.com (Johan Tibell) Date: Thu Jan 10 22:39:17 2008 Subject: [Haskell-cafe] Haskell-mode 2.4 In-Reply-To: References: <90889fe70801081337q5521f3e5yd49a2435d2d96ed2@mail.gmail.com> <90889fe70801100932m15c1e08ey90c7a04578a35d54@mail.gmail.com> Message-ID: <90889fe70801101945j6371d7bal4ee45f4eca7dc617@mail.gmail.com> On Jan 11, 2008 12:05 AM, Stefan Monnier wrote: > > >> First of all, thanks. My Aqua Emacs (on OS X Leopard) hangs when I > >> send a command like C-c C-l or C-c C-t to the interpreter (I can quit > >> the command using C-g) . Starting the interpreter and using :l from > >> inside it works fine. This is using GHC 6.8 (and I think I also tried > >> 6.6.) What could be the problem? > >> > >> I also tried to eval this but it didn't make a difference: > >> > >> (setq inferior-haskell-find-project-root nil) > > > It looks like this is a problem with 6.8.2 as haskell-mode-2.3 has the > > same problem? Seems like the commands being sent to the haskell > > process never reaches it. > > Try can you try to look into the nature of the hang? > Is Emacs completely frozen? Does C-g get you back to something usable? > If so, can you set Options => Enter Debugger on Quit, then reproduce the > problem than hit C-g and show me the backtrace? > If not, can you run Emacs under a debugger and give me a backtrace of > when Emacs is frozen? Emacs is completely frozen until I press C-g and then it goes back to normal (without loading the file). Here's the back trace: Debugger entered--Lisp error: (quit) accept-process-output(#) (and (not (re-search-forward comint-prompt-regexp nil t)) (accept-process-output proc)) (progn (goto-char comint-last-input-end) (and (not ...) (accept-process-output proc))) (while (progn (goto-char comint-last-input-end) (and ... ...))) (save-current-buffer (set-buffer (process-buffer proc)) (while (progn ... ...))) (with-current-buffer (process-buffer proc) (while (progn ... ...))) inferior-haskell-wait-for-prompt(#) (save-current-buffer (set-buffer (process-buffer proc)) (inferior-haskell-wait-for-prompt proc) (goto-char (process-mark proc)) (insert-before-markers str) (move-marker comint-last-input-end (point)) (comint-send-string proc str)) (with-current-buffer (process-buffer proc) (inferior-haskell-wait-for-prompt proc) (goto-char (process-mark proc)) (insert-before-markers str) (move-marker comint-last-input-end (point)) (comint-send-string proc str)) inferior-haskell-send-command(# ":cd /Users/tibell/src/hyena/") (if (equal default-directory root) nil (setq default-directory root) (inferior-haskell-send-command proc (concat ":cd " default-directory))) (unless (equal default-directory root) (setq default-directory root) (inferior-haskell-send-command proc (concat ":cd " default-directory))) (progn (unless (equal default-directory root) (setq default-directory root) (inferior-haskell-send-command proc ...)) (setq file (file-relative-name file))) (if (and inferior-haskell-find-project-root (setq root ...)) (progn (unless ... ... ...) (setq file ...))) (when (and inferior-haskell-find-project-root (setq root ...)) (unless (equal default-directory root) (setq default-directory root) (inferior-haskell-send-command proc ...)) (setq file (file-relative-name file))) (let ((parsing-end ...) root) (when (and inferior-haskell-find-project-root ...) (unless ... ... ...) (setq file ...)) (inferior-haskell-send-command proc (if reload ":reload" ...)) (if (boundp ...) (if ... ... ...))) (save-current-buffer (set-buffer (process-buffer proc)) (compilation-forget-errors) (let (... root) (when ... ... ...) (inferior-haskell-send-command proc ...) (if ... ...)) (with-selected-window (display-buffer ...) (goto-char ...)) (when inferior-haskell-wait-and-jump (inferior-haskell-wait-for-prompt proc) (ignore-errors ...))) (with-current-buffer (process-buffer proc) (compilation-forget-errors) (let (... root) (when ... ... ...) (inferior-haskell-send-command proc ...) (if ... ...)) (with-selected-window (display-buffer ...) (goto-char ...)) (when inferior-haskell-wait-and-jump (inferior-haskell-wait-for-prompt proc) (ignore-errors ...))) (let ((buf ...) (file buffer-file-name) (proc ...)) (with-current-buffer (process-buffer proc) (compilation-forget-errors) (let ... ... ... ...) (with-selected-window ... ...) (when inferior-haskell-wait-and-jump ... ...))) inferior-haskell-load-file(nil) call-interactively(inferior-haskell-load-file) From benja.fallenstein at gmail.com Thu Jan 10 22:53:28 2008 From: benja.fallenstein at gmail.com (Benja Fallenstein) Date: Thu Jan 10 22:46:59 2008 Subject: [Haskell-cafe] \_ -> not equivalent to const $ In-Reply-To: <7ca3f0160801101454g27267cd4qdbe3b93300b30a56@mail.gmail.com> References: <7ca3f0160801101454g27267cd4qdbe3b93300b30a56@mail.gmail.com> Message-ID: On Jan 10, 2008 11:54 PM, Luke Palmer wrote: > Can someone explain what the heck is going on here? Evaluating (const EXPR) creates a closure object with a pointer to 'const' and a pointer to the EXPR thunk. Call this closure object C. Evaluating (C undefined) calls 'const' with the EXPR and C thunks as its arguments, which returns the EXPR thunk. The EXPR thunk is then forced by your code. Evaluating (C undefined) again calls 'const' with the EXPR and C pointers as its arguments again, which again returns the *now forced* EXPR thunk. I.e., evaluating (const EXPR) creates a closure with a pointer to a single EXPR thunk, and then applying the same closure to some argument multiple times uses that same EXPR thunk every time. An unoptimized (\_ -> EXPR) creates a new thunk each time the function is applied to an argument. Hope that helps with understanding what is going on? - Benja From monnier at iro.umontreal.ca Thu Jan 10 23:02:46 2008 From: monnier at iro.umontreal.ca (Stefan Monnier) Date: Thu Jan 10 22:56:19 2008 Subject: [Haskell-cafe] Haskell-mode 2.4 In-Reply-To: <90889fe70801101945j6371d7bal4ee45f4eca7dc617@mail.gmail.com> (Johan Tibell's message of "Fri, 11 Jan 2008 04:45:45 +0100") References: <90889fe70801081337q5521f3e5yd49a2435d2d96ed2@mail.gmail.com> <90889fe70801100932m15c1e08ey90c7a04578a35d54@mail.gmail.com> <90889fe70801101945j6371d7bal4ee45f4eca7dc617@mail.gmail.com> Message-ID: >> >> First of all, thanks. My Aqua Emacs (on OS X Leopard) hangs when I >> >> send a command like C-c C-l or C-c C-t to the interpreter (I can quit >> >> the command using C-g) . Starting the interpreter and using :l from >> >> inside it works fine. This is using GHC 6.8 (and I think I also tried >> >> 6.6.) What could be the problem? >> >> >> >> I also tried to eval this but it didn't make a difference: >> >> >> >> (setq inferior-haskell-find-project-root nil) >> >> > It looks like this is a problem with 6.8.2 as haskell-mode-2.3 has the >> > same problem? Seems like the commands being sent to the haskell >> > process never reaches it. >> >> Try can you try to look into the nature of the hang? >> Is Emacs completely frozen? Does C-g get you back to something usable? >> If so, can you set Options => Enter Debugger on Quit, then reproduce the >> problem than hit C-g and show me the backtrace? >> If not, can you run Emacs under a debugger and give me a backtrace of >> when Emacs is frozen? > Emacs is completely frozen until I press C-g and then it goes back to > normal (without loading the file). Here's the back trace: > Debugger entered--Lisp error: (quit) > accept-process-output(#) > (and (not (re-search-forward comint-prompt-regexp nil t)) > (accept-process-output proc)) So it seems to be waiting for the prompt but can't find it. If you look at the buffer containing the interactive process, is there a prompt there? If not, can you try and figure out why not? If yes, can you try and figure out why it is not recognized by the comint-prompt-regexp? Stefan From jonathanccast at fastmail.fm Thu Jan 10 23:37:49 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Thu Jan 10 23:31:29 2008 Subject: [Haskell-cafe] Comments and suggestions on code In-Reply-To: <1199989288.5309.12.camel@homesick> References: <1199937429.8936.33.camel@homesick> <6C68D342-F1B3-4333-8D7E-83E21E1FDB57@fastmail.fm> <1199989288.5309.12.camel@homesick> Message-ID: <7FF4DBDE-202A-43BC-A084-2D2E816EC3C9@fastmail.fm> On 10 Jan 2008, at 10:21 AM, Andre Nathan wrote: > Hi Jonathan > > On Wed, 2008-01-09 at 21:32 -0800, Jonathan Cast wrote: >> An actual coding question, abuse? We should be so lucky. > > :) Your comments are much appreciated. You're welcome. >> This function is fairly complicated, simply because of the number of >> separate definitions involved; I would be looking for opportunities >> to inline definitions here, so it's clearer what the definitions >> are. (Also, I would try to build a single, self-recursive function >> at the top level, put the call to procInfo there, and make everything >> else pure). > > I rewrote insertInTree like below. Now it is the only function that > has > a StateT return type, and I also got rid of addProc, insertPid and > insertParent :) > > insertInTree :: Pid -> StateT PsTree IO () > insertInTree pid = do > tree <- get > if Map.member pid tree > then return () > else do > info <- lift $ procInfo pid > modify (Map.insert pid info) > let ppid = parentPid info > if ppid /= "0" > then do > insertInTree ppid > modify (appendChild ppid pid) > else return () > > I also rewrote createTree like this: > > createTree :: IO PsTree > createTree = do > entries <- getDirectoryContents "/proc" > let procs = filter (=~ "^[0-9]+$") entries > execStateT (mapM_ insertInTree procs) Map.empty > > Is that a bad way to do it? If haskell wasn't lazy this would be 3 O > (n) > operations, and I could write it using readDirStream to process all > entries in one pass. I'm not sure if that's really necessary when > laziness is present though. It might be faster; laziness usually has higher constants than direct implementations. But I doubt the difference is critical in this case, and I would definitely time a re-writing and throw it away unless it was significantly faster. But I don't think this is a case where laziness actually alters either the time or the space asymptotics of the algorithm (you end up creating an ~ O(n) tree anyway, so I'd figure O(n) space was OK for the loop, too). jcc From jonathanccast at fastmail.fm Thu Jan 10 23:52:10 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Thu Jan 10 23:45:50 2008 Subject: [Haskell-cafe] confusion about 'instance'.... In-Reply-To: References: <2608b8a80801020549k1fe4f756q8e7337b81c032a6e@mail.gmail.com> <002c01c84e00$76b74d30$6425e790$@be> <7ca3f0160801100514l43003d25g59c799498ba6a221@mail.gmail.com> <1903939160.20080110163621@gmail.com> Message-ID: On 10 Jan 2008, at 6:04 AM, Nicholls, Mark wrote: > >> -----Original Message----- >> From: Bulat Ziganshin [mailto:bulat.ziganshin@gmail.com] >> Sent: 10 January 2008 13:36 >> To: Nicholls, Mark >> Cc: Luke Palmer; haskell-cafe@haskell.org >> Subject: Re[2]: [Haskell-cafe] confusion about 'instance'.... >> >> Hello Mark, >> >> Thursday, January 10, 2008, 4:25:20 PM, you wrote: >> >> "instance Num a =>> A a" >> >>> Mean the same thing as >> >>> "instance A (forall a.Num a=>a)" >> >> programmers going from OOP world always forget that classes in >> Haskell >> doesn't the same as classes in C++. *implementation* of this instance >> require to pass dictionary of Num class along with type. now imagine >> the following code: > > My confusion is not between OO classes and Haskell classes, but > exactly > are the members of a Haskell type class...I'd naively believed them to > be types (like it says on the packet!)...but now I'm not so sure. A type class *is* a set of types. But, in Haskell, types like (forall a. Num a => a) aren't quite first-class feeling. A typical example of an expression of this type might be (3 + 5), but if I say x :: Double x = 3 + 5 the compiler won't complain. Furthermore, if the compiler sees instance A Double where somewhere in the code, when it sees foo (3 + 5), for some method foo of the class, it may decide to take (3 + 5) :: Double, not (3 + 5) :: forall a. Num a => a. In that case, you'll get the wrong methods called: class A a where foo :: a -> String instance A Double where foo x = "Double" instance A (forall a. Num a => a) where foo x = "number" If the compiler sees the first instance but not the second, then it will think that foo (3 + 5) = "Double". Adding the second will give foo (3 + 5) = "number". Haskell 98's rules for type classes are chosen so that legal code never changes its meaning when you add an instance (well, this is a bad example --- but the general point is sound). GHC relaxes these rules in quite a few cases, but in this one it's easy enough (in GHC) to get a type isomorphic to forall a. Num a => a that can be an instance of a type class that GHC hasn't bothered relaxing this particular rule. (And paying the subsequent cost in confusion when working code bitrots because somebody added an instance somewhere). jcc From jonathanccast at fastmail.fm Fri Jan 11 00:09:44 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Fri Jan 11 00:10:21 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <20080110165530.3948df88@solaris.tower> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower> <20080110165530.3948df88@solaris.tower> Message-ID: On 10 Jan 2008, at 7:55 AM, Achim Schneider wrote: > "Daniel Yokomizo" wrote: > >> On Jan 10, 2008 3:36 PM, Achim Schneider wrote: >>> jerzy.karczmarczuk@info.unicaen.fr wrote: >>> >>>> Niko Korhonen writes: >>>> >>>> ... >>>>> Although it could be argued that laziness is the cause of some >>>>> very obscure bugs... >>>>> Niko >>>> >>>> Example, PLEASE. >>>> >>> [1..] == [1..] >>> >>> , for assumed operational semantics of ones own axiomatic semantics. >>> Bugs are only a misunderstanding away. >> >> It has nothing to do with laziness, but with using an algebraic >> function (==) with a codata structure (stream). If Haskell kept >> laziness but enforced separation of data and codata such code >> wouldn't >> compile. Lazy lists or streams never are a problem, but you can't >> (generically) fold codata. >> > Exactly. Denotationally it hasn't, but axiomatically it has. > Because it > looks like mathematical terms one can easily get lost in believing it > reduces like mathematics, too. What kind of mathematics? I don't know of any mathematics where algebraic simplifications are employed without proof of the underlying equations (in some denotational model). jcc From jake.mcarthur at gmail.com Fri Jan 11 01:24:59 2008 From: jake.mcarthur at gmail.com (Jake McArthur) Date: Fri Jan 11 01:18:34 2008 Subject: [Haskell-cafe] Re: Tim Sweeney (the gamer) In-Reply-To: <20080110205707.73639010@solaris.tower> References: <5ae4f2ba0801091621t5580361dv6fc5663f0c54c0ca@mail.gmail.com> <9313e97c0801100256r404973fdm9f781a2e8b90cd44@mail.gmail.com> <20080110125149.0f5dd989@solaris.tower> <3d96ac180801100415x54bba49l2bc53553a5b2483d@mail.gmail.com> <20080110134142.3db7479e@solaris.tower> <3d96ac180801100457v16e5a17ah75c88a2bb555815e@mail.gmail.com> <20080110144923.2db79eba@solaris.tower> <3d96ac180801101100q5efc3781i6048ed344c40be28@mail.gmail.com> <20080110204356.361e5cb0@solaris.tower> <20080110195137.GB18003@scytale.galois.com> <20080110205707.73639010@solaris.tower> Message-ID: On Jan 10, 2008, at 1:57 PM, Achim Schneider wrote: > Now don't make me think of using par on a beowolf cluster of ps3's. Never in my life have I _literally_ drooled over using a programming abstraction. - Jake -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080111/9ed98e5f/attachment.htm From cristi at ot.onrc.ro Fri Jan 11 01:30:45 2008 From: cristi at ot.onrc.ro (Cristian Baboi) Date: Fri Jan 11 01:24:46 2008 Subject: [Haskell-cafe] 0/0 > 1 == False In-Reply-To: References: Message-ID: On Thu, 10 Jan 2008 10:22:03 +0200, Mitar wrote: > Hi! > > Why is 0/0 (which is NaN) > 1 == False and at the same time 0/0 < 1 == > False. This means that 0/0 == 1? No, because also 0/0 == 1 == False. > > I understand that proper mathematical behavior would be that as 0/0 is > mathematically undefined that 0/0 cannot be even compared to 1. > > There is probably an implementation reason behind it, but do we really > want such "hidden" behavior? Would not it be better to throw some kind > of an error? NaN is not 'undefined' (0/0) /= (0/0) is True (0/0) == (0/0) is False You can use these to test for NaN. ________ Information from NOD32 ________ This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com From dons at galois.com Fri Jan 11 01:34:10 2008 From: dons at galois.com (Don Stewart) Date: Fri Jan 11 01:27:47 2008 Subject: [Haskell-cafe] 0/0 > 1 == False In-Reply-To: References: Message-ID: <20080111063410.GD19375@scytale.galois.com> cristi: > On Thu, 10 Jan 2008 10:22:03 +0200, Mitar wrote: > > >Hi! > > > >Why is 0/0 (which is NaN) > 1 == False and at the same time 0/0 < 1 == > >False. This means that 0/0 == 1? No, because also 0/0 == 1 == False. > > > >I understand that proper mathematical behavior would be that as 0/0 is > >mathematically undefined that 0/0 cannot be even compared to 1. > > > >There is probably an implementation reason behind it, but do we really > >want such "hidden" behavior? Would not it be better to throw some kind > >of an error? > > NaN is not 'undefined' > > (0/0) /= (0/0) is True > (0/0) == (0/0) is False > > You can use these to test for NaN. You can also use isNaN :) Prelude> isNaN (1/0) False Prelude> isNaN (0/0) True -- Don From cristi at ot.onrc.ro Fri Jan 11 01:58:35 2008 From: cristi at ot.onrc.ro (Cristian Baboi) Date: Fri Jan 11 01:53:07 2008 Subject: [Haskell-cafe] 0/0 > 1 == False In-Reply-To: <20080111063410.GD19375@scytale.galois.com> References: <20080111063410.GD19375@scytale.galois.com> Message-ID: On Fri, 11 Jan 2008 08:34:10 +0200, Don Stewart wrote: >> NaN is not 'undefined' >> >> (0/0) /= (0/0) is True >> (0/0) == (0/0) is False >> >> You can use these to test for NaN. > You can also use isNaN :) > > Prelude> isNaN (1/0) > False > Prelude> isNaN (0/0) > True Not true in Hugs. ________ Information from NOD32 ________ This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com From dons at galois.com Fri Jan 11 02:05:02 2008 From: dons at galois.com (Don Stewart) Date: Fri Jan 11 01:58:44 2008 Subject: [Haskell-cafe] 0/0 > 1 == False In-Reply-To: References: <20080111063410.GD19375@scytale.galois.com> Message-ID: <20080111070502.GE19375@scytale.galois.com> cristi: > On Fri, 11 Jan 2008 08:34:10 +0200, Don Stewart wrote: > > >>NaN is not 'undefined' > >> > >>(0/0) /= (0/0) is True > >>(0/0) == (0/0) is False > >> > >>You can use these to test for NaN. > > >You can also use isNaN :) > > > > Prelude> isNaN (1/0) > > False > > Prelude> isNaN (0/0) > > True > > Not true in Hugs. Report it to the Hugs guys (iirc they use their own math lib). P.S. Why are you using Hugs? -- Don From lennart at augustsson.net Fri Jan 11 02:11:52 2008 From: lennart at augustsson.net (Lennart Augustsson) Date: Fri Jan 11 02:05:22 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower> <20080110185659.4d7117ff@solaris.tower> Message-ID: Some people seem to think that == is an equality predicate. This is a big source of confusion for them; until they realize that == is just another function returning Bool they will make claims like [1..]==[1..] having an unnatural result. The == function is only vaguely related to the equality predicate in that it is meant to be a computable approximation of semantic equality (but since it's overloaded it can be anything, of course). -- Lennart On Jan 10, 2008 10:34 AM, wrote: > Achim Schneider: > > > jerzy.karczmarczuk asks what's wrong with: > >> > [1..] == [1..] > >> > >> Whatever you may say more, this is neither obscure nor a bug. I still > >> wait for a relevant example. But I don't insist too much... > >> > > It's not an example of a bug, but of a cause. > > A cause of WHAT?? This is a perfect, nice, runaway computation, which > agrees with all dogmas of my religion. > > Now, if somebody says that the fact that some people find it difficult to > grasp the essence of laziness, and THIS is a source of bugs, I may > believe. > But not the laziness itself. (For some people the (==) operator seems to > be a permanent source of bugs.) > > The difference between fold and stricter fold' won't convince me either. > People who want to use laziness must simply read the documentation... > > On the other hand, what Don Stewart pointed out, the inconsistency between > enumFrom and enumFromTo, and the difference of behaviours when one passes > from Int to Integer, now, this is another story, worrying a little... > Thanks. > > > Perhaps another example is more relevant, the tradeoffs space-time in the > "optimized" version of the powerset generator... > > Jerzy Karczmarczuk > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080110/1820696d/attachment.htm From lennart at augustsson.net Fri Jan 11 02:16:12 2008 From: lennart at augustsson.net (Lennart Augustsson) Date: Fri Jan 11 02:09:43 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <1200015747.7279.192.camel@localhost> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower> <20080110185659.4d7117ff@solaris.tower> <20080110203922.0c4deb87@solaris.tower> <4786A4C6.9080905@rbg.informatik.tu-darmstadt.de> <20080111011202.6354e435@solaris.tower> <1200015747.7279.192.camel@localhost> Message-ID: Thank you Duncan, you took the words out of my mouth. :) On Jan 10, 2008 5:42 PM, Duncan Coutts wrote: > > On Fri, 2008-01-11 at 01:12 +0100, Achim Schneider wrote: > > Tillmann Rendel wrote: > > > > > Achim Schneider wrote: > > > > [1..] == [1..] > > > > > > > > [some discussion about the nontermination of this expression] > > > > > > > > The essence of laziness is to do the least work necessary to cause > > > > the desired effect, which is to see that the set of natural numbers > > > > equals the set of natural numbers, which, axiomatically, is always > > > > computable in O(1) by equality by identity. > > > > > > This would make sense if Haskell had inbuild equality and (==) where > > > part of the formal semantics of Haskell, wich it isn't. (==) is a > > > library function like every other library function. How could the > > > language or a system implementing the language decide wether this or > > > any other library function returns True without actually running it? > > > > > The list instance for Eq might eg. know something about the structure > > of the lists and be smart enough not to get caught in the recursion of x > > = 1:1:x and y = 1:1:1:y so it could successfully compare x == y to > > True in six compares. > > So let's imagine: > > ones = 1 : ones > > ones' = repeat 1 > where repeat n = n : repeat n > > So you're suggesting that: > > ones == ones = True > but > ones' == ones' = _|_ > > > Well if that were the case then it is distinguishing two equal values > and hence breaking referential transparency. We can fairly trivially > prove that ones and ones' are equal so == is not allowed to distinguish > them. Fortunately it is impossible to write == above, at least using > primitives within the language. > > Duncan > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080110/8bdff035/attachment.htm From cristi at ot.onrc.ro Fri Jan 11 03:07:28 2008 From: cristi at ot.onrc.ro (Cristian Baboi) Date: Fri Jan 11 03:01:21 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <478657FF.2060509@rbg.informatik.tu-darmstadt.de> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> <478657FF.2060509@rbg.informatik.tu-darmstadt.de> Message-ID: On Thu, 10 Jan 2008 19:38:07 +0200, Tillmann Rendel wrote: > jerzy.karczmarczuk@info.unicaen.fr wrote: >>> Although it could be argued that laziness is the cause of some very >>> obscure bugs... Niko >> Example, PLEASE. > > Prelude> sum [1..1000000] > *** Exception: stack overflow Not true in Hugs. > Prelude> Data.List.foldl' (+) 0 [1..1000000] > 500000500000 > > Tillmann > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > > ________ Information from NOD32 ________ > This message was checked by NOD32 Antivirus System for Linux Mail > Servers. > part000.txt - is OK > http://www.eset.com ________ Information from NOD32 ________ This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com From bortzmeyer at nic.fr Fri Jan 11 03:21:32 2008 From: bortzmeyer at nic.fr (Stephane Bortzmeyer) Date: Fri Jan 11 03:15:03 2008 Subject: [Haskell-cafe] [IETF Apps meeting] A Theory of Templating Languages Message-ID: <20080111082132.GA28106@nic.fr> The IETF (http://www.ietf.org/) holds a meeting of its Application Area and is looking for papers. In a position paper, Joe Gregorio asked for information about the theory of templating languages. Giving the interest here in DSLs and conceptualization, he may find on this list the help he wants and the references he searches: >From: "Joe Gregorio" >Date: December 14, 2007 8:20:17 AM PST >Subject: Re: Position papers due Dec 14 > >Here is my brief position paper: > >Working on the URI Templating specification has made me realize that >there is a pretty substantial hole >in computer science theory: a lack of a theory of templating >languages. For example, the current version of >URI Templates is not Turing-complete, which excludes a whole bunch of >possible attacks. In the specification I state: > > On the balance, the template processing is not Turing complete, >thus avoiding a number of > security issues, ala the billion-laughs attack of XML DTDs. > >I was rightly called out on this on the W3C URI mailing list: > > This reads a little odd, as not being Turing-complete is not >sufficient > to avoid the attack. (And DTDs are not Turing-complete either.) > >The criticism is correct. The problem is that I don't know of any >finer grained levels of classifications >of templating languages than Turing/non-Turing, and not only for >security reasons, but for general capabilities. > >For example, if there were classes of templating languages, I could >say that URI Templates fell into 'class X', and >if that class had a known set of limitations and capabilities then I >could say that URI Templates thus had those >limitations and capabilities. The weakness to the billion laughs >attack comes from two facets of DTD usage, the >first being that templates can be defined in terms of other templates, >and the second is that the depth of template >definition, in terms of other templates, isn't limited. But the >converse isn't true, that is, I don't have a general >theory of templating to lean on that says since URI Template >expansions are never defined in terms of other >expansions then URI Templates are immune to such resource >exhaustion attacks. > >I did find one paper that makes a start at such work, "Enforcing >Strict Model-View Separation in Template Engines", >but the theory is a little weak and it focuses on the nebulous idea of >separation of model and view, as opposed to >a classification of capabilities and limitations. In addition there >seems to not be a lot of work on sub-turing languages, >and most interestingly the contemporary work that is being done is on >Membrane Computing Systems, which >is in turn motivated by studying cell evolutions and chemical >reactions. I am bringing this topic forward in the >hopes of learning of other pointers into the literature, and also >learning if this problem applies to others >in the Apps area, of if I'm all alone with this problem in URI >Templates. ----- End forwarded message ----- From johan.tibell at gmail.com Fri Jan 11 03:43:52 2008 From: johan.tibell at gmail.com (Johan Tibell) Date: Fri Jan 11 03:37:21 2008 Subject: [Haskell-cafe] Haskell-mode 2.4 In-Reply-To: References: <90889fe70801081337q5521f3e5yd49a2435d2d96ed2@mail.gmail.com> <90889fe70801100932m15c1e08ey90c7a04578a35d54@mail.gmail.com> <90889fe70801101945j6371d7bal4ee45f4eca7dc617@mail.gmail.com> Message-ID: <90889fe70801110043n7f47fc2eo69208b73c1db527c@mail.gmail.com> > > Emacs is completely frozen until I press C-g and then it goes back to > > normal (without loading the file). Here's the back trace: > > > Debugger entered--Lisp error: (quit) > > accept-process-output(#) > > (and (not (re-search-forward comint-prompt-regexp nil t)) > > (accept-process-output proc)) > > So it seems to be waiting for the prompt but can't find it. > If you look at the buffer containing the interactive process, is there > a prompt there? If not, can you try and figure out why not? > If yes, can you try and figure out why it is not recognized by the > comint-prompt-regexp? I had the following in my .ghci to make GHCi's prompt less verbose: :set prompt "> " Removing that solves the problem. Thanks! -- Johan From cristi at ot.onrc.ro Fri Jan 11 04:20:39 2008 From: cristi at ot.onrc.ro (Cristian Baboi) Date: Fri Jan 11 04:16:15 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower> <20080110185659.4d7117ff@solaris.tower> <20080110203922.0c4deb87@solaris.tower> <4786A4C6.9080905@rbg.informatik.tu-darmstadt.de> <20080111011202.6354e435@solaris.tower> <1200015747.7279.192.camel@localhost> Message-ID: On Fri, 11 Jan 2008 09:16:12 +0200, Lennart Augustsson wrote: > Thank you Duncan, you took the words out of my mouth. :) > On Jan 10, 2008 5:42 PM, Duncan Coutts > wrote: >> > >> So let's imagine: >> >> ones = 1 : ones >> >> ones' = repeat 1 >> where repeat n = n : repeat n >> >> So you're suggesting that: >> >> ones == ones = True >> but >> ones' == ones' = _|_ >> >> >> Well if that were the case then it is distinguishing two equal values >> and hence breaking referential transparency. We can fairly trivially >> prove that ones and ones' are equal so == is not allowed to distinguish >> them. Fortunately it is impossible to write == above, at least using >> primitives within the language. If one can prove ones == ones = True with some method, why that method cannot be made to work on ones' ? Are you thinking about repeat (f x) by any chance ? ________ Information from NOD32 ________ This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com From g9ks157k at acme.softbase.org Fri Jan 11 04:27:44 2008 From: g9ks157k at acme.softbase.org (Wolfgang Jeltsch) Date: Fri Jan 11 04:22:11 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> Message-ID: <200801111027.44693.g9ks157k@acme.softbase.org> Am Freitag, 11. Januar 2008 08:11 schrieb Lennart Augustsson: > Some people seem to think that == is an equality predicate. > This is a big source of confusion for them; until they realize that == is > just another function returning Bool they will make claims like > [1..]==[1..] having an unnatural result. > > The == function is only vaguely related to the equality predicate in that > it is meant to be a computable approximation of semantic equality (but > since it's overloaded it can be anything, of course). > > -- Lennart But class methods are expected to fulfill some axioms. I?d suppose that (==) should be an equivalence relation. Of course, this is not implementable because of infininte data structures. But one could relax the axioms such that it?s allowed for (==) to return _|_ instead of the expected value. Differentiating between data and codata would of course be the better solution. However, the fact that (0 / 0) == (0 / 0) yields False is quite shocking. It doesn?t adhere to any meaningful axiom set for Eq. So I think that this behavior should be changed. Think of a set implementation which uses (==) to compare set elements for equality. The NaN behavior would break this implementation since it would allow for sets which contain NaN multiple times. Best wishes, Wolfgang From cristi at ot.onrc.ro Fri Jan 11 04:32:47 2008 From: cristi at ot.onrc.ro (Cristian Baboi) Date: Fri Jan 11 04:27:18 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower> <20080110185659.4d7117ff@solaris.tower> Message-ID: On Fri, 11 Jan 2008 09:11:52 +0200, Lennart Augustsson wrote: > Some people seem to think that == is an equality predicate. > This is a big source of confusion for them; until they realize that == is > just another function returning Bool they will make claims like > [1..]==[1..] > having an unnatural result. > The == function is only vaguely related to the equality predicate in > that it > is meant to be a computable approximation of semantic equality (but since > it's overloaded it can be anything, of course). I think that confusion came from the fact that the type of == is called (Eq a)=> a -> a -> Bool and not (Bla a) => a -> a -> Binary and not realizing it's just an overloaded polimorphic function. ________ Information from NOD32 ________ This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com From miguelimo38 at yandex.ru Fri Jan 11 04:47:55 2008 From: miguelimo38 at yandex.ru (Miguel Mitrofanov) Date: Fri Jan 11 04:41:35 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: 1630000000230526283 References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> 1630000000230526283 Message-ID: <210051200044875@webmail25.yandex.ru> > However, the fact that (0 / 0) == (0 / 0) yields False is quite shocking. Just for the record: the following is from Firebug (JavaScript debugger for Firefox) session: >>> a = 0/0 NaN >>> a == a false >>> a === a false From wb at arb-phys.uni-dortmund.de Fri Jan 11 04:54:28 2008 From: wb at arb-phys.uni-dortmund.de (Wilhelm B. Kloke) Date: Fri Jan 11 04:48:16 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <200801111027.44693.g9ks157k@acme.softbase.org> Message-ID: Wolfgang Jeltsch schrieb: > > However, the fact that (0 / 0) == (0 / 0) yields False is quite shocking. It > doesn?t adhere to any meaningful axiom set for Eq. So I think that this > behavior should be changed. Think of a set implementation which uses (==) to > compare set elements for equality. The NaN behavior would break this > implementation since it would allow for sets which contain NaN multiple > times. You forget, that the intention of NaN is denial of membership of any set of numbers. -- Dipl.-Math. Wilhelm Bernhard Kloke Institut fuer Arbeitsphysiologie an der Universitaet Dortmund Ardeystrasse 67, D-44139 Dortmund, Tel. 0231-1084-257 PGP: http://vestein.arb-phys.uni-dortmund.de/~wb/mypublic.key From ashley at semantic.org Fri Jan 11 04:56:59 2008 From: ashley at semantic.org (Ashley Yakeley) Date: Fri Jan 11 04:50:47 2008 Subject: [Haskell-cafe] Subtypes and Co/Contra-variance Message-ID: Consider this: type Super = forall a. [a] type Sub = forall b. b cast0 :: Sub -> Super cast0 s = s cast1a :: forall p. (Super -> p) -> (Sub -> p) cast1a sp x = sp x cast1b :: forall p. (Super -> p) -> (Sub -> p) cast1b sp = sp This compiles except for cast1b (ghc -c -fglasgow-exts): Occurs check: cannot construct the infinite type: a = [a] When generalising the type(s) for `cast1b' I get a similar result when I try a different Super and Sub: type Super = (?x :: Bool) => Int type Sub = Int Couldn't match expected type `Sub' against inferred type `Super' When matching `(?x::Bool) => Int' and `Int' Expected type: Sub -> p Inferred type: Super -> p In the expression: sp In either case, if cast1a compiles, shouldn't cast1b compile? -- Ashley Yakeley From asviraspossible at gmail.com Fri Jan 11 04:58:01 2008 From: asviraspossible at gmail.com (Victor Nazarov) Date: Fri Jan 11 04:51:33 2008 Subject: [Haskell-cafe] Re: Displaying steps in my interpreter In-Reply-To: References: Message-ID: On Jan 10, 2008 8:39 PM, apfelmus wrote: > Victor Nazarov wrote: > > > Yes, there is: you can use a zipper > > http://en.wikibooks.org/wiki/Haskell/Zippers > > Here's how: > > data Branch v = AppL (Term v) > | AppR (Term v) > | Lamb v > type Context v = [Branch v] > type Zipper v = (Context v, Term v) > > unwind :: Zipper v -> Term v > unwind ([] , t) = t > unwind (AppL e:cxt, f) = unwind (cxt, App f e) > unwind (AppR f:cxt, e) = unwind (cxt, App f e) > unwind (Lamb x:cxt, e) = unwind (cxt, Lam x e) > Thanks. Zippers seemed very cool when I first encountered them in some text about xmonad. But I've never used them in my own code. > Concerning the problem of printing intermediate steps, I don't quite > understand your approach. I'd simply use a Writer monad to keep track of > intermediate terms > My version just return when the state in State monad is not Nothing, so we can print result and start over again. > import Control.Monad.Writer > > -- use a difference list or something for better performance > type Trace v = [Zipper v] > > whnf :: Term v -> Writer (Trace v) (Term v) > whnf t = whnf' ([],t) > where > whnf' (AppL e':cxt, Lam x e) = tell (cxt, App (Lam x e) e') >> > whnf' (cxt , subst x e' e) > whnf' (cxt , App f e) = whnf' (AppL e:cxt, f) > whnf' z = return $ unwind z > > The definition of whnf is basically left unchanged, except that a > redex is recorded via tell whenever a beta-reduction is about to be > performed. The recorded terms can be printed afterwards > > printTrace :: Writer (Trace v) (Term v) -> IO () > printTrace w = let (t, ts) = runWriter t ts > putStrLn . unlines . map show $ ts > Is this function lazy? Can I run this code on term without nf and print n-first steps: > printTraceN :: Int -> Writer (Trace v) (Term v) -> IO () > printTraceN n w = > let (t, ts) = runWriter t ts > in putStrLn . unlines . map show $ take n ts > Will this work: > printTraceN 5 (read "(\x. x x x) (\x. x x x)") ? > > Last but not least, there is a nice introductory paper about the many > possible reduction strategies for lambda calculus > > http://www.itu.dk/people/sestoft/papers/sestoft-lamreduce.pdf > Thank you. -- vir http://vir.comtv.ru/ From felipe.lessa at gmail.com Fri Jan 11 05:03:03 2008 From: felipe.lessa at gmail.com (Felipe Lessa) Date: Fri Jan 11 04:56:33 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <210051200044875@webmail25.yandex.ru> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <210051200044875@webmail25.yandex.ru> Message-ID: On Jan 11, 2008 7:47 AM, Miguel Mitrofanov wrote: > > However, the fact that (0 / 0) == (0 / 0) yields False is quite shocking. > > Just for the record: the following is from Firebug (JavaScript debugger for Firefox) session: > > >>> a = 0/0 > NaN > >>> a == a > false > >>> a === a > false Another thing for the record: Goldberg says "The introduction of NaNs can be confusing, because a NaN is never equal to any other number (including another NaN), so x = x is no longer always true. In fact, the expression x /= x is the simplest way to test for a NaN if the IEEE recommended function Isnan is not provided. Furthermore, NaNs are unordered with respect to all other numbers, so x <= y cannot be defined as not x > y. Since the introduction of NaNs causes floating-point numbers to become partially ordered, a compare function that returns one of <, =, >, or unordered can make it easier for the programmer to deal with comparisons." Goldberg, David. What Every Computer Scientist Should Know About Floating-Point Arithmetic. http://docs.sun.com/source/806-3568/ncg_goldberg.html . As GNU is not Unix, NaN is not a number, so what is standard about numbers doesn't work for them. I don't think there's a compeling reason about changing this behavior, specially because it's what's specified in the IEEE 754. However you can always define something like newtype NotADouble = N Double ... instance Eq NotADouble where N x == N y = (isNaN x && isNaN y) || (x == y) ... -- Felipe. From cristi at ot.onrc.ro Fri Jan 11 05:07:57 2008 From: cristi at ot.onrc.ro (Cristian Baboi) Date: Fri Jan 11 05:02:17 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower> <20080110185659.4d7117ff@solaris.tower> Message-ID: On Fri, 11 Jan 2008 09:11:52 +0200, Lennart Augustsson wrote: > Some people seem to think that == is an equality predicate. > This is a big source of confusion for them; until they realize that == is > just another function returning Bool they will make claims like > [1..]==[1..] > having an unnatural result. > The == function is only vaguely related to the equality predicate in > that it > is meant to be a computable approximation of semantic equality (but since > it's overloaded it can be anything, of course). > >> So let's imagine: >> >> ones = 1 : ones >> >> ones' = repeat 1 >> where repeat n = n : repeat n (==) :: Eq a => a -> a -> Bool -- what is (y (y) ) by the way ? -- how about ( y id ) ? y f = f (y f). ones :: Num a => [a] ones = y (1 :) repeat :: a -> [a] repeat = \n -> y (n:) ones' :: Num a => [a] ones' = repeat 1 = (\n->y(n:)) 1 = y (1 : ) To be able to test them for equality, we must have Eq a. So, the reason we cannot test them for equality is that we cannot test y (a : ) == y (a : ) where a == a is testable. ________ Information from NOD32 ________ This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com From miguelimo38 at yandex.ru Fri Jan 11 05:12:17 2008 From: miguelimo38 at yandex.ru (Miguel Mitrofanov) Date: Fri Jan 11 05:05:55 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: 1630000000230531461 References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <210051200044875@webmail25.yandex.ru> 1630000000230531461 Message-ID: <1107631200046337@webmail33.yandex.ru> > As GNU is not Unix, NaN is not a number, Since NaN /= NaN, I think, we should decipher "NaN" as "Not a NaN" instead. From ketil+haskell at ii.uib.no Fri Jan 11 05:17:22 2008 From: ketil+haskell at ii.uib.no (Ketil Malde) Date: Fri Jan 11 05:11:02 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False In-Reply-To: <20080110220408.47186b19@solaris.tower> (Achim Schneider's message of "Thu\, 10 Jan 2008 22\:04\:08 +0100") References: <2608b8a80801100117wda28551ida0166f548147aac@mail.gmail.com> <20080110201613.GA30239@momenergy.repetae.net> <20080110212434.07e18eb8@solaris.tower> <20080110202724.GO28763@darcs.net> <20080110214153.46ad3395@solaris.tower> <20080110205220.GR28763@darcs.net> <20080110220408.47186b19@solaris.tower> Message-ID: <87k5mgsm31.fsf@nmd9999.imr.no> Achim Schneider writes: >> You need to use the / operator, if you want to do floating-point >> division. > Yes, exactly, integers don't have +-0 and +-infinity... only > (obviously) a kind of nan. No, failure (exception, bottom) is different from NaN, which is just another value in the domain - admittedly one which behaves rather strangely. > Said differently: I don't know a thing about floats or numerics. Perhaps it helps to think of floating point values as intervals? If +0 means some number between 0 and the next possible representable number (and similar for -0), it may make more sense to have 1/+0 and 1/-0 behave differently. -k -- If I haven't seen further, it is by standing in the footprints of giants From vlado at dikini.net Fri Jan 11 05:19:54 2008 From: vlado at dikini.net (Vladimir Zlatanov) Date: Fri Jan 11 05:11:40 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <200801111027.44693.g9ks157k@acme.softbase.org> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <200801111027.44693.g9ks157k@acme.softbase.org> Message-ID: <1200046794.22908.46.camel@localhost.localdomain> > However, the fact that (0 / 0) == (0 / 0) yields False is quite shocking. In my opinion it is the better than yielding True. 0/0 doesn't make sense. So it can't be compared to anything else which doesn't make sense. Whether == should yield False at all is another matter. It may be better to yield some kind of bottom (undefined?), but then compatibility with IEEE 754 might be an issue, hence using external libraries like BLAS, gmp, ... From jules at jellybean.co.uk Fri Jan 11 05:28:03 2008 From: jules at jellybean.co.uk (Jules Bean) Date: Fri Jan 11 05:21:35 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <20080111011202.6354e435@solaris.tower> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower> <20080110185659.4d7117ff@solaris.tower> <20080110203922.0c4deb87@solaris.tower> <4786A4C6.9080905@rbg.informatik.tu-darmstadt.de> <20080111011202.6354e435@solaris.tower> Message-ID: <478744B3.6050809@jellybean.co.uk> Achim Schneider wrote: > The list instance for Eq might eg. know something about the structure > of the lists and be smart enough not to get caught in the recursion of x > = 1:1:x and y = 1:1:1:y so it could successfully compare x == y to > True in six compares. This would not be "something about the structure of lists" This would be "somethign about the structure of thunks". Thunks are not supposed to be observable. If you augment the language to make thunks observable and comparable, you will break referential transparency. Jules From lemming at henning-thielemann.de Fri Jan 11 05:29:29 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Fri Jan 11 05:23:25 2008 Subject: [Haskell-cafe] Why purely in haskell? In-Reply-To: <20080110201222.GN28763@darcs.net> References: <2d3641330801090706m4ed9a927l282bb840a7dfcb7f@mail.gmail.com> <1199897022.18821.24.camel@derek-laptop> <4785339B.7050308@telenet.be> <47853A2C.2060508@appsolutions.com> <20080109212104.GD29472@scytale.galois.com> <117f2cc80801091415x643bec1cmf09931d4d16d59e5@mail.gmail.com> <117f2cc80801100759o23af9f8dtdbaff6ca8213171a@mail.gmail.com> <87zlvdsawi.fsf@nmd9999.imr.no> <3d96ac180801101210p616db74ah9dcc4be8167cf3ba@mail.gmail.com> <20080110201222.GN28763@darcs.net> Message-ID: On Thu, 10 Jan 2008, David Roundy wrote: > On Thu, Jan 10, 2008 at 08:10:57PM +0000, Sebastian Sylvan wrote: > > On Jan 10, 2008 8:06 PM, Ketil Malde wrote: > > > "David Roundy" writes: > > > > > > >> > I just want to point out that unsafePerformIO is at the core of the > > > >> > (safe) bytestring library. As SPJ et al pointed out, this is crucial > > > >> > functionality, and is only unsafe if unsafely used. > > > > > > >> In Modula-3 modules using hacks must be explicitly marked as UNSAFE. See > > > >> http://www.cs.purdue.edu/homes/hosking/m3/reference/unsafe.html > > > >> Maybe this is also an option for Haskell? > > > > > > > I don't think this is a good idea. > > > > > > I think the point is (should be) to mark functions unsafe when they > > > may be unsafe to /use/, > > > > I think using the IO monad for this works well... > > Would you suggest moving head and tail into the IO monad? I'm afraid we are talking about different notions of 'safe'. Modula-3's 'safe' means no "segmentation fault", but program abortion due to ASSERT is still allowed. Ported to Haskell this means: 'head' and 'tail' are safe, but not total. I've seen function definitions like 'safeHead', that I would have named 'maybeHead'. For running untrusted code this means: I think it is ok that the program aborts with an error or runs into an infinite loop and must be terminated after a time-out, but it is not ok, that it overwrites some memory area or deletes some files, because unsafePerformIO was invoked. From ketil+haskell at ii.uib.no Fri Jan 11 05:33:01 2008 From: ketil+haskell at ii.uib.no (Ketil Malde) Date: Fri Jan 11 05:26:40 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <200801111027.44693.g9ks157k@acme.softbase.org> (Wolfgang Jeltsch's message of "Fri\, 11 Jan 2008 10\:27\:44 +0100") References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <200801111027.44693.g9ks157k@acme.softbase.org> Message-ID: <87fxx4slcy.fsf@nmd9999.imr.no> Wolfgang Jeltsch writes: > However, the fact that (0 / 0) == (0 / 0) yields False is quite shocking. It > doesn?t adhere to any meaningful axiom set for Eq. Tough luck, but that's how floating point works, and what the numericalists know, and possibly even love (although I have my doubts). Sanitizing this behavior would make Haskell less usable for real-world numerical problems. As a compromise, what about an option to make NaN (and presumably the infinities) cause an immediate exception? (And, cetero censeo, exceptions for Int overflow as well.) -k -- If I haven't seen further, it is by standing in the footprints of giants From cristi at ot.onrc.ro Fri Jan 11 05:50:53 2008 From: cristi at ot.onrc.ro (Cristian Baboi) Date: Fri Jan 11 05:44:49 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower> <20080110185659.4d7117ff@solaris.tower> Message-ID: On Fri, 11 Jan 2008 09:11:52 +0200, Lennart Augustsson wrote: > Some people seem to think that == is an equality predicate. > This is a big source of confusion for them; until they realize that == is > just another function returning Bool they will make claims like > [1..]==[1..] > having an unnatural result. > The == function is only vaguely related to the equality predicate in > that it > is meant to be a computable approximation of semantic equality (but since > it's overloaded it can be anything, of course). Imagine one can manage to define a function which stops when applied on any value of type T1, but not when applied on some values of type T2 including bottom. Because bottom is a member of any type and referential transparency must not be broken, such a function cannot be defined. ________ Information from NOD32 ________ This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com From g9ks157k at acme.softbase.org Fri Jan 11 06:29:35 2008 From: g9ks157k at acme.softbase.org (Wolfgang Jeltsch) Date: Fri Jan 11 06:23:54 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <200801111027.44693.g9ks157k@acme.softbase.org> Message-ID: <200801111229.35499.g9ks157k@acme.softbase.org> Am Freitag, 11. Januar 2008 10:54 schrieb Wilhelm B. Kloke: > Wolfgang Jeltsch schrieb: > > However, the fact that (0 / 0) == (0 / 0) yields False is quite shocking. > > It doesn?t adhere to any meaningful axiom set for Eq. So I think that > > this behavior should be changed. Think of a set implementation which > > uses (==) to compare set elements for equality. The NaN behavior would > > break this implementation since it would allow for sets which contain NaN > > multiple times. > > You forget, that the intention of NaN is denial of membership of any set of > numbers. This doesn?t matter. The Set data type I?m talking about would not know about NaN and would therefore allow multiple NaNs in a set. Best wishes, Wolfgang From cristi at ot.onrc.ro Fri Jan 11 06:33:10 2008 From: cristi at ot.onrc.ro (Cristian Baboi) Date: Fri Jan 11 06:26:57 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <200801111229.35499.g9ks157k@acme.softbase.org> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <200801111027.44693.g9ks157k@acme.softbase.org> <200801111229.35499.g9ks157k@acme.softbase.org> Message-ID: On Fri, 11 Jan 2008 13:29:35 +0200, Wolfgang Jeltsch wrote: > Am Freitag, 11. Januar 2008 10:54 schrieb Wilhelm B. Kloke: >> Wolfgang Jeltsch schrieb: >> > However, the fact that (0 / 0) == (0 / 0) yields False is quite >> shocking. >> > It doesn?t adhere to any meaningful axiom set for Eq. So I think >> that >> > this behavior should be changed. Think of a set implementation which >> > uses (==) to compare set elements for equality. The NaN behavior >> would >> > break this implementation since it would allow for sets which contain >> NaN >> > multiple times. >> >> You forget, that the intention of NaN is denial of membership of any >> set of >> numbers. > This doesn?t matter. The Set data type I?m talking about would not know > about > NaN and would therefore allow multiple NaNs in a set. This is a good thing because one can define natural numbers with such sets :-) ________ Information from NOD32 ________ This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com From g9ks157k at acme.softbase.org Fri Jan 11 06:36:13 2008 From: g9ks157k at acme.softbase.org (Wolfgang Jeltsch) Date: Fri Jan 11 06:30:24 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <210051200044875@webmail25.yandex.ru> Message-ID: <200801111236.14073.g9ks157k@acme.softbase.org> Am Freitag, 11. Januar 2008 11:03 schrieb Felipe Lessa: > Another thing for the record: Goldberg says > > "The introduction of NaNs can be confusing, because a NaN is never > equal to any other number (including another NaN), so x = x is no > longer always true. In fact, the expression x /= x is the simplest way > to test for a NaN if the IEEE recommended function Isnan is not > provided. Furthermore, NaNs are unordered with respect to all other > numbers, so x <= y cannot be defined as not x > y. Since the > introduction of NaNs causes floating-point numbers to become partially > ordered, a compare function that returns one of <, =, >, or unordered > can make it easier for the programmer to deal with comparisons." > > Goldberg, David. What Every Computer Scientist Should Know About > Floating-Point Arithmetic. > http://docs.sun.com/source/806-3568/ncg_goldberg.html . > > As GNU is not Unix, NaN is not a number, so what is standard about > numbers doesn't work for them. I don't think there's a compeling > reason about changing this behavior, specially because it's what's > specified in the IEEE 754. There is a really compelling reason: If the order on floating point numbers is partial then there is no meaningful Ord instance for them. And what do Hugs and GHCi say? Their answers are plain horror: Hugs, version 20050308: compare (0 / 0) (0 / 0) => EQ 0 / 0 == 0 / 0 => False GHCi 6.8.2: compare (0 / 0) (0 / 0) => GT 0 / 0 > 0 / 0 => False Anyone interested in filing bug reports? > [?] Best wishes, Wolfgang From g9ks157k at acme.softbase.org Fri Jan 11 06:41:29 2008 From: g9ks157k at acme.softbase.org (Wolfgang Jeltsch) Date: Fri Jan 11 06:35:41 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <87fxx4slcy.fsf@nmd9999.imr.no> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <200801111027.44693.g9ks157k@acme.softbase.org> <87fxx4slcy.fsf@nmd9999.imr.no> Message-ID: <200801111241.29253.g9ks157k@acme.softbase.org> Am Freitag, 11. Januar 2008 11:33 schrieben Sie: > Wolfgang Jeltsch writes: > > However, the fact that (0 / 0) == (0 / 0) yields False is quite shocking. > > It doesn?t adhere to any meaningful axiom set for Eq. > > Tough luck, but that's how floating point works, and what the > numericalists know, and possibly even love (although I have my > doubts). Sanitizing this behavior would make Haskell less usable for > real-world numerical problems. The IEEE floating point equivalence test has to yield false when comparing NaN with NaN. Haskell?s (==) has to yield True or undefined when comparing a value with itself. So Haskell?s (==) just has to be different from the IEEE floating point equivalence test. What about providing a separate function for the latter? > As a compromise, what about an option to make NaN (and presumably the > infinities) cause an immediate exception? (And, cetero censeo, > exceptions for Int overflow as well.) This would be far better (and far more Haskell-like). > -k Best wishes, Wolfgang From wss at Cs.Nott.AC.UK Fri Jan 11 06:49:09 2008 From: wss at Cs.Nott.AC.UK (Wouter Swierstra) Date: Fri Jan 11 06:43:34 2008 Subject: [Haskell-cafe] The Monad.Reader (10) - Second call for copy Message-ID: <39F5DBA4-4079-467B-A101-6B08ADE551E6@Cs.Nott.AC.UK> Call for Copy The Monad.Reader - Issue 10 It is not too late to consider writing something for the next issue of The Monad.Reader. The deadline for Issue 10 is ** January 25, 2007 ** It doesn't matter if you're an established academic or if you have only just started learning Haskell, if you have something to say, please write article for The Monad.Reader. The Monad.Reader is a electronic magazine about all things Haskell. It is less-formal than journal, but somehow more enduring than a wiki- page. There have been a wide variety of articles, including: exciting code fragments, intriguing puzzles, book reviews, tutorials, and even half-baked research ideas. * Submission Details * Get in touch with me if you intend to submit something -- the sooner you let me know what you're up to, the better. Please submit articles for the next issue to me by e-mail (wss at cs.nott.ac.uk). Articles should be written according to the guidelines available from http://www.haskell.org/haskellwiki/The_Monad.Reader Please submit your article in PDF, together with any source files you used. The sources will be released together with the magazine under a BSD license. If you would like to submit an article, but have trouble with LaTeX please let me know and we'll sort something out. All the best, Wouter This message has been checked for viruses but the contents of an attachment may still contain software viruses, which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation. From apfelmus at quantentunnel.de Fri Jan 11 07:04:56 2008 From: apfelmus at quantentunnel.de (apfelmus) Date: Fri Jan 11 06:58:40 2008 Subject: [Haskell-cafe] Re: Displaying steps in my interpreter In-Reply-To: References: Message-ID: Victor Nazarov wrote: >> import Control.Monad.Writer >> >> -- use a difference list or something for better performance >> type Trace v = [Zipper v] >> >> whnf :: Term v -> Writer (Trace v) (Term v) >> whnf t = whnf' ([],t) >> where >> whnf' (AppL e':cxt, Lam x e) = tell (cxt, App (Lam x e) e') >> >> whnf' (cxt , subst x e' e) >> whnf' (cxt , App f e) = whnf' (AppL e:cxt, f) >> whnf' z = return $ unwind z >> >> The definition of whnf is basically left unchanged, except that a >> redex is recorded via tell whenever a beta-reduction is about to be >> performed. The recorded terms can be printed afterwards >> >> printTrace :: Writer (Trace v) (Term v) -> IO () >> printTrace w = let (t, ts) = runWriter t ts >> putStrLn . unlines . map show $ ts >> > > Is this function lazy? Can I run this code on term without nf and > print n-first steps: > >> printTraceN :: Int -> Writer (Trace v) (Term v) -> IO () >> printTraceN n w = >> let (t, ts) = runWriter t ts >> in putStrLn . unlines . map show $ take n ts >> > > Will this work: > >> printTraceN 5 (read "(\x. x x x) (\x. x x x)") Yes, it should (you can just try, right? :). That's because tell w >> something is basically let (w', x) = something in (w ++ w', x) Now, something may loop forever, but w ++ w' doesn't care, it prepends w no matter what w' is. Of course, asking for x (the normal form in our case) instead of w ++ w' won't succeed when something loops forever. (Cave: this is only true for the writer monad in Control.Monad.Writer.Lazy which is imported by default. The writer monad in Control.Monad.Writer.Strict intentionally behaves differently.) Regards, apfelmus From jerzy.karczmarczuk at info.unicaen.fr Fri Jan 11 07:21:45 2008 From: jerzy.karczmarczuk at info.unicaen.fr (jerzy.karczmarczuk@info.unicaen.fr) Date: Fri Jan 11 07:15:15 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <87fxx4slcy.fsf@nmd9999.imr.no> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <200801111027.44693.g9ks157k@acme.softbase.org> <87fxx4slcy.fsf@nmd9999.imr.no> Message-ID: Ketil Malde: > Wolfgang Jeltsch: >> However, the fact that (0 / 0) == (0 / 0) yields False is quite shocking. >> It doesn?t adhere to any meaningful axiom set for Eq. > > Tough luck, but that's how floating point works, and what the > numericalists know, and possibly even love (although I have my > doubts). Sanitizing this behavior would make Haskell less usable for > real-world numerical problems. > > As a compromise, what about an option to make NaN (and presumably the > infinities) cause an immediate exception? (And, cetero censeo, > exceptions for Int overflow as well.) People, you are monsters. First, despite the *common, well known* truth that Haskell is not Mathematics, this illusion seems to be extremely persistent! Haskell is a victim - no, some users are victims of its success as a formal language, not just as a coding tool... They *want* to have Eq as they imagine the equality, including the comparison between incomparable. This is BTW a long standing philosophical problem. For centuries some speculative guys tried to analyse such "assertions" as God == God, or death==death. Or myself==myself. Of course, even if they produced some cute conclusions, they had no whatsoever sense for the others. Now we have the modern variants of it: NaN == NaN, bottom == bottom ... Of course, there are differences, since NaN is, no - ARE well defined *objects*. In IEEE there may be several NaNs, if the exponent is e_max+1, then *any* significand (mantissa for the dinosaurs) is good for a NaN. ++ Then, I see here, and on some other lists some tendency to speculate on the numerics by people who really don't need it, and don't use it. The bombing of NaN *might* be a profound compilation option, but for people who really do numerical work, this is a blessing NOT to have it. - Zero (or minimum, etc.) finders don't explode on your face when the automaton gets out of the range because of the instabilities. - Vectorized computations which produce plenty of good numbers and sometimes diverge, do not invalidate all work. - Ignoring Int overflow is a cheap way of having `mod` (MAXINT+1). Useful for many purposes. - In such vector/matrix packages as Matlab, where arrays may represent geometric objects, NaNs mean: "no coordinates here, empty". Simple and useful. etc. So, don't "sanitize" anything, unless you know what you are really doing! I would suggest to Wolfgang Jeltsch a little more of reserve before making sharp categorical proposals concerning the fl. point computations (and also acknowledge that NaN is not a unique entity). It is easy to propose - in the name of "purity" to massacre existing structures; several religious sects and political doctrines were born in such a way. The result was usually horrible... The Num hierarchy in Haskell is bad, we know it, especially for people who do some more formal mathematics. There are more interesting problems to solve than organising a crusade against IEEE, "illegalizing" the Ord instance for numbers, etc. Jerzy Karczmarczuk From cristi at ot.onrc.ro Fri Jan 11 07:37:40 2008 From: cristi at ot.onrc.ro (Cristian Baboi) Date: Fri Jan 11 07:31:08 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <200801111027.44693.g9ks157k@acme.softbase.org> <87fxx4slcy.fsf@nmd9999.imr.no> Message-ID: On Fri, 11 Jan 2008 14:21:45 +0200, wrote: > Ketil Malde: >> Wolfgang Jeltsch: >>> However, the fact that (0 / 0) == (0 / 0) yields False is quite >>> shocking. >>> It doesn?t adhere to any meaningful axiom set for Eq. >> >> Tough luck, but that's how floating point works, and what the >> numericalists know, and possibly even love (although I have my >> doubts). Sanitizing this behavior would make Haskell less usable for >> real-world numerical problems. >> >> As a compromise, what about an option to make NaN (and presumably the >> infinities) cause an immediate exception? (And, cetero censeo, >> exceptions for Int overflow as well.) > > People, you are monsters. > First, despite the *common, well known* truth that Haskell is not > Mathematics, this illusion seems to be extremely persistent! Haskell is > a victim - > no, some users are victims of its success as a formal language, not just > as a coding tool... They *want* to have Eq as they imagine the equality, > including the comparison between incomparable. This is BTW a long > standing > philosophical problem. For centuries some speculative guys tried to > analyse > such "assertions" as God == God, or death==death. Or myself==myself. > Of course, even if they produced some cute conclusions, they had no > whatsoever sense for the others. Now we have the modern variants of it: > NaN == NaN, bottom == bottom ... Well, Haskell has this "referential transparency" thing which say that a function is a function and you will never be able to build anything else :-) ________ Information from NOD32 ________ This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com From ketil+haskell at ii.uib.no Fri Jan 11 07:54:59 2008 From: ketil+haskell at ii.uib.no (Ketil Malde) Date: Fri Jan 11 07:48:40 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: (jerzy karczmarczuk's message of "Fri\, 11 Jan 2008 13\:21\:45 +0100") References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <200801111027.44693.g9ks157k@acme.softbase.org> <87fxx4slcy.fsf@nmd9999.imr.no> Message-ID: <8763y0sesc.fsf@nmd9999.imr.no> jerzy.karczmarczuk@info.unicaen.fr writes: > People, you are monsters. Well, bring on the torches and the pitchforks (although the image in my mind is more like a mob carrying lenses and bananas). > no, some users are victims of its success as a formal language, not > just as a coding tool I think Haskell's theoretical basis is part of its success as a coding tool. > ... They *want* to have Eq as they imagine the equality, > including the comparison between incomparable. In an ideal world, yes, but I think the monster to which you respond was fairly clear on being 'practical' here? > The bombing of NaN *might* be a profound compilation option, but for > people who really do numerical work, this is a blessing NOT to have > it. I don't understand this. Are you worried users will edit the language pragmas in your code, and complain about NaN errors? Back when I *was* using the abbreviation FP for 'Floatin Point', I often got NaNs due to programming errors. Given the NaN's nature of contaminating subsequent results, getting an exception at the first occurrence would aid in tracking it down. > - Ignoring Int overflow is a cheap way of having `mod` (MAXINT+1). Useful > for many purposes. ...and ditto for this. The usefulness of one case in no way justifies sabotagin all other cases. I'd wager Ints see wider use in settings where the silent 'mod' is harmful, than where this effect is desired. Again, the current behavior causes errors that are very hard to track down. IMHO, these are two very different types, and I'm sligtly baffled that the fact is not reflected in Haskell. -k -- If I haven't seen further, it is by standing in the footprints of giants From ketil+haskell at ii.uib.no Fri Jan 11 08:10:40 2008 From: ketil+haskell at ii.uib.no (Ketil Malde) Date: Fri Jan 11 08:04:20 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <8763y0sesc.fsf@nmd9999.imr.no> (Ketil Malde's message of "Fri\, 11 Jan 2008 13\:54\:59 +0100") References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <200801111027.44693.g9ks157k@acme.softbase.org> <87fxx4slcy.fsf@nmd9999.imr.no> <8763y0sesc.fsf@nmd9999.imr.no> Message-ID: <87y7awqzhr.fsf@nmd9999.imr.no> Ketil Malde writes: >> The bombing of NaN *might* be a profound compilation option, but for >> people who really do numerical work, this is a blessing NOT to have >> it. I'll expand a bit of this, after I've checked with Wikipedia. Please correct me (and it) if I'm wrong, but: 1) Intel CPUs generate exceptions, not NaNs (unless a NaN is already involved), so NaNs are introduced by choice in the run-time system. 2) IEE754 supports both 'signaling' and 'quiet' NaNs, so it seems the standard is not blessed in this regard. And, in Haskell, I'd consider using NaNs for missing values slightly abusive of the system, this is just a poor man's way of spelling "Maybe Double". -k -- If I haven't seen further, it is by standing in the footprints of giants From barsoap at web.de Fri Jan 11 08:13:52 2008 From: barsoap at web.de (Achim Schneider) Date: Fri Jan 11 08:07:37 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower> <20080110165530.3948df88@solaris.tower> Message-ID: <20080111141352.47b470cb@solaris.tower> Jonathan Cast wrote: > On 10 Jan 2008, at 7:55 AM, Achim Schneider wrote: > > > "Daniel Yokomizo" wrote: > > > >> On Jan 10, 2008 3:36 PM, Achim Schneider wrote: > >>> jerzy.karczmarczuk@info.unicaen.fr wrote: > >>> > >>>> Niko Korhonen writes: > >>>> > >>>> ... > >>>>> Although it could be argued that laziness is the cause of some > >>>>> very obscure bugs... > >>>>> Niko > >>>> > >>>> Example, PLEASE. > >>>> > >>> [1..] == [1..] > >>> > >>> , for assumed operational semantics of ones own axiomatic > >>> semantics. Bugs are only a misunderstanding away. > >> > >> It has nothing to do with laziness, but with using an algebraic > >> function (==) with a codata structure (stream). If Haskell kept > >> laziness but enforced separation of data and codata such code > >> wouldn't > >> compile. Lazy lists or streams never are a problem, but you can't > >> (generically) fold codata. > >> > > Exactly. Denotationally it hasn't, but axiomatically it has. > > Because it > > looks like mathematical terms one can easily get lost in believing > > it reduces like mathematics, too. > > What kind of mathematics? I don't know of any mathematics where > algebraic simplifications are employed without proof of the > underlying equations (in some denotational model). > Mathematics as, as my professor put it, "Solving by staring". -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From jerzy.karczmarczuk at info.unicaen.fr Fri Jan 11 08:49:43 2008 From: jerzy.karczmarczuk at info.unicaen.fr (jerzy.karczmarczuk@info.unicaen.fr) Date: Fri Jan 11 08:43:13 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <200801111027.44693.g9ks157k@acme.softbase.org> <87fxx4slcy.fsf@nmd9999.imr.no> Message-ID: Cristian Baboi writes after my long political speech on numerics: > Well, Haskell has this "referential transparency" thing which say that a > function is a function and you will never be able to build anything else > :-) What do you want to say/claim/suggest/propose/deny?? All these speculations about NaN==NaN, and other disgraceful exceptions don't convey anything which would really break the referential transparency, unless you outlaw yourself. Travesting a US military saying: If 'em things are not comparable, don't! We can formalize this attitude, e.g. by extending/modifying the Num (and the Eq and Ord) classes to take into account the specificity of the non-standard arithmetic, but in general this contains plenty of traps. It will be eventually done, but perhaps not tomorrow... Ketil Malde reacts to: >> The bombing of NaN *might* be a profound compilation option, but for >> people who really do numerical work, this is a blessing NOT to have >> it. > > I don't understand this. Are you worried users will edit the > language pragmas in your code, and complain about NaN errors? I do not worry about anything. I signal that the philosophy of crashing the program as soon as an exceptional number is created (or even used), is not the only one possible. > Back when I *was* using the abbreviation FP for 'Floatin Point', I > often got NaNs due to programming errors. Given the NaN's nature of > contaminating subsequent results, getting an exception at the first > occurrence would aid in tracking it down. > >> - Ignoring Int overflow is a cheap way of having `mod` (MAXINT+1). Useful >> for many purposes. > > ...and ditto for this. The usefulness of one case in no way justifies > sabotagin all other cases. As I said, the exceptional treatment of exceptional values might be a compilation option, as it was in some Fortrans I used long time ago. You want your programs to react histerically to all difficulties in math, since you are afraid of propagating NaNs, etc. And *then* you will have to sit down and correct your code. If there is no exception, your program may run happily, and produce rubbish, yes? I am more conservative. If you are afraid of rubbish, protect your code by appropriate checks *before* the errors occur. What you call a "sabotage" I call the programmers negligence. You say that the usage of NaN as "empty" is a <>. I presume you want to say "Nothing". In a sense yes, but not "poor man". It is a way of admitting that we have a hidden extended type, Nums, and other stuff, such as NaNs and infinities. Floating-point numbers seem not to be a *one* pure, primitive type, but a variant one. The problem is that this new type values may come out of computations on normal values, so the static type system of Haskell *in its actual shape* seems to be a bit too weak. Instead of making a mess with the existing structures, please, propose a non-standard Num class, and the appropriate instancing, which distinguish between normal, and anormal numbers. Be free to bomb, or to react silently to exceptional values. The difference between you (and/or Wolfgang J.) and myself is that I enjoy more my freedom, even if I have to pay with a little more work. You want to enforce rigid reactions of the system. You should be free to do it on *your* machine, not on mine. Jerzy Karczmarczuk From rl at cse.unsw.edu.au Fri Jan 11 08:52:59 2008 From: rl at cse.unsw.edu.au (Roman Leshchinskiy) Date: Fri Jan 11 08:46:36 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <200801111241.29253.g9ks157k@acme.softbase.org> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <200801111027.44693.g9ks157k@acme.softbase.org> <87fxx4slcy.fsf@nmd9999.imr.no> <200801111241.29253.g9ks157k@acme.softbase.org> Message-ID: <478774BB.6030305@cse.unsw.edu.au> Wolfgang Jeltsch wrote: > Am Freitag, 11. Januar 2008 11:33 schrieben Sie: >> Wolfgang Jeltsch writes: >>> However, the fact that (0 / 0) == (0 / 0) yields False is quite shocking. >>> It doesn?t adhere to any meaningful axiom set for Eq. >> Tough luck, but that's how floating point works, and what the >> numericalists know, and possibly even love (although I have my >> doubts). Sanitizing this behavior would make Haskell less usable for >> real-world numerical problems. > > The IEEE floating point equivalence test has to yield false when comparing NaN > with NaN. Haskell?s (==) has to yield True or undefined when comparing a > value with itself. So Haskell?s (==) just has to be different from the IEEE > floating point equivalence test. What about providing a separate function > for the latter? I wonder where the requirement on (==) you mention above is specified. I can't find it in the report but maybe I just overlooked it. OTOH, the report does say: "The Ord class is used for totally ordered datatypes". IEEE comparisons are not a total ordering so in principle, they can't be used in the Ord methods. Also, comparing IEEE-like numbers for equality is practically always a mistake (the cases where it isn't are exceedingly rare) so the Eq instance for Float and Double doesn't actually provide any meaningful functionality. Anyway, having "correct" but inefficient implementations of Eq and Ord method for floating-point numbers sounds like a good idea to me, provided that the fast comparisons are still available. Personally, I'd be fine with not having those instances at all but that's just me, I guess. >> As a compromise, what about an option to make NaN (and presumably the >> infinities) cause an immediate exception? (And, cetero censeo, >> exceptions for Int overflow as well.) > > This would be far better (and far more Haskell-like). No, it would be far more Haskell-like not to use Float and Double (nor Int, for that matter) for things they shouldn't be used for. If all you want are fractions use Rational. Float and Double are (or should be) only for high-performance computations and people implementing those ought to know what they are doing. If they don't, they'll have much bigger problems than NaNs not being equal to themselves. BTW, some algorithms depend on silent NaNs and many depend on infinity. As an aside, I'd recommend http://citeseer.ist.psu.edu/goldberg91what.html as an introduction to some of the problems with floating point. The paper also talks about some uses for silent NaNs. Roman From barsoap at web.de Fri Jan 11 08:54:20 2008 From: barsoap at web.de (Achim Schneider) Date: Fri Jan 11 08:48:04 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False References: <2608b8a80801100117wda28551ida0166f548147aac@mail.gmail.com> <20080110201613.GA30239@momenergy.repetae.net> <20080110212434.07e18eb8@solaris.tower> <20080110202724.GO28763@darcs.net> <20080110214153.46ad3395@solaris.tower> <20080110205220.GR28763@darcs.net> <20080110220408.47186b19@solaris.tower> <87k5mgsm31.fsf@nmd9999.imr.no> Message-ID: <20080111145420.1c82c377@solaris.tower> Ketil Malde wrote: > Achim Schneider writes: > > >> You need to use the / operator, if you want to do floating-point > >> division. > > > Yes, exactly, integers don't have +-0 and +-infinity... only > > (obviously) a kind of nan. > > No, failure (exception, bottom) is different from NaN, which is just > another value in the domain - admittedly one which behaves rather > strangely. > s/a kind of/not entirely unlike a/ > > Said differently: I don't know a thing about floats or numerics. > > Perhaps it helps to think of floating point values as intervals? If +0 > means some number between 0 and the next possible representable > number (and similar for -0), it may make more sense to have 1/+0 and > 1/-0 behave differently. > Hmmm... ah. +-0 / +-0 is always NaN 'cos you can't tell which one is bigger and thus can't decide between positive and negative Infinity, and it isn't both, either. But then there's +0/0 and -0/0, which would be +Infinity and -Infinity, and +0 > 0 > -0. AFAIK there are no floats with three zero values, though. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From g9ks157k at acme.softbase.org Fri Jan 11 08:56:05 2008 From: g9ks157k at acme.softbase.org (Wolfgang Jeltsch) Date: Fri Jan 11 08:50:15 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <87fxx4slcy.fsf@nmd9999.imr.no> Message-ID: <200801111456.05819.g9ks157k@acme.softbase.org> Am Freitag, 11. Januar 2008 13:21 schrieb jerzy.karczmarczuk@info.unicaen.fr: > Ketil Malde: > > Wolfgang Jeltsch: > >> However, the fact that (0 / 0) == (0 / 0) yields False is quite > >> shocking. It doesn?t adhere to any meaningful axiom set for Eq. > > > > Tough luck, but that's how floating point works, and what the > > numericalists know, and possibly even love (although I have my > > doubts). Sanitizing this behavior would make Haskell less usable for > > real-world numerical problems. > > > > As a compromise, what about an option to make NaN (and presumably the > > infinities) cause an immediate exception? (And, cetero censeo, > > exceptions for Int overflow as well.) > > People, you are monsters. > First, despite the *common, well known* truth that Haskell is not > Mathematics, this illusion seems to be extremely persistent! Haskell is > a victim - I was arguing from a software technology point of view: if (==) yields false when comparing a value with itself, this can break code (like a set implementation) which relies on certain guarantees. The fact that Haskell allows to define (==) rather arbitrarily doesn?t mean that the use of arbitrary definitions of (==) is what we want. It?s just that the language is to weak to express axioms. My impression is that staying close to math is good from a software technology point of view. And it has the advantage of less confusion for the user. > [?] > Then, I see here, and on some other lists some tendency to speculate on the > numerics by people who really don't need it, and don't use it. Even if I don?t use numerics, I do care about the Haskell language as a whole. > [?] > I would suggest to Wolfgang Jeltsch a little more of reserve before making > sharp categorical proposals concerning the fl. point computations (and > also acknowledge that NaN is not a unique entity). It is easy to propose - > in the name of "purity" to massacre existing structures; several religious > sects and political doctrines were born in such a way. The result was > usually horrible... I don?t see what?s so extreme about suggesting that IEEE floating point comparison should maybe be a seperate operator. And I think, it is really inappropriate to compare this to horrible sects and doctrines. Do you really want to argue that someone who insists on a rather clean language is dangerous? Than more or less everyone on this list would be dangerous?from a C programmer?s point of view. > The Num hierarchy in Haskell is bad, we know it, especially for people who > do some more formal mathematics. There are more interesting problems to > solve than organising a crusade against IEEE, "illegalizing" the Ord > instance for numbers, etc. Please don?t suggest that ?illegalizing? some Ord instance is similar to killing people out of religious motives. > Jerzy Karczmarczuk Best wishes, Wolfgang From barsoap at web.de Fri Jan 11 08:59:50 2008 From: barsoap at web.de (Achim Schneider) Date: Fri Jan 11 08:53:29 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower> <20080110185659.4d7117ff@solaris.tower> Message-ID: <20080111145950.1cbaeb81@solaris.tower> "Cristian Baboi" wrote: > On Fri, 11 Jan 2008 09:11:52 +0200, Lennart Augustsson > wrote: > > > Some people seem to think that == is an equality predicate. > > This is a big source of confusion for them; until they realize that > > == is just another function returning Bool they will make claims > > like [1..]==[1..] > > having an unnatural result. > > The == function is only vaguely related to the equality predicate > > in that it > > is meant to be a computable approximation of semantic equality (but > > since it's overloaded it can be anything, of course). > > > > >> So let's imagine: > >> > >> ones = 1 : ones > >> > >> ones' = repeat 1 > >> where repeat n = n : repeat n > > (==) :: Eq a => a -> a -> Bool > > -- what is (y (y) ) by the way ? > -- how about ( y id ) ? > > y f = f (y f). > > ones :: Num a => [a] > ones = y (1 :) > > repeat :: a -> [a] > repeat = \n -> y (n:) > > ones' :: Num a => [a] > ones' = repeat 1 = (\n->y(n:)) 1 = y (1 : ) > > To be able to test them for equality, we must have Eq a. > > So, the reason we cannot test them for equality is that we cannot > test y (a : ) == y (a : ) where a == a is testable. > Yes, thanks. I actually do think that many things would be easier if every recursion would be translated to its fixpoint, making the term tree completely finite and defining y internal, as it's arcane, black magic. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From cristi at ot.onrc.ro Fri Jan 11 09:04:55 2008 From: cristi at ot.onrc.ro (Cristian Baboi) Date: Fri Jan 11 08:58:40 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <20080111145950.1cbaeb81@solaris.tower> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower> <20080110185659.4d7117ff@solaris.tower> <20080111145950.1cbaeb81@solaris.tower> Message-ID: The thing is that y already is a *builtin* function in Haskell. On Fri, 11 Jan 2008 15:59:50 +0200, Achim Schneider wrote: > "Cristian Baboi" wrote: >> >> >> So let's imagine: >> >> >> >> ones = 1 : ones >> >> >> >> ones' = repeat 1 >> >> where repeat n = n : repeat n >> >> (==) :: Eq a => a -> a -> Bool >> >> -- what is (y (y) ) by the way ? >> -- how about ( y id ) ? >> >> y f = f (y f). >> >> ones :: Num a => [a] >> ones = y (1 :) >> >> repeat :: a -> [a] >> repeat = \n -> y (n:) >> >> ones' :: Num a => [a] >> ones' = repeat 1 = (\n->y(n:)) 1 = y (1 : ) >> >> To be able to test them for equality, we must have Eq a. >> >> So, the reason we cannot test them for equality is that we cannot >> test y (a : ) == y (a : ) where a == a is testable. >> > Yes, thanks. I actually do think that many things would be easier if > every recursion would be translated to its fixpoint, making the term > tree completely finite and defining y internal, as it's arcane, black > magic. > ________ Information from NOD32 ________ This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com From niko.korhonen at gmail.com Fri Jan 11 09:22:34 2008 From: niko.korhonen at gmail.com (Niko Korhonen) Date: Fri Jan 11 09:16:12 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> Message-ID: jerzy.karczmarczuk@info.unicaen.fr wrote: > Niko Korhonen writes: > ... >> Although it could be argued that laziness is the cause of some very >> obscure bugs... Niko > > Example, PLEASE. > Jerzy Karczmarczuk Write any piece of code that processes data from hard disk in a non-trivial manner, uses buffering with IOUArray or does pretty much anything IO heavy. You're bound to hit into a few laziness-related stack/heap overflows before you get it right. Sometimes finding the space leak can be really, really hard and causes the amount of strictness annotations in your code to explode. Hence the notion that the art of optimizing Haskell programs is akin to black magic and is fully understood only by a handful of some of the best minds in the universe. For some concrete examples see my posts on randomR and IOUArray on this newsgroup. Niko From monnier at iro.umontreal.ca Fri Jan 11 09:24:23 2008 From: monnier at iro.umontreal.ca (Stefan Monnier) Date: Fri Jan 11 09:17:54 2008 Subject: [Haskell-cafe] Haskell-mode 2.4 In-Reply-To: <90889fe70801110043n7f47fc2eo69208b73c1db527c@mail.gmail.com> (Johan Tibell's message of "Fri, 11 Jan 2008 09:43:52 +0100") References: <90889fe70801081337q5521f3e5yd49a2435d2d96ed2@mail.gmail.com> <90889fe70801100932m15c1e08ey90c7a04578a35d54@mail.gmail.com> <90889fe70801101945j6371d7bal4ee45f4eca7dc617@mail.gmail.com> <90889fe70801110043n7f47fc2eo69208b73c1db527c@mail.gmail.com> Message-ID: >>>>> "Johan" == Johan Tibell writes: >> > Emacs is completely frozen until I press C-g and then it goes back to >> > normal (without loading the file). Here's the back trace: >> >> > Debugger entered--Lisp error: (quit) >> > accept-process-output(#) >> > (and (not (re-search-forward comint-prompt-regexp nil t)) >> > (accept-process-output proc)) >> >> So it seems to be waiting for the prompt but can't find it. >> If you look at the buffer containing the interactive process, is there >> a prompt there? If not, can you try and figure out why not? >> If yes, can you try and figure out why it is not recognized by the >> comint-prompt-regexp? > I had the following in my .ghci to make GHCi's prompt less verbose: > :set prompt "> " > Removing that solves the problem. You can also add the following to your .emacs: (add-hook 'inferior-haskell-mode-hook (lambda () (set (make-local-variable 'comint-prompt-regexp) "^> "))) Or some fancier regexp (the default is "^\\*?[A-Z][\\._a-zA-Z0-9]*\\( \\*?[A-Z][\\._a-zA-Z0-9]*\\)*> "). Stefan From ketil+haskell at ii.uib.no Fri Jan 11 09:43:04 2008 From: ketil+haskell at ii.uib.no (Ketil Malde) Date: Fri Jan 11 09:36:45 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: (jerzy karczmarczuk's message of "Fri\, 11 Jan 2008 14\:49\:43 +0100") References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <200801111027.44693.g9ks157k@acme.softbase.org> <87fxx4slcy.fsf@nmd9999.imr.no> Message-ID: <87fxx4qv7r.fsf@nmd9999.imr.no> jerzy.karczmarczuk@info.unicaen.fr writes: > The difference between you (and/or Wolfgang J.) and myself is that I enjoy > more my freedom, even if I have to pay with a little more work. You want > to enforce rigid reactions of the system. You should be free to do it on > *your* machine, not on mine. You are putting words in my mouth! I do not want to enforce rigid reactions on the system, I want the option to enforce them on my programs. > As I said, the exceptional treatment of exceptional values might be > a compilation option, as it was in some Fortrans I used long time ago. *I* proposed a compile-time option, *you* responded that it is a "blessing NOT to have it". > You want your programs to react histerically to all difficulties in > math, since you are afraid of propagating NaNs, etc. If you consider halting execution to be a hysterical reaction, arithmetic errors to be all difficulties in math, and wishing for accurate error messages to be afraid, I guess the answer is 'yes'. > And *then* you will have to sit down and correct your code. If there > is no exception, your program may run happily, and produce rubbish, yes? Yes. > I am more conservative. If you are afraid of rubbish, protect your code > by appropriate checks *before* the errors occur. I've written a bit of checking code in my time. The problem is that you quickly end up with more checking code than 'real' code, that the checking code paths are rarely used, and thus even more bug prone than the rest of the code, and that usually, there is little you can sensibly do other than halt execution anyway. The nice thing about checking for integer overflow and arithmetic exception is that they can be added with no cost in code size or complexity, and (at least on some architectures) no cost in performance - perhaps even improvements, for signaling NaNs. My Haskell programs tend to be rather Spartan, and I think this makes them more readable, and thus more likely to actually be correct. > What you call a "sabotage" I.e. the insistence on wrap-around Ints (a minority use case!) and quiet NaNs as the One True Way, disallowing all other approaches. > I call the programmers negligence. I'll pleade guilty to the charge of being negiligent and not checking intermediate results for errors and overflows. But the only reason for using Int (and not Integer) and arguably floating point, is performance. Wrapping everything in checks will be laborious, and I am fairly certain that performance will suffer by magnitudes. So yes, I am lazy, I use Int and cross my fingers. (I'm not alone; I've read a fair bit of Haskell code (starting with the Prelude), I must just have been unfortunate to miss all the code written by the industrious and serious people who actually check their Int operations...) -k -- If I haven't seen further, it is by standing in the footprints of giants From lrpalmer at gmail.com Fri Jan 11 10:06:19 2008 From: lrpalmer at gmail.com (Luke Palmer) Date: Fri Jan 11 09:59:48 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <200801111027.44693.g9ks157k@acme.softbase.org> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <200801111027.44693.g9ks157k@acme.softbase.org> Message-ID: <7ca3f0160801110706j64d48db0yf983e8acd0f87aa1@mail.gmail.com> On Jan 11, 2008 9:27 AM, Wolfgang Jeltsch wrote: > However, the fact that (0 / 0) == (0 / 0) yields False is quite shocking. It > doesn't adhere to any meaningful axiom set for Eq. So I think that this > behavior should be changed. Think of a set implementation which uses (==) to > compare set elements for equality. The NaN behavior would break this > implementation since it would allow for sets which contain NaN multiple > times. Here's another thing that makes me want to throw up. Prelude> let nan :: Double = 0/0 Prelude> compare nan nan GT Prelude> nan > nan False Luke From lennart at augustsson.net Fri Jan 11 10:11:53 2008 From: lennart at augustsson.net (Lennart Augustsson) Date: Fri Jan 11 10:05:23 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <200801111027.44693.g9ks157k@acme.softbase.org> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <200801111027.44693.g9ks157k@acme.softbase.org> Message-ID: If you talk to anyone who uses floating point numbers for real they would find (0/0)==(0/0) perfectly natural. It disobeys some axioms that Eq instances don't fulfill anyway, but changing it would make a lot of people surprised too. In general, the floating point instances break almost all axioms that you might think exist for numbers. -- Lennart On Jan 11, 2008 1:27 AM, Wolfgang Jeltsch wrote: > Am Freitag, 11. Januar 2008 08:11 schrieb Lennart Augustsson: > > Some people seem to think that == is an equality predicate. > > This is a big source of confusion for them; until they realize that == > is > > just another function returning Bool they will make claims like > > [1..]==[1..] having an unnatural result. > > > > The == function is only vaguely related to the equality predicate in > that > > it is meant to be a computable approximation of semantic equality (but > > since it's overloaded it can be anything, of course). > > > > -- Lennart > > But class methods are expected to fulfill some axioms. I'd suppose that > (==) > should be an equivalence relation. Of course, this is not implementable > because of infininte data structures. But one could relax the axioms such > that it's allowed for (==) to return _|_ instead of the expected value. > Differentiating between data and codata would of course be the better > solution. > > However, the fact that (0 / 0) == (0 / 0) yields False is quite shocking. > It > doesn't adhere to any meaningful axiom set for Eq. So I think that this > behavior should be changed. Think of a set implementation which uses (==) > to > compare set elements for equality. The NaN behavior would break this > implementation since it would allow for sets which contain NaN multiple > times. > > Best wishes, > Wolfgang > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080111/f55ba20b/attachment.htm From lennart at augustsson.net Fri Jan 11 10:17:12 2008 From: lennart at augustsson.net (Lennart Augustsson) Date: Fri Jan 11 10:10:44 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <200801111236.14073.g9ks157k@acme.softbase.org> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <210051200044875@webmail25.yandex.ru> <200801111236.14073.g9ks157k@acme.softbase.org> Message-ID: If you can't stomach the weirdness of floating point then perhaps you should try to define your own type that obeys all the expected laws? :) On Jan 11, 2008 3:36 AM, Wolfgang Jeltsch wrote: > Am Freitag, 11. Januar 2008 11:03 schrieb Felipe Lessa: > > Another thing for the record: Goldberg says > > > > "The introduction of NaNs can be confusing, because a NaN is never > > equal to any other number (including another NaN), so x = x is no > > longer always true. In fact, the expression x /= x is the simplest way > > to test for a NaN if the IEEE recommended function Isnan is not > > provided. Furthermore, NaNs are unordered with respect to all other > > numbers, so x <= y cannot be defined as not x > y. Since the > > introduction of NaNs causes floating-point numbers to become partially > > ordered, a compare function that returns one of <, =, >, or unordered > > can make it easier for the programmer to deal with comparisons." > > > > Goldberg, David. What Every Computer Scientist Should Know About > > Floating-Point Arithmetic. > > http://docs.sun.com/source/806-3568/ncg_goldberg.html . > > > > As GNU is not Unix, NaN is not a number, so what is standard about > > numbers doesn't work for them. I don't think there's a compeling > > reason about changing this behavior, specially because it's what's > > specified in the IEEE 754. > > There is a really compelling reason: If the order on floating point > numbers is > partial then there is no meaningful Ord instance for them. > > And what do Hugs and GHCi say? Their answers are plain horror: > > Hugs, version 20050308: > > compare (0 / 0) (0 / 0) => EQ > > 0 / 0 == 0 / 0 => False > > GHCi 6.8.2: > > compare (0 / 0) (0 / 0) => GT > > 0 / 0 > 0 / 0 => False > > Anyone interested in filing bug reports? > > > [?] > > Best wishes, > Wolfgang > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080111/50a0d113/attachment-0001.htm From lennart at augustsson.net Fri Jan 11 10:25:55 2008 From: lennart at augustsson.net (Lennart Augustsson) Date: Fri Jan 11 10:19:25 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <20080111145950.1cbaeb81@solaris.tower> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower> <20080110185659.4d7117ff@solaris.tower> <20080111145950.1cbaeb81@solaris.tower> Message-ID: That would give you a language with a semantics I don't want to touch. Sometimes useful, yes, but far to intensional for my taste. -- Lennart On Jan 11, 2008 5:59 AM, Achim Schneider wrote: > > Yes, thanks. I actually do think that many things would be easier if > every recursion would be translated to its fixpoint, making the term > tree completely finite and defining y internal, as it's arcane, black > magic. > > -- > (c) this sig last receiving data processing entity. Inspect headers for > past copyright information. All rights reserved. Unauthorised copying, > hiring, renting, public performance and/or broadcasting of this > signature prohibited. > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080111/8cf76918/attachment.htm From andre at digirati.com.br Fri Jan 11 10:27:33 2008 From: andre at digirati.com.br (Andre Nathan) Date: Fri Jan 11 10:20:08 2008 Subject: [Haskell-cafe] Comments and suggestions on code In-Reply-To: <7FF4DBDE-202A-43BC-A084-2D2E816EC3C9@fastmail.fm> References: <1199937429.8936.33.camel@homesick> <6C68D342-F1B3-4333-8D7E-83E21E1FDB57@fastmail.fm> <1199989288.5309.12.camel@homesick> <7FF4DBDE-202A-43BC-A084-2D2E816EC3C9@fastmail.fm> Message-ID: <1200065253.5415.6.camel@homesick> On Thu, 2008-01-10 at 20:37 -0800, Jonathan Cast wrote: > It might be faster; laziness usually has higher constants than direct > implementations. But I doubt the difference is critical in this > case, and I would definitely time a re-writing and throw it away > unless it was significantly faster. But I don't think this is a case > where laziness actually alters either the time or the space > asymptotics of the algorithm (you end up creating an ~ O(n) tree > anyway, so I'd figure O(n) space was OK for the loop, too). I was wondering if laziness would make it run as if it was a single O(n) operation (get one directory entry "on demand", pass it to filter and then to insertInTree), because only one entry is used at a time, so that only the "current" entry needs to be evaluated. I still find it hard to evaluate the effects of laziness on the complexity of programs... Andre From niko.korhonen at gmail.com Fri Jan 11 11:35:58 2008 From: niko.korhonen at gmail.com (Niko Korhonen) Date: Fri Jan 11 11:29:35 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> Message-ID: Actually, here's a better example: Prelude> foldl (+) 0 [1..1000000] *** Exception: stack overflow Prelude Data.List> foldl' (+) 0 [1..1000000] 500000500000 The explanation to what happens here is trivial to Haskell gurus but completely baffling to newbies. It is difficult to explain to someone why the first example doesn't work, although at a glance it should. The virtue of laziness is that allows constructs like [1..1000000], but the downside is that it can bite you on the backside when you least expect it. Niko From Nicholls.Mark at mtvne.com Fri Jan 11 11:42:02 2008 From: Nicholls.Mark at mtvne.com (Nicholls, Mark) Date: Fri Jan 11 11:42:33 2008 Subject: [Haskell-cafe] type questions again.... In-Reply-To: References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower><20080110185659.4d7117ff@solaris.tower><20080111145950.1cbaeb81@solaris.tower> Message-ID: Can someone explain (in simple terms) what is meant by existential and universal types. Preferably illustrating it in terms of logic rather than lambda calculus. There's plenty of stuff out there on it....but most of it seems double dutch (no offense to the dutch intended). -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080111/f1e94534/attachment.htm From r.kelsall at millstream.com Fri Jan 11 11:49:05 2008 From: r.kelsall at millstream.com (Richard Kelsall) Date: Fri Jan 11 11:42:44 2008 Subject: [Haskell-cafe] Re: Not to load Prelude In-Reply-To: References: Message-ID: <47879E01.6050201@millstream.com> Maur??cio wrote: > >> Is it possible not to load Prelude (...) > > >(...) NoImplicitPrelude is more aggressive > > than 'import Prelude()'. You will have to > > look elsewhere for a better explanation of > > the difference. > > I tried google and ghc homepage, but could > not find ?elsewhere? :) Can you give me a > link or somewhere to start from? I often find it easier, rather than doing a full Google search, to start with a "Search haskell.org" on the front page here http://haskell.org/ This is a Google site search of *.haskell.org/* But ignore the type-in search box and button at the top of the front page - they don't work properly. Richard. From ithika at gmail.com Fri Jan 11 11:54:50 2008 From: ithika at gmail.com (Dougal Stanton) Date: Fri Jan 11 11:48:19 2008 Subject: [Haskell-cafe] type questions again.... In-Reply-To: References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower> <20080110185659.4d7117ff@solaris.tower> <20080111145950.1cbaeb81@solaris.tower> Message-ID: <2d3641330801110854s7c0aa62cid4cb80577c1f2ebf@mail.gmail.com> On 11/01/2008, Nicholls, Mark wrote: > Preferably illustrating it in terms of logic rather than lambda calculus. > > > There's plenty of stuff out there on it?.but most of it seems double dutch > (no offense to the dutch intended). > I think the preferred idiom, considering the notation, is that "it's all Greek to me" ;-) D -- Dougal Stanton dougal@dougalstanton.net // http://www.dougalstanton.net From droundy at darcs.net Fri Jan 11 12:03:36 2008 From: droundy at darcs.net (David Roundy) Date: Fri Jan 11 11:57:05 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False In-Reply-To: <20080111145420.1c82c377@solaris.tower> References: <2608b8a80801100117wda28551ida0166f548147aac@mail.gmail.com> <20080110201613.GA30239@momenergy.repetae.net> <20080110212434.07e18eb8@solaris.tower> <20080110202724.GO28763@darcs.net> <20080110214153.46ad3395@solaris.tower> <20080110205220.GR28763@darcs.net> <20080110220408.47186b19@solaris.tower> <87k5mgsm31.fsf@nmd9999.imr.no> <20080111145420.1c82c377@solaris.tower> Message-ID: <20080111170335.GH27808@darcs.net> On Fri, Jan 11, 2008 at 02:54:20PM +0100, Achim Schneider wrote: > +-0 / +-0 is always NaN 'cos you can't tell which one is bigger and > thus can't decide between positive and negative Infinity, and it > isn't both, either. > > But then there's +0/0 and -0/0, which would be +Infinity and > -Infinity, and +0 > 0 > -0. AFAIK there are no floats with three zero > values, though. No, +0/0 might be 0 or finite instead of +Infinity, so it's a NaN. e.g. consider Prelude> let x=1e-300/1e300 Prelude> x 0.0 Prelude> x/x NaN The "true" answer here is that x/x == 1.0 (not 0 or +Infinity), but there's no way for the computer to know this, so it's NaN. -- David Roundy Department of Physics Oregon State University From lrpalmer at gmail.com Fri Jan 11 12:11:07 2008 From: lrpalmer at gmail.com (Luke Palmer) Date: Fri Jan 11 12:04:35 2008 Subject: [Haskell-cafe] type questions again.... In-Reply-To: References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower> <20080110185659.4d7117ff@solaris.tower> <20080111145950.1cbaeb81@solaris.tower> Message-ID: <7ca3f0160801110911s694b5323k906a203d73ab6cae@mail.gmail.com> 2008/1/11 Nicholls, Mark : > Can someone explain (in simple terms) what is meant by existential and > universal types. > > Preferably illustrating it in terms of logic rather than lambda calculus. Well, I don't know about logic. While they are certainly related to existential and universal types in logic, I don't really see a way to explain them in terms of that. Universal types are easy, you use them every day in Haskell. Take for example id: > id :: a -> a Or better illustrated (using ghc extension): > id :: forall a. a -> a That means that for any type a I pick, I can get a value of type a -> a from id. If you wrap an existential type up in a constructor, not much changes: > newtype ID = ID (forall a. a -> a) ID can hold any value of type forall a. a -> a; i.e. it can hold any value which exhibits the property that it can give me a value of type a -> a for any type a I choose. In this case the only things ID can hold are id and _|_, because id is the only function that has that type. Here's how I might use it: > applyID :: ID -> (Int,String) -> (Int,String) > applyID (ID f) (i,s) = (f i, f s) Note how I can use f, which is a universal type, on both an Int and a String in the same place. You can also put typeclass constraints on universals. Take the universal type forall a. Num a => a -> a. Among functions that have this type are: > add1 :: forall a. Num a => a -> a > add1 x = x + 1 > id' :: forall a. Num a => a -> a > id' = id -- it doesn't have to use the constraint if it doesn't want to Wrapping this up in a constructor: > newtype NUM = NUM (forall a. Num a => a -> a) We can create values: > NUM add1 :: NUM > NUM id :: NUM And use them: > applyNUM :: NUM -> (Int, Double) -> (Int, Double) > applyNUM (NUM f) (i,d) = (f i, f d) Existential types are dual, but you need to use constructors to use them. I'll write them using GADTs, because I think they're a lot clearer that way: data NUM' where NUM' :: Num a => a -> NUM' Look at the type of the constructor NUM'. It has a universal type, meaning whatever type a you pick (as long as it is a Num), you can create a NUM' value with it. So the type contained inside the NUM' constructor is called existential (note that NUM' itself is just a regular ADT; NUM' is not existential). So when you have: > negNUM' :: NUM' -> NUM' > negNUM' (NUM' n) = NUM' (negate n) Here the argument could have been constructed using any numeric type n, so we know very little about it. The only thing we know is that it is of some type a, and that type has a Num instance. So we can perform operations to it which work for any Num type, such as negate, but not things that only work for particular Num types, such as div. > doubleNUM' :: NUM' -> NUM' > doubleNUM' (NUM' n) = NUleM' (n + n) We can add it to itself, but note: > addNUM' :: NUM' -> NUM' -> NUM' > addNUM' (NUM' a) (NUM' b) = NUM (a + b) -- Illegal! We can't add them to each other, because the first argument could have been constructed with, say, a Double and the other with a Rational. But do you see why we're allowed to add it to itself? How about this: > data Variant where > Variant :: a -> Variant This is a type that can be constructed with any value whatsoever. Looks pretty powerful... but it isn't. Why not? Luke From jerzy.karczmarczuk at info.unicaen.fr Fri Jan 11 12:25:09 2008 From: jerzy.karczmarczuk at info.unicaen.fr (jerzy.karczmarczuk@info.unicaen.fr) Date: Fri Jan 11 12:18:39 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <200801111456.05819.g9ks157k@acme.softbase.org> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <87fxx4slcy.fsf@nmd9999.imr.no> <200801111456.05819.g9ks157k@acme.softbase.org> Message-ID: Wolfgang Jeltsch protests (all this is about pathologies of the floating point computations in Haskell, of course...): > Please don?t suggest that ?illegalizing? some Ord instance is similar to > killing people out of religious motives. Did I? Where?? This is silly... I admit that I have over-reacted to Ketil, I didn't notice that he proposed the "bombing reaction" as an *option*, not as the Only True way of dealing with NaNs. I am sorry, although then Ketil seems saying that raising the exception *is* the correct approach, while I think it is not, being too brutal. OK, probably the best for people who learn the language. No good for professionals, and impossible for some library procedures. But *you* seem to have decided that all "weakness" in treating exceptional values is absolutely wrong and sinful. The analogy with religious issues is weak, there is simply a thought pattern of "purists" who want to break the existing imperfections in name of their visions. You demonstrate this kind of absolute thinking through the usage of the clause "as a whole": > Even if I don?t use numerics, I do care about the Haskell language > as a whole. Your name is Legion... But I think that Lennart is right. *DO* something positive. In other terms, instead of destroying an existing church, gather some followers, and make your own. Seriously. No type Double, but something possessing variants: * Float2 (regular) * UnderF (non-normalizable, underflow fl.p.) * PositiveInfinity | NegativeInfinity * NaN Mantissa [where Mantissa is a restricted numerical thingie, their number is the no. of floats between 0.5 and 1] etc. With appropriate arithmetic operators. And if you are unhappy with: blah>blah = False, but: compare blah blah giving GT, please tell what do you think SHOULD be the answer. I say that those operators are being used outside their allowed domain. Any answer is bad. Exception? Maybe... Better: leave it... But anyway, I don't buy this: > if (==) yields false > when comparing a value with itself, this can break code (like a set > implementation) which relies on certain guarantees. In pathological cases you are not allowed really to use the word "itself" as casually as you would like to. I agree that > The fact that Haskell allows to define (==) rather arbitrarily doesn?t > mean that the use of arbitrary definitions of (==) is what we want. The problem of equality/identity of things relies partially in the fact that it is a human construction. The Nature does not "compare things for equality". So, the arbitrariness is unavoidable. > My impression is that staying close to math is good from a software > technology point of view. And it has the advantage of less confusion > for the user. What does it mean "close to math"? How close? Does math raise exceptions upon the division by zero? Does *MATH* answer the question what is: (0/0)==(0/0) ? Nope! David Roundy says ... > Prelude> x/x > NaN > The "true" answer here is that x/x == 1.0 (not 0 or +Infinity), > but there's no way for the computer to know this, so it's NaN. His comment uses not very legally the word "true", even in quotes. Who is to say what the "truth" mean here? We cannot oblige the computer to interpret the division operator as we think, in math terms! Wherever you look, you will see some red lines not to neglect. If the physical processes which implement real arithmetics are far from true real math, trying to purify a programming language to make it more math- oriented serves nobody. Or the Devil... We are discussing simple things, but I have seen already a guy who claimed that all computer logic is inherently wrong because of the G?del's theorem... This is a neverending discussion. > I don?t see what?s so extreme about suggesting that IEEE floating point > comparison should maybe be a seperate operator. You were more picky than that. Here, I would only repeat that this - for me - is not just a question of operators, but of the *type* of numbers. > And I think, it is really > inappropriate to compare this to horrible sects and doctrines. Ugh... Again. Sorry if you took it personally. But a doctrine is just that, a system which is meant to be autoritative, and if applied, then without discussion. Usually based on personal visions of one or a few people. It doesn't need to be negative nor horrible, although often is. http://en.wikipedia.org/wiki/Doctrine I mentioned a particular variant of doctrinal thinking: the *purification* of existing. It doesn't need to be dangerous, but often is... ==== An anecdote. At the time of Konrad Duden (Vater der deutschen Rechtschreibung, 1829?1911 as you probably know much better than I...) there was a tendency to "purify" the German language, full of foreign words, roots, forms, etc. There is a story of one of such words, the shortwriting: "stenography". Stenografie. Who needs Greek? And a good Germanic word has been proposed: Kurzschrift. Yes! Please - (if you are not German, they don't need to do that) - repeat a few times: Kurzschrift, Kurzschrift, Kurzschrift, Kurzschrift ... You will hear the Walkyrien galloping through the skies, the huge shadow of Siegfried or some other Lohengrin will lie over the murky fields, etc. *absolutely* Germanic! But... This word comes from "curtus", "short" in Latin, and the verb "scribere", "scriptus", Latin again... In such a way, German purists translated Greek into Latin. This is the story, I hope nobody will shout that I have something against a particular European nation; I know this story from a decent Berliner, who told me it while eating a Hamburger. Or, perhaps it was vice-versa. Too much beer... Jerzy Karczmarczuk From Nicholls.Mark at mtvne.com Fri Jan 11 12:47:20 2008 From: Nicholls.Mark at mtvne.com (Nicholls, Mark) Date: Fri Jan 11 12:40:51 2008 Subject: [Haskell-cafe] type questions again.... In-Reply-To: <7ca3f0160801110911s694b5323k906a203d73ab6cae@mail.gmail.com> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower> <20080110185659.4d7117ff@solaris.tower> <20080111145950.1cbaeb81@solaris.tower> <7ca3f0160801110911s694b5323k906a203d73ab6cae@mail.gmail.com> Message-ID: > -----Original Message----- > From: Luke Palmer [mailto:lrpalmer@gmail.com] > Sent: 11 January 2008 17:11 > To: Nicholls, Mark > Cc: haskell-cafe@haskell.org > Subject: Re: [Haskell-cafe] type questions again.... > > 2008/1/11 Nicholls, Mark : > > Can someone explain (in simple terms) what is meant by existential and > > universal types. > > > > Preferably illustrating it in terms of logic rather than lambda > calculus. > > Well, I don't know about logic. While they are certainly related to > existential and universal types in logic, I don't really see a way to > explain them in terms of that. > > Universal types are easy, you use them every day in Haskell. Take for > example id: > > > id :: a -> a > > Or better illustrated (using ghc extension): > > > id :: forall a. a -> a > > That means that for any type a I pick, I can get a value of type a -> > a from id. Yep....it's universal because forall types a. > If you wrap an existential type up in a constructor, not > much changes: If you wrap a what?....should this read existential or universal? > > > newtype ID = ID (forall a. a -> a) > > ID can hold any value of type forall a. a -> a; i.e. it can hold any > value which exhibits the property that it can give me a value of type > a -> a for any type a I choose. In this case the only things ID can > hold are id and _|_, because id is the only function that has that > type. Here's how I might use it: It's the only function you've defined the type of.... Id2 :: forall a. a -> a Now it can hold id2? > > > applyID :: ID -> (Int,String) -> (Int,String) > > applyID (ID f) (i,s) = (f i, f s) > > Note how I can use f, which is a universal type, on both an Int and a > String in the same place. Yep. > > You can also put typeclass constraints on universals. Take the > universal type forall a. Num a => a -> a. Among functions that have > this type are: > > > add1 :: forall a. Num a => a -> a > > add1 x = x + 1 > > > id' :: forall a. Num a => a -> a > > id' = id -- it doesn't have to use the constraint if it doesn't want to "it doesn't have to use the constraint if it doesn't want to" ? If id was of type.. Id::forall a. Ord a => a -> a Then I assume it would complain? > > Wrapping this up in a constructor: > > > newtype NUM = NUM (forall a. Num a => a -> a) > > We can create values: > > > NUM add1 :: NUM > > NUM id :: NUM > > And use them: > > > applyNUM :: NUM -> (Int, Double) -> (Int, Double) > > applyNUM (NUM f) (i,d) = (f i, f d) > Yep. > > > Existential types are dual, Dual? (like a dual basis rather than double?) > but you need to use constructors to use > them. I'll write them using GADTs, because I think they're a lot > clearer that way: > > data NUM' where > NUM' :: Num a => a -> NUM' > > Look at the type of the constructor NUM'. It has a universal type, > meaning whatever type a you pick (as long as it is a Num), you can > create a NUM' value with it. yes and then it goes wrong... > So the type contained inside the NUM' > constructor ? > is called existential (note that NUM' itself is just a > regular ADT; NUM' is not existential). > Why existential....see below...I have a guess > So when you have: > > > negNUM' :: NUM' -> NUM' > > negNUM' (NUM' n) = NUM' (negate n) > > Here the argument could have been constructed using any numeric type > n, so we know very little about it. The only thing we know is that it > is of some type a, and that type has a Num instance. I think one of the harrowing things about Haskell is the practice of overloading data constructors with type names....it confuses the hell out of me.... OK so this declaration says that forall x constructed using "NUM' n"...there *exists* a type T s.t. T is a member of type class NUM"... which in term implies that that there exists the function negate... yes? It's existential...because the word "exists" occurred in the above translation. > So we can > perform operations to it which work for any Num type, such as negate, > but not things that only work for particular Num types, such as div. Because the existence of the value implies the existence of a type in the typeclass? > > > doubleNUM' :: NUM' -> NUM' > > doubleNUM' (NUM' n) = NUleM' (n + n) > > We can add it to itself, but note: > > > addNUM' :: NUM' -> NUM' -> NUM' > > addNUM' (NUM' a) (NUM' b) = NUM (a + b) -- Illegal! > > We can't add them to each other, because the first argument could have > been constructed with, say, a Double and the other with a Rational. > > But do you see why we're allowed to add it to itself? We can add it to itself because "+" is of type "a->a->a"... I think.... > > How about this: > > > data Variant where > > Variant :: a -> Variant > > This is a type that can be constructed with any value whatsoever. > Looks pretty powerful... but it isn't. Why not? > Eeek..... Because a could be of any type whatsover?...so how I actually do anything with it? Don't know complete guess really. > Luke From lemming at henning-thielemann.de Fri Jan 11 12:49:38 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Fri Jan 11 12:43:07 2008 Subject: [Haskell-cafe] Field updates in a state monad In-Reply-To: <47863362.3000408@nessie.de> References: <47863362.3000408@nessie.de> Message-ID: On Thu, 10 Jan 2008, Michael Roth wrote: > Hello list, > > still playing with monads and states, I have the following question: > > Given: > > import Control.Monad.State.Lazy > > data MyData = MyData { content :: String } > > foobar :: State MyData String > foobar = do > gets content > > Ok, that looks nice and tidy. But: > > foobar2 :: State MyData () > foobar2 = do > modify $ \x -> x { content = "hello haskell"} > > ...looks not so nice. > > > Exists there a way to write this cleaner without writing countless > "set_xyz" helper functions? http://www.haskell.org/haskellwiki/Record_access From bf3 at telenet.be Fri Jan 11 12:50:02 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Fri Jan 11 12:43:58 2008 Subject: [Haskell-cafe] Gtk2HS and GHC 6.8.2 In-Reply-To: <001301c84591$a5de4180$f19ac480$@be> References: <001301c84591$a5de4180$f19ac480$@be> Message-ID: <4787AC4A.5030708@telenet.be> It seems GHC 6.8.2 fixes a couple of bugs in GHC 6.8.1, so I'm using that one. Gtk2HS does not yet detect my GHC 6.8.2 installation, but I guess it is 100% compatible. Is it possible to get the Gtk2HS installer detect GHC 6.8.2? I?m on Windows. Thanks again, Peter From lrpalmer at gmail.com Fri Jan 11 13:03:02 2008 From: lrpalmer at gmail.com (Luke Palmer) Date: Fri Jan 11 12:56:30 2008 Subject: [Haskell-cafe] type questions again.... In-Reply-To: References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <20080110185659.4d7117ff@solaris.tower> <20080111145950.1cbaeb81@solaris.tower> <7ca3f0160801110911s694b5323k906a203d73ab6cae@mail.gmail.com> Message-ID: <7ca3f0160801111003w74c4f283nf3fe050a3545cbc6@mail.gmail.com> On Jan 11, 2008 5:47 PM, Nicholls, Mark wrote: > > If you wrap an existential type up in a constructor, not > > much changes: > > If you wrap a what?....should this read existential or universal? Whoops, right, universal. > > > newtype ID = ID (forall a. a -> a) > > > > ID can hold any value of type forall a. a -> a; i.e. it can hold any > > value which exhibits the property that it can give me a value of type > > a -> a for any type a I choose. In this case the only things ID can > > hold are id and _|_, because id is the only function that has that > > type. Here's how I might use it: > > It's the only function you've defined the type of.... > > Id2 :: forall a. a -> a > > Now it can hold id2? Well, that's not what I meant, but yes it can hold id2. What I meant was that, in this case, id2 = _|_ or id2 = id, there are no other possibilities. > > > id' :: forall a. Num a => a -> a > > > id' = id -- it doesn't have to use the constraint if it doesn't > want to > > "it doesn't have to use the constraint if it doesn't want to" ? > > If id was of type.. > > Id::forall a. Ord a => a -> a > > Then I assume it would complain? Yes. > > but you need to use constructors to use > > them. I'll write them using GADTs, because I think they're a lot > > clearer that way: > > > > data NUM' where > > NUM' :: Num a => a -> NUM' > > > > Look at the type of the constructor NUM'. It has a universal type, > > meaning whatever type a you pick (as long as it is a Num), you can > > create a NUM' value with it. > > yes > > and then it goes wrong... > > > So the type contained inside the NUM' > > constructor > > ? > > > is called existential (note that NUM' itself is just a > > regular ADT; NUM' is not existential). > > > > Why existential....see below...I have a guess Okay, I was being handwavy here. Explaining this will allow me to clear this up. If you take the non-GADT usage of an existential type: data Foo = forall a. Num a => Foo a That is isomorphic to a type: data Foo = Foo (exists a. Num a => a) Except GHC doesn't support a keyword 'exists', and if it did, it would only be able to be used inside constructors like this (in order for inference to be decidable), so why bother? That's what I meant by "the type inside the constructor", Foo is not existential, (exists a. Num a => a) is. > > So when you have: > > > > > negNUM' :: NUM' -> NUM' > > > negNUM' (NUM' n) = NUM' (negate n) Here n has an existential type, specifically (exists a. Num a => a). > > Here the argument could have been constructed using any numeric type > > n, so we know very little about it. The only thing we know is that it > > is of some type a, and that type has a Num instance. > > I think one of the harrowing things about Haskell is the practice of > overloading data constructors with type names....it confuses the hell > out of me.... Yeah that took a little getting used to for me too. But how am I supposed to come up with enough names if I want to name them differently!? That would require too much creativity... :-) > OK so this declaration says that forall x constructed using "NUM' > n"...there *exists* a type T s.t. T is a member of type class NUM"... (you probably meant type class Num here) > which in term implies that that there exists the function negate... > > yes? Huh, I had never thought of it like that, but yes. I just realized that I think of programming in a way quite different than I think of logic. Maybe I should try to have my brain unify them. > > > doubleNUM' :: NUM' -> NUM' > > > doubleNUM' (NUM' n) = NUleM' (n + n) > > > > We can add it to itself, but note: > > > > > addNUM' :: NUM' -> NUM' -> NUM' > > > addNUM' (NUM' a) (NUM' b) = NUM (a + b) -- Illegal! > > > > We can't add them to each other, because the first argument could have > > been constructed with, say, a Double and the other with a Rational. > > > > But do you see why we're allowed to add it to itself? > > We can add it to itself because "+" is of type "a->a->a"... Yep, so whatever type a n happens to have, it matches both arguments. > > How about this: > > > > > data Variant where > > > Variant :: a -> Variant > > > > This is a type that can be constructed with any value whatsoever. > > Looks pretty powerful... but it isn't. Why not? > > > > Eeek..... > > Because a could be of any type whatsover?...so how I actually do > anything with it? Right. Luke From barsoap at web.de Fri Jan 11 13:12:47 2008 From: barsoap at web.de (Achim Schneider) Date: Fri Jan 11 13:06:29 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False References: <2608b8a80801100117wda28551ida0166f548147aac@mail.gmail.com> <20080110201613.GA30239@momenergy.repetae.net> <20080110212434.07e18eb8@solaris.tower> <20080110202724.GO28763@darcs.net> <20080110214153.46ad3395@solaris.tower> <20080110205220.GR28763@darcs.net> <20080110220408.47186b19@solaris.tower> <87k5mgsm31.fsf@nmd9999.imr.no> <20080111145420.1c82c377@solaris.tower> <20080111170335.GH27808@darcs.net> Message-ID: <20080111191247.55ab360d@solaris.tower> David Roundy wrote: > Prelude> let x=1e-300/1e300 > Prelude> x > 0.0 > Prelude> x/x > NaN > > The "true" answer here is that x/x == 1.0 (not 0 or +Infinity), but > there's no way for the computer to know this, so it's NaN. > Weeeeeeeelllllllll...... math philosophy, Ok. You can't divide something in a way that uses no slices. You just don't cut, if you cut zero times. Which is what you do when you divide by one, mind you, not when you divide by zero. Division by [1..0] equals multiplication by [1..]. You can't get to the end of either spectrum, just axiomatically dodge around the singularities to axiomatically connect the loose ends. There is no true answer here, the question is wrong. And you're using floats where only rationals can tackle the problem. I was wrong in claiming that > > But then there's +0/0 and -0/0, which would be +Infinity and > > -Infinity, and +0 > 0 > -0. AFAIK there are no floats with three > > zero values, though. , both are NaN. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From dons at galois.com Fri Jan 11 13:46:09 2008 From: dons at galois.com (Don Stewart) Date: Fri Jan 11 13:39:45 2008 Subject: [Haskell-cafe] Next PDXFunc Meeting (Portland/Oregon FP Group): Monday, January 14, 7pm, CubeSpace Message-ID: <20080111184609.GA21327@scytale.galois.com> Join us at the next meeting of pdxfunc, the Portland Functional Programming Study Group, on Monday, 14th January, at CubeSpace. ------------------------------------------------------------------------ We'll have presentations, demos and discussions. We welcome programmers interested in all functional languages and our meetings have content for coders of all skill levels. If interested, please also subscribe to our mailing list at http://groups.google.com/group/pdxfunc PRESENTATIONS (1) Justin Bailey: Exploring Haskell's space and time profiling tools A presentation on the space and time profiling tools available for GHC Haskell, featuring slides and interactive demos. Heap profiling tools and methods will be discussed, along with a demonstration of how to use them to detect a space leak. Time profiling tactics will be covered using "cost-centre" annotations to help select candidates for optimization. Recommendations will be given on how to read the "Core" language with an eye for optimization. Justin Bailey (jgbailey@gmail.com) has been programming professionally for 12 years, and is currently a Computer Science master's student at Portland State University. Until 2006, he coded exclusively with object-oriented languages like Java and C#, but then discovered Haskell and hasn't looked back. He's released a Haskell library for building command-line applications called HCL, made contributions to several other Haskell libraries, and continues to hack Haskell every day he can. (2) Iavor Diatchki: Writing parsing combinators with Haskell A presentation on parsing combinators, given as a hands-on demonstration for developing a small library to parse JSON data using Haskell. The entire process will be shown from scratch, starting with defining the concept of JSON values, using pretty-printer combinators to turn values into strings, and finally using parser combinators to turn strings into values. Iavor S. Diatchki is an engineer at Galois Inc., where he uses functional programming for the development of high assurance software. Iavor obtained his PhD degree in 2007. His research focused on various aspect of using functional languages for the development of low-level systems software such as OS kernels. From jeremy.shaw at linspireinc.com Fri Jan 11 15:13:35 2008 From: jeremy.shaw at linspireinc.com (Jeremy Shaw) Date: Fri Jan 11 15:05:51 2008 Subject: [Haskell-cafe] Re: Not to load Prelude In-Reply-To: References: Message-ID: <63y0p1cg.wl%jeremy.shaw@linspireinc.com> At Thu, 10 Jan 2008 22:16:27 -0200, Maur??cio wrote: > I tried google and ghc homepage, but could > not find ?elsewhere? :) Can you give me a > link or somewhere to start from? No. What I meant to say was, I'm not really sure myself, I just know there is a difference and -fno-implicit-prelude is more aggressive. If you do find a clear explaination, I would love to see it. j. From lrpalmer at gmail.com Fri Jan 11 15:26:38 2008 From: lrpalmer at gmail.com (Luke Palmer) Date: Fri Jan 11 15:20:07 2008 Subject: [Haskell-cafe] Re: Not to load Prelude In-Reply-To: <63y0p1cg.wl%jeremy.shaw@linspireinc.com> References: <63y0p1cg.wl%jeremy.shaw@linspireinc.com> Message-ID: <7ca3f0160801111226k2ab7a05ag3aaddbafcc5165db@mail.gmail.com> On Jan 11, 2008 8:13 PM, Jeremy Shaw wrote: > At Thu, 10 Jan 2008 22:16:27 -0200, > Maur??cio wrote: > > > I tried google and ghc homepage, but could > > not find "elsewhere" :) Can you give me a > > link or somewhere to start from? > > No. What I meant to say was, I'm not really sure myself, I just know > there is a difference and -fno-implicit-prelude is more aggressive. I > you do find a clear explaination, I would love to see it. So, when you write the number 3 in Haskell, GHC converts this to essentially (Prelude.fromInteger (3::Integer)) in its internal format. So it doesn't matter if you import Prelude (), Prelude's version of fromInteger still gets called. If you give -fno-implicit-prelude, then this is converted to simply (fromInteger (3::Integer)), without the hard-coded prelude reference. That means you could write your own version of fromInteger that does something different. A common usage for -fno-implicit-prelude (insofar as it is used at all, which is seldom) is to replace the standard Num hierarchy with a saner one, with numeric literals resolving to that one instead. There are a few other hard-coded references to Prelude in the internal format, but I don't remember what they are offhand. -fno-implicit-prelude gets rid of those, too. Luke From lennart at augustsson.net Fri Jan 11 17:19:07 2008 From: lennart at augustsson.net (Lennart Augustsson) Date: Fri Jan 11 17:12:37 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False In-Reply-To: <20080111191247.55ab360d@solaris.tower> References: <20080110212434.07e18eb8@solaris.tower> <20080110202724.GO28763@darcs.net> <20080110214153.46ad3395@solaris.tower> <20080110205220.GR28763@darcs.net> <20080110220408.47186b19@solaris.tower> <87k5mgsm31.fsf@nmd9999.imr.no> <20080111145420.1c82c377@solaris.tower> <20080111170335.GH27808@darcs.net> <20080111191247.55ab360d@solaris.tower> Message-ID: Also, there are only two zeros, +0 and -0 and they compare equal. On Jan 11, 2008 10:12 AM, Achim Schneider wrote: > > > I was wrong in claiming that > > > But then there's +0/0 and -0/0, which would be +Infinity and > > > -Infinity, and +0 > 0 > -0. AFAIK there are no floats with three > > > zero values, though. > , both are NaN. > > > -- > (c) this sig last receiving data processing entity. Inspect headers for > past copyright information. All rights reserved. Unauthorised copying, > hiring, renting, public performance and/or broadcasting of this > signature prohibited. > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080111/262db077/attachment.htm From andre at digirati.com.br Fri Jan 11 17:20:40 2008 From: andre at digirati.com.br (Andre Nathan) Date: Fri Jan 11 17:13:18 2008 Subject: [Haskell-cafe] Comments and suggestions on code In-Reply-To: <1200065253.5415.6.camel@homesick> References: <1199937429.8936.33.camel@homesick> <6C68D342-F1B3-4333-8D7E-83E21E1FDB57@fastmail.fm> <1199989288.5309.12.camel@homesick> <7FF4DBDE-202A-43BC-A084-2D2E816EC3C9@fastmail.fm> <1200065253.5415.6.camel@homesick> Message-ID: <1200090040.6732.15.camel@homesick> On Fri, 2008-01-11 at 13:27 -0200, Andre Nathan wrote: > I was wondering if laziness would make it run as if it was a single O(n) > operation (get one directory entry "on demand", pass it to filter and > then to insertInTree), because only one entry is used at a time, so that > only the "current" entry needs to be evaluated. I did some experiments. This for 1000 reads of the entries of a directory with 10000 entries, checking if they match ^[0-9]+$ and printing those which do (half of them). getDirectoryEntries, filter, mapM_: 65.52s user 6.01s system 87% cpu 1:22.21 total openDirStream, readDirStream: 39.68s user 5.69s system 95% cpu 47.746 total getDirectoryContents, mapM_: 63.40s user 5.96s system 95% cpu 1:12.70 total Both versions which use getDirectoryContents also use much more memory than the one which uses readDirStream (about 8M vs about 2M). Maybe I'm not exploting getDirectoryContents' laziness correctly? I expected the second and third versions to run in about the same time. Andre From andre at digirati.com.br Fri Jan 11 17:24:04 2008 From: andre at digirati.com.br (Andre Nathan) Date: Fri Jan 11 17:16:42 2008 Subject: [Haskell-cafe] Comments and suggestions on code In-Reply-To: <1200090040.6732.15.camel@homesick> References: <1199937429.8936.33.camel@homesick> <6C68D342-F1B3-4333-8D7E-83E21E1FDB57@fastmail.fm> <1199989288.5309.12.camel@homesick> <7FF4DBDE-202A-43BC-A084-2D2E816EC3C9@fastmail.fm> <1200065253.5415.6.camel@homesick> <1200090040.6732.15.camel@homesick> Message-ID: <1200090244.6732.19.camel@homesick> On Fri, 2008-01-11 at 20:20 -0200, Andre Nathan wrote: > Both versions which use getDirectoryContents also use much more memory > than the one which uses readDirStream (about 8M vs about 2M). Maybe I'm > not exploting getDirectoryContents' laziness correctly? I expected the > second and third versions to run in about the same time. Forgot to paste the code... foo :: IO () foo = do entries <- getDirectoryContents "." let procs = filter (=~ "^[0-9]+$") entries mapM_ putStrLn procs processEntry :: DirStream -> IO () processEntry ds = do entry <- readDirStream ds if entry =~ "^[0-9]+$" then do putStrLn entry processEntry ds else if entry == "" then return () else processEntry ds bar :: IO () bar = do ds <- openDirStream "." processEntry ds closeDirStream ds processEntry' :: FilePath -> IO () processEntry' entry = do if entry =~ "^[0-9]+$" then putStrLn entry else return () baz :: IO () baz = do entries <- getDirectoryContents "." mapM_ processEntry' entries main = forM_ [1..1000] $ \_ -> foo {- bar -} {- baz -} From lemming at henning-thielemann.de Fri Jan 11 17:36:14 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Fri Jan 11 17:29:43 2008 Subject: [Haskell-cafe] Re: Not to load Prelude In-Reply-To: <7ca3f0160801111226k2ab7a05ag3aaddbafcc5165db@mail.gmail.com> References: <63y0p1cg.wl%jeremy.shaw@linspireinc.com> <7ca3f0160801111226k2ab7a05ag3aaddbafcc5165db@mail.gmail.com> Message-ID: On Fri, 11 Jan 2008, Luke Palmer wrote: > So, when you write the number 3 in Haskell, GHC converts this to > essentially (Prelude.fromInteger (3::Integer)) in its internal format. > So it doesn't matter if you import Prelude (), Prelude's version of > fromInteger still gets called. If you give -fno-implicit-prelude, > then this is converted to simply (fromInteger (3::Integer)), without > the hard-coded prelude reference. That means you could write your own > version of fromInteger that does something different. A common usage > for -fno-implicit-prelude (insofar as it is used at all, which is > seldom) is to replace the standard Num hierarchy with a saner one, > with numeric literals resolving to that one instead. > > There are a few other hard-coded references to Prelude in the internal > format, but I don't remember what they are offhand. > -fno-implicit-prelude gets rid of those, too. For details, see: http://www.haskell.org/ghc/docs/latest/html/users_guide/ghc-language-features.html I have summarized the answers so far: http://www.haskell.org/haskellwiki/No_import_of_Prelude From vigalchin at gmail.com Fri Jan 11 19:15:52 2008 From: vigalchin at gmail.com (Galchin Vasili) Date: Fri Jan 11 19:09:20 2008 Subject: [Haskell-cafe] where is the FFI glue code for STM? Message-ID: <5ae4f2ba0801111615y403a7732tff64fd4cef0317a4@mail.gmail.com> Hello, I see where the top level code (written in Haskell)for STM. I have found STM.c;however, I can't seem to find the FFI glue code.? Thanks, Vasili -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080111/67c4ea9f/attachment.htm From stefanor at cox.net Fri Jan 11 19:28:19 2008 From: stefanor at cox.net (Stefan O'Rear) Date: Fri Jan 11 19:21:49 2008 Subject: [Haskell-cafe] where is the FFI glue code for STM? In-Reply-To: <5ae4f2ba0801111615y403a7732tff64fd4cef0317a4@mail.gmail.com> References: <5ae4f2ba0801111615y403a7732tff64fd4cef0317a4@mail.gmail.com> Message-ID: <20080112002819.GA3646@localhost.localdomain> On Fri, Jan 11, 2008 at 06:15:52PM -0600, Galchin Vasili wrote: > Hello, > > I see where the top level code (written in Haskell)for STM. I have > found STM.c;however, I can't seem to find the FFI glue code.? > > Thanks, Vasili There isn't any. readTVar# etc are primops. Stefan -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080111/722d221f/attachment.bin From jonathanccast at fastmail.fm Fri Jan 11 22:01:08 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Fri Jan 11 21:54:43 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <20080111141352.47b470cb@solaris.tower> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower> <20080110165530.3948df88@solaris.tower> <20080111141352.47b470cb@solaris.tower> Message-ID: On 11 Jan 2008, at 5:13 AM, Achim Schneider wrote: > Jonathan Cast wrote: >> What kind of mathematics? I don't know of any mathematics where >> algebraic simplifications are employed without proof of the >> underlying equations (in some denotational model). >> > Mathematics as, as my professor put it, "Solving by staring". Professor of what? I would have been flunked for such an approach. jcc From jonathanccast at fastmail.fm Fri Jan 11 22:10:20 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Fri Jan 11 22:03:58 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False In-Reply-To: <20080111191247.55ab360d@solaris.tower> References: <2608b8a80801100117wda28551ida0166f548147aac@mail.gmail.com> <20080110201613.GA30239@momenergy.repetae.net> <20080110212434.07e18eb8@solaris.tower> <20080110202724.GO28763@darcs.net> <20080110214153.46ad3395@solaris.tower> <20080110205220.GR28763@darcs.net> <20080110220408.47186b19@solaris.tower> <87k5mgsm31.fsf@nmd9999.imr.no> <20080111145420.1c82c377@solaris.tower> <20080111170335.GH27808@darcs.net> <20080111191247.55ab360d@solaris.tower> Message-ID: <51AF6510-6CC0-4D8A-94AA-D704CE47510A@fastmail.fm> On 11 Jan 2008, at 10:12 AM, Achim Schneider wrote: > David Roundy wrote: > >> Prelude> let x=1e-300/1e300 >> Prelude> x >> 0.0 >> Prelude> x/x >> NaN >> >> The "true" answer here is that x/x == 1.0 (not 0 or +Infinity), but >> there's no way for the computer to know this, so it's NaN. Didn't catch this the first time around, but: only to a physicist. (I mean no disrespect to the author of darcs, but nevertheless the point stands). Back in the real world, 0 / 0 may be defined arbitrarily, or left undefined. (Defining it breaks the wonderful property that, if lim (xn) = x, lim (yn) = y, and x/y = z, then lim (xn / yn) = z. This is considered a Bad Thing by real mathematicians). In fact, in integration theory 0 * inf = 0 for certain 'multiplications', which gives the lie to 0 / 0. >> > Weeeeeeeelllllllll...... math philosophy, Ok. > > You can't divide something in a way that uses no slices. You just > don't > cut, if you cut zero times. Which is what you do when you divide by > one, mind you, not when you divide by zero. Division by [1..0] equals > multiplication by [1..]. Right. (Although 0 * inf is defined by fiat, as noted above). > You can't get to the end of either spectrum, > just axiomatically dodge around the singularities to axiomatically > connect the loose ends. `Axiomatically' --- you mean by re-defining standard notation like * and / to mean what you need in this case. I think this is a different thing than setting up ZFC so everyone agrees on what a `set' is from henceforth. > There is no true answer here, the question is wrong. Exactly. jcc From jonathanccast at fastmail.fm Fri Jan 11 22:12:16 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Fri Jan 11 22:05:51 2008 Subject: [Haskell-cafe] Comments and suggestions on code In-Reply-To: <1200065253.5415.6.camel@homesick> References: <1199937429.8936.33.camel@homesick> <6C68D342-F1B3-4333-8D7E-83E21E1FDB57@fastmail.fm> <1199989288.5309.12.camel@homesick> <7FF4DBDE-202A-43BC-A084-2D2E816EC3C9@fastmail.fm> <1200065253.5415.6.camel@homesick> Message-ID: On 11 Jan 2008, at 7:27 AM, Andre Nathan wrote: > On Thu, 2008-01-10 at 20:37 -0800, Jonathan Cast wrote: >> It might be faster; laziness usually has higher constants than direct >> implementations. But I doubt the difference is critical in this >> case, and I would definitely time a re-writing and throw it away >> unless it was significantly faster. But I don't think this is a case >> where laziness actually alters either the time or the space >> asymptotics of the algorithm (you end up creating an ~ O(n) tree >> anyway, so I'd figure O(n) space was OK for the loop, too). > > I was wondering if laziness would make it run as if it was a single > O(n) > operation (get one directory entry "on demand", pass it to filter and > then to insertInTree), That should be the evaluation order, yes. I think big-O notation is the wrong notation for this; you get a single loop with three sequenced operations, rather than three sequenced loops, but both are O(n). > because only one entry is used at a time, so that > only the "current" entry needs to be evaluated. > > I still find it hard to evaluate the effects of laziness on the > complexity of programs... jcc From jonathanccast at fastmail.fm Fri Jan 11 22:14:41 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Fri Jan 11 22:08:15 2008 Subject: [Haskell-cafe] Comments and suggestions on code In-Reply-To: <1200090040.6732.15.camel@homesick> References: <1199937429.8936.33.camel@homesick> <6C68D342-F1B3-4333-8D7E-83E21E1FDB57@fastmail.fm> <1199989288.5309.12.camel@homesick> <7FF4DBDE-202A-43BC-A084-2D2E816EC3C9@fastmail.fm> <1200065253.5415.6.camel@homesick> <1200090040.6732.15.camel@homesick> Message-ID: <18891E57-2B9D-4F01-B5EA-DA6DC5E19C1B@fastmail.fm> On 11 Jan 2008, at 2:20 PM, Andre Nathan wrote: > On Fri, 2008-01-11 at 13:27 -0200, Andre Nathan wrote: >> I was wondering if laziness would make it run as if it was a >> single O(n) >> operation (get one directory entry "on demand", pass it to filter and >> then to insertInTree), because only one entry is used at a time, >> so that >> only the "current" entry needs to be evaluated. > > I did some experiments. This for 1000 reads of the entries of a > directory with 10000 entries, checking if they match ^[0-9]+$ and > printing those which do (half of them). > > getDirectoryEntries, filter, mapM_: > 65.52s user 6.01s system 87% cpu 1:22.21 total > > openDirStream, readDirStream: > 39.68s user 5.69s system 95% cpu 47.746 total > > getDirectoryContents, mapM_: > 63.40s user 5.96s system 95% cpu 1:12.70 total These are all known and expected. As I said, you can expect lazy versions to normally be slower than explicit loops. The question is whether 50% more time and 300% more memory has a higher cost in your case than the extra complexity and reduced modularity of the lazy code. jcc From jonathanccast at fastmail.fm Fri Jan 11 22:17:55 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Fri Jan 11 22:11:30 2008 Subject: [Haskell-cafe] Comments and suggestions on code In-Reply-To: <1200090244.6732.19.camel@homesick> References: <1199937429.8936.33.camel@homesick> <6C68D342-F1B3-4333-8D7E-83E21E1FDB57@fastmail.fm> <1199989288.5309.12.camel@homesick> <7FF4DBDE-202A-43BC-A084-2D2E816EC3C9@fastmail.fm> <1200065253.5415.6.camel@homesick> <1200090040.6732.15.camel@homesick> <1200090244.6732.19.camel@homesick> Message-ID: <690437FC-5924-4926-91D2-DAA6B2FA8F36@fastmail.fm> On 11 Jan 2008, at 2:24 PM, Andre Nathan wrote: > processEntry :: DirStream -> IO () > processEntry ds = do > entry <- readDirStream ds > if entry =~ "^[0-9]+$" > then do > putStrLn entry > processEntry ds > else > if entry == "" then return () else processEntry ds > > bar :: IO () > bar = do > ds <- openDirStream "." > processEntry ds > closeDirStream ds This is a 200% increase in code size for a 75% decrease in execution time. (And, in general, the complexity can be much higher). That's an engineering tradeoff, and one you'll have to decide yourself; there's not much that can be done to make it go away. jcc From barsoap at web.de Sat Jan 12 02:16:12 2008 From: barsoap at web.de (Achim Schneider) Date: Sat Jan 12 02:09:49 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <404396ef0801090655l338dd9fdl63f3c4af77f78b3f@mail.gmail.com> <20080110163630.056dc3e2@solaris.tower> <20080110165530.3948df88@solaris.tower> <20080111141352.47b470cb@solaris.tower> Message-ID: <20080112081612.7f05a95f@solaris.tower> Jonathan Cast wrote: > On 11 Jan 2008, at 5:13 AM, Achim Schneider wrote: > > > Jonathan Cast wrote: > >> What kind of mathematics? I don't know of any mathematics where > >> algebraic simplifications are employed without proof of the > >> underlying equations (in some denotational model). > >> > > Mathematics as, as my professor put it, "Solving by staring". > > Professor of what? I would have been flunked for such an approach. > Professor as in "gives lectures", he's a Dipl. Ing... and also also as in "got a Job for life", although not formally. I think his main point in telling it is to stop people from blindly expanding and reducing around. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From barsoap at web.de Sat Jan 12 02:25:19 2008 From: barsoap at web.de (Achim Schneider) Date: Sat Jan 12 02:18:55 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False References: <2608b8a80801100117wda28551ida0166f548147aac@mail.gmail.com> <20080110201613.GA30239@momenergy.repetae.net> <20080110212434.07e18eb8@solaris.tower> <20080110202724.GO28763@darcs.net> <20080110214153.46ad3395@solaris.tower> <20080110205220.GR28763@darcs.net> <20080110220408.47186b19@solaris.tower> <87k5mgsm31.fsf@nmd9999.imr.no> <20080111145420.1c82c377@solaris.tower> <20080111170335.GH27808@darcs.net> <20080111191247.55ab360d@solaris.tower> <51AF6510-6CC0-4D8A-94AA-D704CE47510A@fastmail.fm> Message-ID: <20080112082519.4e7d81f2@solaris.tower> Jonathan Cast wrote: > On 11 Jan 2008, at 10:12 AM, Achim Schneider wrote: > > > David Roundy wrote: > > > >> Prelude> let x=1e-300/1e300 > >> Prelude> x > >> 0.0 > >> Prelude> x/x > >> NaN > >> > >> The "true" answer here is that x/x == 1.0 (not 0 or +Infinity), but > >> there's no way for the computer to know this, so it's NaN. > > Didn't catch this the first time around, but: only to a physicist. > (I mean no disrespect to the author of darcs, but nevertheless the > point stands). Back in the real world, 0 / 0 may be defined > arbitrarily, or left undefined. (Defining it breaks the wonderful > property that, if lim (xn) = x, lim (yn) = y, and x/y = z, then lim > (xn / yn) = z. This is considered a Bad Thing by real > mathematicians). In fact, in integration theory 0 * inf = 0 for > certain 'multiplications', which gives the lie to 0 / 0. whereas lim( 0 ) * lim( inf ) is anything you want, or, more precisely, the area of the thing you started with. It's like taking seven balls, assembling them into a hexagon and claiming it's a circle. Such things just "happen" if you are working with pure abstractions. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From kalman.noel at bluebottle.com Sat Jan 12 04:20:33 2008 From: kalman.noel at bluebottle.com (Kalman Noel) Date: Sat Jan 12 04:14:02 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False In-Reply-To: <20080112082519.4e7d81f2@solaris.tower> References: <20080110202724.GO28763@darcs.net> <20080110214153.46ad3395@solaris.tower> <20080110205220.GR28763@darcs.net> <20080110220408.47186b19@solaris.tower> <87k5mgsm31.fsf@nmd9999.imr.no> <20080111145420.1c82c377@solaris.tower> <20080111170335.GH27808@darcs.net> <20080111191247.55ab360d@solaris.tower> <51AF6510-6CC0-4D8A-94AA-D704CE47510A@fastmail.fm> <20080112082519.4e7d81f2@solaris.tower> Message-ID: <200801120920.m0C9KXdT009948@mi1.bluebottle.com> Achim Schneider wrote: > whereas lim( 0 ) * lim( inf ) is anything you want Indeed I suppose that ?lim inf?, which is a notation I'm not familiar with, is not actually defined to mean anything? Kalman ---------------------------------------------------------------------- Find out how you can get spam free email. http://www.bluebottle.com/tag/3 From barsoap at web.de Sat Jan 12 04:45:17 2008 From: barsoap at web.de (Achim Schneider) Date: Sat Jan 12 04:38:57 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False References: <20080110202724.GO28763@darcs.net> <20080110214153.46ad3395@solaris.tower> <20080110205220.GR28763@darcs.net> <20080110220408.47186b19@solaris.tower> <87k5mgsm31.fsf@nmd9999.imr.no> <20080111145420.1c82c377@solaris.tower> <20080111170335.GH27808@darcs.net> <20080111191247.55ab360d@solaris.tower> <51AF6510-6CC0-4D8A-94AA-D704CE47510A@fastmail.fm> <20080112082519.4e7d81f2@solaris.tower> <200801120920.m0C9KXdT009948@mi1.bluebottle.com> Message-ID: <20080112104517.411627aa@solaris.tower> Kalman Noel wrote: > Achim Schneider wrote: > > whereas lim( 0 ) * lim( inf ) is anything you want > > Indeed I suppose that ?lim inf?, which is a notation I'm not familiar > with, is not actually defined to mean anything? > It's an ad-hoc expression of "as the slices approach zero size, their number approaches infinity". It's more an observation than anything else. I have no idea how a professional mathematician would formalise it. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From lemming at henning-thielemann.de Sat Jan 12 04:58:11 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Sat Jan 12 04:51:37 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False In-Reply-To: <20080112104517.411627aa@solaris.tower> References: <20080110202724.GO28763@darcs.net> <20080110214153.46ad3395@solaris.tower> <20080110205220.GR28763@darcs.net> <20080110220408.47186b19@solaris.tower> <87k5mgsm31.fsf@nmd9999.imr.no> <20080111145420.1c82c377@solaris.tower> <20080111170335.GH27808@darcs.net> <20080111191247.55ab360d@solaris.tower> <51AF6510-6CC0-4D8A-94AA-D704CE47510A@fastmail.fm> <20080112082519.4e7d81f2@solaris.tower> <200801120920.m0C9KXdT009948@mi1.bluebottle.com> <20080112104517.411627aa@solaris.tower> Message-ID: On Sat, 12 Jan 2008, Achim Schneider wrote: > Kalman Noel wrote: > > > Achim Schneider wrote: > > > whereas lim( 0 ) * lim( inf ) is anything you want > > > > Indeed I suppose that ?lim inf?, which is a notation I'm not familiar > > with, is not actually defined to mean anything? > > > It's an ad-hoc expression of "as the slices approach zero size, their > number approaches infinity". It's more an observation than anything > else. I have no idea how a professional mathematician would formalise > it. In Haskell you could professionally formalize it, if you would have a function, which computes the limit of a sequence: limit :: [Real] -> Real (Cf. "Why functional progrmaming matters" http://www.math.chalmers.se/~rjmh/Papers/whyfp.html) let xs = iterate (1+) 1 -- example for "lim (inf)" ys = map recip xs -- example for "lim (0)" in limit (zipWith (*) xs ys) If 'limit xs' and 'limit ys' are defined, then it holds limit (zipWith (*) xs ys) == limit xs * limit ys but in your case 'limit xs' does not exist. You can imagine it as infinity, but to make it formally safe, you need something non-standard analysis. From barsoap at web.de Sat Jan 12 05:24:32 2008 From: barsoap at web.de (Achim Schneider) Date: Sat Jan 12 05:18:06 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False References: <20080110202724.GO28763@darcs.net> <20080110214153.46ad3395@solaris.tower> <20080110205220.GR28763@darcs.net> <20080110220408.47186b19@solaris.tower> <87k5mgsm31.fsf@nmd9999.imr.no> <20080111145420.1c82c377@solaris.tower> <20080111170335.GH27808@darcs.net> <20080111191247.55ab360d@solaris.tower> <51AF6510-6CC0-4D8A-94AA-D704CE47510A@fastmail.fm> <20080112082519.4e7d81f2@solaris.tower> <200801120920.m0C9KXdT009948@mi1.bluebottle.com> <20080112104517.411627aa@solaris.tower> Message-ID: <20080112112432.674dcaff@solaris.tower> Achim Schneider wrote: > Kalman Noel wrote: > > > Achim Schneider wrote: > > > whereas lim( 0 ) * lim( inf ) is anything you want > > > > Indeed I suppose that ?lim inf?, which is a notation I'm not > > familiar with, is not actually defined to mean anything? > > > It's an ad-hoc expression of "as the slices approach zero size, their > number approaches infinity". It's more an observation than anything > else. I have no idea how a professional mathematician would formalise > it. > Actually, lim( 0 ) * lim( inf ) isn't anything but equals one, and the anything is defined to one (or, rather, is _one_ anything) to be able to use the abstraction. It's a bit like the difference between eight pens and a box of pens. If someone knows how to properly formalise n = 1, please speak up. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From kalman.noel at bluebottle.com Sat Jan 12 06:23:41 2008 From: kalman.noel at bluebottle.com (Kalman Noel) Date: Sat Jan 12 06:17:05 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False In-Reply-To: <20080112112432.674dcaff@solaris.tower> References: <20080110220408.47186b19@solaris.tower> <87k5mgsm31.fsf@nmd9999.imr.no> <20080111145420.1c82c377@solaris.tower> <20080111170335.GH27808@darcs.net> <20080111191247.55ab360d@solaris.tower> <51AF6510-6CC0-4D8A-94AA-D704CE47510A@fastmail.fm> <20080112082519.4e7d81f2@solaris.tower> <200801120920.m0C9KXdT009948@mi1.bluebottle.com> <20080112104517.411627aa@solaris.tower> <20080112112432.674dcaff@solaris.tower> Message-ID: <200801121127.m0CBRX3E023254@mi0.bluebottle.com> Achim Schneider wrote: > Actually, lim( 0 ) * lim( inf ) isn't anything but equals one, and > the anything is defined to one (or, rather, is _one_ anything) to be > able to use the abstraction. It's a bit like the difference between > eight pens and a box of pens. If someone knows how to properly > formalise n = 1, please speak up. Sorry if I still don't follow at all. Here is how I understand (i. e. have learnt) lim notation, with n ? N, a_n ? R. (Excuse my poor terminology, I have to translate this in my mind from German maths language ;-). My point of posting this is that I don't see how to accommodate the lim notation as I know it with your term. The limit of infinity? What is the limit of infinity, and why should I multiplicate it with 0? Why should I get 1? (1) lim a_n = a (where a ? R) (2) lim a_n = ? (3) lim a_n = ? ? (4) lim { x ? x0 } f(x) = y (where f is a function into R) (1) means that the sequence of reals a_n converges towards a. (2) means that the sequence does not converge, because you can always find a value that is /larger/ than what you hoped might be the limit. (3) means that the sequence does not converge, because you can always find a value that is /smaller/ than what you hoped might be the limit. (4) means that for any sequence of reals (x_n ? dom f) converging towards x0, we have lim f(x_n) = y. For this equation again, we have the three cases above. Kalman ---------------------------------------------------------------------- Find out how you can get spam free email. http://www.bluebottle.com/tag/3 From Nicholls.Mark at mtvne.com Sat Jan 12 06:20:00 2008 From: Nicholls.Mark at mtvne.com (Nicholls, Mark) Date: Sat Jan 12 06:17:57 2008 Subject: [Haskell-cafe] type questions again.... References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com><20080110185659.4d7117ff@solaris.tower><20080111145950.1cbaeb81@solaris.tower><7ca3f0160801110911s694b5323k906a203d73ab6cae@mail.gmail.com> <7ca3f0160801111003w74c4f283nf3fe050a3545cbc6@mail.gmail.com> Message-ID: Is my problem here, simply that the forall extension in GHC is misleading.....that the "forall" in "MkSwizzle :: (forall a. Ord a => [a] -> [a]) -> Swizzle" is not the same beast as the "forall" in.. data Accum a = forall s. MkAccum s (a -> s -> s) (s -> a) really data Accum a = exists s. MkAccum s (a -> s -> s) (s -> a) would be much better syntax.... don't get me wrong....I still don't especially understand...but if it's a misleading label...I can mentally substitute "exists" whenever I see a "forall" without a "=>". ________________________________ From: Luke Palmer [mailto:lrpalmer@gmail.com] Sent: Fri 11/01/2008 18:03 To: Nicholls, Mark Cc: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] type questions again.... On Jan 11, 2008 5:47 PM, Nicholls, Mark wrote: > > If you wrap an existential type up in a constructor, not > > much changes: > > If you wrap a what?....should this read existential or universal? Whoops, right, universal. > > > newtype ID = ID (forall a. a -> a) > > > > ID can hold any value of type forall a. a -> a; i.e. it can hold any > > value which exhibits the property that it can give me a value of type > > a -> a for any type a I choose. In this case the only things ID can > > hold are id and _|_, because id is the only function that has that > > type. Here's how I might use it: > > It's the only function you've defined the type of.... > > Id2 :: forall a. a -> a > > Now it can hold id2? Well, that's not what I meant, but yes it can hold id2. What I meant was that, in this case, id2 = _|_ or id2 = id, there are no other possibilities. > > > id' :: forall a. Num a => a -> a > > > id' = id -- it doesn't have to use the constraint if it doesn't > want to > > "it doesn't have to use the constraint if it doesn't want to" ? > > If id was of type.. > > Id::forall a. Ord a => a -> a > > Then I assume it would complain? Yes. > > but you need to use constructors to use > > them. I'll write them using GADTs, because I think they're a lot > > clearer that way: > > > > data NUM' where > > NUM' :: Num a => a -> NUM' > > > > Look at the type of the constructor NUM'. It has a universal type, > > meaning whatever type a you pick (as long as it is a Num), you can > > create a NUM' value with it. > > yes > > and then it goes wrong... > > > So the type contained inside the NUM' > > constructor > > ? > > > is called existential (note that NUM' itself is just a > > regular ADT; NUM' is not existential). > > > > Why existential....see below...I have a guess Okay, I was being handwavy here. Explaining this will allow me to clear this up. If you take the non-GADT usage of an existential type: data Foo = forall a. Num a => Foo a That is isomorphic to a type: data Foo = Foo (exists a. Num a => a) Except GHC doesn't support a keyword 'exists', and if it did, it would only be able to be used inside constructors like this (in order for inference to be decidable), so why bother? That's what I meant by "the type inside the constructor", Foo is not existential, (exists a. Num a => a) is. > > So when you have: > > > > > negNUM' :: NUM' -> NUM' > > > negNUM' (NUM' n) = NUM' (negate n) Here n has an existential type, specifically (exists a. Num a => a). > > Here the argument could have been constructed using any numeric type > > n, so we know very little about it. The only thing we know is that it > > is of some type a, and that type has a Num instance. > > I think one of the harrowing things about Haskell is the practice of > overloading data constructors with type names....it confuses the hell > out of me.... Yeah that took a little getting used to for me too. But how am I supposed to come up with enough names if I want to name them differently!? That would require too much creativity... :-) > OK so this declaration says that forall x constructed using "NUM' > n"...there *exists* a type T s.t. T is a member of type class NUM"... (you probably meant type class Num here) > which in term implies that that there exists the function negate... > > yes? Huh, I had never thought of it like that, but yes. I just realized that I think of programming in a way quite different than I think of logic. Maybe I should try to have my brain unify them. > > > doubleNUM' :: NUM' -> NUM' > > > doubleNUM' (NUM' n) = NUleM' (n + n) > > > > We can add it to itself, but note: > > > > > addNUM' :: NUM' -> NUM' -> NUM' > > > addNUM' (NUM' a) (NUM' b) = NUM (a + b) -- Illegal! > > > > We can't add them to each other, because the first argument could have > > been constructed with, say, a Double and the other with a Rational. > > > > But do you see why we're allowed to add it to itself? > > We can add it to itself because "+" is of type "a->a->a"... Yep, so whatever type a n happens to have, it matches both arguments. > > How about this: > > > > > data Variant where > > > Variant :: a -> Variant > > > > This is a type that can be constructed with any value whatsoever. > > Looks pretty powerful... but it isn't. Why not? > > > > Eeek..... > > Because a could be of any type whatsover?...so how I actually do > anything with it? Right. Luke -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080112/3cedce9f/attachment.htm From cristi at ot.onrc.ro Sat Jan 12 06:33:26 2008 From: cristi at ot.onrc.ro (Cristian Baboi) Date: Sat Jan 12 06:28:38 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False In-Reply-To: <200801121127.m0CBRX3E023254@mi0.bluebottle.com> References: <20080110220408.47186b19@solaris.tower> <87k5mgsm31.fsf@nmd9999.imr.no> <20080111145420.1c82c377@solaris.tower> <20080111170335.GH27808@darcs.net> <20080111191247.55ab360d@solaris.tower> <51AF6510-6CC0-4D8A-94AA-D704CE47510A@fastmail.fm> <20080112082519.4e7d81f2@solaris.tower> <200801120920.m0C9KXdT009948@mi1.bluebottle.com> <20080112104517.411627aa@solaris.tower> <20080112112432.674dcaff@solaris.tower> <200801121127.m0CBRX3E023254@mi0.bluebottle.com> Message-ID: On Sat, 12 Jan 2008 13:23:41 +0200, Kalman Noel wrote: > Achim Schneider wrote: >> Actually, lim( 0 ) * lim( inf ) isn't anything but equals one, and >> the anything is defined to one (or, rather, is _one_ anything) to be >> able to use the abstraction. It's a bit like the difference between >> eight pens and a box of pens. If someone knows how to properly >> formalise n = 1, please speak up. > > Sorry if I still don't follow at all. Here is how I understand (i. e. > have learnt) lim notation, with n ? N, a_n ? R. (Excuse my poor > terminology, I have to translate this in my mind from German maths > language ;-). My point of posting this is that I don't see how to > accommodate the lim notation as I know it with your term. The limit of > infinity? What is the limit of infinity, and why should I multiplicate > it with 0? Why should I get 1? > > (1) lim a_n = a (where a ? R) > (2) lim a_n = ? > (3) lim a_n = ? ? > (4) lim { x ? x0 } f(x) = y (where f is a function into R) > > (1) means that the sequence of reals a_n converges towards a. > > (2) means that the sequence does not converge, because you can > always find a value that is /larger/ than what you hoped might > be the limit. > (3) means that the sequence does not converge, because you can > always find a value that is /smaller/ than what you hoped might > be the limit. > > (4) means that for any sequence of reals (x_n ? dom f) converging > towards x0, we have lim f(x_n) = y. For this equation again, we > have the three cases above. Suppose lim a_n = a , lim b_n = b, c_2n = a_n, c_2n+1 = b_n. What is lim c_n ? ________ Information from NOD32 ________ This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com From johan.tibell at gmail.com Sat Jan 12 06:53:31 2008 From: johan.tibell at gmail.com (Johan Tibell) Date: Sat Jan 12 06:46:58 2008 Subject: [Haskell-cafe] Typo in ByteString documentation Message-ID: <90889fe70801120353t74e300ccife46db59748eb2fa@mail.gmail.com> In Data.ByteString.Unsafe in the documentation of unsafePackAddress the documentation reads: "Use unsafePackAddress if you know the length of the string statically." I assume that unsafePackAddressLen is the being function referred to here. If I was sitting in front of my laptop I would send you a patch. :) -- Johan From jerzy.karczmarczuk at info.unicaen.fr Sat Jan 12 06:53:55 2008 From: jerzy.karczmarczuk at info.unicaen.fr (jerzy.karczmarczuk@info.unicaen.fr) Date: Sat Jan 12 06:47:22 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False In-Reply-To: References: <20080110220408.47186b19@solaris.tower> <87k5mgsm31.fsf@nmd9999.imr.no> <20080111145420.1c82c377@solaris.tower> <20080111170335.GH27808@darcs.net> <20080111191247.55ab360d@solaris.tower> <51AF6510-6CC0-4D8A-94AA-D704CE47510A@fastmail.fm> <20080112082519.4e7d81f2@solaris.tower> <200801120920.m0C9KXdT009948@mi1.bluebottle.com> <20080112104517.411627aa@solaris.tower> <20080112112432.674dcaff@solaris.tower> <200801121127.m0CBRX3E023254@mi0.bluebottle.com> Message-ID: We agree that the absolute freedom to discuss the issue of how many angels could dance on the head of a pin is very important, but - must it hold on *this* list? The problem was there: the incapacity of Haskell to deal with the complexity of the floating-point computations. Important issue. Now you are juggling with infinities "as such", speculating on what are limits of non-converging sequences, etc. It becomes sad. Normal people - of course - just throw away all these messages without reacting. I react, because I feel that diluting an important problem in a scholastic discussion discourages people to think how to solve the true question... Jerzy Karczmarczuk From kalman.noel at bluebottle.com Sat Jan 12 06:55:19 2008 From: kalman.noel at bluebottle.com (Kalman Noel) Date: Sat Jan 12 06:48:45 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False In-Reply-To: References: <20080111145420.1c82c377@solaris.tower> <20080111170335.GH27808@darcs.net> <20080111191247.55ab360d@solaris.tower> <51AF6510-6CC0-4D8A-94AA-D704CE47510A@fastmail.fm> <20080112082519.4e7d81f2@solaris.tower> <200801120920.m0C9KXdT009948@mi1.bluebottle.com> <20080112104517.411627aa@solaris.tower> <20080112112432.674dcaff@solaris.tower> <200801121127.m0CBRX3E023254@mi0.bluebottle.com> Message-ID: <200801121155.m0CBtImO021144@mi1.bluebottle.com> Cristian Baboi: > Suppose lim a_n = a , lim b_n = b, c_2n = a_n, c_2n+1 = b_n. > > What is lim c_n ? If my intuition was of any importance here, it would claim that c_n diverges, because if I roughly approximate c_n by the sequence c' = ?a,b,a,b,...?, then I note that c' oscillates, so c_n ?roughly oscillates?. Kalman ---------------------------------------------------------------------- Get a free email address with REAL anti-spam protection. http://www.bluebottle.com/tag/1 From barsoap at web.de Sat Jan 12 07:06:31 2008 From: barsoap at web.de (Achim Schneider) Date: Sat Jan 12 07:00:12 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False References: <20080110220408.47186b19@solaris.tower> <87k5mgsm31.fsf@nmd9999.imr.no> <20080111145420.1c82c377@solaris.tower> <20080111170335.GH27808@darcs.net> <20080111191247.55ab360d@solaris.tower> <51AF6510-6CC0-4D8A-94AA-D704CE47510A@fastmail.fm> <20080112082519.4e7d81f2@solaris.tower> <200801120920.m0C9KXdT009948@mi1.bluebottle.com> <20080112104517.411627aa@solaris.tower> <20080112112432.674dcaff@solaris.tower> <200801121127.m0CBRX3E023254@mi0.bluebottle.com> Message-ID: <20080112130631.45bcfc68@solaris.tower> Kalman Noel wrote: > Achim Schneider wrote: > > Actually, lim( 0 ) * lim( inf ) isn't anything but equals one, and > > the anything is defined to one (or, rather, is _one_ anything) to be > > able to use the abstraction. It's a bit like the difference between > > eight pens and a box of pens. If someone knows how to properly > > formalise n = 1, please speak up. > > Sorry if I still don't follow at all. Here is how I understand (i. e. > have learnt) lim notation, with n ? N, a_n ? R. (Excuse my poor > terminology, I have to translate this in my mind from German maths > language ;-). My point of posting this is that I don't see how to > accommodate the lim notation as I know it with your term. The limit of > infinity? What is the limit of infinity, and why should I > multiplicate it with 0? Why should I get 1? > n * n = 1 where lim lim n -> 0 n -> oo You don't get 1, you start off with it. If you want to find the area of a function, you slice 1^2 into infinitely many parts and then look how much every single slice differs from lim( 0 ) * 1, all that lim( inf ) many times. When you've finished counting pebble, you know how to scale this 1^2 to match it with your "normal" value of 1. n = 12 n = 1 * n now, 1 is twelve. QED: The wrath of algebra. "One" as a pure concept is a very strange beast, as it can mean anything. Like, if you take something and try to understand it by dividing it successively into infinitely many parts, the meaning of each part will approach zero, as you don't change the thing you're analysing but the nature of your lenses. If you ever want to watch a zen master frowning or despair, tell him exactly that. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From cristi at ot.onrc.ro Sat Jan 12 07:54:54 2008 From: cristi at ot.onrc.ro (Cristian Baboi) Date: Sat Jan 12 07:48:46 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False In-Reply-To: References: <20080110220408.47186b19@solaris.tower> <87k5mgsm31.fsf@nmd9999.imr.no> <20080111145420.1c82c377@solaris.tower> <20080111170335.GH27808@darcs.net> <20080111191247.55ab360d@solaris.tower> <51AF6510-6CC0-4D8A-94AA-D704CE47510A@fastmail.fm> <20080112082519.4e7d81f2@solaris.tower> <200801120920.m0C9KXdT009948@mi1.bluebottle.com> <20080112104517.411627aa@solaris.tower> <20080112112432.674dcaff@solaris.tower> <200801121127.m0CBRX3E023254@mi0.bluebottle.com> Message-ID: On Sat, 12 Jan 2008 13:53:55 +0200, wrote: > We agree that the absolute freedom to discuss the issue > of how many angels could dance on the head of a pin is very > important, but - must it hold on *this* list? This list is called "Cafe". It seems you took too much of it at once. > The problem was there: the incapacity of Haskell to deal with the > complexity of the floating-point computations. Important issue. The original post was answered. You can stop reading this thread. > Now you are juggling with infinities "as such", speculating on what > are limits of non-converging sequences, etc. It becomes sad. Haskell juggle with infinities "as such" in constructs as x=x. > Normal people - of course - just throw away all these messages without > reacting. Would you define Haskell users as normal people ? :-) > I react, because I feel that diluting an important problem > in a scholastic discussion discourages people to think how to solve > the true question... Jerzy Karczmarczuk In order to solve the true question one should first be able to ask it. The truth is the original poster was sent chasing green horses on the walls with answers like NaN is 'undefined' and go read this and that. ________ Information from NOD32 ________ This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com From hughperkins at gmail.com Sat Jan 12 08:19:44 2008 From: hughperkins at gmail.com (Hugh Perkins) Date: Sat Jan 12 08:13:11 2008 Subject: [Haskell-cafe] Why purely in haskell? In-Reply-To: <1199897022.18821.24.camel@derek-laptop> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <2d3641330801090706m4ed9a927l282bb840a7dfcb7f@mail.gmail.com> <1199897022.18821.24.camel@derek-laptop> Message-ID: <837db430801120519sb5fc090sc7035b603322466b@mail.gmail.com> On Jan 9, 2008 5:43 PM, Derek Elkins wrote: > A shorter and lighter and and also interesting and entertaining read is: > http://research.microsoft.com/~simonpj/Papers/haskell-retrospective/index.htm > > While the reason Haskell was pure was to support laziness, at this point > though it's safe to say Haskell "insists" on being pure no more than > water "insists" on being wet. Wow, cool presentation. From hughperkins at gmail.com Sat Jan 12 08:46:11 2008 From: hughperkins at gmail.com (Hugh Perkins) Date: Sat Jan 12 08:39:37 2008 Subject: [Haskell-Cafe] Linq (FP in C#) Message-ID: <837db430801120546j55fcd915pd7ef05218efb8888@mail.gmail.com> Linq went live in C# in November, as part of .Net 3.5. It adds lots of FP-things to C#. It's really fun to be able to use Haskell-ish things in C#. Manipulating lists and collections just got *much* easier. Things it does: - map, fold, filter are all there (they're called "select", "agregate", "where") - limited support for laziness (since .Net 2.0; you can write a lazy "zip" function; I couldnt figure out how to write a lazy "unzip" function) - you can extend the methods available on all lists and collections - lambda expressions - type inferrence (technically, this is part of .Net 3.x, rather than specific to Linq). Things it doesnt do: - recursion doesnt seem particularly optimized (quick 2 minute test, I could be wrong) - no way to enforce purity It's an interesting vindication of the ideas in Haskell that C#, a big mainstream language, has integrated ideas from it, and that they're in production today. From bf3 at telenet.be Sat Jan 12 09:17:23 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Sat Jan 12 09:11:16 2008 Subject: [Haskell-Cafe] Linq (FP in C#) In-Reply-To: <837db430801120546j55fcd915pd7ef05218efb8888@mail.gmail.com> References: <837db430801120546j55fcd915pd7ef05218efb8888@mail.gmail.com> Message-ID: <4788CBF3.7010807@telenet.be> Yes indeed. And you forget "expression trees": code gets translated into an AST like tree, and then you can use that tree for anything you want (like compiling different other code, or code for another platform) Hugh Perkins wrote: > Linq went live in C# in November, as part of .Net 3.5. > > It adds lots of FP-things to C#. > > It's really fun to be able to use Haskell-ish things in C#. > Manipulating lists and collections just got *much* easier. > > Things it does: > - map, fold, filter are all there (they're called "select", "agregate", "where") > - limited support for laziness (since .Net 2.0; you can write a lazy > "zip" function; I couldnt figure out how to write a lazy "unzip" > function) > - you can extend the methods available on all lists and collections > - lambda expressions > - type inferrence (technically, this is part of .Net 3.x, rather than > specific to Linq). > > Things it doesnt do: > - recursion doesnt seem particularly optimized (quick 2 minute test, I > could be wrong) > - no way to enforce purity > > It's an interesting vindication of the ideas in Haskell that C#, a big > mainstream language, has integrated ideas from it, and that they're in > production today. > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > > From igloo at earth.li Sat Jan 12 09:40:03 2008 From: igloo at earth.li (Ian Lynagh) Date: Sat Jan 12 09:33:30 2008 Subject: [Haskell-cafe] Gtk2HS and GHC 6.8.2 In-Reply-To: <4787AC4A.5030708@telenet.be> References: <001301c84591$a5de4180$f19ac480$@be> <4787AC4A.5030708@telenet.be> Message-ID: <20080112144003.GA2557@matrix.chaos.earth.li> On Fri, Jan 11, 2008 at 06:50:02PM +0100, Peter Verswyvelen wrote: > It seems GHC 6.8.2 fixes a couple of bugs in GHC 6.8.1, so I'm using > that one. > > Gtk2HS does not yet detect my GHC 6.8.2 installation, but I guess it is > 100% compatible. No, it's not binary-compatible. You'll need a Gtk2HS built for 6.8.2. > Is it possible to get the Gtk2HS installer detect GHC 6.8.2? I?m on > Windows. I believe Duncan plans to make a Windows installer soon. Thanks Ian From pedagand at gmail.com Sat Jan 12 10:05:28 2008 From: pedagand at gmail.com (Pierre-Evariste Dagand) Date: Sat Jan 12 09:58:55 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False In-Reply-To: References: <20080110220408.47186b19@solaris.tower> <20080111170335.GH27808@darcs.net> <20080111191247.55ab360d@solaris.tower> <51AF6510-6CC0-4D8A-94AA-D704CE47510A@fastmail.fm> <20080112082519.4e7d81f2@solaris.tower> <200801120920.m0C9KXdT009948@mi1.bluebottle.com> <20080112104517.411627aa@solaris.tower> <20080112112432.674dcaff@solaris.tower> <200801121127.m0CBRX3E023254@mi0.bluebottle.com> Message-ID: <6cb897b30801120705s2de73497sbae72a57d78666dd@mail.gmail.com> 2008/1/12, Cristian Baboi : > Suppose lim a_n = a , lim b_n = b, c_2n = a_n, c_2n+1 = b_n. > > What is lim c_n ? This reminds me of these good old days in "Classe pr?pa" (something typically french) doing these silly things with sequences and Epsilons... So let's try to do it : First, if we assume that a = b, that's ok : lim c_n = a = b Second, we consider that a \neq b. We will show that c_n do not have a limit. By contraction, we assume that c_n has a limit c. Then, by definition of limit, we have : \exists N, \forall n \geq N, | c_n - c | \leq \epsilon Therefore, this result holds for the suits (c_2n) and (c_{2n+1}), ie. : \exists N, \forall n \geq N, | c_2n - c | \leq \epsilon and \exists N, \forall n \geq N, | c_{2n+1} - c | \leq \epsilon By definition of c_2n and c_{2n+1}, we can replace them by a_n and b_n : \exists N, \forall n \geq N, | a_n - c | \leq \epsilon and \exists N, \forall n \geq N, | b_n -c | \leq \epsilon By definition of limit, this means that : lim a_n = c and lim b_n = c By unicity of the limit, this means that : a = c and b = c Leading to a contradiction as we have assumed that a \neq b. Q.E.D. But I'm still wondering about the relation between this and Haskell... -- Pierre-Evariste DAGAND From andre at digirati.com.br Sat Jan 12 10:19:28 2008 From: andre at digirati.com.br (Andre Nathan) Date: Sat Jan 12 10:12:07 2008 Subject: [Haskell-cafe] Comments and suggestions on code In-Reply-To: <18891E57-2B9D-4F01-B5EA-DA6DC5E19C1B@fastmail.fm> References: <1199937429.8936.33.camel@homesick> <6C68D342-F1B3-4333-8D7E-83E21E1FDB57@fastmail.fm> <1199989288.5309.12.camel@homesick> <7FF4DBDE-202A-43BC-A084-2D2E816EC3C9@fastmail.fm> <1200065253.5415.6.camel@homesick> <1200090040.6732.15.camel@homesick> <18891E57-2B9D-4F01-B5EA-DA6DC5E19C1B@fastmail.fm> Message-ID: <1200151168.5269.9.camel@homesick> On Fri, 2008-01-11 at 19:14 -0800, Jonathan Cast wrote: > These are all known and expected. As I said, you can expect lazy > versions to normally be slower than explicit loops. The question is > whether 50% more time and 300% more memory has a higher cost in your > case than the extra complexity and reduced modularity of the lazy code. I think I understand... I expected the getDirectoryContents + mapM_ to have about the same memory usage of the readDirStream version, because getDirectoryContents would lazily give me one entry at a time, but the list of entries returned by it ends up being created anyway, hence the larger memory usage, as the readDirStream version never builds a list. Andre From dominic.steinitz at blueyonder.co.uk Sat Jan 12 11:41:54 2008 From: dominic.steinitz at blueyonder.co.uk (Dominic Steinitz) Date: Sat Jan 12 11:54:48 2008 Subject: [Haskell-cafe] ANN: Haskell Cryptographic Library 4.1.0 Message-ID: <4788EDD2.4050605@blueyonder.co.uk> I'd like to announce the release of a new version of the library following various contributions (contributors are bcc'd). Additions include: BubbleBabble, TEA, HMAC and more large word support. It no longer includes Base64. This is provided by http://hackage.haskell.org/cgi-bin/hackage-scripts/package/dataenc-0.10.1. Many thanks to all contributors. Dominic. PS I always mention this but the library really needs to be reviewed holistically and possibly restructured given the advent of bytestrings. If anyone would like to volunteer to do this or take over as library maintainer, please let me know. From jonathanccast at fastmail.fm Sat Jan 12 13:01:55 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Sat Jan 12 12:55:32 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False In-Reply-To: <20080112104517.411627aa@solaris.tower> References: <20080110202724.GO28763@darcs.net> <20080110214153.46ad3395@solaris.tower> <20080110205220.GR28763@darcs.net> <20080110220408.47186b19@solaris.tower> <87k5mgsm31.fsf@nmd9999.imr.no> <20080111145420.1c82c377@solaris.tower> <20080111170335.GH27808@darcs.net> <20080111191247.55ab360d@solaris.tower> <51AF6510-6CC0-4D8A-94AA-D704CE47510A@fastmail.fm> <20080112082519.4e7d81f2@solaris.tower> <200801120920.m0C9KXdT009948@mi1.bluebottle.com> <20080112104517.411627aa@solaris.tower> Message-ID: On 12 Jan 2008, at 1:45 AM, Achim Schneider wrote: > Kalman Noel wrote: > >> Achim Schneider wrote: >>> whereas lim( 0 ) * lim( inf ) is anything you want >> >> Indeed I suppose that ?lim inf?, which is a notation I'm not familiar >> with, is not actually defined to mean anything? >> > It's an ad-hoc expression of "as the slices approach zero size, their > number approaches infinity". It's more an observation than anything > else. I have no idea how a professional mathematician would formalise > it. I suspected as much. You mean that, for any extended real number z, two sequences of real numbers xn and yn may be chosen so that lim(xn) = 0, lim(yn) = inf, and lim(xn * yn) = z. jcc > > > -- > (c) this sig last receiving data processing entity. Inspect headers > for > past copyright information. All rights reserved. Unauthorised copying, > hiring, renting, public performance and/or broadcasting of this > signature prohibited. > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From jonathanccast at fastmail.fm Sat Jan 12 13:11:43 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Sat Jan 12 13:05:13 2008 Subject: [Haskell-cafe] Comments and suggestions on code In-Reply-To: <1200151168.5269.9.camel@homesick> References: <1199937429.8936.33.camel@homesick> <6C68D342-F1B3-4333-8D7E-83E21E1FDB57@fastmail.fm> <1199989288.5309.12.camel@homesick> <7FF4DBDE-202A-43BC-A084-2D2E816EC3C9@fastmail.fm> <1200065253.5415.6.camel@homesick> <1200090040.6732.15.camel@homesick> <18891E57-2B9D-4F01-B5EA-DA6DC5E19C1B@fastmail.fm> <1200151168.5269.9.camel@homesick> Message-ID: <253AEE34-AD9B-4283-BDEB-CED93B31E4BC@fastmail.fm> On 12 Jan 2008, at 7:19 AM, Andre Nathan wrote: > On Fri, 2008-01-11 at 19:14 -0800, Jonathan Cast wrote: >> These are all known and expected. As I said, you can expect lazy >> versions to normally be slower than explicit loops. The question is >> whether 50% more time and 300% more memory has a higher cost in your >> case than the extra complexity and reduced modularity of the lazy >> code. > > I think I understand... I expected the getDirectoryContents + mapM_ to > have about the same memory usage of the readDirStream version, because > getDirectoryContents would lazily give me one entry at a time, but the > list of entries returned by it ends up being created anyway, A nit: the list is almost certainly getting created lazily, or you'd get more than 300% more memory usage. But you still get the list's cons cells as your bookkeeping baggage, and they take up space in exchange for greater flexibility. > hence the > larger memory usage, as the readDirStream version never builds a list. jcc From andre at digirati.com.br Sat Jan 12 13:26:13 2008 From: andre at digirati.com.br (Andre Nathan) Date: Sat Jan 12 13:18:51 2008 Subject: [Haskell-cafe] Comments and suggestions on code In-Reply-To: <253AEE34-AD9B-4283-BDEB-CED93B31E4BC@fastmail.fm> References: <1199937429.8936.33.camel@homesick> <6C68D342-F1B3-4333-8D7E-83E21E1FDB57@fastmail.fm> <1199989288.5309.12.camel@homesick> <7FF4DBDE-202A-43BC-A084-2D2E816EC3C9@fastmail.fm> <1200065253.5415.6.camel@homesick> <1200090040.6732.15.camel@homesick> <18891E57-2B9D-4F01-B5EA-DA6DC5E19C1B@fastmail.fm> <1200151168.5269.9.camel@homesick> <253AEE34-AD9B-4283-BDEB-CED93B31E4BC@fastmail.fm> Message-ID: <1200162374.5269.13.camel@homesick> On Sat, 2008-01-12 at 10:11 -0800, Jonathan Cast wrote: > A nit: the list is almost certainly getting created lazily, or you'd > get more than 300% more memory usage. But you still get the list's > cons cells as your bookkeeping baggage, and they take up space in > exchange for greater flexibility. But when I'm processing, say, the last directory entry, I have memory allocated for the other 9999 entries that have already been processed, right? I think that's where the 8M vs 2M difference comes from. Andre From cristian.baboi at gmail.com Sat Jan 12 15:45:16 2008 From: cristian.baboi at gmail.com (Cristian Baboi) Date: Sat Jan 12 15:38:05 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False In-Reply-To: <200801121155.m0CBtImO021144@mi1.bluebottle.com> References: <20080111145420.1c82c377@solaris.tower> <20080111170335.GH27808@darcs.net> <20080111191247.55ab360d@solaris.tower> <51AF6510-6CC0-4D8A-94AA-D704CE47510A@fastmail.fm> <20080112082519.4e7d81f2@solaris.tower> <200801120920.m0C9KXdT009948@mi1.bluebottle.com> <20080112104517.411627aa@solaris.tower> <20080112112432.674dcaff@solaris.tower> <200801121127.m0CBRX3E023254@mi0.bluebottle.com> <200801121155.m0CBtImO021144@mi1.bluebottle.com> Message-ID: On Sat, 12 Jan 2008 13:55:19 +0200, Kalman Noel wrote: > Cristian Baboi: >> Suppose lim a_n = a , lim b_n = b, c_2n = a_n, c_2n+1 = b_n. >> >> What is lim c_n ? > > If my intuition was of any importance here, it would claim that c_n > diverges, because if I roughly approximate c_n by the sequence c' = > ?a,b,a,b,...?, then I note that c' oscillates, so c_n ?roughly > oscillates?. > > Kalman You mean something like this x=a:b:x ? From almeidaraf at gmail.com Sat Jan 12 16:19:43 2008 From: almeidaraf at gmail.com (Rafael Almeida) Date: Sat Jan 12 16:13:10 2008 Subject: [Haskell-cafe] Solving a geometry problem with Haskell Message-ID: <6de6b1650801121319k3d2350ax77158ef31250fb13@mail.gmail.com> Hello, I have been browsing through the problems at projecteuler.net and I found one that seemed interesting. It's the problem 176, I'll state it here: The four rectangular triangles with sides (9,12,15), (12,16,20), (5,12,13) and (12,35,37) all have one of the shorter sides (catheti) equal to 12. It can be shown that no other integer sided rectangular triangle exists with one of the catheti equal to 12. Find the smallest integer that can be the length of a cathetus of exactly 47547 different integer sided rectangular triangles. I thought I've solved it nicely, only to find later on that my solution was too slow (it has been running for almost three days now). While I was creating my solution I used literate haskell, which I think helped me a bunch to think about the problem. I wrote it originally in portuguese -- the portuguese literate version has all the attempts I've made until getting to the final one. For posting it here I've translated the reasoning around the attempt that solved the problem -- although it does it very slow -- into a new .lhs file: http://www.dcc.ufmg.br/~rafaelc/problem176.lhs After some profiling I found out that about 94% of the execution time is spent in the ``isPerfectSquare'' function. So I began researching about better ways to write that functio. Someone pointed to me on #haskell that the C library gmp has such a function. So I went ahead and wrote a C version of the program using gmp: http://www.dcc.ufmg.br/~rafaelc/problem176.c It's not the prettiest C code, as I did it really quickly, simply translating haskell code into C, but I believe it works. That C solution has been running for more than one hour now and no solution has come up yet. So I don't think it's worthed even writing a faster isPerfectSquare in haskell. As I was translating from Portuguese to English I revisited my logic and I can't see any problems with it. I think the problem is only of slowness, really. Does anyone have a better idea for how I should try to solve this problem? I'm all out of ideas. []'s Rafael From hughperkins at gmail.com Sat Jan 12 16:39:07 2008 From: hughperkins at gmail.com (Hugh Perkins) Date: Sat Jan 12 16:32:33 2008 Subject: [Haskell-cafe] Solving a geometry problem with Haskell In-Reply-To: <6de6b1650801121319k3d2350ax77158ef31250fb13@mail.gmail.com> References: <6de6b1650801121319k3d2350ax77158ef31250fb13@mail.gmail.com> Message-ID: <837db430801121339y69a77a5ehbfd0db2e6bdffd54@mail.gmail.com> On Jan 12, 2008 10:19 PM, Rafael Almeida wrote: > After some profiling I found out that about 94% of the execution time is > spent in the ``isPerfectSquare'' function. I guess that Haskell's referential transparence means the answers to the isPerfectSquare will be cached, ie automatically memoized? (not sure if is correct term?) Just out of interest, what is the upper bound for the catheti in the question? How much memory is the perfectSquares list taking up? One thought: - you're calculating the square by multiplying two numbers, maybe that could be done more quickly Quick back of envelope: 1 x 1 = 1 2 x 2 = 4 = 1 + 1 + 2 3 x 3 = 9 = 4 + 2 + 3 4 x 4 = 16 = 9 + 3 + 4 ... in other words, you can use dynamic programming to calculate each perfect square, getting each square as: square(n+1) = square(n) + (n - 1) + (n) Maybe this could save some CPU? From lrpalmer at gmail.com Sat Jan 12 16:48:39 2008 From: lrpalmer at gmail.com (Luke Palmer) Date: Sat Jan 12 16:42:04 2008 Subject: [Haskell-cafe] Solving a geometry problem with Haskell In-Reply-To: <6de6b1650801121319k3d2350ax77158ef31250fb13@mail.gmail.com> References: <6de6b1650801121319k3d2350ax77158ef31250fb13@mail.gmail.com> Message-ID: <7ca3f0160801121348i2db8c33fua6be1ab86f13a5ad@mail.gmail.com> On Jan 12, 2008 9:19 PM, Rafael Almeida wrote: > After some profiling I found out that about 94% of the execution time is > spent in the ``isPerfectSquare'' function. That function is quite inefficient for large numbers. You might try something like this: isPerfectSquare n = searchSquare 0 n where searchSquare lo hi | lo == hi = False | otherwise = let mid = (lo + hi) `div` 2 in case mid^2 `compare` n of EQ -> True LT -> searchSquare mid hi GT -> searchSquare lo mid Luke From lrpalmer at gmail.com Sat Jan 12 17:04:18 2008 From: lrpalmer at gmail.com (Luke Palmer) Date: Sat Jan 12 16:57:43 2008 Subject: [Haskell-cafe] Solving a geometry problem with Haskell In-Reply-To: <7ca3f0160801121348i2db8c33fua6be1ab86f13a5ad@mail.gmail.com> References: <6de6b1650801121319k3d2350ax77158ef31250fb13@mail.gmail.com> <7ca3f0160801121348i2db8c33fua6be1ab86f13a5ad@mail.gmail.com> Message-ID: <7ca3f0160801121404x261172f0te1d945fb757fe663@mail.gmail.com> You can do better than this, too, actually. It looks like you're using isPerfectSquare inside a filter, which is given a monotone sequence. That means we can do: -- finds the intersection of two monotone sequences intersectMonotone :: (Ord a) => [a] -> [a] -> [a] intersectMonotone (x:xs) (y:ys) = case x `compare` y of EQ -> x : intersectMonotone x y LT -> intersectMonotone xs (y:ys) GT -> intersectMonotone (x:xs) ys intersectMonotone _ _ = [] Then you can change (filter isPerfectSquare) to (intersectMonotone perfectSquares) and you should get a big speed boost. Luke On Jan 12, 2008 9:48 PM, Luke Palmer wrote: > On Jan 12, 2008 9:19 PM, Rafael Almeida wrote: > > After some profiling I found out that about 94% of the execution time is > > spent in the ``isPerfectSquare'' function. > > That function is quite inefficient for large numbers. You might try > something like this: > > isPerfectSquare n = searchSquare 0 n > where > searchSquare lo hi > | lo == hi = False > | otherwise = > let mid = (lo + hi) `div` 2 in > case mid^2 `compare` n of > EQ -> True > LT -> searchSquare mid hi > GT -> searchSquare lo mid > > Luke > From barsoap at web.de Sat Jan 12 17:12:24 2008 From: barsoap at web.de (Achim Schneider) Date: Sat Jan 12 17:05:58 2008 Subject: [Haskell-cafe] Re: Solving a geometry problem with Haskell References: <6de6b1650801121319k3d2350ax77158ef31250fb13@mail.gmail.com> Message-ID: <20080112231224.6c83cf55@solaris.tower> "Rafael Almeida" wrote: > perfectSquares :: [Integer] > perfectSquares = zipWith (*) [1..] [1..] > isPerfectSquare :: Integer -> Bool > isPerfectSquare x = (head $ dropWhile ( Bool isPerfectSquare n = sqrrt == fromIntegral (truncate sqrrt) where sqrrt = sqrt $ fromIntegral n ? It's a hell alot faster, but I have no idea if some numerical property of square roots could make it give different results than your version, in rare cases. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From barsoap at web.de Sat Jan 12 17:26:45 2008 From: barsoap at web.de (Achim Schneider) Date: Sat Jan 12 17:20:17 2008 Subject: [Haskell-cafe] Re: Solving a geometry problem with Haskell References: <6de6b1650801121319k3d2350ax77158ef31250fb13@mail.gmail.com> <20080112231224.6c83cf55@solaris.tower> Message-ID: <20080112232645.18b89a3d@solaris.tower> Achim Schneider wrote: > "Rafael Almeida" wrote: > > > perfectSquares :: [Integer] > > perfectSquares = zipWith (*) [1..] [1..] > > > isPerfectSquare :: Integer -> Bool > > isPerfectSquare x = (head $ dropWhile ( > what about > > module Main where > > isPerfectSquare :: Integer -> Bool > isPerfectSquare n = sqrrt == fromIntegral (truncate sqrrt) > where sqrrt = sqrt $ fromIntegral n > > ? It's a hell alot faster, but I have no idea if some numerical > property of square roots could make it give different results than > your version, in rare cases. > Well, even if so, I bet calculating the square root by successive approximation using integers would still be faster, it's O(ld(n)) instead of O(n). -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From andrei.formiga at gmail.com Sat Jan 12 17:28:30 2008 From: andrei.formiga at gmail.com (Andrei Formiga) Date: Sat Jan 12 17:21:57 2008 Subject: [Haskell-cafe] Re: Solving a geometry problem with Haskell In-Reply-To: <20080112231224.6c83cf55@solaris.tower> References: <6de6b1650801121319k3d2350ax77158ef31250fb13@mail.gmail.com> <20080112231224.6c83cf55@solaris.tower> Message-ID: On Jan 12, 2008 7:12 PM, Achim Schneider wrote: > what about > > module Main where > > isPerfectSquare :: Integer -> Bool > isPerfectSquare n = sqrrt == fromIntegral (truncate sqrrt) > where sqrrt = sqrt $ fromIntegral n > > ? It's a hell alot faster, but I have no idea if some numerical > property of square roots could make it give different results than your > version, in rare cases. > I did something similar: isSquare :: Integer -> Bool isSquare x = x == (sqx * sqx) where sqx = round $ sqrt $ fromInteger x perfectSquares :: [Integer] perfectSquares = zipWith (*) [1..] [1..] findSorted :: [Integer] -> Integer -> Bool findSorted xs x = h == x where h : _ = dropWhile ( test 100000 (True,False) -- []s, Andrei Formiga From lemming at henning-thielemann.de Sat Jan 12 17:15:18 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Sat Jan 12 17:25:50 2008 Subject: [Haskell-cafe] Re: Solving a geometry problem with Haskell In-Reply-To: <20080112231224.6c83cf55@solaris.tower> References: <6de6b1650801121319k3d2350ax77158ef31250fb13@mail.gmail.com> <20080112231224.6c83cf55@solaris.tower> Message-ID: On Sat, 12 Jan 2008, Achim Schneider wrote: > "Rafael Almeida" wrote: > > > perfectSquares :: [Integer] > > perfectSquares = zipWith (*) [1..] [1..] > > > isPerfectSquare :: Integer -> Bool > > isPerfectSquare x = (head $ dropWhile ( > what about > > module Main where > > isPerfectSquare :: Integer -> Bool > isPerfectSquare n = sqrrt == fromIntegral (truncate sqrrt) > where sqrrt = sqrt $ fromIntegral n > > ? It's a hell alot faster, but I have no idea if some numerical > property of square roots could make it give different results than your > version, in rare cases. The rare cases occur for big numbers. http://www.haskell.org/haskellwiki/Generic_number_type#isSquare From barsoap at web.de Sat Jan 12 17:33:02 2008 From: barsoap at web.de (Achim Schneider) Date: Sat Jan 12 17:26:35 2008 Subject: [Haskell-cafe] Re: Solving a geometry problem with Haskell References: <6de6b1650801121319k3d2350ax77158ef31250fb13@mail.gmail.com> <20080112231224.6c83cf55@solaris.tower> <20080112232645.18b89a3d@solaris.tower> Message-ID: <20080112233302.28e0c37f@solaris.tower> Achim Schneider wrote: > Achim Schneider wrote: > > > "Rafael Almeida" wrote: > > > > > perfectSquares :: [Integer] > > > perfectSquares = zipWith (*) [1..] [1..] > > > > > isPerfectSquare :: Integer -> Bool > > > isPerfectSquare x = (head $ dropWhile ( > > > what about > > > > module Main where > > > > isPerfectSquare :: Integer -> Bool > > isPerfectSquare n = sqrrt == fromIntegral (truncate sqrrt) > > where sqrrt = sqrt $ fromIntegral n > > > > ? It's a hell alot faster, but I have no idea if some numerical > > property of square roots could make it give different results than > > your version, in rare cases. > > > Well, even if so, I bet calculating the square root by successive > approximation using integers would still be faster, it's O(ld(n)) > instead of O(n). > (and you can use a truncated sqrt as initial guess) This may seem like cheating, but then I'm a game programmer... -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From daniel.is.fischer at web.de Sat Jan 12 17:36:43 2008 From: daniel.is.fischer at web.de (Daniel Fischer) Date: Sat Jan 12 17:28:46 2008 Subject: [Haskell-cafe] Solving a geometry problem with Haskell In-Reply-To: <7ca3f0160801121348i2db8c33fua6be1ab86f13a5ad@mail.gmail.com> References: <6de6b1650801121319k3d2350ax77158ef31250fb13@mail.gmail.com> <7ca3f0160801121348i2db8c33fua6be1ab86f13a5ad@mail.gmail.com> Message-ID: <200801122336.43595.daniel.is.fischer@web.de> Am Samstag, 12. Januar 2008 22:48 schrieb Luke Palmer: > On Jan 12, 2008 9:19 PM, Rafael Almeida wrote: > > After some profiling I found out that about 94% of the execution time is > > spent in the ``isPerfectSquare'' function. > > That function is quite inefficient for large numbers. You might try > something like this: > > isPerfectSquare n = searchSquare 0 n > where > searchSquare lo hi > > | lo == hi = False > | otherwise = > > let mid = (lo + hi) `div` 2 in > case mid^2 `compare` n of > EQ -> True > LT -> searchSquare mid hi > GT -> searchSquare lo mid > > Luke I don't want to be a spoil-sport, but that won't help much either. And although the logic of the programme is correct, the numbers involved are so large that I'd expect the running time to be rather years than days (it took a minute to solve for the smallest cathetus of 6 triangles, 128). Suppose the answer were 10^9 (it's much larger, actually). Then the limit for the other cathetus would be roughly 5*10^17 and for all these values it has to be checked whether n^2 + y^2 is a perfect square. If one check took a nanosecond, that would be roughly 5*10^8 seconds or nearly 16 years. Rafael, you have some good starts, but to get the answer in a reasonable time, you must employ some more algebra. Find a way to determine a cathetus of how many triangles a number is without actually constructing them is a good step. Cheers, Daniel From kalman.noel at bluebottle.com Sat Jan 12 17:36:18 2008 From: kalman.noel at bluebottle.com (Kalman Noel) Date: Sat Jan 12 17:29:43 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False In-Reply-To: References: <20080111191247.55ab360d@solaris.tower> <51AF6510-6CC0-4D8A-94AA-D704CE47510A@fastmail.fm> <20080112082519.4e7d81f2@solaris.tower> <200801120920.m0C9KXdT009948@mi1.bluebottle.com> <20080112104517.411627aa@solaris.tower> <20080112112432.674dcaff@solaris.tower> <200801121127.m0CBRX3E023254@mi0.bluebottle.com> <200801121155.m0CBtImO021144@mi1.bluebottle.com> Message-ID: <200801122240.m0CMeCkJ007985@mi0.bluebottle.com> Cristian Baboi wrote: >>Cristian Baboi: >>> Suppose lim a_n = a , lim b_n = b, c_2n = a_n, c_2n+1 = b_n. >>> What is lim c_n ? >> >> If my intuition was of any importance here, it would claim that c_n >> diverges, because if I roughly approximate c_n by the sequence c' = >> ?a,b,a,b,...?, then I note that c' oscillates, so c_n ?roughly >> oscillates?. > > You mean something like this x=a:b:x ? Ah, you try to be on-topic by using Haskell syntax :) Obviously though, I really forgot to consider the case a = b... But that's enough OT for today, I guess. Kalman ---------------------------------------------------------------------- Get a free email account with anti spam protection. http://www.bluebottle.com/tag/2 From lemming at henning-thielemann.de Sat Jan 12 16:54:08 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Sat Jan 12 17:42:16 2008 Subject: [Haskell-cafe] Solving a geometry problem with Haskell In-Reply-To: <837db430801121339y69a77a5ehbfd0db2e6bdffd54@mail.gmail.com> References: <6de6b1650801121319k3d2350ax77158ef31250fb13@mail.gmail.com> <837db430801121339y69a77a5ehbfd0db2e6bdffd54@mail.gmail.com> Message-ID: On Sat, 12 Jan 2008, Hugh Perkins wrote: > On Jan 12, 2008 10:19 PM, Rafael Almeida wrote: > > After some profiling I found out that about 94% of the execution time is > > spent in the ``isPerfectSquare'' function. > > I guess that Haskell's referential transparence means the answers to > the isPerfectSquare will be cached, ie automatically memoized? (not > sure if is correct term?) http://www.haskell.org/haskellwiki/Memoization From hughperkins at gmail.com Sat Jan 12 18:16:36 2008 From: hughperkins at gmail.com (Hugh Perkins) Date: Sat Jan 12 18:10:03 2008 Subject: [Haskell-cafe] [newbie question] Memoization automatic in Haskell? Message-ID: <837db430801121516yb7f58d4m6c95e14cc9c2fb5a@mail.gmail.com> On Jan 12, 2008 10:54 PM, Henning Thielemann wrote: > > On Sat, 12 Jan 2008, Hugh Perkins wrote: > > > I guess that Haskell's referential transparence means the answers to > > the isPerfectSquare will be cached, ie automatically memoized? (not > > sure if is correct term?) > > http://www.haskell.org/haskellwiki/Memoization > Interesting... but I dont understand... I thought that referential transparence meant that once the answer to a function has been calculated once, it will always be the same, and that the interpreter can, and will, cache this answer? So, if I call f( 20 ) once, for some, arbitrary, f, it will have to go away and calculate f(20), but if I call it multiple times, it will just return the value it already calculated? From allbery at ece.cmu.edu Sat Jan 12 18:19:22 2008 From: allbery at ece.cmu.edu (Brandon S. Allbery KF8NH) Date: Sat Jan 12 18:12:49 2008 Subject: [Haskell-cafe] [newbie question] Memoization automatic in Haskell? In-Reply-To: <837db430801121516yb7f58d4m6c95e14cc9c2fb5a@mail.gmail.com> References: <837db430801121516yb7f58d4m6c95e14cc9c2fb5a@mail.gmail.com> Message-ID: <19B1A524-5442-41A0-AD71-21352A1C5C64@ece.cmu.edu> On Jan 12, 2008, at 18:16 , Hugh Perkins wrote: > On Jan 12, 2008 10:54 PM, Henning Thielemann > wrote: >> >> On Sat, 12 Jan 2008, Hugh Perkins wrote: >> >>> I guess that Haskell's referential transparence means the answers to >>> the isPerfectSquare will be cached, ie automatically memoized? (not >>> sure if is correct term?) >> >> http://www.haskell.org/haskellwiki/Memoization >> > > Interesting... but I dont understand... I thought that referential > transparence meant that once the answer to a function has been > calculated once, it will always be the same, and that the interpreter > can, and will, cache this answer? It *can* cache the answer, if it so chooses... but that often turns out to be a pessimization, as it caches values that are only used once or twice. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH From jonathanccast at fastmail.fm Sat Jan 12 18:21:25 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Sat Jan 12 18:14:57 2008 Subject: [Haskell-cafe] [newbie question] Memoization automatic in Haskell? In-Reply-To: <837db430801121516yb7f58d4m6c95e14cc9c2fb5a@mail.gmail.com> References: <837db430801121516yb7f58d4m6c95e14cc9c2fb5a@mail.gmail.com> Message-ID: On 12 Jan 2008, at 3:16 PM, Hugh Perkins wrote: > On Jan 12, 2008 10:54 PM, Henning Thielemann > wrote: >> >> On Sat, 12 Jan 2008, Hugh Perkins wrote: >> >>> I guess that Haskell's referential transparence means the answers to >>> the isPerfectSquare will be cached, ie automatically memoized? (not >>> sure if is correct term?) >> >> http://www.haskell.org/haskellwiki/Memoization >> > > Interesting... but I dont understand... I thought that referential > transparence meant that once the answer to a function has been > calculated once, it will always be the same, Right. > and that the interpreter > can, Right. > and will, Caching is not infrequently a terrible implementation strategy, for space reasons (and sometimes for time reasons as well). Deciding whether to use it is a delicate engineering tradeoff, and, while the compiler will do its best, the starting point is decided by the programmer. Lists get cached by default; functions over integers do not. The compiler may change that decision, but it will make sure to nail down in triplicate that doing so is an improvement for every program subject to the optimization first, which means it probably won't. > cache this answer? jcc From jonathanccast at fastmail.fm Sat Jan 12 16:11:40 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Sat Jan 12 18:15:08 2008 Subject: [Haskell-cafe] Comments and suggestions on code In-Reply-To: <1200162374.5269.13.camel@homesick> References: <1199937429.8936.33.camel@homesick> <6C68D342-F1B3-4333-8D7E-83E21E1FDB57@fastmail.fm> <1199989288.5309.12.camel@homesick> <7FF4DBDE-202A-43BC-A084-2D2E816EC3C9@fastmail.fm> <1200065253.5415.6.camel@homesick> <1200090040.6732.15.camel@homesick> <18891E57-2B9D-4F01-B5EA-DA6DC5E19C1B@fastmail.fm> <1200151168.5269.9.camel@homesick> <253AEE34-AD9B-4283-BDEB-CED93B31E4BC@fastmail.fm> <1200162374.5269.13.camel@homesick> Message-ID: <2C29EEB5-465A-4687-94B0-F6B72DA1F4E9@fastmail.fm> On 12 Jan 2008, at 10:26 AM, Andre Nathan wrote: > On Sat, 2008-01-12 at 10:11 -0800, Jonathan Cast wrote: >> A nit: the list is almost certainly getting created lazily, or you'd >> get more than 300% more memory usage. But you still get the list's >> cons cells as your bookkeeping baggage, and they take up space in >> exchange for greater flexibility. > > But when I'm processing, say, the last directory entry, I have memory > allocated for the other 9999 entries that have already been processed, > right? No. That would lead to a much larger difference. What you're seeing is the result of allocating a node in a linked list, not just a single directory entry. getDirectoryContents in this case certainly does not read in the entire directory, nor does it allocate space for it --- either of those would require much more than a 4x increase in the amount of memory. > I think that's where the 8M vs 2M difference comes from. jcc From tom.davie at gmail.com Sat Jan 12 18:22:41 2008 From: tom.davie at gmail.com (Thomas Davie) Date: Sat Jan 12 18:16:10 2008 Subject: [Haskell-cafe] [newbie question] Memoization automatic in Haskell? In-Reply-To: <837db430801121516yb7f58d4m6c95e14cc9c2fb5a@mail.gmail.com> References: <837db430801121516yb7f58d4m6c95e14cc9c2fb5a@mail.gmail.com> Message-ID: <52CCC75A-C79C-4C09-BBFB-2B905E491500@gmail.com> On 12 Jan 2008, at 23:16, Hugh Perkins wrote: > On Jan 12, 2008 10:54 PM, Henning Thielemann > wrote: >> >> On Sat, 12 Jan 2008, Hugh Perkins wrote: >> >>> I guess that Haskell's referential transparence means the answers to >>> the isPerfectSquare will be cached, ie automatically memoized? (not >>> sure if is correct term?) >> >> http://www.haskell.org/haskellwiki/Memoization >> > > Interesting... but I dont understand... I thought that referential > transparence meant that once the answer to a function has been > calculated once, it will always be the same, and that the interpreter > can, and will, cache this answer? > > So, if I call f( 20 ) once, for some, arbitrary, f, it will have to go > away and calculate f(20), but if I call it multiple times, it will > just return the value it already calculated? No, Memorisation has it's costs too... Suppose you wanted to computer map f [1..100000000000000]? Each time f was called, your program would look up a table of on average 50000000000000 results for f. That doesn't sound very efficient if f is a simple function. Now suppose you're running a program for several hours -- imagine how large your table would become, and how slow your lookup would be. What you can do however, is introduced constants. Constants are evaluated once and only once, so using them, you can tell the compiler exactly what should be memorized. Bob From felipe.lessa at gmail.com Sat Jan 12 18:25:43 2008 From: felipe.lessa at gmail.com (Felipe Lessa) Date: Sat Jan 12 18:19:09 2008 Subject: [Haskell-cafe] [newbie question] Memoization automatic in Haskell? In-Reply-To: <837db430801121516yb7f58d4m6c95e14cc9c2fb5a@mail.gmail.com> References: <837db430801121516yb7f58d4m6c95e14cc9c2fb5a@mail.gmail.com> Message-ID: (While writing this message GMail told me I was too late to answer the question. Oh well, as I already typed it, let's send =) On Jan 12, 2008 9:16 PM, Hugh Perkins wrote: > Interesting... but I dont understand... I thought that referential > transparence meant that once the answer to a function has been > calculated once, it will always be the same, and that the interpreter > can, and will, cache this answer? It *can*, but all Haskell implementations I know do not. The reason is very simple, it would need a veery large amount of memory, and sometimes searching to see if the answer was already calculated could be worse than recalculating it (think of (+1) or perhaps (null)). Polimorphic functions would also complicate the matter, as multiple different caches would be needed. > So, if I call f( 20 ) once, for some, arbitrary, f, it will have to go > away and calculate f(20), but if I call it multiple times, it will > just return the value it already calculated? If you do something like let x = f 20 in x + x it *probably* will be calculated only once (although it could be calculated twice). But in the (bad) implementaion of fibonacci below, fib 0 = 0 fib 1 = 1 fib n = fib (n-1) + fib (n-2) when calculating (fib 40), (fib 38) will be calculated twice, (fib 37) will be calculated thrice, etc. -- Felipe. From lemming at henning-thielemann.de Sat Jan 12 18:25:53 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Sat Jan 12 18:19:20 2008 Subject: [Haskell-cafe] [newbie question] Memoization automatic in Haskell? In-Reply-To: <837db430801121516yb7f58d4m6c95e14cc9c2fb5a@mail.gmail.com> References: <837db430801121516yb7f58d4m6c95e14cc9c2fb5a@mail.gmail.com> Message-ID: On Sun, 13 Jan 2008, Hugh Perkins wrote: > On Jan 12, 2008 10:54 PM, Henning Thielemann > wrote: > > > > On Sat, 12 Jan 2008, Hugh Perkins wrote: > > > > > I guess that Haskell's referential transparence means the answers to > > > the isPerfectSquare will be cached, ie automatically memoized? (not > > > sure if is correct term?) > > > > http://www.haskell.org/haskellwiki/Memoization > > Interesting... but I dont understand... I thought that referential > transparence meant that once the answer to a function has been > calculated once, it will always be the same, and that the interpreter > can, and will, cache this answer? Caching is not the default, but you can easily code this by yourself: Define an array and initialize it with all function values. Because of lazy evaluation the function values are computed only when they are requested and then they persist in the array. One should add this most simple case to the Wiki. From dbenbenn at gmail.com Sat Jan 12 18:30:45 2008 From: dbenbenn at gmail.com (David Benbennick) Date: Sat Jan 12 18:24:09 2008 Subject: [Haskell-cafe] [newbie question] Memoization automatic in Haskell? In-Reply-To: References: <837db430801121516yb7f58d4m6c95e14cc9c2fb5a@mail.gmail.com> Message-ID: On 1/12/08, Henning Thielemann wrote: > Caching is not the default, but you can easily code this by yourself: > Define an array and initialize it with all function values. Because of > lazy evaluation the function values are computed only when they are > requested and then they persist in the array. But how can I implement memoization for a more complicated function? For example, perhaps I want to memoize f :: String -> Int -> Double -> String -> Bool In Python, it's pretty easy to memoize this. How can I do it in Haskell? I suspect the only way would involve changing the function signature to use IO or ST. It would be nice if I could just tell the compiler "I command you to memoize this function", and have it produce the required code automatically. From jonathanccast at fastmail.fm Sat Jan 12 18:35:41 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Sat Jan 12 18:29:09 2008 Subject: [Haskell-cafe] [newbie question] Memoization automatic in Haskell? In-Reply-To: References: <837db430801121516yb7f58d4m6c95e14cc9c2fb5a@mail.gmail.com> Message-ID: <8C981CF6-61BD-463F-BD9E-C90A377AC850@fastmail.fm> On 12 Jan 2008, at 3:30 PM, David Benbennick wrote: > On 1/12/08, Henning Thielemann wrote: >> Caching is not the default, but you can easily code this by >> yourself: >> Define an array and initialize it with all function values. >> Because of >> lazy evaluation the function values are computed only when they are >> requested and then they persist in the array. > > But how can I implement memoization for a more complicated function? > For example, perhaps I want to memoize > > f :: String -> Int -> Double -> String -> Bool > > In Python, it's pretty easy to memoize this. How can I do it in > Haskell? I suspect the only way would involve changing the function > signature to use IO or ST. > > It would be nice if I could just tell the compiler "I command you to > memoize this function", and have it produce the required code > automatically. You can cache anything using mutable hash tables, as you know, and googling will find you `function's in Haskell that do this for you. jcc From barsoap at web.de Sat Jan 12 18:42:24 2008 From: barsoap at web.de (Achim Schneider) Date: Sat Jan 12 18:36:02 2008 Subject: [Haskell-cafe] Re: Solving a geometry problem with Haskell References: <6de6b1650801121319k3d2350ax77158ef31250fb13@mail.gmail.com> Message-ID: <20080113004224.0976cae9@solaris.tower> "Rafael Almeida" wrote: > [perfect square problem] most of this is shamelessly stolen from http://www.haskell.org/haskellwiki/Generic_number_type#squareRoot (^!) :: Num a => a -> Int -> a (^!) x n = x^n isSquare :: Integer -> Bool isSquare n = let newtonStep x = div (x + div n x) 2 iters = iterate newtonStep $ truncate $ sqrt $ fromIntegral n isRoot r = r^!2 <= n && n < (r+1)^!2 root = head $ dropWhile (not . isRoot) iters in root^!2 == n *Main> isSquare (2^1024) True *Main> isSquare (2^1024+1) False *Main> isSquare (2^1024-1) False *Main> isSquare (2^2^16) True the last one take a bit less than 20 secs on my pc. And 2^2^16 is a number that takes at least an hour to pronounce. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From lemming at henning-thielemann.de Sat Jan 12 18:56:57 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Sat Jan 12 18:50:24 2008 Subject: [Haskell-cafe] [newbie question] Memoization automatic in Haskell? In-Reply-To: References: <837db430801121516yb7f58d4m6c95e14cc9c2fb5a@mail.gmail.com> Message-ID: On Sat, 12 Jan 2008, David Benbennick wrote: > On 1/12/08, Henning Thielemann wrote: > > Caching is not the default, but you can easily code this by yourself: > > Define an array and initialize it with all function values. Because of > > lazy evaluation the function values are computed only when they are > > requested and then they persist in the array. > > But how can I implement memoization for a more complicated function? > For example, perhaps I want to memoize > > f :: String -> Int -> Double -> String -> Bool There was a long thread about a sophisticated technique called "blue prints", which allows you to use binary search trees as memoizing structure. http://www.haskell.org/pipermail/haskell-cafe/2006-September/018204.html From barsoap at web.de Sat Jan 12 18:58:09 2008 From: barsoap at web.de (Achim Schneider) Date: Sat Jan 12 18:51:51 2008 Subject: [Haskell-cafe] Re: Solving a geometry problem with Haskell References: <6de6b1650801121319k3d2350ax77158ef31250fb13@mail.gmail.com> <20080113004224.0976cae9@solaris.tower> Message-ID: <20080113005809.2bd87ea6@solaris.tower> Achim Schneider wrote: > the last one take a bit less than 20 secs on my pc. And 2^2^16 is a > number that takes at least an hour to pronounce. > Which means that I'm an absolute genius when it comes to fucking up perfectly good algorithms. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From lrpalmer at gmail.com Sat Jan 12 19:00:04 2008 From: lrpalmer at gmail.com (Luke Palmer) Date: Sat Jan 12 18:53:29 2008 Subject: [Haskell-cafe] [newbie question] Memoization automatic in Haskell? In-Reply-To: References: <837db430801121516yb7f58d4m6c95e14cc9c2fb5a@mail.gmail.com> Message-ID: <7ca3f0160801121600w1911bdd2j9a7a8ef219c29532@mail.gmail.com> On Jan 12, 2008 11:30 PM, David Benbennick wrote: > On 1/12/08, Henning Thielemann wrote: > > Caching is not the default, but you can easily code this by yourself: > > Define an array and initialize it with all function values. Because of > > lazy evaluation the function values are computed only when they are > > requested and then they persist in the array. > > But how can I implement memoization for a more complicated function? > For example, perhaps I want to memoize > > f :: String -> Int -> Double -> String -> Bool > > In Python, it's pretty easy to memoize this. How can I do it in > Haskell? I suspect the only way would involve changing the function > signature to use IO or ST. No, that is one way to do it, and probably the easiest to think about. Because its conceptually pure, I wouldn't be opposed to wrapping it in unsafePerformIO (but that can be, well, unsafe if you do it wrong :-) But there is a way to do it if you demand to be a purist, but only if you can code a data structure representing all values of a type. Doing this for a particular type is one of my favorite ways to spend a half hour when I'm bored :-) For an obvious case, but to illustrate the point, I'll do Bool. data BoolCache a = BC a a bools :: BoolCache Bool bools = BC True False lookupBool :: BoolCache a -> Bool -> a lookupBool (BC t f) True = t lookupBool (BC t f) False = f memoBool :: (Bool -> a) -> (Bool -> a) memoBool f = lookupBool (fmap f bools) The pattern is the same for any type. You can do it for types with infinitely many members, like Integer, but it's trickier (but it's the same pattern, just a trickier data structure). The Integer case is scattered here and there online. I haven't found any other cases online, but I've implemented a few. > It would be nice if I could just tell the compiler "I command you to > memoize this function", and have it produce the required code > automatically. Tru dat! But it's not clear what the best way for the compiler writer to do that is. For example, if I know the access patterns of the function, I can design the aforementioned data structure to favor those. Also, not every type admits memoization, for example functions. But I can certainly envisage a library providing: class Memo a where memo :: (a -> b) -> (a -> b) For a bunch of different types. Hmm, one probably already exists, actually... Luke From jonathanccast at fastmail.fm Sat Jan 12 19:00:15 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Sat Jan 12 18:53:44 2008 Subject: [Haskell-cafe] Comments and suggestions on code In-Reply-To: <1200162374.5269.13.camel@homesick> References: <1199937429.8936.33.camel@homesick> <6C68D342-F1B3-4333-8D7E-83E21E1FDB57@fastmail.fm> <1199989288.5309.12.camel@homesick> <7FF4DBDE-202A-43BC-A084-2D2E816EC3C9@fastmail.fm> <1200065253.5415.6.camel@homesick> <1200090040.6732.15.camel@homesick> <18891E57-2B9D-4F01-B5EA-DA6DC5E19C1B@fastmail.fm> <1200151168.5269.9.camel@homesick> <253AEE34-AD9B-4283-BDEB-CED93B31E4BC@fastmail.fm> <1200162374.5269.13.camel@homesick> Message-ID: On 12 Jan 2008, at 10:26 AM, Andre Nathan wrote: > On Sat, 2008-01-12 at 10:11 -0800, Jonathan Cast wrote: >> A nit: the list is almost certainly getting created lazily, or you'd >> get more than 300% more memory usage. But you still get the list's >> cons cells as your bookkeeping baggage, and they take up space in >> exchange for greater flexibility. > > But when I'm processing, say, the last directory entry, I have memory > allocated for the other 9999 entries that have already been processed, Wait, the last entry? If you're just printing out the values, then no --- those should have been garbage collected already. jcc From lemming at henning-thielemann.de Sat Jan 12 19:08:49 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Sat Jan 12 19:02:14 2008 Subject: [Haskell-cafe] fast fractional part of floating point number - modf? Message-ID: Is there a fast and reliable way to compute the fraction of a floating point number? I can implement fraction x = snd (properFraction x :: (Int, Double)) or fraction x = x - fromIntegral (truncate x :: Int) (actually I need 'floor' not 'truncate' but this is another issue) but these need considerably more time than fraction x = x - GHC.Float.int2Double (GHC.Float.double2Int x) Is there a fast 'fraction' built-in function? Or do I have to use FFI to modf ? From ajb at spamcop.net Sat Jan 12 19:09:58 2008 From: ajb at spamcop.net (ajb@spamcop.net) Date: Sat Jan 12 19:03:23 2008 Subject: [Haskell-cafe] Re: Solving a geometry problem with Haskell In-Reply-To: References: <6de6b1650801121319k3d2350ax77158ef31250fb13@mail.gmail.com> <20080112231224.6c83cf55@solaris.tower> Message-ID: <20080112190958.sx00khgtck4s8ss4@webmail.spamcop.net> G'day all. Quoting Henning Thielemann : > The rare cases occur for big numbers. > http://www.haskell.org/haskellwiki/Generic_number_type#isSquare How big, you might ask? Prelude> let dd = undefined :: Double in floatRadix dd ^ floatDigits dd 9007199254740992 Pretty big, and covering enough cases that it's worth the optimisation when it applies: http://andrew.bromage.org/darcs/numbertheory/Math/Util.hs Cheers, Andrew Bromage From bhurt at spnz.org Sat Jan 12 19:47:40 2008 From: bhurt at spnz.org (Brian Hurt) Date: Sat Jan 12 19:19:48 2008 Subject: [Haskell-cafe] the trivial monad- thoughts and a question Message-ID: So, I've been playing around with what I call the trivial monad: module TrivialMonad where data TrivialMonad a = M a recover :: TrivialMonad a -> a recover (M x) = x instance Monad TrivialMonad where (M x) >>= f = f x (M x) >> f = f return x = M x fail s = undefined This is actually a surprisingly usefull little sucker- it allows you to "demonadify" code. Which is usefull when you have some places where you want to use the code within a monad, and some places where you don't. You write the base bit of code monadically, and then demonadify it as needed. The first question I have is it is possible to implement this guy without wrapping the value in a constructor? What I'd like to do is replace the: data TrivialMonad a = M a with something like: type TrivialMonad a = a and then be able to junk the recover function. The second question I have is: is there any hope of getting something like this into the standard library? Thanks, Brian From isaacdupree at charter.net Sat Jan 12 19:34:10 2008 From: isaacdupree at charter.net (Isaac Dupree) Date: Sat Jan 12 19:27:38 2008 Subject: [Haskell-cafe] the trivial monad- thoughts and a question In-Reply-To: References: Message-ID: <47895C82.8070004@charter.net> Brian Hurt wrote: > The second question I have is: is there any hope of getting something > like this into the standard library? the newtype Identity in module Control.Monad.Identity in package `mtl` is what you describe: http://www.haskell.org/ghc/docs/latest/html/libraries/mtl/Control-Monad-Identity.html in other words, it already is practically in the standard library. The type-synonym technique doesn't work very well because, e.g., is (TrivialMonad (IO ())) ">>=" an IO function or a Trivial function? It has been thoroughly discussed before, IIRC... ~Isaac From daniel.is.fischer at web.de Sat Jan 12 19:40:30 2008 From: daniel.is.fischer at web.de (Daniel Fischer) Date: Sat Jan 12 19:32:31 2008 Subject: [Haskell-cafe] the trivial monad- thoughts and a question In-Reply-To: References: Message-ID: <200801130140.30574.daniel.is.fischer@web.de> Am Sonntag, 13. Januar 2008 01:47 schrieb Brian Hurt: > So, I've been playing around with what I call the trivial monad: > > module TrivialMonad where > > data TrivialMonad a = M a > > recover :: TrivialMonad a -> a > recover (M x) = x > > instance Monad TrivialMonad where > > (M x) >>= f = f x > (M x) >> f = f > return x = M x > fail s = undefined > > This is actually a surprisingly usefull little sucker- it allows you to > "demonadify" code. Which is usefull when you have some places where you > want to use the code within a monad, and some places where you don't. You > write the base bit of code monadically, and then demonadify it as needed. > > The first question I have is it is possible to implement this guy without > wrapping the value in a constructor? What I'd like to do is replace the: > data TrivialMonad a = M a > with something like: > type TrivialMonad a = a > and then be able to junk the recover function. No, but you can use a newtype instead of data, so you have no run-time overhead. > > The second question I have is: is there any hope of getting something like > this into the standard library? It's already there: Control.Monad.Identity > > Thanks, > Brian > Cheers, Daniel From lrpalmer at gmail.com Sat Jan 12 19:39:55 2008 From: lrpalmer at gmail.com (Luke Palmer) Date: Sat Jan 12 19:33:19 2008 Subject: [Haskell-cafe] the trivial monad- thoughts and a question In-Reply-To: References: Message-ID: <7ca3f0160801121639o338648a9sb2db4dd3b636a7ea@mail.gmail.com> On Jan 13, 2008 12:47 AM, Brian Hurt wrote: > So, I've been playing around with what I call the trivial monad: > > module TrivialMonad where > > data TrivialMonad a = M a Better to use newtype here; then it really is operationally equivalent to using just "a", except that it's possible to implement a monad instance for it (see below). > The first question I have is it is possible to implement this guy without > wrapping the value in a constructor? What I'd like to do is replace the: > data TrivialMonad a = M a > with something like: > type TrivialMonad a = a > and then be able to junk the recover function. Nope. That would mean that every type is a monad, which would cause endless troubles for type inference. For example, what monad is (putStrLn "x") a member of: IO () or TrivialMonad (IO ()) (or even TrivialMonad (TrivialMonad (IO())))? > The second question I have is: is there any hope of getting something like > this into the standard library? Control.Monad.Identity, perhaps? http://www.haskell.org/ghc/docs/latest/html/libraries/mtl/Control-Monad-Identity.html Luke From andre at digirati.com.br Sat Jan 12 19:42:20 2008 From: andre at digirati.com.br (Andre Nathan) Date: Sat Jan 12 19:35:04 2008 Subject: [Haskell-cafe] Comments and suggestions on code In-Reply-To: References: <1199937429.8936.33.camel@homesick> <6C68D342-F1B3-4333-8D7E-83E21E1FDB57@fastmail.fm> <1199989288.5309.12.camel@homesick> <7FF4DBDE-202A-43BC-A084-2D2E816EC3C9@fastmail.fm> <1200065253.5415.6.camel@homesick> <1200090040.6732.15.camel@homesick> <18891E57-2B9D-4F01-B5EA-DA6DC5E19C1B@fastmail.fm> <1200151168.5269.9.camel@homesick> <253AEE34-AD9B-4283-BDEB-CED93B31E4BC@fastmail.fm> <1200162374.5269.13.camel@homesick> Message-ID: <1200184941.7121.4.camel@homesick> On Sat, 2008-01-12 at 16:00 -0800, Jonathan Cast wrote: > Wait, the last entry? If you're just printing out the values, then > no --- those should have been garbage collected already. Won't they be garbage collected only after the last entry is used, though? Since getDirectoryEntries returns a list, won't its elements have to be kept until the list is not used anymore, i.e., after the last entry is processed? Andre From miguelimo38 at yandex.ru Sat Jan 12 19:45:22 2008 From: miguelimo38 at yandex.ru (Miguel Mitrofanov) Date: Sat Jan 12 19:39:19 2008 Subject: [Haskell-cafe] the trivial monad- thoughts and a question In-Reply-To: References: Message-ID: > The first question I have is it is possible to implement this guy > without wrapping the value in a constructor? No. > The second question I have is: is there any hope of getting > something like this into the standard library? It's there already. It's called "Identity monad". From lrpalmer at gmail.com Sat Jan 12 20:09:07 2008 From: lrpalmer at gmail.com (Luke Palmer) Date: Sat Jan 12 20:02:32 2008 Subject: [Haskell-cafe] Comments and suggestions on code In-Reply-To: <1200184941.7121.4.camel@homesick> References: <1199937429.8936.33.camel@homesick> <7FF4DBDE-202A-43BC-A084-2D2E816EC3C9@fastmail.fm> <1200065253.5415.6.camel@homesick> <1200090040.6732.15.camel@homesick> <18891E57-2B9D-4F01-B5EA-DA6DC5E19C1B@fastmail.fm> <1200151168.5269.9.camel@homesick> <253AEE34-AD9B-4283-BDEB-CED93B31E4BC@fastmail.fm> <1200162374.5269.13.camel@homesick> <1200184941.7121.4.camel@homesick> Message-ID: <7ca3f0160801121709p55341315n293ef66bc4823a2f@mail.gmail.com> On Jan 13, 2008 12:42 AM, Andre Nathan wrote: > On Sat, 2008-01-12 at 16:00 -0800, Jonathan Cast wrote: > > Wait, the last entry? If you're just printing out the values, then > > no --- those should have been garbage collected already. > > Won't they be garbage collected only after the last entry is used, > though? Since getDirectoryEntries returns a list, won't its elements > have to be kept until the list is not used anymore, i.e., after the last > entry is processed? Well, if you're using the list like this: map (\i -> f (list !! i)) [0..10000] Then yes (it will not be garbage collected), but if you're using the list like this: map f list Then no (depending on the surroundings, of course). Recall what a list is: data List a = Empty | Cons a (List a) So once you process the first element and move to its tail, if there are no references to the original list, only its tail, then the first element will be garbage collected. Which is why you can do things like: filter isPowerOfTwo [1..] And get a list back without running out of memory when you get as high as 2^32. Luke From dons at galois.com Sat Jan 12 23:19:23 2008 From: dons at galois.com (Don Stewart) Date: Sat Jan 12 23:12:56 2008 Subject: [Haskell-cafe] ANNOUNCE: pcre-light, a light, portable regular expression library for Haskell Message-ID: <20080113041923.GC14000@scytale.galois.com> pcre-light A light regular expression library, using Perl 5 compatible regexes I'm pleased to announce the first release of pcre-light. This library provides a simple, efficient interface to PCRE regular expressions, via either strict ByteStrings or classical Strings. Compilation and matching of regular expressions is done via two functions: compile :: ByteString -> [PCREOption] -> Either String Regex match :: Regex -> ByteString -> [PCREExecOption] -> Maybe [ByteString] A convenience interface for 'Char8' Strings is also provided. == Examples == Although the operations by default take ByteStrings, we can avoid unnecessary 'pack' calls using GHC's support for ByteStrings literals, enabled with -XOverloadedStrings: > :m + Text.Regex.PCRE.Light > :m + Data.ByteString.Char8 > :set -XOverloadedStrings > let Right r = compile "the quick brown fox" [] > match r "the quick brown fox" [] Just ["the quick brown fox"] > match r "the quick brown FOX" [] Nothing We can also enable various matching extensions, > let Right r = compile "the quick brown fox" [caseless] > match r "the quick brown FOX" [] Just ["the quick brown FOX"] Subpatterns, and fancy Perl regex extensions are happily supported: > let Right r = compile "^(abc){1,2}zz" [] > match r "abczz" [] Just ["abczz","abc"] Where the subpattern bound by ( ) was returned as the second element of the list. > let Right r = compile "\\w+(?=\t)" [] > match r "the quick brown\t fox" [] Just ["brown"] You can do lots of silly things with this: > let Right r = compile "^(a()+)+" [] > match r "aaaa" Just ["aaaa", "a", ""] The full set of compile and runtime PCRE extensions are supported. == Get it == * Stable tarballs, (on Hackage, of course): http://hackage.haskell.org/cgi-bin/hackage-scripts/package/pcre-light * Cabal install it! Using the new 'cabal-install', you can automatically download, build and install the package: $ cabal update $ cabal install pcre-light Downloading 'pcre-light-0.1'... Configuring pcre-light-0.1... Preprocessing library pcre-light-0.1... Building pcre-light-0.1... Registering pcre-light-0.1.. And off we go! For more information about cabal-install, see the hackage page for this excellent tool. * Darcs repository: http://code.haskell.org/~dons/code/pcre-light/ * Documentation: http://code.haskell.org/~dons/docs/pcre-light/ * Stability The library takes correctness seriously, and comes with a reasonable testsuite (with plans to greatly extend it), and code coverage data for those tests (using GHC's new -fhpc flag). You can see the test coverage results here: http://code.haskell.org/~dons/tests/pcre-light/hpc_index.html Yours in code, Don P.S. I'd like to encourage other authors to distribute code coverage results for their libraries! hpc is an invaluable tool to ensure high quality libraries for the Haskell community. P.P.S. Consider consider contributing your own light bindings to useful C libraries. The more we have, the more certain and sustainable Haskell development will be :) P.P.P.S. Thanks to #haskell for testing and advice. From jonathanccast at fastmail.fm Sun Jan 13 00:39:10 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Sun Jan 13 00:32:38 2008 Subject: [Haskell-cafe] Comments and suggestions on code In-Reply-To: <1200184941.7121.4.camel@homesick> References: <1199937429.8936.33.camel@homesick> <6C68D342-F1B3-4333-8D7E-83E21E1FDB57@fastmail.fm> <1199989288.5309.12.camel@homesick> <7FF4DBDE-202A-43BC-A084-2D2E816EC3C9@fastmail.fm> <1200065253.5415.6.camel@homesick> <1200090040.6732.15.camel@homesick> <18891E57-2B9D-4F01-B5EA-DA6DC5E19C1B@fastmail.fm> <1200151168.5269.9.camel@homesick> <253AEE34-AD9B-4283-BDEB-CED93B31E4BC@fastmail.fm> <1200162374.5269.13.camel@homesick> <1200184941.7121.4.camel@homesick> Message-ID: On 12 Jan 2008, at 4:42 PM, Andre Nathan wrote: > On Sat, 2008-01-12 at 16:00 -0800, Jonathan Cast wrote: >> Wait, the last entry? If you're just printing out the values, then >> no --- those should have been garbage collected already. > > Won't they be garbage collected only after the last entry is used, > though? No. A cell is generated once either (a) it, or (b) a cell earlier in the list, is required. A cell is garbage collected once both (a) it, and (b) all cells earlier in the list, are no longer required. So if you process the list strictly sequentially, it will be generated and garbage collected sequentially. > Since getDirectoryEntries returns a list, won't its elements > have to be kept until the list is not used anymore, i.e., after the > last > entry is processed? jcc From apfelmus at quantentunnel.de Sun Jan 13 04:13:36 2008 From: apfelmus at quantentunnel.de (apfelmus) Date: Sun Jan 13 04:07:18 2008 Subject: [Haskell-cafe] Re: [newbie question] Memoization automatic in Haskell? In-Reply-To: References: <837db430801121516yb7f58d4m6c95e14cc9c2fb5a@mail.gmail.com> Message-ID: Henning Thielemann wrote: > David Benbennick wrote: > >> But how can I implement memoization for a more complicated function? >> For example, perhaps I want to memoize >> >> f :: String -> Int -> Double -> String -> Bool > > There was a long thread about a sophisticated technique called "blue > prints", which allows you to use binary search trees as memoizing > structure. > http://www.haskell.org/pipermail/haskell-cafe/2006-September/018204.html That's not what blueprints were for. You want generalized tries here Ralf Hinze. Generalizing generalized tries. http://www.informatik.uni-bonn.de/~ralf/publications/GGTries.ps.gz as Luke pointed out. Regards, apfelmus From apfelmus at quantentunnel.de Sun Jan 13 04:17:54 2008 From: apfelmus at quantentunnel.de (apfelmus) Date: Sun Jan 13 04:13:32 2008 Subject: [Haskell-cafe] Re: [newbie question] Memoization automatic in Haskell? In-Reply-To: <7ca3f0160801121600w1911bdd2j9a7a8ef219c29532@mail.gmail.com> References: <837db430801121516yb7f58d4m6c95e14cc9c2fb5a@mail.gmail.com> <7ca3f0160801121600w1911bdd2j9a7a8ef219c29532@mail.gmail.com> Message-ID: Luke Palmer wrote: > David Benbennick wrote: > >> It would be nice if I could just tell the compiler "I command you to >> memoize this function", and have it produce the required code >> automatically. > > Tru dat! > > But it's not clear what the best way for the compiler writer to do > that is. For example, if I know the access patterns of the function, > I can design the aforementioned data structure to favor those. > Also, not every type admits memoization, for example functions. Indeed. There are plenty of choices of data structures for memo "tables" and hash tables are not the best of them. Such choices are better left to the programmer. Regards, apfelmus From jerzy.karczmarczuk at info.unicaen.fr Sun Jan 13 05:27:12 2008 From: jerzy.karczmarczuk at info.unicaen.fr (jerzy.karczmarczuk@info.unicaen.fr) Date: Sun Jan 13 05:20:37 2008 Subject: [Haskell-cafe] [newbie question] Memoization automatic in Haskell? In-Reply-To: References: <837db430801121516yb7f58d4m6c95e14cc9c2fb5a@mail.gmail.com> Message-ID: Henning Thielemann writes: > Caching is not the default, but you can easily code this by yourself: > Define an array and initialize it with all function values. Because of > lazy evaluation the function values are computed only when they are > requested and then they persist in the array. > One should add this most simple case to the Wiki. A posteriori thought, when I reread that... This is a =part= of the story. Whatever you do with the initial calls, if there is no automatic memoization, further calls will be executed normally. The user has to replace his/her calls with the elements of the memo-array. Suppose (sorry for the awful Fibonacci again...) we define fibs = [fib n | n<-[0 ..]] fib 0 = 0 fib 1 = 1 fib n = fib(n-1) + fib(n-2) If you try to get fibs!!1000 you will die before anyway. The solution is obviously to replace the recursive definition of fib by fib n = fibs!!(n-1) + fibs!!(n-2) This works well. I had a similar problem in physics, perturbation theory offers often some quite intricate, knotty recurrencies, and the memoization offers a solution for the worse than exponential complexity. But I had to use trees, 2_dim lists of lists, etc. in order to sort the order of the creation of the results appropriately. So, I agree wholeheartly with the statement that memoization is not a blind automaton, it should be used consciously, and adapted to concrete needs. Jerzy Karczmarczuk From nionita at lycos.de Sun Jan 13 05:48:09 2008 From: nionita at lycos.de (Nicu Ionita) Date: Sun Jan 13 05:41:41 2008 Subject: AW: [Haskell-cafe] Solving a geometry problem with Haskell In-Reply-To: <6de6b1650801121319k3d2350ax77158ef31250fb13@mail.gmail.com> Message-ID: <000001c855d1$c9e40970$14b2a8c0@A64X2> Hi Rafael, I have just two ideas, that could improve your strategy to reduce the computation time: 1. perhaps there is also a minimum (not only a maximul) for the values you should try 2. is the function howManyTriangles monotone? If yes, then you could try to solve: howManyTriangles n = 47547 by finding an upper n, nmax, where howManyTriangles nmax > 47547, and than using Euler to reduce the interval (from 12 to nmax, then probably from (12 + nmax)/2 to nmax, a.s.o) Then you will have ~ ln nmax computations of the function, which could be better than computing it from 1 to ... Nicu Ionita > -----Urspr?ngliche Nachricht----- > Von: haskell-cafe-bounces@haskell.org > [mailto:haskell-cafe-bounces@haskell.org] Im Auftrag von > Rafael Almeida > Gesendet: Samstag, 12. Januar 2008 22:20 > An: haskell-cafe@haskell.org > Betreff: [Haskell-cafe] Solving a geometry problem with Haskell > > > Hello, > > I have been browsing through the problems at projecteuler.net > and I found one that seemed interesting. It's the problem > 176, I'll state it > here: > > The four rectangular triangles with sides (9,12,15), > (12,16,20), > (5,12,13) and (12,35,37) all have one of the shorter sides > (catheti) equal to 12. It can be shown that no other integer > sided rectangular triangle exists with one of the > catheti equal > to 12. > > Find the smallest integer that can be the length of a cathetus > of exactly 47547 different integer sided rectangular > triangles. > > I thought I've solved it nicely, only to find later on that > my solution was too slow (it has been running for almost > three days now). While I was creating my solution I used > literate haskell, which I think helped me a bunch to think > about the problem. I wrote it originally in portuguese -- the > portuguese literate version has all the attempts I've made > until getting to the final one. For posting it here I've > translated the reasoning around the attempt that solved the > problem -- although it does it very slow -- into a new .lhs file: > > http://www.dcc.ufmg.br/~rafaelc/problem176.lhs > > After some profiling I found out that about 94% of the > execution time is spent in the ``isPerfectSquare'' function. > So I began researching about better ways to write that > functio. Someone pointed to me on #haskell that the C library > gmp has such a function. So I went ahead and wrote a C > version of the program using gmp: > > http://www.dcc.ufmg.br/~rafaelc/problem176.c > > It's not the prettiest C code, as I did it really quickly, > simply translating haskell code into C, but I believe it > works. That C solution has been running for more than one > hour now and no solution has come up yet. So I don't think > it's worthed even writing a faster isPerfectSquare in haskell. > > As I was translating from Portuguese to English I revisited > my logic and I can't see any problems with it. I think the > problem is only of slowness, really. Does anyone have a > better idea for how I should try to solve this problem? I'm > all out of ideas. > > []'s > Rafael > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From almeidaraf at gmail.com Sun Jan 13 07:26:01 2008 From: almeidaraf at gmail.com (Rafael Almeida) Date: Sun Jan 13 07:19:26 2008 Subject: [Haskell-cafe] Solving a geometry problem with Haskell In-Reply-To: <200801122336.43595.daniel.is.fischer@web.de> References: <6de6b1650801121319k3d2350ax77158ef31250fb13@mail.gmail.com> <7ca3f0160801121348i2db8c33fua6be1ab86f13a5ad@mail.gmail.com> <200801122336.43595.daniel.is.fischer@web.de> Message-ID: <6de6b1650801130426x2260a32bmd2a36d13e68afaca@mail.gmail.com> On Sat, 12 Jan 2008 23:36:43 +0100, Daniel Fischer wrote: > > Am Samstag, 12. Januar 2008 22:48 schrieb Luke Palmer: > > On Jan 12, 2008 9:19 PM, Rafael Almeida wrote: > > > After some profiling I found out that about 94% of the execution time is > > > spent in the ``isPerfectSquare'' function. > > > > That function is quite inefficient for large numbers. You might try > > something like this: > > > > isPerfectSquare n > where > > searchSquare lo hi > > > > | lo = hi > | otherwise > > > let mid > case mid^2 `compare` n of > > EQ -> True > > LT -> searchSquare mid hi > > GT -> searchSquare lo mid > > > > Luke > > I don't want to be a spoil-sport, but that won't help much either. And > although the logic of the programme is correct, the numbers involved are so > large that I'd expect the running time to be rather years than days (it took > a minute to solve for the smallest cathetus of 6 triangles, 128). > Suppose the answer were 10^9 (it's much larger, actually). Then the limit for > the other cathetus would be roughly 5*10^17 and for all these values it has > to be checked whether n^2 + y^2 is a perfect square. If one check took a > nanosecond, that would be roughly 5*10^8 seconds or nearly 16 years. > Rafael, you have some good starts, but to get the answer in a reasonable time, > you must employ some more algebra. > Find a way to determine a cathetus of how many triangles a number is without > actually constructing them is a good step. > > Cheers, > Daniel > Now you really conviced me that the algorithm isn't right. Although I already thought I needed to come up with a new algorithm when the GMP's perfect square function didn't help. I thank for all the feedback on how to make isPerfectSquare faster, though. It has been educational. I'm trying to come up with something other than constructing the triangles, but maybe I'm just not that strong at algebra. Thanks for de feedback, though. From almeidaraf at gmail.com Sun Jan 13 07:43:52 2008 From: almeidaraf at gmail.com (Rafael Almeida) Date: Sun Jan 13 07:37:17 2008 Subject: AW: [Haskell-cafe] Solving a geometry problem with Haskell In-Reply-To: <000001c855d1$c9e40970$14b2a8c0@A64X2> References: <6de6b1650801121319k3d2350ax77158ef31250fb13@mail.gmail.com> <000001c855d1$c9e40970$14b2a8c0@A64X2> Message-ID: <6de6b1650801130443g4b17cc4aj2281c3a284cd8f0c@mail.gmail.com> On Sun, 13 Jan 2008 11:48:09 +0100, "Nicu Ionita" wrote: > > Hi Rafael, > > I have just two ideas, that could improve your strategy to reduce the > computation time: > > 1. perhaps there is also a minimum (not only a maximul) for the values you > should try Yeah, that's a good one, the most I can narrow down the results the better. But if I can figure out the number of triangles without actually constructing them would be the real winner algorithm. > 2. is the function howManyTriangles monotone? If yes, then you could try to > solve: > > howManyTriangles n = 47547 > > by finding an upper n, nmax, where howManyTriangles nmax > 47547, and than > using Euler to reduce the interval (from 12 to nmax, then probably from (12 > + nmax)/2 to nmax, a.s.o) > > Then you will have ~ ln nmax computations of the function, which could be > better than computing it from 1 to ... I wish it was monotone, but it doesn't seem to be anything, I even plotted the relation cathetus size x number of triangles, but it didn't really show any pattern. It seems there are more likely results, but there are a few of them that looks just random. If you want to see the plotted graph: http://homepages.dcc.ufmg.br/~rafaelc/problem176.png From t-otto-news at gmx.de Sun Jan 13 08:54:20 2008 From: t-otto-news at gmx.de (Torsten Otto) Date: Sun Jan 13 08:47:44 2008 Subject: [Haskell-cafe] Getting frantic with FranTk Message-ID: Howdy, with a just-in-time-learning approach I managed to teach my class of advanced high schoolers the basics of functional programming using Haskell (I had only used Scheme before). Now to show them that Haskell is not a weirdo esoteric command line only language, I thought I'd end the class with spoken output (easy enough with the System module and "say" in Mac OS) and a GUI for input using FranTk. There is however something very basic I'm missing: I have Hugs installed at /opt/local/bin/hugs in MacOS 10.4/10.5. What do I do to get Hugs to recognize FranTk? I have downloaded it, but I can't even get the demo to work, none of the imports can be found: module Main where import FranTk import qualified StaticTypes as S import IOExts For Windows, there's a .bat to use, but I can't figure out how to get it to work on a Unix-system like Mac OS. I seems to be more than just to include the path when starting Hugs... Thanks in advance for any hints, regards, Torsten Otto From andre at digirati.com.br Sun Jan 13 09:46:12 2008 From: andre at digirati.com.br (Andre Nathan) Date: Sun Jan 13 09:38:47 2008 Subject: [Haskell-cafe] Comments and suggestions on code In-Reply-To: References: <1199937429.8936.33.camel@homesick> <6C68D342-F1B3-4333-8D7E-83E21E1FDB57@fastmail.fm> <1199989288.5309.12.camel@homesick> <7FF4DBDE-202A-43BC-A084-2D2E816EC3C9@fastmail.fm> <1200065253.5415.6.camel@homesick> <1200090040.6732.15.camel@homesick> <18891E57-2B9D-4F01-B5EA-DA6DC5E19C1B@fastmail.fm> <1200151168.5269.9.camel@homesick> <253AEE34-AD9B-4283-BDEB-CED93B31E4BC@fastmail.fm> <1200162374.5269.13.camel@homesick> <1200184941.7121.4.camel@homesick> Message-ID: <1200235572.5334.0.camel@homesick> On Sat, 2008-01-12 at 21:39 -0800, Jonathan Cast wrote: > No. A cell is generated once either (a) it, or (b) a cell earlier in > the list, is required. A cell is garbage collected once both (a) it, > and (b) all cells earlier in the list, are no longer required. So if > you process the list strictly sequentially, it will be generated and > garbage collected sequentially. Understood. Thanks Jonathan and Luke for your answers! Best, Andre From frr149 at easyjob.net Sun Jan 13 10:55:18 2008 From: frr149 at easyjob.net (Fernando Rodriguez) Date: Sun Jan 13 10:48:56 2008 Subject: [Haskell-cafe] Access to list Message-ID: Hi, If I define the follwoing functions: car (x:_) = x car [] = [] cdr (_:xs) = xs cdr [] = [] and try to apply them to some list, such as car [1,2,3] I get this odd error: :1:9: No instance for (Num [a]) arising from the literal `3' at :1:9 Possible fix: add an instance declaration for (Num [a]) In the expression: 3 In the first argument of `car', namely `[1, 2, 3]' In the expression: car [1, 2, 3] What am I doing wrong this time? :-P Thanks From jerzy.karczmarczuk at info.unicaen.fr Sun Jan 13 11:06:28 2008 From: jerzy.karczmarczuk at info.unicaen.fr (jerzy.karczmarczuk@info.unicaen.fr) Date: Sun Jan 13 10:59:52 2008 Subject: [Haskell-cafe] Access to list In-Reply-To: References: Message-ID: Fernando Rodriguez writes: > car (x:_) = x > car [] = [] ... > and try to apply them to some list, such as > > car [1,2,3] > > I get this odd error: > No instance for (Num [a]) > arising from the literal `3' ... The error is really a bit cryptic (who cares, Nums or whatever...) but the error is here. Your 'car' picks the first element, or the empty LIST. So, the first element of the argument also must be a list, not a number, otherwise the type-checker yells. Jerzy Karczmarczuk From jed at 59A2.org Sun Jan 13 11:06:50 2008 From: jed at 59A2.org (Jed Brown) Date: Sun Jan 13 11:00:19 2008 Subject: [Haskell-cafe] Access to list In-Reply-To: (Fernando Rodriguez's message of "Sun, 13 Jan 2008 15:55:18 +0000 (UTC)") References: Message-ID: <87prw5676t.fsf@59A2.org> On 13 Jan 2008, frr149@easyjob.net wrote: > > If I define the follwoing functions: > > car (x:_) = x > car [] = [] This won't typecheck. It helps to add a type signature car :: [a] -> a The first element of an empty list is undefined, so you can do what Prelude.head does and write: car [] = undefined > cdr (_:xs) = xs > cdr [] = [] This is entirely valid, but may not be what you want. cdr [] = undefined -- like Prelude.tail Jed -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080113/30d285c3/attachment.bin From rootbeer at redcat.com Sun Jan 13 11:07:16 2008 From: rootbeer at redcat.com (Tom Phoenix) Date: Sun Jan 13 11:00:39 2008 Subject: [Haskell-cafe] Access to list In-Reply-To: References: Message-ID: <31086b240801130807p6fdbdbaaseb668022b85adfd1@mail.gmail.com> On Jan 13, 2008 7:55 AM, Fernando Rodriguez wrote: > If I define the follwoing functions: > > car (x:_) = x > car [] = [] What's the type signature for that function? Cheers! --Tom Phoenix From felipe.lessa at gmail.com Sun Jan 13 11:08:51 2008 From: felipe.lessa at gmail.com (Felipe Lessa) Date: Sun Jan 13 11:02:14 2008 Subject: [Haskell-cafe] Access to list In-Reply-To: <31086b240801130807p6fdbdbaaseb668022b85adfd1@mail.gmail.com> References: <31086b240801130807p6fdbdbaaseb668022b85adfd1@mail.gmail.com> Message-ID: On Jan 13, 2008 2:07 PM, Tom Phoenix wrote: > On Jan 13, 2008 7:55 AM, Fernando Rodriguez wrote: > > > If I define the follwoing functions: > > > > car (x:_) = x > > car [] = [] > > What's the type signature for that function? car :: [[a]] -> [a] -- Felipe. From jerzy.karczmarczuk at info.unicaen.fr Sun Jan 13 11:10:07 2008 From: jerzy.karczmarczuk at info.unicaen.fr (jerzy.karczmarczuk@info.unicaen.fr) Date: Sun Jan 13 11:03:29 2008 Subject: [Haskell-cafe] Access to list In-Reply-To: <87prw5676t.fsf@59A2.org> References: <87prw5676t.fsf@59A2.org> Message-ID: Jed Brown writes: > On 13 Jan 2008, frr149@easyjob.net wrote: >> >> If I define the follwoing functions: >> >> car (x:_) = x >> car [] = [] > > This won't typecheck. It helps to add a type signature > car :: [a] -> a Good will, wrong diagnosis. This WILL check. car :: forall a. [[a]] -> [a] J. Karczmarczuk From felipe.lessa at gmail.com Sun Jan 13 11:53:14 2008 From: felipe.lessa at gmail.com (Felipe Lessa) Date: Sun Jan 13 11:46:38 2008 Subject: [Haskell-cafe] MonadPrompt + Gtk2Hs = ? Message-ID: (This e-mail is a literate Haskell file.) Ryan Ingram enlightened us with MonadPrompt as a very nice abstraction for turn-based games, allowing easy programming and testing. http://www.mail-archive.com/haskell-cafe@haskell.org/msg33040.html http://ryani.freeshell.org/haskell/ I wonder how nicely it fits on a Gtk2Hs application. =) > {-# OPTIONS_GHC -fglasgow-exts -Wall #-} > import Control.Concurrent > import Control.Concurrent.MVar > import Control.Monad > import Control.Monad.Fix > import Graphics.UI.Gtk > import System.IO > import System.Random Needed for the GADTs and some type signatures. (yes, I'm stuck with GHC 6.6.1 for now =/ ) While you read the e-mail, choose the appropriate main function > main :: IO () > main = consoleMain > -- main = gtkApp forkAttempt > -- main = gtkApp subLoopAttempt > -- main = gtkApp lastAttempt For the purposes of this e-mail, I'll present here a simplified version of his MonadPrompt: > class Monad m => MonadPrompt p m | m -> p where > prompt :: p a -> m a > > data Prompt (p :: * -> *) r where > PromptDone :: r -> Prompt p r > Prompt :: p a -> (a -> Prompt p r) -> Prompt p r > > instance Monad (Prompt p) where > return = PromptDone > PromptDone x >>= f = f x > Prompt p cont >>= f = Prompt p ((>>= f) . cont) > > instance MonadPrompt p (Prompt p) where > prompt p = Prompt p return With the monad above, we may program a simple guessing game. This is based on http://ryani.freeshell.org/haskell/Main.lhs and you can do every analysis done here with his sources, but I'm again trying to keep everything as simple as possible. > guessGame :: MonadPrompt GuessP m => Int -> m Int > guessGame answer = guessMe 1 where > guessMe tries = do > prompt (Print $ "Guess #" ++ show tries ++ ":") > guess <- prompt Guess > if guess == answer > then do prompt (Print "Right!") > return tries > else do prompt (Print $ "You guessed too " ++ > if guess < answer then "low" else "high" ++ > "! Try again.") > guessMe (tries + 1) Okay, so our game do prompts over the GuessP data type, > data GuessP a where where you may ask the user for a guess > Guess :: GuessP Int or you may show him some info about the game. > Print :: String -> GuessP () To play our little game, we have to execute the Prompt. We have > runPromptM :: Monad m => (forall a. p a -> m a) -> Prompt p r -> m r > runPromptM _ (PromptDone result) = return result > runPromptM f (Prompt p cont) = f p >>= runPromptM f . cont which basically maps prompts to actions on some monad -- in particular, IO. Doing a console interface isn't hard at all: > consolePrompt :: forall a. GuessP a -> IO a > consolePrompt (Print s) = putStrLn s > consolePrompt Guess = fmap read getLine > guessGameNew :: MonadPrompt GuessP m => IO (m Int) > guessGameNew = randomRIO (1, 10) >>= return . guessGame > consoleMain :: IO () > consoleMain = do > hSetBuffering stdout NoBuffering > game <- guessGameNew > attempts <- runPromptM consolePrompt game > putStrLn $ "You took " ++ show attempts ++ " attempts." That's really cool =). However, mapping runPromptM into a Gtk2Hs application isn't easy at all (we'll see why shortly). Before that, let's take the common blocks of code away. All of our attempts will develop a function that takes a function for showing info, an entry for reading guesses and a button that will be clicked to make the guess. > type AttemptCode = (String -> IO ()) -> Entry -> Button -> IO () > > gtkApp :: AttemptCode -> IO () > gtkApp run = do > unsafeInitGUIForThreadedRTS -- allows runghc > w <- windowNew > w `onDestroy` mainQuit > container <- vBoxNew False 7 > w `containerAdd` container > > let showInfo info = do m <- messageDialogNew (Just w) [] MessageInfo > ButtonsOk info > dialogRun m >> widgetDestroy m > > entry <- entryNew > boxPackStart container entry PackNatural 0 > > button <- buttonNewWithLabel "Guess" > boxPackStart container button PackNatural 0 > > widgetShowAll w > timeoutAdd (run showInfo entry button >> return False) 0 > mainGUI With everything in place, let's start! The first na?ve attempt would be to just connect every point > {- > na?veAttempt :: AttemptCode > na?veAttempt showInfo entry button = do > game <- guessGameNew > let mapping (Print s) = showInfo s > mapping Guess = -- Oops > -} It's easy to see that we can't get the guess from our user using a function like 'getLine'. The problem lies in the fact that Gtk is event-driven, so every time we ask the user for something, we have to wait for the corresponding event that will bring us his answer. 'runPromptM' basically creates one big monolithic monad that will run from the beginning to the end of the game -- exactly the same thing 'mainGUI' does! The standard way of solving the problem of running two sequential things at once is using threads, and this solution is specially appealing since Control.Concurrent simplifies the matters *a lot*. So let's try this instead > forkAttempt :: AttemptCode > forkAttempt showInfo entry button = do > game <- guessGameNew > forkIO $ do attempts <- runPromptM forkedMapping game > postGUIAsync (showInfo $ "You took " ++ show attempts ++ > " attempts.") > return () > where > forkedMapping :: forall a. GuessP a -> IO a > forkedMapping (Print s) = postGUIAsync (showInfo s) > forkedMapping Guess = do > v <- newEmptyMVar > cid <- postGUISync $ onClicked button $ entryGetText entry > >>= putMVar v > guess <- takeMVar v -- f1 > postGUISync (signalDisconnect cid) -- f2 > return (read guess) Problem solved? Not really: - This kind of implementation hides lots of subtle bugs. For example, because of postGUIAsync being used in Print case, the user will see multiple dialog boxes at once and -- strangely enough -- he'll see first the last message printed. It isn't always easy to see this kind of bug at first sight, and it can be very hard to track it down. - Another problem may happen with scheduling. For some reason, there are times in which it takes some time for the control to pass from the Gtk thread to the forkIO one, effectively 'freezing' the game for some time. Unfortunately this problem doesn't show up above, but I have experienced it on a larger game I'm currently programming using Prompt. - It is possible that the user clicks on the button between f1 and f2. Again, on this very simple example nothing seems to go wrong, but there shouldn't be anything between f1 and f2 as the GUI is on an inconsistent state. It should be noted that the scheduling problem can be mitigated using 'yield' on some key spots. This not only feels hackish, but also doesn't scale very well. Another approach that is sometimes adopted to solve this kind of problem is creating a main "sub-loop" with 'mainIteration'. This essentially removes the need for those nasty evil threads =). > subLoopAttempt :: AttemptCode > subLoopAttempt showInfo entry button = do > game <- guessGameNew > attempts <- runPromptM subLoopMapping game > showInfo $ "You took " ++ show attempts ++ " attempts." > where > subLoopMapping :: forall a. GuessP a -> IO a > subLoopMapping (Print s) = showInfo s > subLoopMapping Guess = do > v <- newEmptyMVar > cid <- onClicked button $ entryGetText entry >>= putMVar v > guess <- subLoopGetMVar v > signalDisconnect cid > return (read guess) Here comes the magic! > subLoopGetMVar :: MVar a -> IO a > subLoopGetMVar v = do > m <- tryTakeMVar v > case m of > Just r -> return r > Nothing -> do > quitting <- mainIteration > when quitting (fail "quitting") > subLoopGetMVar v There are a couple of pitfalls in this approach as well: - The quitting code doesn't work very well anymore. Try to close the window before guessing right and you'll see an "user error" on the console. Some 'bracket' magic is needed to get out of the subloop without throwing errors at the user's face. - Every time we get into a subloop we add an overhead for every event the application receives. I don't know if this is important at all, maybe with lots of nested subloop. - The real problem is: what if the MVar gets full but does not generate an event? While 'subLoopGetMVar' waits for 'mainIteration', the game code should be executing already for a long time! Unfortunately I couldn't come up with a simple example that exposes the last problem listed above. But, for example, some network code could fill that MVar in a multiplayer internet game. In this case the game wouldn't proceed until an event was generated. It's known that to partially solve this problem it is possible to create a signal generator that runs every X milliseconds, giving an upper bound to the amount of time between putMVar being called and subLoopGetMVar finishing. This feels hackish and fragile as well, specially because it is difficult to hunt down bugs. But Prompt has a very *very* nice property we're missing to take advantage of here: it's is *pure*. In fact, I think that is one of the reasons why Ryan bothered sending us an e-mail -- you can not only plug different interfaces codes, but also plug no interface at all to make tests, with purity making matters very simple. Ryan also notes that "If you wanted to add undo, all you have to do is save off the current Prompt in the middle of runPromptM; you can return to the old state at any time." Eventually this feature rang some bells: you can save not only when you want to undo, but also when you want to ask something to the user. Unfortunately, I still haven't come up with a nice higher order function that generalizes this work without reinventing Prompt on an isomorphic type. Enough said, let's see how: > lastAttempt :: AttemptCode > lastAttempt showInfo entry button = do > game <- guessGameNew > runPromptM' game > where > -- Signature required > runPromptM' :: Prompt GuessP Int -> IO () -- note: not (IO Int)! > runPromptM' (Prompt (Print s) c) = showInfo s >> runPromptM' (c ()) > runPromptM' (Prompt Guess c) = do > mfix $ \cid -> do > let cont guess = do {signalDisconnect cid; > runPromptM' (c $ read guess)} > onClicked button $ entryGetText entry >>= cont > return () > runPromptM' (PromptDone attempts) = do > showInfo $ "You took " ++ show attempts ++ " attempts." After so many attempts looking with some much similar code, it may be hard to see exactly how our last attempt work. No threads, no MVars, no nothing. So I took out features, and now everything is better? =) Basically, we first assume that every time 'runPromptM'' is called, we're on Gtk's thread (which is easy in this case since there are no threads at all). Next, we see if we need to *wait* for something. In the Print case, we just call 'showInfo', so the code is the same as expanding 'subLoopMapping (Print s)' inside 'runPromptM'. This means that the Gtk event that called 'runPromptM'' will continue to execute the the next call to 'runPromptM'' as well. This is very nice, since it introduces no delays to the user (imagine a non-blocking showInfo -- e.g. printing on a textview). The PromptDone case is also very similar to what has been done before. However, in the Guess case we connect a signal to the button and return! This is where things get very different from the other approaches. When using 'forkIO', the forked thread would run from the game start until its end. When using 'mainIteration', the event that called 'subLoopAttempt' (in our case, the timeout) would execute until the end of the game. Instead, 'lastAttempt' will run only until the first Guess. Okay, so how do we proceed from here? The continuation of the 'Prompt' constructor goes inside 'cont's closure. When the user clicks on the button, it disconnects the signal and calls 'runPromptM'' again. Everything happens sequentially as I'm saying because there aren't any other threads playing with our continuation, so this not only removes the need for MVars but also fixes the whole problem of "will this run in the middle of that?". Even if the user could click twice at the same time, the Gtk main loop would execute only one event callback "concurrently" and by the time the other event gets its chance to execute we'll have disconnected its signal handler already. It's true that *another* callback would be connected if the guess was not right, but that doesn't cause any inconsistencies at all. Note also that we could have, for example, two buttons sharing the same continuation if their callbacks disconnected both 'ConnectID's before going on. No freezes, no races, no exceptions, no overheads. No generic 'runPromptM' abstraction as well, but I think the price is worth paying, specially because the other approaches have nasty subtle bugs. And we continue to have the possibility of using 'runPromptM' in our tests, for example. -- Oh, well. This e-mail got longer than I initially imagined, thanks God I started typing it on emacs already =). I'm looking forward suggestions on improvements and critics about problems in this last approach. Unfortunately the game I'm developing is still in an early stage, but I promise to release it under the GPL sometime soon =). Also, I welcome any meaningful comparison between 'lastAttempt' and 'callCC'. Thanks for reading until here, -- Felipe. From duncan.coutts at worc.ox.ac.uk Sun Jan 13 13:01:41 2008 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Sun Jan 13 12:55:05 2008 Subject: [Haskell-cafe] MonadPrompt + Gtk2Hs = ? In-Reply-To: References: Message-ID: <1200247301.5639.16.camel@localhost> On Sun, 2008-01-13 at 14:53 -0200, Felipe Lessa wrote: > Problem solved? Not really: > > - This kind of implementation hides lots of subtle bugs. For example, > because of postGUIAsync being used in Print case, the user will see > multiple dialog boxes at once and -- strangely enough -- he'll see > first the last message printed. It isn't always easy to see > this kind of bug at first sight, and it can be very hard to track it down. You could use another thread :-) That is have an output thread that reads a queue from your game engine and only looks for the next output message at appropriate points. > - Another problem may happen with scheduling. For some reason, there are > times in which it takes some time for the control to pass from the Gtk > thread to the forkIO one, effectively 'freezing' the game for some time. > Unfortunately this problem doesn't show up above, but I have experienced > it on a larger game I'm currently programming using Prompt. Are you linking using -threaded or not? If not then you need another trick to use cooperative scheduling between Gtk and the RTS. > - It is possible that the user clicks on the button between f1 and f2. > Again, on this very simple example nothing seems to go wrong, but there > shouldn't be anything between f1 and f2 as the GUI is on an inconsistent > state. > > It should be noted that the scheduling problem can be mitigated using 'yield' > on some key spots. This not only feels hackish, but also doesn't scale very > well. You must not be using -threaded then I'm guessing. That'd solve the problem. > Another approach that is sometimes adopted to solve this kind of problem is > creating a main "sub-loop" with 'mainIteration'. This essentially removes the > need for those nasty evil threads =). That's pretty ugly. I'd avoid that if I were you. Here's my suggestion: use two threads. One thread for the game logic and one thread for communicating with the user interface. Then use an input an output channel to post interesting events between the two. The GUI would then also post interesting events into the incoming channel for the view/ui thread. Of course you'd have to link using -threaded and use postGUISync/Async as appropriate from the view/ui thread. By serialising all button events into a channel it allows you to ignore button presses that happen at certain moments. And as I suggested above, it allows you to serialise the output events so you don't end up showing several dialogues to the user at once. Duncan From ruderphilipp at web.de Sun Jan 13 13:12:02 2008 From: ruderphilipp at web.de (Philipp Riemer) Date: Sun Jan 13 13:05:34 2008 Subject: [Haskell-cafe] Possibility to port vshaskell to VS2008? Message-ID: <001301c8560f$cc227e90$64677bb0$@de> Because my university is in the MSNDAA-program I could download the new Visual Studio 2008 Professional, what I've done today. Now I tried to install the vshaskell-extension to start learning Haskell but the installer only quits with the message that (of course) VS2005 is not installed. Now is my question if I have to download the "old" VS2005 or if it is somehow possible to get this extension running with VS9.0? I already tried to use the EclipseFP-plugin so I already have (win)hugs, ghc and haddoc installed (if it helps for the problem above). The problem with this plugin was that Ctrl+Space does apparently not work for code hints and because I'm just started to learn the language, I don't know every keyword... So I have to look it up everytime somewhere, I want to implement something new. The fact that Prelude.hs and others are plain text are a great help, but what I have seen in the screenshot at http://www.haskell.org/visualhaskell/screenshots.html would be much better... From felipe.lessa at gmail.com Sun Jan 13 13:37:55 2008 From: felipe.lessa at gmail.com (Felipe Lessa) Date: Sun Jan 13 13:31:18 2008 Subject: [Haskell-cafe] MonadPrompt + Gtk2Hs = ? In-Reply-To: <1200247301.5639.16.camel@localhost> References: <1200247301.5639.16.camel@localhost> Message-ID: On Jan 13, 2008 4:01 PM, Duncan Coutts wrote: > On Sun, 2008-01-13 at 14:53 -0200, Felipe Lessa wrote: > You could use another thread :-) LOL, at first I thought of mail threads =). > That is have an output thread that reads a queue from your game engine > and only looks for the next output message at appropriate points. I'll comment on this shortly. > Are you linking using -threaded or not? If not then you need another > trick to use cooperative scheduling between Gtk and the RTS. [snip] > You must not be using -threaded then I'm guessing. That'd solve the > problem. Actually I tried with all combinations of -threaded/not -threaded and forkIO/forkOS. I'm using an uniprocessor, but a simple turn-based game shouldn't depend on dual-cores anyway =). Yes, those freezes do seem rather strange, and when I introduced some (unsafePerformIO . putStrLn) with the wall time they magically disappeared. I didn't try to pursue those little insects further because I got the feeling that no mather what, they would come back. > > [...] using 'mainIteraction' [...] > That's pretty ugly. I'd avoid that if I were you. Yes. =) > Here's my suggestion: use two threads. One thread for the game logic and > one thread for communicating with the user interface. Then use an input > an output channel to post interesting events between the two. The GUI > would then also post interesting events into the incoming channel for > the view/ui thread. > > Of course you'd have to link using -threaded and use postGUISync/Async > as appropriate from the view/ui thread. > > By serialising all button events into a channel it allows you to ignore > button presses that happen at certain moments. And as I suggested above, > it allows you to serialise the output events so you don't end up showing > several dialogues to the user at once. It seems to be a nice idea. I worry about intermediate states that shouldn't be observable (in my game the inputs the user is allowed to give change over the time -- it's a board game, so which pieces can move vary according to the current board), but what concerns me more after that bad experience with only one forked thread are the delays between the user giving an input (e.g. moving a piece) and the feedback being given (an animation of the result). The chain would be something like input given --> processed --> new board created --> shown (1) (2) (3) (4) So the interaction between the threads would be gtk: (1) ===\ /===> (4) channel: \===\ /===/ runPromptM: \===> (2) ===> (3) ===/ I'll try to code that ASAP and see how everything works together. If I do observe the same delay problem, I'll try to at least reproduce it on another machine and maybe create a simple test case. Other than that, I'm surprised you didn't comment about the last solution, as that's where I'm currently heading. =) Thanks for the reply, -- Felipe. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080113/46cde269/attachment.htm From frr149 at easyjob.net Sun Jan 13 13:59:28 2008 From: frr149 at easyjob.net (Fernando Rodriguez) Date: Sun Jan 13 13:53:07 2008 Subject: [Haskell-cafe] Patterns overlapped? Message-ID: Hi, When I compile this code, ghc complains about some overlapped patterns in function depth. What on Earth is ghc talking about? O:-) data BinTree a = EmptyTree | NodeBT a (BinTree a) (BinTree a) deriving Show emptyBT = EmptyTree depth emptyBT = 0 depth (NodeBT _ left right) = max (1 + depth left) (1 + depth right) From allbery at ece.cmu.edu Sun Jan 13 14:02:31 2008 From: allbery at ece.cmu.edu (Brandon S. Allbery KF8NH) Date: Sun Jan 13 13:55:55 2008 Subject: [Haskell-cafe] Patterns overlapped? In-Reply-To: References: Message-ID: <80B0E87F-408B-4668-8B21-C227465FF511@ece.cmu.edu> On Jan 13, 2008, at 13:59 , Fernando Rodriguez wrote: > When I compile this code, ghc complains about some overlapped > patterns in function depth. What on Earth is ghc talking about? O:-) > > emptyBT = EmptyTree > > depth emptyBT = 0 > depth (NodeBT _ left right) = max (1 + depth left) (1 + depth right) If you use a variable in a pattern match, it creates a new binding which irrefutably matches the corresponding argument. In other words, you get a new local variable "emptyBT", ignoring your global. You must use the actual constructor instead. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH From frr149 at easyjob.net Sun Jan 13 14:05:07 2008 From: frr149 at easyjob.net (Fernando Rodriguez) Date: Sun Jan 13 13:58:50 2008 Subject: [Haskell-cafe] Re: Patterns overlapped? References: Message-ID: Hello Fernando, > Hi, > > When I compile this code, ghc complains about some overlapped patterns > in function depth. What on Earth is ghc talking about? O:-) > > data BinTree a = EmptyTree > | NodeBT a (BinTree a) (BinTree a) > deriving Show > emptyBT = EmptyTree > depth emptyBT = 0 > depth (NodeBT _ left right) = max (1 + depth left) (1 + depth right) Sorry, the exact error is: Warning: Pattern match(es) are overlapped In the definition of `depth': depth (NodeBT _ left right) = ... From allbery at ece.cmu.edu Sun Jan 13 14:06:55 2008 From: allbery at ece.cmu.edu (Brandon S. Allbery KF8NH) Date: Sun Jan 13 14:00:52 2008 Subject: [Haskell-cafe] Re: Patterns overlapped? In-Reply-To: References: Message-ID: On Jan 13, 2008, at 14:05 , Fernando Rodriguez wrote: >> depth emptyBT = 0 >> depth (NodeBT _ left right) = max (1 + depth left) (1 + depth right) > > Sorry, the exact error is: > Warning: Pattern match(es) are overlapped > In the definition of `depth': depth (NodeBT _ left right) = ... Right. emptyBT matches anything and stores it in a new local variable "emptyBT", so the second pattern overlaps this. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH From jerzy.karczmarczuk at info.unicaen.fr Sun Jan 13 14:09:18 2008 From: jerzy.karczmarczuk at info.unicaen.fr (jerzy.karczmarczuk@info.unicaen.fr) Date: Sun Jan 13 14:02:41 2008 Subject: [Haskell-cafe] Patterns overlapped? In-Reply-To: References: Message-ID: Fernando Rodriguez writes: > What on Earth is ghc talking about? O:-) (overlapping paterns) > emptyBT = EmptyTree > > depth emptyBT = 0 > depth (NodeBT _ left right) = max (1 + depth left) (1 + depth right) GHC is always right... Your first clause is GENERIC, the pattern is a variable, not a constant. Replace emptyBT by EmptyTree. Jerzy Karczmarczuk From frr149 at easyjob.net Sun Jan 13 14:23:12 2008 From: frr149 at easyjob.net (Fernando Rodriguez) Date: Sun Jan 13 14:17:04 2008 Subject: [Haskell-cafe] Re: Patterns overlapped? References: <80B0E87F-408B-4668-8B21-C227465FF511@ece.cmu.edu> Message-ID: Hello Brandon S. Allbery KF8NH, >> depth emptyBT = 0 >> depth (NodeBT _ left right) = max (1 + depth left) (1 + depth right) > If you use a variable in a pattern match, it creates a new binding > which irrefutably matches the corresponding argument. In other > words, you get a new local variable "emptyBT", ignoring your global. > You must use the actual constructor instead. I was wondering why depth always returned zero... Thanks. :-) From jerzy.karczmarczuk at info.unicaen.fr Sun Jan 13 14:32:22 2008 From: jerzy.karczmarczuk at info.unicaen.fr (jerzy.karczmarczuk@info.unicaen.fr) Date: Sun Jan 13 14:25:45 2008 Subject: [Haskell-cafe] Re: Patterns overlapped? In-Reply-To: References: Message-ID: Brian Sniffen writes: [[send to me as a private message, probably by mistake]] > Or, if you really want to use emptyBT for some reason, with > depth x | x == emptyBT = 0 > > -- > Brian T. Sniffen OK, but then it is necessary to define the Eq instance for the trees Jerzy Karczmarczuk From duncan.coutts at worc.ox.ac.uk Sun Jan 13 14:48:54 2008 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Sun Jan 13 14:42:20 2008 Subject: [Haskell-cafe] MonadPrompt + Gtk2Hs = ? In-Reply-To: References: <1200247301.5639.16.camel@localhost> Message-ID: <1200253734.5639.32.camel@localhost> On Sun, 2008-01-13 at 16:37 -0200, Felipe Lessa wrote: > On Jan 13, 2008 4:01 PM, Duncan Coutts > wrote: > > On Sun, 2008-01-13 at 14:53 -0200, Felipe Lessa wrote: > > Are you linking using -threaded or not? If not then you need another > > trick to use cooperative scheduling between Gtk and the RTS. > [snip] > > You must not be using -threaded then I'm guessing. That'd solve the > > problem. > > Actually I tried with all combinations of -threaded/not -threaded and > forkIO/forkOS. Use forkIO not forkOS. > I'm using an uniprocessor, but a simple turn-based game shouldn't > depend on dual-cores anyway =). Yes, those freezes do seem rather > strange, and when I introduced some (unsafePerformIO . putStrLn) with > the wall time they magically disappeared. Weirder. > I didn't try to pursue those little insects further because I got the > feeling that no mather what, they would come back. Is this unix or windows btw? > > > [...] using 'mainIteraction' [...] > > That's pretty ugly. I'd avoid that if I were you. > > Yes. =) > > > Here's my suggestion: use two threads. One thread for the game logic > and > > one thread for communicating with the user interface. [..] > It seems to be a nice idea. I worry about intermediate states that > shouldn't be observable (in my game the inputs the user is allowed to > give change over the time -- it's a board game, so which pieces can > move vary according to the current board), but what concerns me more > after that bad experience with only one forked thread are the delays > between the user giving an input ( e.g. moving a piece) and the > feedback being given (an animation of the result). The chain would be > something like > > input given --> processed --> new board created --> shown > (1) (2) (3) (4) > > So the interaction between the threads would be > > gtk: (1) ===\ /===> (4) > channel: \===\ /===/ > runPromptM: \===> (2) ===> (3) ===/ That should be fine. Haskell thread are quite sufficiently fast. The delays you're seeing are not because of general thread implementation slowness. > I'll try to code that ASAP and see how everything works together. If I > do observe the same delay problem, I'll try to at least reproduce it > on another machine and maybe create a simple test case. Good plan. If you're using -threaded make sure you really only ever call gui methods from event callbacks or within postGUISync/Async or things will go wrong in various random ways. In fact it might be a better idea to use the cooperative scheduling trick and make sure it works with the single threaded rts. > Other than that, I'm surprised you didn't comment about the last > solution, as that's where I'm currently heading. =) Oh sorry, I didn't get that far :-) It looks like it works a lot nicer so go with it :-). Remember, in general it is possible to switch between the console IO style where you're in control and the GUI event inversion of control style system. It's the thread/event duality thing. Duncan From hughperkins at gmail.com Sun Jan 13 14:59:06 2008 From: hughperkins at gmail.com (Hugh Perkins) Date: Sun Jan 13 14:52:28 2008 Subject: [Haskell-cafe] Possibilities for website construction using Haskell? Message-ID: <837db430801131159r6c9505dcq7115a9ad32673f78@mail.gmail.com> What are the possibilities for website construction using Haskell? From derek.a.elkins at gmail.com Sun Jan 13 14:13:05 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Sun Jan 13 15:07:01 2008 Subject: [Haskell-cafe] Possibilities for website construction using Haskell? In-Reply-To: <837db430801131159r6c9505dcq7115a9ad32673f78@mail.gmail.com> References: <837db430801131159r6c9505dcq7115a9ad32673f78@mail.gmail.com> Message-ID: <1200251585.5703.0.camel@derek-laptop> On Sun, 2008-01-13 at 20:59 +0100, Hugh Perkins wrote: > What are the possibilities for website construction using Haskell? http://hackage.haskell.org/packages/archive/pkg-list.html http://www.haskell.org/haskellwiki/Applications_and_libraries/Web_programming I'm sure you can figure it out from here, or at least come back with a more specific question. From hughperkins at gmail.com Sun Jan 13 15:26:51 2008 From: hughperkins at gmail.com (Hugh Perkins) Date: Sun Jan 13 15:20:14 2008 Subject: [Haskell-cafe] Possibilities for website construction using Haskell? In-Reply-To: <1200251585.5703.0.camel@derek-laptop> References: <837db430801131159r6c9505dcq7115a9ad32673f78@mail.gmail.com> <1200251585.5703.0.camel@derek-laptop> Message-ID: <837db430801131226u6c08541dp16f998ce7e73f2fe@mail.gmail.com> On Jan 13, 2008 8:13 PM, Derek Elkins wrote: > http://www.haskell.org/haskellwiki/Applications_and_libraries/Web_programming Good link. Lots of options apparently :-) > I'm sure you can figure it out from here, or at least come back with a > more specific question. Which ones are most widely used? HWS and Wash Server Pages sounds interesting? ... as does Haskell Server Pages ... and HASP... and .... Are there any popular websites using any of these technologies? Which technologies are most powerful? Which ones are easiest to use? Which ones are most stable? From dons at galois.com Sun Jan 13 15:33:01 2008 From: dons at galois.com (Don Stewart) Date: Sun Jan 13 15:26:29 2008 Subject: [Haskell-cafe] Possibilities for website construction using Haskell? In-Reply-To: <837db430801131226u6c08541dp16f998ce7e73f2fe@mail.gmail.com> References: <837db430801131159r6c9505dcq7115a9ad32673f78@mail.gmail.com> <1200251585.5703.0.camel@derek-laptop> <837db430801131226u6c08541dp16f998ce7e73f2fe@mail.gmail.com> Message-ID: <20080113203301.GA20928@scytale.galois.com> hughperkins: > On Jan 13, 2008 8:13 PM, Derek Elkins wrote: > > http://www.haskell.org/haskellwiki/Applications_and_libraries/Web_programming > > Good link. Lots of options apparently :-) > > > I'm sure you can figure it out from here, or at least come back with a > > more specific question. > > Which ones are most widely used? HWS and Wash Server Pages sounds interesting? > > ... as does Haskell Server Pages ... and HASP... and .... > > Are there any popular websites using any of these technologies? > Which technologies are most powerful? Which ones are easiest to use? > Which ones are most stable? The main tools I've seen real projects done in are: * HAppS (see hpaste.org) * fastcgi + xhtml + maybe some JSON (used for lots of things) * cgi + xhtml * WASH (see braintreehemp.com.au) So it depends on what you're comfortable with. -- Don From apfelmus at quantentunnel.de Sun Jan 13 15:49:49 2008 From: apfelmus at quantentunnel.de (apfelmus) Date: Sun Jan 13 15:43:34 2008 Subject: [Haskell-cafe] Re: MonadPrompt + Gtk2Hs = ? In-Reply-To: References: Message-ID: Felipe Lessa wrote: (abridged) > Ryan Ingram enlightened us with MonadPrompt as a very nice abstraction for > turn-based games, allowing easy programming and testing. > > I wonder how nicely it fits on a Gtk2Hs application. =) > > The problem lies in the fact that Gtk is event-driven, so > every time we ask the user for something, we have to wait for the > corresponding event that will bring us his answer. > > The standard way of solving the problem of running two sequential things at > once is using threads > [...]This not only feels hackish, but also doesn't scale very > well. > [...]This feels hackish and fragile as well, specially > because it is difficult to hunt down bugs. > > > But Prompt has a very *very* nice property we're missing to take advantage of > here: it's is *pure*. > > "If you wanted to add undo, all you have to do is save off the current Prompt > in the middle of runPromptM; you can return to the old state at any time." > > Eventually this feature rang some bells: you can save not only when you > want to undo, but also when you want to ask something to the user. > > let's see how: > >> lastAttempt :: AttemptCode >> lastAttempt showInfo entry button = do >> game <- guessGameNew >> runPromptM' game >> where >> -- Signature required >> runPromptM' :: Prompt GuessP Int -> IO () -- note: not (IO Int)! >> runPromptM' (Prompt (Print s) c) = showInfo s >> runPromptM' (c ()) >> runPromptM' (Prompt Guess c) = do >> mfix $ \cid -> do >> let cont guess = do {signalDisconnect cid; >> runPromptM' (c $ read guess)} >> onClicked button $ entryGetText entry >>= cont >> return () >> runPromptM' (PromptDone attempts) = do >> showInfo $ "You took " ++ show attempts ++ " attempts." > > No threads, no MVars, no nothing. > No freezes, no races, no exceptions, no overheads. Marvelous work! Here's a short summary: The general idea was to implement a game in a modular way, namely such that the game and interaction logic is written in a separate monad which can be "plugged" into different interfaces like command line, undo, GUI etc. . MonadPrompt (aka the free monad) lets you do exactly that. Command line is straightforward, Ryan showed how to do undo and Felipe's post shows how to do it in a GUI framework which are notorious for being event-based and thus a tricky target for this particular task. The insight is that the actions from the MonadPrompt like Prompt Guess c or Prompt (Print s) c *are* the game state. What to do in the state Prompt Guess c -- some function c ? Well, we wait for the user to press a button, and then we feed the text he entered in some text field to c which advances the game to a new state. More precisely, we register a button event for that and return control to the GUI framework for the waiting. What to do with a monadic value Prompt (Print s) c ? Well, we print the message and immediately proceed with c , i.e. without waiting for user input this time. In the end, the only unusual thing about our game state is that it already know how to continue, namely via the continuation c . Felipe explored another option, namely to run the game monad in a thread that communicates with a separate GUI thread. Conceptually, this is closer to the feeling of the game monad, namely that it "runs through". But getting the communication between threads right is a nightmare. And in a sense, /threads are exactly the abstraction we wanted to implement in the first place/, only with more problems. How are threads themselves implemented? Well, in essence, the scheduler which runs threads just sees states like Prompt ReadMVar c -- this thread waits for a message Prompt (PutMVar x) c -- dispatch a message and proceed and evolves them. Of course, ghc's threads are closer to the machine and hence more fine-grained than that (pure computations can be suspended) with corresponding advantages (more interleaving, good for staying responsive while doing work) and drawbacks (loss of atomicity). The reader may want to try to implement his own (toy-) thread library with Prompt . Solution here: K. Claessen. Poor man's concurrency monad. http://www.cs.chalmers.se/~koen/pubs/jfp99-monad.ps For less "toy", see also P. Li, S. Zdancewic. Combining events and threads for scalable network services. http://www.seas.upenn.edu/~lipeng/homepage/papers/lz07pldi.pdf Maybe the property that distinguishes the harmless game monad from the dreaded threads is: they have forks. :) I mean, threads run in parallel and can/need to communicate and spawn whereas the game monad runs as one and is unable to soliloquize. > Eventually this feature rang some bells: you can save not only when you > want to undo, but also when you want to ask something to the user. > Unfortunately, I still haven't come up with a nice higher order function > that generalizes this work without reinventing Prompt on an isomorphic type. Oh, what kind of generalization do you have in mind? Regards, apfelmus From ndmitchell at gmail.com Sun Jan 13 16:13:17 2008 From: ndmitchell at gmail.com (Neil Mitchell) Date: Sun Jan 13 16:06:40 2008 Subject: [Haskell-cafe] Possibilities for website construction using Haskell? In-Reply-To: <20080113203301.GA20928@scytale.galois.com> References: <837db430801131159r6c9505dcq7115a9ad32673f78@mail.gmail.com> <1200251585.5703.0.camel@derek-laptop> <837db430801131226u6c08541dp16f998ce7e73f2fe@mail.gmail.com> <20080113203301.GA20928@scytale.galois.com> Message-ID: <404396ef0801131313p5277825y2adfd4227c04f848@mail.gmail.com> Hi > > Which ones are most widely used? HWS and Wash Server Pages sounds interesting? Hoogle (http://haskell.org/hoogle) uses Haskell Source Extensions (http://www.cs.chalmers.se/~d00nibro/haskell-src-exts/) My academic website (http://www-users.cs.york.ac.uk/~ndm/) uses some custom code (http://www-users.cs.york.ac.uk/~ndm/Main.hs) Thanks Neil From dons at galois.com Sun Jan 13 16:18:33 2008 From: dons at galois.com (Don Stewart) Date: Sun Jan 13 16:11:58 2008 Subject: [Haskell-cafe] Possibilities for website construction using Haskell? In-Reply-To: <404396ef0801131313p5277825y2adfd4227c04f848@mail.gmail.com> References: <837db430801131159r6c9505dcq7115a9ad32673f78@mail.gmail.com> <1200251585.5703.0.camel@derek-laptop> <837db430801131226u6c08541dp16f998ce7e73f2fe@mail.gmail.com> <20080113203301.GA20928@scytale.galois.com> <404396ef0801131313p5277825y2adfd4227c04f848@mail.gmail.com> Message-ID: <20080113211833.GC20928@scytale.galois.com> ndmitchell: > Hi > > > > Which ones are most widely used? HWS and Wash Server Pages sounds interesting? > > Hoogle (http://haskell.org/hoogle) uses Haskell Source Extensions > (http://www.cs.chalmers.se/~d00nibro/haskell-src-exts/) I thought haskell-src-exts was an extended Language.Haskell parser? Do you mean HSP -- haskell server pages? > My academic website (http://www-users.cs.york.ac.uk/~ndm/) uses some > custom code (http://www-users.cs.york.ac.uk/~ndm/Main.hs) So that's CGI, or offline page generation? -- Don From ndmitchell at gmail.com Sun Jan 13 16:27:14 2008 From: ndmitchell at gmail.com (Neil Mitchell) Date: Sun Jan 13 16:20:37 2008 Subject: [Haskell-cafe] Possibilities for website construction using Haskell? In-Reply-To: <20080113211833.GC20928@scytale.galois.com> References: <837db430801131159r6c9505dcq7115a9ad32673f78@mail.gmail.com> <1200251585.5703.0.camel@derek-laptop> <837db430801131226u6c08541dp16f998ce7e73f2fe@mail.gmail.com> <20080113203301.GA20928@scytale.galois.com> <404396ef0801131313p5277825y2adfd4227c04f848@mail.gmail.com> <20080113211833.GC20928@scytale.galois.com> Message-ID: <404396ef0801131327r25d91a66u71d530f765a38356@mail.gmail.com> Hi > > Hoogle (http://haskell.org/hoogle) uses Haskell Source Extensions > > (http://www.cs.chalmers.se/~d00nibro/haskell-src-exts/) > > I thought haskell-src-exts was an extended Language.Haskell parser? > Do you mean HSP -- haskell server pages? No, I mean haskell-src-exts. It's a translator from Haskell with embedded XML to pure Haskell. > > My academic website (http://www-users.cs.york.ac.uk/~ndm/) uses some > > custom code (http://www-users.cs.york.ac.uk/~ndm/Main.hs) > > So that's CGI, or offline page generation? Offline page generation. Thanks Neil From dot at dotat.at Sun Jan 13 16:27:52 2008 From: dot at dotat.at (Tony Finch) Date: Sun Jan 13 16:21:15 2008 Subject: [Haskell-cafe] hash-cons Message-ID: I've been thinking about hashlife recently. I've written part of a fairly didactic C implementation but I there are more interesting things that can be done with it. In particular, the core calc2() function is essentially implementing lazy evaluation, so it ought to be possible to write it even more nicely in Haskell. However it relies crucially on a hash-cons aka intern aka memoized constructor find(). How can one implement this in Haskell? Google doesn't turn up anything very helpful. If I can solve the hash cons problem, then it ought to be fairly straightforward to use Parallel Haskell to speed up the algorithm on multicore machines. Tony. -- f.a.n.finch http://dotat.at/ PORTLAND: SOUTH 7 TO SEVERE GALE 9 VEERING SOUTHWEST 5 TO 7. ROUGH OR VERY ROUGH. RAIN AT FIRST, THEN SQUALLY SHOWERS. MODERATE OR GOOD. From dons at galois.com Sun Jan 13 16:48:15 2008 From: dons at galois.com (Don Stewart) Date: Sun Jan 13 16:41:43 2008 Subject: [Haskell-cafe] Possibilities for website construction using Haskell? In-Reply-To: <404396ef0801131327r25d91a66u71d530f765a38356@mail.gmail.com> References: <837db430801131159r6c9505dcq7115a9ad32673f78@mail.gmail.com> <1200251585.5703.0.camel@derek-laptop> <837db430801131226u6c08541dp16f998ce7e73f2fe@mail.gmail.com> <20080113203301.GA20928@scytale.galois.com> <404396ef0801131313p5277825y2adfd4227c04f848@mail.gmail.com> <20080113211833.GC20928@scytale.galois.com> <404396ef0801131327r25d91a66u71d530f765a38356@mail.gmail.com> Message-ID: <20080113214815.GD20928@scytale.galois.com> ndmitchell: > Hi > > > > Hoogle (http://haskell.org/hoogle) uses Haskell Source Extensions > > > (http://www.cs.chalmers.se/~d00nibro/haskell-src-exts/) > > > > I thought haskell-src-exts was an extended Language.Haskell parser? > > Do you mean HSP -- haskell server pages? > > No, I mean haskell-src-exts. It's a translator from Haskell with > embedded XML to pure Haskell. > > > > My academic website (http://www-users.cs.york.ac.uk/~ndm/) uses some > > > custom code (http://www-users.cs.york.ac.uk/~ndm/Main.hs) > > > > So that's CGI, or offline page generation? > > Offline page generation. Hugh asked on #haskell about how to do offline / cgi with xhtml combinators, I threw together a little example (since it seems this isn't widely known): import Text.XHtml.Transitional import System.Environment import System.Time main = do time <- getClockTime putStrLn . prettyHtml $ (header (thetitle (toHtml "testing"))) +++ (body $ (center $ h2 (toHtml (hotlink "http://haskell.org" (toHtml "Haskell is fun")))) +++ toHtml (show time)) Generates this page, http://galois.com/~dons/tmp/test.html Note that using string overloading we can remove some of the toHtml's... {-# LANGUAGE OverloadedStrings #-} instance IsString Html where fromString = toHtml main = do time <- getClockTime putStrLn . prettyHtml $ (header (thetitle "testing")) +++ (body $ center $ h2 (toHtml (hotlink "http://haskell.org" "Haskell is fun"))) +++ show time Cheers, Don From bf3 at telenet.be Sun Jan 13 16:15:22 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Sun Jan 13 16:54:21 2008 Subject: [Haskell-cafe] Possibility to port vshaskell to VS2008? In-Reply-To: <001301c8560f$cc227e90$64677bb0$@de> References: <001301c8560f$cc227e90$64677bb0$@de> Message-ID: <1200258922.3530.4.camel@localhost.localdomain> It might be even better to port it to the freely available downloadable Visual Studio Shell: http://msdn2.microsoft.com/en-us/vsx2008/products/bb933751.aspx The F# plugin works for that environment, giving a very good free IDE. Cheers, Peter (on Fedora 8 using, woohoo, my first steps on Linux :) On Sun, 2008-01-13 at 19:12 +0100, Philipp Riemer wrote: > Because my university is in the MSNDAA-program I could download the new > Visual Studio 2008 Professional, what I've done today. Now I tried to > install the vshaskell-extension to start learning Haskell but the installer > only quits with the message that (of course) VS2005 is not installed. Now is > my question if I have to download the "old" VS2005 or if it is somehow > possible to get this extension running with VS9.0? > > I already tried to use the EclipseFP-plugin so I already have (win)hugs, ghc > and haddoc installed (if it helps for the problem above). > > The problem with this plugin was that Ctrl+Space does apparently not work > for code hints and because I'm just started to learn the language, I don't > know every keyword... So I have to look it up everytime somewhere, I want to > implement something new. The fact that Prelude.hs and others are plain text > are a great help, but what I have seen in the screenshot at > http://www.haskell.org/visualhaskell/screenshots.html would be much > better... > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From hughperkins at gmail.com Sun Jan 13 17:18:53 2008 From: hughperkins at gmail.com (Hugh Perkins) Date: Sun Jan 13 17:12:16 2008 Subject: [Haskell-Cafe] Add "number of downloads" to hackageDB page? Message-ID: <837db430801131418v5e4d5ebehe096d7f57f6f6392@mail.gmail.com> I seem to remember a thread about this a while back actually, but... Any chance of adding the number of downloads to the hackageDB page? For those packages that are included in ghc, hugs etc, perhaps add a green tick with "included in ghc", "included in hugs", etc? That way it should be relatively easier to know for newbies which packages are more or less mature/stable. Optional: perhaps include a tick-box/dropdown to only show packages with more than a certain (configurable) number of downloads? From anton at appsolutions.com Sun Jan 13 17:23:08 2008 From: anton at appsolutions.com (Anton van Straaten) Date: Sun Jan 13 17:15:18 2008 Subject: [Haskell-cafe] Possibilities for website construction using Haskell? In-Reply-To: <20080113214815.GD20928@scytale.galois.com> References: <837db430801131159r6c9505dcq7115a9ad32673f78@mail.gmail.com> <1200251585.5703.0.camel@derek-laptop> <837db430801131226u6c08541dp16f998ce7e73f2fe@mail.gmail.com> <20080113203301.GA20928@scytale.galois.com> <404396ef0801131313p5277825y2adfd4227c04f848@mail.gmail.com> <20080113211833.GC20928@scytale.galois.com> <404396ef0801131327r25d91a66u71d530f765a38356@mail.gmail.com> <20080113214815.GD20928@scytale.galois.com> Message-ID: <478A8F4C.4080805@appsolutions.com> Don Stewart wrote: > Note that using string overloading we can remove some of the toHtml's... > > {-# LANGUAGE OverloadedStrings #-} > > instance IsString Html where fromString = toHtml > > main = do > time <- getClockTime > > putStrLn . prettyHtml $ > (header (thetitle "testing")) > +++ > (body $ > center $ > h2 (toHtml (hotlink "http://haskell.org" "Haskell is fun"))) > +++ show time You can also eliminate the toHtmls by using the "<<" operator defined by XHTML. It has type (HTML a) => (Html -> b) -> a -> b, where HTML is a type class which has strings, among other things, already defined as instances. So the above can be written as follows, without an additional string overloading: main = do time <- getClockTime putStrLn . prettyHtml $ (header (thetitle << "testing")) +++ (body $ (center $ h2 << (hotlink "http://haskell.org" << "Haskell is fun")) +++ p << show time) (Wrapping the time in an HTML element like a paragraph allows the use of << to "fill" the paragraph.) Anton From andy at nobugs.org Sun Jan 13 17:34:05 2008 From: andy at nobugs.org (Andrew Birkett) Date: Sun Jan 13 17:27:21 2008 Subject: [Haskell-cafe] Yi editor tutorial Message-ID: <478A91DD.1020403@nobugs.org> Hi, I've recently started using Yi, the haskell editor. I found it slightly non-trivial to get started, so I've written up my installation method and a "beginners guide" tutorial which I hope will be of interest to other people who'd like to try Yi. It lives at: http://nobugs.org/developer/yi/ Let me know if it's useful or if you have suggestions (to andy@nobugs.org) Andrew -- - http://www.nobugs.org - From ndmitchell at gmail.com Sun Jan 13 18:12:52 2008 From: ndmitchell at gmail.com (Neil Mitchell) Date: Sun Jan 13 18:06:13 2008 Subject: [Haskell-cafe] All equations must have the same arity - why? Message-ID: <404396ef0801131512j69927949g1dcaed2884e31890@mail.gmail.com> Hi, It's nice to write functions in point free style: f = sort . nub But sometimes I have to add an extra case, on a certain value: f [] = [1] f = sort . nub But now these equations have different arities, and its rejected by Haskell. Why does this not simply desugar to: f [] = [1] f x = (sort . nub) x i.e. lift the arities to the longest argument list. Is there a reason this isn't done? Thanks Neil From duncan.coutts at worc.ox.ac.uk Sun Jan 13 18:19:41 2008 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Sun Jan 13 18:13:06 2008 Subject: [Haskell-Cafe] Add "number of downloads" to hackageDB page? In-Reply-To: <837db430801131418v5e4d5ebehe096d7f57f6f6392@mail.gmail.com> References: <837db430801131418v5e4d5ebehe096d7f57f6f6392@mail.gmail.com> Message-ID: <1200266381.5639.60.camel@localhost> On Sun, 2008-01-13 at 23:18 +0100, Hugh Perkins wrote: > I seem to remember a thread about this a while back actually, but... > > Any chance of adding the number of downloads to the hackageDB page? > > For those packages that are included in ghc, hugs etc, perhaps add a > green tick with "included in ghc", "included in hugs", etc? > > That way it should be relatively easier to know for newbies which > packages are more or less mature/stable. That is indeed the highest priority for hackage at the moment, that is, getting enough information onto the hackage pages for people to make sensible decisions about what packages to choose. This is also closely related to measuring package QA, ie what packages work on what platforms. > Optional: perhaps include a tick-box/dropdown to only show packages > with more than a certain (configurable) number of downloads? There are loads of great ideas like these floating around and we've had a few discussions on what the most important ones are and how to go about implementing them. The block to progress is enough people with enough time to actually implement these suggestions. So let me take this opportunity to invite everyone who is interested in improving hackage to speak up. If you're interested you should: * Join the cabal-devel mailing list * Take a look at the feature requests in the hackage trac and make sure all your suggestions are properly documented * Post to cabal-devel to say that you're interested and we can discuss things in more detail and suggest where to start and what approach to take http://www.haskell.org/mailman/listinfo/cabal-devel http://hackage.haskell.org/trac/hackage At the moment I am particularly keen on the idea of getting cabal-install to send build reports back to the hackage server and then using that information to show what packages work on what platforms (where platform is the os, compiler version etc etc). So if someone is interested in helping with that then do get in touch. Duncan From conal at conal.net Sun Jan 13 18:46:14 2008 From: conal at conal.net (Conal Elliott) Date: Sun Jan 13 18:39:36 2008 Subject: [Haskell-cafe] All equations must have the same arity - why? In-Reply-To: <404396ef0801131512j69927949g1dcaed2884e31890@mail.gmail.com> References: <404396ef0801131512j69927949g1dcaed2884e31890@mail.gmail.com> Message-ID: That eta-expansion desugaring would lose sharing. Offhand, I don't know of a desugaring that would do the trick and preserve sharing. Any ideas? - Conal On Jan 13, 2008 3:12 PM, Neil Mitchell wrote: > Hi, > > It's nice to write functions in point free style: > > f = sort . nub > > But sometimes I have to add an extra case, on a certain value: > > f [] = [1] > f = sort . nub > > But now these equations have different arities, and its rejected by > Haskell. Why does this not simply desugar to: > > f [] = [1] > f x = (sort . nub) x > > i.e. lift the arities to the longest argument list. > > Is there a reason this isn't done? > > Thanks > > Neil > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080113/02537de9/attachment.htm From ajb at spamcop.net Sun Jan 13 18:53:01 2008 From: ajb at spamcop.net (ajb@spamcop.net) Date: Sun Jan 13 18:46:23 2008 Subject: [Haskell-cafe] All equations must have the same arity - why? In-Reply-To: <404396ef0801131512j69927949g1dcaed2884e31890@mail.gmail.com> References: <404396ef0801131512j69927949g1dcaed2884e31890@mail.gmail.com> Message-ID: <20080113185301.2hv0ovu8048scs8s@webmail.spamcop.net> G'day all. Quoting Neil Mitchell : > It's nice to write functions in point free style: > > f = sort . nub > > But sometimes I have to add an extra case, on a certain value: > > f [] = [1] > f = sort . nub > > But now these equations have different arities, and its rejected by > Haskell. I don't know why Haskell does it specifically, but here's why I like the behaviour: 1. Equations with different arities more often signal bugs than correct intentions. One common situation is adding an argument to a function, and accidentally leaving one equation out. 2. It's highly misleading. This: f [] = [1] f = sort . nub suggests that f is (sort . nub), which is most decidedly is not. By forcing you to add the argument: f [] = [1] f xs = sort . num $ xs it reminds you more strongly that what you're actually writing is a shorthand for this: f [] = [1] f xs@(_:_) = sort . num $ xs Cheers, Andrew Bromage From ajb at spamcop.net Sun Jan 13 18:58:36 2008 From: ajb at spamcop.net (ajb@spamcop.net) Date: Sun Jan 13 18:51:57 2008 Subject: [Haskell-cafe] All equations must have the same arity - why? In-Reply-To: References: <404396ef0801131512j69927949g1dcaed2884e31890@mail.gmail.com> Message-ID: <20080113185836.hxwaw43728skow4s@webmail.spamcop.net> G'day all. Quoting Conal Elliott : > That eta-expansion desugaring would lose sharing. Offhand, I don't know of > a desugaring that would do the trick and preserve sharing. Any ideas? How about this? f = let body = sort . nub in \xs -> case xs of [] -> [1] (_:_) -> body I suspect we're well out of the territory of mere "desugaring" here, though. Cheers, Andrew Bromage From jonathanccast at fastmail.fm Sun Jan 13 19:15:33 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Sun Jan 13 19:08:56 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False In-Reply-To: <20080112082519.4e7d81f2@solaris.tower> References: <2608b8a80801100117wda28551ida0166f548147aac@mail.gmail.com> <20080110201613.GA30239@momenergy.repetae.net> <20080110212434.07e18eb8@solaris.tower> <20080110202724.GO28763@darcs.net> <20080110214153.46ad3395@solaris.tower> <20080110205220.GR28763@darcs.net> <20080110220408.47186b19@solaris.tower> <87k5mgsm31.fsf@nmd9999.imr.no> <20080111145420.1c82c377@solaris.tower> <20080111170335.GH27808@darcs.net> <20080111191247.55ab360d@solaris.tower> <51AF6510-6CC0-4D8A-94AA-D704CE47510A@fastmail.fm> <20080112082519.4e7d81f2@solaris.tower> Message-ID: <4735145B-EC5C-4320-864E-2E242A079140@fastmail.fm> On 11 Jan 2008, at 11:25 PM, Achim Schneider wrote: > Jonathan Cast wrote: > >> On 11 Jan 2008, at 10:12 AM, Achim Schneider wrote: >> >>> David Roundy wrote: >>> >>>> Prelude> let x=1e-300/1e300 >>>> Prelude> x >>>> 0.0 >>>> Prelude> x/x >>>> NaN >>>> >>>> The "true" answer here is that x/x == 1.0 (not 0 or +Infinity), but >>>> there's no way for the computer to know this, so it's NaN. >> >> Didn't catch this the first time around, but: only to a physicist. >> (I mean no disrespect to the author of darcs, but nevertheless the >> point stands). Back in the real world, 0 / 0 may be defined >> arbitrarily, or left undefined. (Defining it breaks the wonderful >> property that, if lim (xn) = x, lim (yn) = y, and x/y = z, then lim >> (xn / yn) = z. This is considered a Bad Thing by real >> mathematicians). In fact, in integration theory 0 * inf = 0 for >> certain 'multiplications', which gives the lie to 0 / 0. > > whereas lim( 0 ) * lim( inf ) is anything you want, or, more > precisely, > the area of the thing you started with. I think you're thinking of the Riemann integral (I was thinking of the Lebesgue integral, and in particular the definition of the integral for step functions). That integral can be informally characterized as the sum of infinitely many terms, each zero (it's a limit of finite sums, where the largest (in the sense of absolute value) term in each sum goes to 0 as the sequence proceeds). That's scarcely a rigorous characterization, and it overlooks a ton of issues (like the fact that neither an infinite sum nor a sum identically 0 terms is actually involved), and it's scarcely relevant to the numerical analysis question of what 0/0 should return except to point out that any definition is going to make *somebody*'s algorithm silently go wrong... jcc From barsoap at web.de Sun Jan 13 19:15:34 2008 From: barsoap at web.de (Achim Schneider) Date: Sun Jan 13 19:09:13 2008 Subject: [Haskell-cafe] Re: All equations must have the same arity - why? References: <404396ef0801131512j69927949g1dcaed2884e31890@mail.gmail.com> Message-ID: <20080114011534.797e9a89@solaris.tower> "Neil Mitchell" wrote: > i.e. lift the arities to the longest argument list. > > Is there a reason this isn't done? > Most likely not, there are being made up right now. Because f = sort.nub is different from f x = (\x -> sort.nub x) or f = sort.nub.id or f = sort.nub.id.id.id.id.id.id , and such behaviour would confuse the hell out of me as well as seriously hurt my sense of semantic aesthetics, even if it's just no-ops. Or the same lambda term, which is exactly my point. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From barsoap at web.de Sun Jan 13 19:18:31 2008 From: barsoap at web.de (Achim Schneider) Date: Sun Jan 13 19:13:28 2008 Subject: [Haskell-cafe] Re: All equations must have the same arity - why? References: <404396ef0801131512j69927949g1dcaed2884e31890@mail.gmail.com> <20080114011534.797e9a89@solaris.tower> Message-ID: <20080114011831.77588553@solaris.tower> Achim Schneider wrote: > Most likely not, there are being made up right now. > s/there/they/ > f x = (\x -> sort.nub x) > s/x// -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From jonathanccast at fastmail.fm Sun Jan 13 19:20:23 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Sun Jan 13 19:13:47 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False In-Reply-To: <200801121127.m0CBRX3E023254@mi0.bluebottle.com> References: <20080110220408.47186b19@solaris.tower> <87k5mgsm31.fsf@nmd9999.imr.no> <20080111145420.1c82c377@solaris.tower> <20080111170335.GH27808@darcs.net> <20080111191247.55ab360d@solaris.tower> <51AF6510-6CC0-4D8A-94AA-D704CE47510A@fastmail.fm> <20080112082519.4e7d81f2@solaris.tower> <200801120920.m0C9KXdT009948@mi1.bluebottle.com> <20080112104517.411627aa@solaris.tower> <20080112112432.674dcaff@solaris.tower> <200801121127.m0CBRX3E023254@mi0.bluebottle.com> Message-ID: <720E886C-9817-4006-B034-23F4911149E1@fastmail.fm> On 12 Jan 2008, at 3:23 AM, Kalman Noel wrote: > Achim Schneider wrote: >> Actually, lim( 0 ) * lim( inf ) isn't anything but equals one, and >> the anything is defined to one (or, rather, is _one_ anything) to be >> able to use the abstraction. It's a bit like the difference between >> eight pens and a box of pens. If someone knows how to properly >> formalise n = 1, please speak up. > > Sorry if I still don't follow at all. That's ok, neither does he. > Here is how I understand (i. e. > have learnt) lim notation, with n ? N, a_n ? R. (Excuse my poor > terminology, I have to translate this in my mind from German maths > language ;-). OK so far. I actually had a professor in uni who would randomly switch to German during lectures; I'll do my best to follow your notation :) > My point of posting this is that I don't see how to > accommodate the lim notation as I know it with your term. The limit of > infinity? What is the limit of infinity, If you extend your concept of `sequence' to include sequences of extended real numbers, the limit of the sequence that is identically inf is inf. Otherwise, the notation isn't really meaningful. > and why should I multiplicate > it with 0? Why should I get 1? > > (1) lim a_n = a (where a ? R) > (2) lim a_n = ? > (3) lim a_n = ? ? > (4) lim { x ? x0 } f(x) = y (where f is a function into R) > > (1) means that the sequence of reals a_n converges towards a. > > (2) means that the sequence does not converge, To a value in R. Again, inf is a perfectly well defined extended real number, and behaves like any other element of R u {-inf, inf}. (Although that structure isn't quite a field --- 0 * inf isn't defined, nor is inf - inf). > because you can > always find a value that is /larger/ than what you hoped might > be the limit. > > (3) means that the sequence does not converge, because you can > always find a value that is /smaller/ than what you hoped > might > be the limit. > > (4) means that for any sequence of reals (x_n ? dom f) > converging > towards x0, we have lim f(x_n) = y. For this equation > again, we > have the three cases above. jcc From jonathanccast at fastmail.fm Sun Jan 13 19:21:59 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Sun Jan 13 19:15:23 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False In-Reply-To: References: <20080110220408.47186b19@solaris.tower> <87k5mgsm31.fsf@nmd9999.imr.no> <20080111145420.1c82c377@solaris.tower> <20080111170335.GH27808@darcs.net> <20080111191247.55ab360d@solaris.tower> <51AF6510-6CC0-4D8A-94AA-D704CE47510A@fastmail.fm> <20080112082519.4e7d81f2@solaris.tower> <200801120920.m0C9KXdT009948@mi1.bluebottle.com> <20080112104517.411627aa@solaris.tower> <20080112112432.674dcaff@solaris.tower> <200801121127.m0CBRX3E023254@mi0.bluebottle.com> Message-ID: <0EF136E2-687B-4CFA-9B74-12AAB62B4240@fastmail.fm> On 12 Jan 2008, at 3:33 AM, Cristian Baboi wrote: > On Sat, 12 Jan 2008 13:23:41 +0200, Kalman Noel > wrote: > >> Achim Schneider wrote: >>> Actually, lim( 0 ) * lim( inf ) isn't anything but equals one, and >>> the anything is defined to one (or, rather, is _one_ anything) to be >>> able to use the abstraction. It's a bit like the difference between >>> eight pens and a box of pens. If someone knows how to properly >>> formalise n = 1, please speak up. >> >> Sorry if I still don't follow at all. Here is how I understand >> (i. e. >> have learnt) lim notation, with n ? N, a_n ? R. (Excuse my poor >> terminology, I have to translate this in my mind from German maths >> language ;-). My point of posting this is that I don't see how to >> accommodate the lim notation as I know it with your term. The >> limit of >> infinity? What is the limit of infinity, and why should I >> multiplicate >> it with 0? Why should I get 1? >> >> (1) lim a_n = a (where a ? R) >> (2) lim a_n = ? >> (3) lim a_n = ? ? >> (4) lim { x ? x0 } f(x) = y (where f is a function into R) >> >> (1) means that the sequence of reals a_n converges towards a. >> >> (2) means that the sequence does not converge, because you can >> always find a value that is /larger/ than what you hoped >> might >> be the limit. >> (3) means that the sequence does not converge, because you can >> always find a value that is /smaller/ than what you hoped >> might >> be the limit. >> >> (4) means that for any sequence of reals (x_n ? dom f) >> converging >> towards x0, we have lim f(x_n) = y. For this equation >> again, we >> have the three cases above. > > Suppose lim a_n = a , lim b_n = b, c_2n = a_n, c_2n+1 = b_n. > > What is lim c_n ? If a = b, lim c_n = a = b. Otherwise lim c_n is undefined, in the sense that there is no number c such that the assertion lim c_n = c is true. The `=' in this assertion isn't an equality; it's just a bit of math syntax, used in the special case where it isn't overly confusing. jcc From jonathanccast at fastmail.fm Sun Jan 13 19:25:42 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Sun Jan 13 19:19:06 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False In-Reply-To: <20080112130631.45bcfc68@solaris.tower> References: <20080110220408.47186b19@solaris.tower> <87k5mgsm31.fsf@nmd9999.imr.no> <20080111145420.1c82c377@solaris.tower> <20080111170335.GH27808@darcs.net> <20080111191247.55ab360d@solaris.tower> <51AF6510-6CC0-4D8A-94AA-D704CE47510A@fastmail.fm> <20080112082519.4e7d81f2@solaris.tower> <200801120920.m0C9KXdT009948@mi1.bluebottle.com> <20080112104517.411627aa@solaris.tower> <20080112112432.674dcaff@solaris.tower> <200801121127.m0CBRX3E023254@mi0.bluebottle.com> <20080112130631.45bcfc68@solaris.tower> Message-ID: On 12 Jan 2008, at 4:06 AM, Achim Schneider wrote: > Kalman Noel wrote: > >> Achim Schneider wrote: >>> Actually, lim( 0 ) * lim( inf ) isn't anything but equals one, and >>> the anything is defined to one (or, rather, is _one_ anything) to be >>> able to use the abstraction. It's a bit like the difference between >>> eight pens and a box of pens. If someone knows how to properly >>> formalise n = 1, please speak up. >> >> Sorry if I still don't follow at all. Here is how I understand >> (i. e. >> have learnt) lim notation, with n ? N, a_n ? R. (Excuse my poor >> terminology, I have to translate this in my mind from German maths >> language ;-). My point of posting this is that I don't see how to >> accommodate the lim notation as I know it with your term. The >> limit of >> infinity? What is the limit of infinity, and why should I >> multiplicate it with 0? Why should I get 1? >> > > n * n = 1 where > > lim lim > n -> 0 n -> oo wtf? > > > > You don't get 1, you start off with it. If you start off with anything, you can often end up with it as well. Enlightenment comes when you realize that sometimes you don't, and you acquire the ability to change your mind. > If you want to find the area > of a function, Under, not of. > you slice 1^2 into infinitely many parts and then look > how much every single slice differs from lim( 0 ) * 1 Beg pardon? lim(0) = 0. lim(0) * 1 = 0. > , all that > lim( inf ) many times. You can't do this. lim(inf) = inf is an extended real number, and is completely unrelated to aleph_0 = the least upper bound of N. inf is not a cardinality and cannot be a number of times. > When you've finished counting pebble, you know > how to scale this 1^2 to match it with your "normal" value of 1. > > n = 12 > n = 1 * n > > now, 1 is twelve. QED: The wrath of algebra. `Algebra' > "One" as a pure concept is > a very strange beast, as it can mean anything. To you. Mathematicians assign a different meaning to the concept. > jcc From jonathanccast at fastmail.fm Sun Jan 13 19:27:58 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Sun Jan 13 19:21:22 2008 Subject: [Haskell-cafe] Re: All equations must have the same arity - why? In-Reply-To: <20080114011534.797e9a89@solaris.tower> References: <404396ef0801131512j69927949g1dcaed2884e31890@mail.gmail.com> <20080114011534.797e9a89@solaris.tower> Message-ID: On 13 Jan 2008, at 4:15 PM, Achim Schneider wrote: > "Neil Mitchell" wrote: > >> i.e. lift the arities to the longest argument list. >> >> Is there a reason this isn't done? >> > Most likely not, there are being made up right now. I'm glad you are capable of ever so nobly assigning the purest imaginable motives to the designers of Haskell. You are an inspiration to us all. jcc From marco-oweber at gmx.de Sun Jan 13 19:57:00 2008 From: marco-oweber at gmx.de (Marc Weber) Date: Sun Jan 13 19:50:23 2008 Subject: [Haskell-cafe] jumping to code every and anywhere : what about installing tagfile and source ? Message-ID: <20080114005700.GC26840@gmx.de> I feel this is the right place to think about this? (I'll crosspost a small announcement on ghc as well pointing to this thread) Copied from http://hackage.haskell.org/trac/hackage/ticket/207#preview: == Introduction == I personally depend on tags because the source code only tells what is really going on. So it would be incredible useful to not only get information using ghci after loading libs but also beeing able to jump to all functions you might be using anywhere (The only solution providing this in all cases is uning tags, right? Because cpp defines can introduce new functions.. To be able to jump to the code source must be installed along with libs (the way you can optionally install haddock docs) == Use case: == setup configure --with-tags --install-source (or something like that) setup build && setup install do this for each dependency given in the .cabal file (VIM:) let tags+=system('ghc-pkg --query-tagfile-location haskell98-1.0.0.0') == Issues: == * Which tool to generate tag files? * ghc(i) when targeting ghc * the hasktags program shipping with ghc * some others? * Tagfile path type relative or absolute? * absolute: After moving/ installing the sources the tagfile must be patched * relative: Do editors take the right base directory to find source files? * When to invoke the tagfile generating program? * Perfect case would be after all preprocessing has been done (Thus the tagging program should understand line number changing comments!) * Template Haskell? ( This is really tricky I think ) * Hmm sorted tagfiles would be useful as well :) == alternatives ? == If you do not think this is useful (mandatory?) how do you lookup code? (Yes I know hoogle :) perhaps using Eclipse or Visual Studio? I'd like to start implementing this somehow the next weeks. So don't hesitate and start discussing Marc Weber From jonathanccast at fastmail.fm Sun Jan 13 20:01:17 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Sun Jan 13 19:54:40 2008 Subject: [Haskell-cafe] Re: All equations must have the same arity - why? In-Reply-To: References: <404396ef0801131512j69927949g1dcaed2884e31890@mail.gmail.com> <20080114011534.797e9a89@solaris.tower> Message-ID: <5606EA78-178D-41BD-B743-AFF12E9F6CED@fastmail.fm> On 13 Jan 2008, at 4:56 PM, jerzy.karczmarczuk@info.unicaen.fr wrote: > Jonathan Cast writes: >> On 13 Jan 2008, at 4:15 PM, Achim Schneider wrote: > ... never mind... >> I'm glad you are capable of ever so nobly assigning the purest >> imaginable motives to the designers of Haskell. You are an >> inspiration to us all. jcc > > Jonathan, please... > You see as well as anybody else what is the point of this discussion. > Perhaps it is not as bad as discussing with Cristian Baboi, but still. Very well, I'll be good. jcc (Meant to send this to the list first time...) From barsoap at web.de Sun Jan 13 20:12:02 2008 From: barsoap at web.de (Achim Schneider) Date: Sun Jan 13 20:05:35 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False References: <20080110220408.47186b19@solaris.tower> <87k5mgsm31.fsf@nmd9999.imr.no> <20080111145420.1c82c377@solaris.tower> <20080111170335.GH27808@darcs.net> <20080111191247.55ab360d@solaris.tower> <51AF6510-6CC0-4D8A-94AA-D704CE47510A@fastmail.fm> <20080112082519.4e7d81f2@solaris.tower> <200801120920.m0C9KXdT009948@mi1.bluebottle.com> <20080112104517.411627aa@solaris.tower> <20080112112432.674dcaff@solaris.tower> <200801121127.m0CBRX3E023254@mi0.bluebottle.com> <20080112130631.45bcfc68@solaris.tower> Message-ID: <20080114021202.0a0c804a@solaris.tower> Jonathan Cast wrote: > > You don't get 1, you start off with it. > > If you start off with anything, you can often end up with it as > well. Enlightenment comes when you realize that sometimes you > don't, and you acquire the ability to change your mind. > > > n = 12 > > n = 1 * n > > > > now, 1 is twelve. QED: The wrath of algebra. > > `Algebra' > Damnit, this is exactly what I meant. It's all about analysing some "1", until you found something interesting, and then continue all over with that new interesting thing that is now "also" a "1", 'cos you want to re-use your framework. I'll better stop right here. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From barsoap at web.de Sun Jan 13 20:18:32 2008 From: barsoap at web.de (Achim Schneider) Date: Sun Jan 13 20:12:11 2008 Subject: [Haskell-cafe] Re: All equations must have the same arity - why? References: <404396ef0801131512j69927949g1dcaed2884e31890@mail.gmail.com> <20080114011534.797e9a89@solaris.tower> Message-ID: <20080114021832.5091800e@solaris.tower> Jonathan Cast wrote: > On 13 Jan 2008, at 4:15 PM, Achim Schneider wrote: > > > "Neil Mitchell" wrote: > > > >> i.e. lift the arities to the longest argument list. > >> > >> Is there a reason this isn't done? > >> > > Most likely not, there are being made up right now. > > I'm glad you are capable of ever so nobly assigning the purest > imaginable motives to the designers of Haskell. You are an > inspiration to us all. > Most likely not. I'm only assigning good taste. There might be some evil conspiracy about warping people's heads somewhere, after all. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From ndmitchell at gmail.com Sun Jan 13 20:21:47 2008 From: ndmitchell at gmail.com (Neil Mitchell) Date: Sun Jan 13 20:15:08 2008 Subject: [Haskell-cafe] All equations must have the same arity - why? In-Reply-To: References: <404396ef0801131512j69927949g1dcaed2884e31890@mail.gmail.com> Message-ID: <404396ef0801131721u72da450fx1ae10979ba3d8b1c@mail.gmail.com> Hi Conal, On 1/13/08, Conal Elliott wrote: > That eta-expansion desugaring would lose sharing. Ah, that will be it. > 1. Equations with different arities more often signal bugs than > correct intentions. I don't believe that. I suspect the type system will mop these up. > 2. It's highly misleading. Again, I don't believe that. Your argument holds for why we shouldn't have multiple equations for definition, not that they should all be the same arity. > Offhand, I don't know of > a desugaring that would do the trick and preserve sharing. Any ideas? - > f = let body = sort . nub > in \xs -> case xs of > [] -> [1] > (_:_) -> body Compared to other desugarings in Haskell, this one is positively tame! I quite like the idea of permitting equations to have different arities. It removes restrictions, makes things more regular etc. Thanks Neil From barsoap at web.de Sun Jan 13 20:27:05 2008 From: barsoap at web.de (Achim Schneider) Date: Sun Jan 13 20:20:40 2008 Subject: [Haskell-cafe] Re: All equations must have the same arity - why? References: <404396ef0801131512j69927949g1dcaed2884e31890@mail.gmail.com> Message-ID: <20080114022705.67f714da@solaris.tower> "Neil Mitchell" wrote: > Hi, > > It's nice to write functions in point free style: > > f = sort . nub > > But sometimes I have to add an extra case, on a certain value: > > f [] = [1] > f = sort . nub > > But now these equations have different arities, and its rejected by > Haskell. Why does this not simply desugar to: > > f [] = [1] > f x = (sort . nub) x > > i.e. lift the arities to the longest argument list. > > Is there a reason this isn't done? > Answer #2: Because you can't write f x = case x of [] -> [1] -> sort.nub -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From jonathanccast at fastmail.fm Sun Jan 13 20:36:13 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Sun Jan 13 20:29:37 2008 Subject: [Haskell-cafe] Re: All equations must have the same arity - why? In-Reply-To: <20080114022705.67f714da@solaris.tower> References: <404396ef0801131512j69927949g1dcaed2884e31890@mail.gmail.com> <20080114022705.67f714da@solaris.tower> Message-ID: On 13 Jan 2008, at 5:27 PM, Achim Schneider wrote: > "Neil Mitchell" wrote: > >> Hi, >> >> It's nice to write functions in point free style: >> >> f = sort . nub >> >> But sometimes I have to add an extra case, on a certain value: >> >> f [] = [1] >> f = sort . nub >> >> But now these equations have different arities, and its rejected by >> Haskell. Why does this not simply desugar to: >> >> f [] = [1] >> f x = (sort . nub) x >> >> i.e. lift the arities to the longest argument list. >> >> Is there a reason this isn't done? >> > Answer #2: > > Because you can't write > > f x = case x of > [] -> [1] > -> sort.nub But why not? Treating case as syntax sugar for a higher-order function, so that all binding occurrences of lambdas in the unsugared code are associated with lambdas, is a good thing, and offers a natural way of desugaring the above, one case at a time. jcc From jerzy.karczmarczuk at info.unicaen.fr Sun Jan 13 20:38:40 2008 From: jerzy.karczmarczuk at info.unicaen.fr (jerzy.karczmarczuk@info.unicaen.fr) Date: Sun Jan 13 20:32:01 2008 Subject: [Haskell-cafe] All equations must have the same arity - why? In-Reply-To: <404396ef0801131721u72da450fx1ae10979ba3d8b1c@mail.gmail.com> References: <404396ef0801131512j69927949g1dcaed2884e31890@mail.gmail.com> <404396ef0801131721u72da450fx1ae10979ba3d8b1c@mail.gmail.com> Message-ID: Neil Mitchell writes: > I quite like the idea of permitting equations to have different > arities. It removes restrictions, makes things more regular etc. More regular??? My goodness... Of course, it removes restrictions. But in the history of humanity rarely the removal of restrictions made things more regular! Sometimes it is useful, but not where it "for free" gives you more opportunities to make bugs. I wonder whether f = g and f x = g x attributes *always* the same type to both variants of f... Jerzy Karczmarczuk From jonathanccast at fastmail.fm Sun Jan 13 20:44:23 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Sun Jan 13 20:37:46 2008 Subject: [Haskell-cafe] All equations must have the same arity - why? In-Reply-To: References: <404396ef0801131512j69927949g1dcaed2884e31890@mail.gmail.com> <404396ef0801131721u72da450fx1ae10979ba3d8b1c@mail.gmail.com> Message-ID: <6A8C4515-DA18-413F-BD2B-519A2102981D@fastmail.fm> On 13 Jan 2008, at 5:38 PM, jerzy.karczmarczuk@info.unicaen.fr wrote: > Neil Mitchell writes: >> I quite like the idea of permitting equations to have different >> arities. It removes restrictions, makes things more regular etc. > > More regular??? > My goodness... Of course, it removes restrictions. But in the > history of > humanity rarely the removal of restrictions made things more regular! > Sometimes it is useful, but not where it "for free" gives you more > opportunities to make bugs. > I wonder whether > f = g > and > f x = g x > attributes *always* the same type to both variants of f... A related variant of this is trivial: f x = x f x y = x y I don't know if eliminating that last argument has similar properties in practice or not. OTOH, the question is only one of eta-expanding until you get a number of arguments we already /know/ the function takes. jcc From barsoap at web.de Sun Jan 13 20:49:58 2008 From: barsoap at web.de (Achim Schneider) Date: Sun Jan 13 20:43:36 2008 Subject: [Haskell-cafe] Re: All equations must have the same arity - why? References: <404396ef0801131512j69927949g1dcaed2884e31890@mail.gmail.com> <20080114022705.67f714da@solaris.tower> Message-ID: <20080114024958.18d97ba9@solaris.tower> Jonathan Cast wrote: > On 13 Jan 2008, at 5:27 PM, Achim Schneider wrote: > > > "Neil Mitchell" wrote: > > > >> Hi, > >> > >> It's nice to write functions in point free style: > >> > >> f = sort . nub > >> > >> But sometimes I have to add an extra case, on a certain value: > >> > >> f [] = [1] > >> f = sort . nub > >> > >> But now these equations have different arities, and its rejected by > >> Haskell. Why does this not simply desugar to: > >> > >> f [] = [1] > >> f x = (sort . nub) x > >> > >> i.e. lift the arities to the longest argument list. > >> > >> Is there a reason this isn't done? > >> > > Answer #2: > > > > Because you can't write > > > > f x = case x of > > [] -> [1] > > -> sort.nub > > But why not? > Because arities aren't lifted to the longest argument list. > Treating case as syntax sugar for a higher-order > function, so that all binding occurrences of lambdas in the > unsugared code are associated with lambdas, is a good thing, and > offers a natural way of desugaring the above, one case at a time. > What about f x = [1] f - = sort.nub ? You could also do things like f - x = (foo x).bar with it. No more rewriting of pointfree code because of added arguments... -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From jonathanccast at fastmail.fm Sun Jan 13 20:57:39 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Sun Jan 13 20:51:02 2008 Subject: [Haskell-cafe] Re: All equations must have the same arity - why? In-Reply-To: <20080114024958.18d97ba9@solaris.tower> References: <404396ef0801131512j69927949g1dcaed2884e31890@mail.gmail.com> <20080114022705.67f714da@solaris.tower> <20080114024958.18d97ba9@solaris.tower> Message-ID: <30B4E831-27DD-421B-9D76-E4F6A2F9AC96@fastmail.fm> On 13 Jan 2008, at 5:49 PM, Achim Schneider wrote: > Jonathan Cast wrote: > >> On 13 Jan 2008, at 5:27 PM, Achim Schneider wrote: >>> Answer #2: >>> >>> Because you can't write >>> >>> f x = case x of >>> [] -> [1] >>> -> sort.nub >> >> But why not? >> > Because arities aren't lifted to the longest argument list. I think you lost the point of my question... >> Treating case as syntax sugar for a higher-order >> function, so that all binding occurrences of lambdas in the >> unsugared code are associated with lambdas, is a good thing, and >> offers a natural way of desugaring the above, one case at a time. >> > What about > > f x = [1] > f - = sort.nub > > ? > > You could also do things like > > f - x = (foo x).bar > > with it. No more rewriting of pointfree code because of added > arguments... So `-' as a pattern means `implicitly apply the RHS to whatever this pattern matches'? I like it. jcc From rl at cse.unsw.edu.au Sun Jan 13 22:20:05 2008 From: rl at cse.unsw.edu.au (Roman Leshchinskiy) Date: Sun Jan 13 22:13:32 2008 Subject: [Haskell-cafe] All equations must have the same arity - why? In-Reply-To: <404396ef0801131512j69927949g1dcaed2884e31890@mail.gmail.com> References: <404396ef0801131512j69927949g1dcaed2884e31890@mail.gmail.com> Message-ID: <478AD4E5.3020709@cse.unsw.edu.au> Neil Mitchell wrote: > Hi, > > It's nice to write functions in point free style: > > f = sort . nub > > But sometimes I have to add an extra case, on a certain value: > > f [] = [1] > f = sort . nub > > But now these equations have different arities, and its rejected by > Haskell. Why does this not simply desugar to: > > f [] = [1] > f x = (sort . nub) x > > i.e. lift the arities to the longest argument list. > > Is there a reason this isn't done? In addition to the sharing problem, consider f True x = x f False = undefined Because of seq, the second equation is not equivalent to the eta-expanded f False x = undefined x Roman From stevelihn at gmail.com Sun Jan 13 22:44:01 2008 From: stevelihn at gmail.com (Steve Lihn) Date: Sun Jan 13 22:37:23 2008 Subject: [Haskell-cafe] How to add ENV variable in runhaskell shell script Message-ID: Hi, In perl scripts (unix), one can do == #!/usr/local/bin/perl BEGIN { $ENV{LD_LIBRARY_PATH} = ...; } do my perl stuff == The setting of ENV variable before the program runs allows me to fix the shell environments. In this case, I need to specify where to look for the shared library. How do I do this in Haskell if I am writing the same script using: == #!/path/to/runhaskell {- how to set LD_LIBRARY_PATH = ... ? -} do my haskell stuff == Thanks, Steve From quancta at gmail.com Sun Jan 13 22:46:44 2008 From: quancta at gmail.com (=?ISO-8859-1?Q?Qu=E2n_Ta?=) Date: Sun Jan 13 22:40:05 2008 Subject: AW: [Haskell-cafe] Solving a geometry problem with Haskell In-Reply-To: <6de6b1650801130443g4b17cc4aj2281c3a284cd8f0c@mail.gmail.com> References: <6de6b1650801121319k3d2350ax77158ef31250fb13@mail.gmail.com> <000001c855d1$c9e40970$14b2a8c0@A64X2> <6de6b1650801130443g4b17cc4aj2281c3a284cd8f0c@mail.gmail.com> Message-ID: I haven't solved this problem yet, but I think it has more to do with multiplicative partition than with perfect-square. - Quan -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080113/3f6497fa/attachment.htm From haskell.org at liyang.hu Sun Jan 13 23:16:41 2008 From: haskell.org at liyang.hu (Liyang HU) Date: Sun Jan 13 23:09:53 2008 Subject: [Haskell-cafe] How to add ENV variable in runhaskell shell script In-Reply-To: References: Message-ID: <0DE8EE31-0382-4776-87B8-E5BA9F292C25@liyang.hu> Hi, On 1/14/08, Steve Lihn wrote: > In perl scripts (unix), one can do > #!/usr/local/bin/perl > BEGIN { $ENV{LD_LIBRARY_PATH} = ...; } I've not tested this (what a great line to start a post...), but see if this works for you: #! /usr/bin/env LD_LIBRARY_PATH=/path/to/libs runhaskell which also has the (desirable? Hmm...) side effect of letting env figure out (using PATH) where to find runhaskell. This doesn't work for compiled binaries, sadly. Modifying LD_LIBRARY_PATH at runtime works for Perl because libraries are loaded at runtime, and the language allows you to sneak in some code before that happens. Even if Haskell had a System.Environment.withEnv (it already has a withArgs), it's probably too late to patch the environment -- you can't get in before the linker. (Unless you're using some sort of funky dynamic plugin thing.) Cheers, /Liyang From allbery at ece.cmu.edu Sun Jan 13 23:21:26 2008 From: allbery at ece.cmu.edu (Brandon S. Allbery KF8NH) Date: Sun Jan 13 23:14:49 2008 Subject: [Haskell-cafe] How to add ENV variable in runhaskell shell script In-Reply-To: <0DE8EE31-0382-4776-87B8-E5BA9F292C25@liyang.hu> References: <0DE8EE31-0382-4776-87B8-E5BA9F292C25@liyang.hu> Message-ID: On Jan 13, 2008, at 23:16 , Liyang HU wrote: > On 1/14/08, Steve Lihn wrote: >> In perl scripts (unix), one can do >> #!/usr/local/bin/perl >> BEGIN { $ENV{LD_LIBRARY_PATH} = ...; } > > I've not tested this (what a great line to start a post...), but see > if this works for you: > > #! /usr/bin/env LD_LIBRARY_PATH=/path/to/libs runhaskell Will probably work on Linux; many other (especially older) Unixlike systems will consider everything after the program name a single argument. Best bet is to use a wrapper script. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH From cgibbard at gmail.com Mon Jan 14 01:04:07 2008 From: cgibbard at gmail.com (Cale Gibbard) Date: Mon Jan 14 00:57:34 2008 Subject: [Haskell-cafe] How to add ENV variable in runhaskell shell script In-Reply-To: References: Message-ID: <89ca3d1f0801132204x78dd7b5cu1126980b12579498@mail.gmail.com> On 13/01/2008, Steve Lihn wrote: > Hi, > In perl scripts (unix), one can do > == > #!/usr/local/bin/perl > BEGIN { > $ENV{LD_LIBRARY_PATH} = ...; > } > do my perl stuff > == > The setting of ENV variable before the program runs allows me to fix > the shell environments. In this case, I need to specify where to look > for the shared library. > > How do I do this in Haskell if I am writing the same script using: > == > #!/path/to/runhaskell > {- > how to set LD_LIBRARY_PATH = ... ? > -} > > do my haskell stuff > == > > Thanks, > Steve In System.Posix.Env there is a function setEnv which will let you set environment variables. I have no idea why this functionality is not exposed in System.Environment. - Cale From cgibbard at gmail.com Mon Jan 14 01:10:43 2008 From: cgibbard at gmail.com (Cale Gibbard) Date: Mon Jan 14 01:04:07 2008 Subject: [Haskell-cafe] Solving a geometry problem with Haskell In-Reply-To: <837db430801121339y69a77a5ehbfd0db2e6bdffd54@mail.gmail.com> References: <6de6b1650801121319k3d2350ax77158ef31250fb13@mail.gmail.com> <837db430801121339y69a77a5ehbfd0db2e6bdffd54@mail.gmail.com> Message-ID: <89ca3d1f0801132210x62528260n6cf79604e280f0d4@mail.gmail.com> On 12/01/2008, Hugh Perkins wrote: > On Jan 12, 2008 10:19 PM, Rafael Almeida wrote: > > After some profiling I found out that about 94% of the execution time is > > spent in the ``isPerfectSquare'' function. > > I guess that Haskell's referential transparence means the answers to > the isPerfectSquare will be cached, ie automatically memoized? (not > sure if is correct term?) This isn't true unless calling isPerfectSquare reads the result out of a lazily generated array of responses or some other data structure at the top-level. There's no memoisation of functions by default because it would typically require ridiculous amounts of memory, however, you can usually rely on values bound to variables to only be computed once, barring those which are typeclass polymorphic. - Cale From ajb at spamcop.net Mon Jan 14 01:42:57 2008 From: ajb at spamcop.net (ajb@spamcop.net) Date: Mon Jan 14 01:36:18 2008 Subject: [Haskell-cafe] All equations must have the same arity - why? In-Reply-To: <404396ef0801131721u72da450fx1ae10979ba3d8b1c@mail.gmail.com> References: <404396ef0801131512j69927949g1dcaed2884e31890@mail.gmail.com> <404396ef0801131721u72da450fx1ae10979ba3d8b1c@mail.gmail.com> Message-ID: <20080114014257.1ln3j0rfcc4o44ws@webmail.spamcop.net> G'day all. Quoting Neil Mitchell : > I don't believe that. I suspect the type system will mop these up. As previously noted, anything involving undefined (thanks to seq) is not equivalent. While undefined is arguably uncommon, error most certainly isn't: f1 (x:xs) = {- something -} f1 [] = error "empty list" -- add an argument, to get... f2 (x:xs) y = {- something -} f2 [] = error "empty list" f2 is type-correct, but is subtly different from f1, both semantically and (I think) performance-wise. On sharing: It's not generally appreciated, but in GHC, there's a subtle difference between: g x y = let z = p x in q x y z and: g x = \y -> let z = p x in q x y z the difference being that in the latter, the definition of z can be let-floated: g x = let z = p x in \y -> q x y z GHC does not float lets over lambdas if it would "break" a group of function arguments. Any proposed desugaring would have to either come up with a better rule than this, or find a way to preserve it. Cheers, Andrew Bromage From prstanley at ntlworld.com Mon Jan 14 02:11:00 2008 From: prstanley at ntlworld.com (PR Stanley) Date: Mon Jan 14 02:04:13 2008 Subject: [Haskell-cafe] Computer Science Books using Haskell Message-ID: <7.0.1.0.0.20080114065433.01cf5470@ntlworld.com> Hi Can the list recommend books that use Haskell - or any FP language but preferably Haskell - to illustrate the principles of compilers and/or algorithms? I think most of you would understand if I said that I'd prefer FP code instead of funny math symbols that don't translate into ANSI characters with the current OCR technology, unless, of course, you know of a book available in latex code. Rather than rushing straight to Google I thought I'd first draw on the wealth of knowledge that exists on this list. Cheers Paul From s.clover at gmail.com Mon Jan 14 02:47:40 2008 From: s.clover at gmail.com (Sterling Clover) Date: Mon Jan 14 02:41:05 2008 Subject: [Haskell-cafe] ANNOUNCE: HStringTemplate -- An Elegant, Functional, Nifty Templating Engine for Haskell Message-ID: <89B71013-9550-4E1F-91DD-A4ABD532F2F1@gmail.com> HStringTemplate is a port of Terrence Parr?s lovely StringTemplate (http://www.stringtemplate.org) engine to Haskell. It is available, cabalized, at: darcs get http://code.haskell.org/HStringTemplate/ As interest has grown in using Haskell for web applications, there has been an increasing buzz about the need for a good templating engine in Haskell. Why might we need this? After all, Haskell has lovely combinator libraries for generating HTML programmatically, enforcing good form through its type system. But sometimes, we don?t want well-formed HTML. We want the ugly stuff that floats around to deal with eight varieties of browser incompatibilities and the latest silly ajax trick. Or sometimes we?re working with a team of graphic designers, and they want to work in almost-HTML. Or sometimes we just want to be able to change the design of a web application on the fly, completely independent of our program logic, and of, heavens forbid, recompiling and possibly messing with a live application. So template engines are popular, and indeed, considered a key part of most web frameworks out there. One problem ? they?re mainly awful, imperatively-conceived behemoths that capriciously mix program logic with display and, consequently, entail a great deal of overhead. Enter StringTemplate, a nifty and fairly-well developed template format that?s both pure and functional, and therefore pretty much the only one of its kind. Indeed, it also seems to be getting heavy use in code generation because its paradigm maps neatly to traversing parse-trees. HStringTemplate is not feature-complete, and indeed is only at version 0.1. But it should implement pretty much everything in the standard StringTemplate 3.0 grammar, only nicer, because it?s in Haskell. There are scads of different recursive constructs and ways to handle inclusion and inheritance. Furthermore, HStringTemplate handles conditionals, and sports also a very Haskellish implementation of custom rendering. Templates can be constructed that return strings, ShowSs, bytestrings, or even pretty printer Docs that handle wrapping, indentation, and fill elegantly. Even better, these templates are parsed and compiled only once, after which point there isn't a syntax tree anymore, just a function that operates on the environment of attributes that have been passed to it. Where I take it from here depends in part on what sort of response I get, so patches, gripes, API comments and feature requests are all more than welcome. Please note that I'm still working in 6.6.1. Everything should be in place to compile properly with the base split, but if it isn't, again, patches more than welcome. Full announcement at: http://fmapfixreturn.wordpress.com/ --SC From dons at galois.com Mon Jan 14 02:52:07 2008 From: dons at galois.com (Don Stewart) Date: Mon Jan 14 02:45:29 2008 Subject: [Haskell-cafe] Computer Science Books using Haskell In-Reply-To: <7.0.1.0.0.20080114065433.01cf5470@ntlworld.com> References: <7.0.1.0.0.20080114065433.01cf5470@ntlworld.com> Message-ID: <20080114075207.GJ20928@scytale.galois.com> Hi Paul, One textbook on algorithms with a functional approach is by Fethi Rabhi and Guy Lapalme: "Algorithms: A functional programming approach" published by Addison-Wesley, 235 pages, ISBN 0-201-59604-0 I'd imagine they wouldn't use many OCR unfriendly characters. "Purely Functional Data Structures" by Chris Okasaki, is also a classic. ISBN 0-521-63124-6 For compiler construction from a functional perspective, Appel's "Modern Compiler Implementation in ML" is well regarded. -- Don From dons at galois.com Mon Jan 14 03:09:40 2008 From: dons at galois.com (Don Stewart) Date: Mon Jan 14 03:03:07 2008 Subject: [Haskell-cafe] Re: [Haskell] ANNOUNCE: HStringTemplate -- An Elegant, Functional, Nifty Templating Engine for Haskell In-Reply-To: <89B71013-9550-4E1F-91DD-A4ABD532F2F1@gmail.com> References: <89B71013-9550-4E1F-91DD-A4ABD532F2F1@gmail.com> Message-ID: <20080114080940.GL20928@scytale.galois.com> s.clover: > HStringTemplate is a port of Terrence Parr?s lovely StringTemplate > (http://www.stringtemplate.org) engine to Haskell. > > It is available, cabalized, at: > darcs get http://code.haskell.org/HStringTemplate/ Looks very useful! Will this be on hackage.haskell.org soon? I can't wait to: cabal install HStringTemplate :) -- Don From lennart at augustsson.net Mon Jan 14 03:14:41 2008 From: lennart at augustsson.net (Lennart Augustsson) Date: Mon Jan 14 03:08:02 2008 Subject: [Haskell-cafe] All equations must have the same arity - why? In-Reply-To: <404396ef0801131512j69927949g1dcaed2884e31890@mail.gmail.com> References: <404396ef0801131512j69927949g1dcaed2884e31890@mail.gmail.com> Message-ID: There is no technical reason for this. It's a matter of taste. As someone else pointed out, different arities is usually a bug. -- Lennart On Jan 13, 2008 3:12 PM, Neil Mitchell wrote: > Hi, > > It's nice to write functions in point free style: > > f = sort . nub > > But sometimes I have to add an extra case, on a certain value: > > f [] = [1] > f = sort . nub > > But now these equations have different arities, and its rejected by > Haskell. Why does this not simply desugar to: > > f [] = [1] > f x = (sort . nub) x > > i.e. lift the arities to the longest argument list. > > Is there a reason this isn't done? > > Thanks > > Neil > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080114/64424b5d/attachment.htm From simonpj at microsoft.com Mon Jan 14 03:45:18 2008 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Mon Jan 14 03:38:40 2008 Subject: [Haskell-cafe] Possibility to port vshaskell to VS2008? In-Reply-To: <1200258922.3530.4.camel@localhost.localdomain> References: <001301c8560f$cc227e90$64677bb0$@de> <1200258922.3530.4.camel@localhost.localdomain> Message-ID: <638ABD0A29C8884A91BC5FB5C349B1C3144D737187@EA-EXMSG-C334.europe.corp.microsoft.com> Yes, the VS Shell indeed looks an attractive platform, because it's free. It'd be great if someone wanted to port Visual Haskell to the VS Shell. Simon | -----Original Message----- | From: Peter Verswyvelen | Sent: 13 January 2008 21:15 | Subject: Re: [Haskell-cafe] Possibility to port vshaskell to VS2008? | | It might be even better to port it to the freely available downloadable | Visual Studio Shell: | http://msdn2.microsoft.com/en-us/vsx2008/products/bb933751.aspx | | The F# plugin works for that environment, giving a very good free IDE. | | Cheers, | Peter (on Fedora 8 using, woohoo, my first steps on Linux :) From bf3 at telenet.be Mon Jan 14 04:40:11 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Mon Jan 14 04:33:37 2008 Subject: [Haskell-cafe] Possibility to port vshaskell to VS2008? In-Reply-To: <638ABD0A29C8884A91BC5FB5C349B1C3144D737187@EA-EXMSG-C334.europe.corp.microsoft.com> References: <001301c8560f$cc227e90$64677bb0$@de> <1200258922.3530.4.camel@localhost.localdomain> <638ABD0A29C8884A91BC5FB5C349B1C3144D737187@EA-EXMSG-C334.europe.corp.microsoft.com> Message-ID: <1200303611.2855.2.camel@localhost.localdomain> Yes, would be really nice. And in the meanwhile update it to GHC 6.8.2 and add support for debugging/stepping now that GHC supports it :-) Peter On Mon, 2008-01-14 at 08:45 +0000, Simon Peyton-Jones wrote: > Yes, the VS Shell indeed looks an attractive platform, because it's free. It'd be great if someone wanted to port Visual Haskell to the VS Shell. > > Simon > > | -----Original Message----- > | From: Peter Verswyvelen > | Sent: 13 January 2008 21:15 > | Subject: Re: [Haskell-cafe] Possibility to port vshaskell to VS2008? > | > | It might be even better to port it to the freely available downloadable > | Visual Studio Shell: > | http://msdn2.microsoft.com/en-us/vsx2008/products/bb933751.aspx > | > | The F# plugin works for that environment, giving a very good free IDE. > | > | Cheers, > | Peter (on Fedora 8 using, woohoo, my first steps on Linux :) > From johan.tibell at gmail.com Mon Jan 14 05:41:48 2008 From: johan.tibell at gmail.com (Johan Tibell) Date: Mon Jan 14 05:35:09 2008 Subject: [Haskell-cafe] Code folding in Emacs Message-ID: <90889fe70801140241l4ba33c3m4bdc4ae9ffd96d0e@mail.gmail.com> It would be pretty neat for Haskell hacking if the Emacs Haskell mode could do the following. Imagine you have written some code like so: -- | The parse state. data S = S {-# UNPACK #-} !B.ByteString -- current chunk L.ByteString -- rest of the input {-# UNPACK #-} !Int64 -- bytes read -- | The 'Parser' monad is just a State monad carrying around the -- input ByteString. newtype Parser a = Parser { unParser :: S -> Consumed (Reply a) } -- | Match byte that fulfills predicate. satisfy :: (Word8 -> Bool) -- ^ Predicate that byte must fulfill. -> Parser Word8 -- ^ Matched byte. satisfy p = Parser $ \(S s ss pos) -> if B.null s then (if L.null ss then Empty (Error (ParseError pos)) else case L.splitAt 1 ss of (consuming,rest) -> let now = B.concat . L.toChunks $ consuming b = B.head now in if p b then Consumed $ Ok b (S (B.tail now) rest (pos + 1)) else Empty $ Error $ ParseError pos ) else let b = B.head s in if p b then Consumed $ Ok (B.head s) (S (B.tail s) ss (pos + 1)) else Empty $ Error $ ParseError pos Now you want an overview of your source file. One way would be to replace all the implementation parts with ellipses, like so: -- | The parse state. data S = S {-# UNPACK #-} !B.ByteString -- current chunk L.ByteString -- rest of the input {-# UNPACK #-} !Int64 -- bytes read -- | The 'Parser' monad is just a State monad carrying around the -- input ByteString. newtype Parser a = Parser { unParser :: S -> Consumed (Reply a) } -- | Match byte that fulfills predicate. satisfy :: (Word8 -> Bool) -- ^ Predicate that byte must fulfill. -> Parser Word8 -- ^ Matched byte. satisfy p = ... Binding a haskell-fold-source function to a key chain would enable you to get a quick overview of your module showing only the comments and type signatures. I've used the little function from http://emacs.wordpress.com/2007/01/16/quick-and-dirty-code-folding/ but it doesn't work well together with indented type signatures like in the example above. Anyone with strong Emacs-fu that knows how one could implement such a function? -- Johan From jerzy.karczmarczuk at info.unicaen.fr Mon Jan 14 05:59:58 2008 From: jerzy.karczmarczuk at info.unicaen.fr (jerzy.karczmarczuk@info.unicaen.fr) Date: Mon Jan 14 05:53:19 2008 Subject: [Haskell-cafe] Computer Science Books using Haskell In-Reply-To: <20080114075207.GJ20928@scytale.galois.com> References: <7.0.1.0.0.20080114065433.01cf5470@ntlworld.com> <20080114075207.GJ20928@scytale.galois.com> Message-ID: Don Stewart writes: > One textbook on algorithms with a functional approach is by Fethi Rabhi > and Guy Lapalme: "Algorithms: A functional programming approach" > published by Addison-Wesley, 235 pages, ISBN 0-201-59604-0 > > I'd imagine they wouldn't use many OCR unfriendly characters. I perhaps misunderstand this phrase, but if you suggest that it would be useful to snatch the code examples from within the book, I believe that no OCR is needed, they are here: http://www.iro.umontreal.ca/~lapalme/AlgoFP/code.html Jerzy Karczmarczuk From john at repetae.net Mon Jan 14 06:20:37 2008 From: john at repetae.net (John Meacham) Date: Mon Jan 14 06:13:57 2008 Subject: [Haskell-cafe] How to add ENV variable in runhaskell shell script In-Reply-To: <0DE8EE31-0382-4776-87B8-E5BA9F292C25@liyang.hu> References: <0DE8EE31-0382-4776-87B8-E5BA9F292C25@liyang.hu> Message-ID: <20080114112037.GB6795@momenergy.repetae.net> only one argument is allowed after the #! on the first line. however the following should be portable if you must set the variable before runhaskell is executed: #!/bin/sh -- > /dev/null 2>&1; MYENV=foo runhaskell $_ import System.Environment main = getEnv "MYENV" >>= print -- John Meacham - ?repetae.net?john? From bulat.ziganshin at gmail.com Mon Jan 14 02:38:44 2008 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Mon Jan 14 07:35:14 2008 Subject: [Haskell-cafe] All equations must have the same arity - why? In-Reply-To: <404396ef0801131512j69927949g1dcaed2884e31890@mail.gmail.com> References: <404396ef0801131512j69927949g1dcaed2884e31890@mail.gmail.com> Message-ID: <1073800476.20080114103844@gmail.com> Hello Neil, Monday, January 14, 2008, 2:12:52 AM, you wrote: > But sometimes I have to add an extra case, on a certain value: > f [] = [1] > f = sort . nub > Is there a reason this isn't done? this may be also due an error, and in most cases it actually will be due an error. then it makes type inference trickier and will led to very strange error messages instead of simple "different amount of arguments". so, we will buy power but lose simplicity -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From valery.vv at gmail.com Mon Jan 14 08:30:38 2008 From: valery.vv at gmail.com (Valery V. Vorotyntsev) Date: Mon Jan 14 08:23:59 2008 Subject: [Haskell-cafe] Code folding in Emacs In-Reply-To: <90889fe70801140241l4ba33c3m4bdc4ae9ffd96d0e@mail.gmail.com> References: <90889fe70801140241l4ba33c3m4bdc4ae9ffd96d0e@mail.gmail.com> Message-ID: On 1/14/08, Johan Tibell wrote: > It would be pretty neat for Haskell hacking if the Emacs Haskell mode > could do the following. Imagine you have written some code like so: > > [...] > > Binding a haskell-fold-source function to a key chain would enable you > to get a quick overview of your module showing only the comments and > type signatures. I've used the little function from > http://emacs.wordpress.com/2007/01/16/quick-and-dirty-code-folding/ > but it doesn't work well together with indented type signatures like > in the example above. AFAIU the problem, .. data StupidTypeNameIntendedToBeLong = Foo functionWithLoooongName :: Foo -> Bar functionWithLoooongName = undefined .. you don't like the way haskell-mode indents the `-> Bar' line. If this is the case, you could `newline-and-indent' (`C-j') right after `::'. anotherFunctionWithLongName :: Foo -> Bar anotherFunctionWithLongName = undefined And what's this "haskell-fold-source function" you were talking about? -- vvv From bortzmeyer at nic.fr Mon Jan 14 08:38:22 2008 From: bortzmeyer at nic.fr (Stephane Bortzmeyer) Date: Mon Jan 14 08:31:43 2008 Subject: [Haskell-cafe] Re: [newbie question] Memoization automatic in Haskell? In-Reply-To: References: <837db430801121516yb7f58d4m6c95e14cc9c2fb5a@mail.gmail.com> Message-ID: <20080114133822.GA14647@nic.fr> On Sun, Jan 13, 2008 at 12:25:53AM +0100, Henning Thielemann wrote a message of 28 lines which said: > Caching is not the default, but you can easily code this by > yourself: Define an array and initialize it with all function > values. Because of lazy evaluation the function values are computed > only when they are requested and then they persist in the array. It works only if the argument of the function is an integer or an enumerated type. If the argument is a string and you do not know the string values in advance, you cannot use the array. From aspam at cox.net Mon Jan 14 09:43:47 2008 From: aspam at cox.net (Joe Buehler) Date: Mon Jan 14 09:37:20 2008 Subject: [Haskell-cafe] Re: Code folding in Emacs In-Reply-To: <90889fe70801140241l4ba33c3m4bdc4ae9ffd96d0e@mail.gmail.com> References: <90889fe70801140241l4ba33c3m4bdc4ae9ffd96d0e@mail.gmail.com> Message-ID: <478B7523.9010304@cox.net> Johan Tibell wrote: > Anyone with strong Emacs-fu that knows how one could implement such a function? This looks like a straightforward application of outline mode. I believe it might be as simple as setting up a regex and enabling the mode, but check the LISP source for outline mode or perhaps the emacs manual. Joe Buehler From mblazevic at stilo.com Mon Jan 14 10:18:39 2008 From: mblazevic at stilo.com (Mario Blazevic) Date: Mon Jan 14 10:12:00 2008 Subject: [Haskell-cafe] [IETF Apps meeting] A Theory of Templating Languages In-Reply-To: <20080111082132.GA28106@nic.fr> References: <20080111082132.GA28106@nic.fr> Message-ID: <478B7D4F.70408@stilo.com> >> I did find one paper that makes a start at such work, "Enforcing >> Strict Model-View Separation in Template Engines", >> but the theory is a little weak and it focuses on the nebulous idea of >> separation of model and view, as opposed to >> a classification of capabilities and limitations. When I did the research for my template engine paper, that was also the most theoretically-inclined paper I could find. In fact, it was almost the only paper focusing on template languages. That entire area, of considerable importance in practice, seems to be completely ignored by computer science. My own work was more on the practical side, but its first section may be of some interest for its (sadly informal) pointing out of relationships between template engines and functional programming. The paper and the slides can be found at: http://www.idealliance.org/papers/extreme/proceedings/html/2007/Blazevic01/EML2007Blazevic01.xml Good luck. -- Mario Blazevic mblazevic@stilo.com Stilo Corporation This message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure, copying, or distribution is strictly prohibited. If you are not the intended recipient(s) please contact the sender by reply email and destroy all copies of the original message and any attachments. From johan.tibell at gmail.com Mon Jan 14 11:38:57 2008 From: johan.tibell at gmail.com (Johan Tibell) Date: Mon Jan 14 11:32:19 2008 Subject: [Haskell-cafe] Code folding in Emacs In-Reply-To: References: <90889fe70801140241l4ba33c3m4bdc4ae9ffd96d0e@mail.gmail.com> Message-ID: <90889fe70801140838r3fde439fw607cf50335a39cae@mail.gmail.com> On Jan 14, 2008 2:30 PM, Valery V. Vorotyntsev wrote: > On 1/14/08, Johan Tibell wrote: > > It would be pretty neat for Haskell hacking if the Emacs Haskell mode > > could do the following. Imagine you have written some code like so: > > > > [...] > > > > Binding a haskell-fold-source function to a key chain would enable you > > to get a quick overview of your module showing only the comments and > > type signatures. I've used the little function from > > http://emacs.wordpress.com/2007/01/16/quick-and-dirty-code-folding/ > > but it doesn't work well together with indented type signatures like > > in the example above. > > AFAIU the problem, .. > > data StupidTypeNameIntendedToBeLong = > Foo > > functionWithLoooongName :: Foo > -> Bar > functionWithLoooongName = undefined > > .. you don't like the way haskell-mode indents the `-> Bar' line. > > If this is the case, you could `newline-and-indent' (`C-j') right > after `::'. No, I like the way haskell-mode indents. :) However the simple folding snippet I linked to above doesn't work with it since that code simple collapses everything that's indented. From barsoap at web.de Mon Jan 14 12:04:39 2008 From: barsoap at web.de (Achim Schneider) Date: Mon Jan 14 11:58:19 2008 Subject: [Haskell-cafe] Re: All equations must have the same arity - why? References: <404396ef0801131512j69927949g1dcaed2884e31890@mail.gmail.com> <20080114022705.67f714da@solaris.tower> <20080114024958.18d97ba9@solaris.tower> <30B4E831-27DD-421B-9D76-E4F6A2F9AC96@fastmail.fm> Message-ID: <20080114180439.7c2ac406@solaris.tower> Jonathan Cast wrote: > On 13 Jan 2008, at 5:49 PM, Achim Schneider wrote: > > > Jonathan Cast wrote: > > > >> On 13 Jan 2008, at 5:27 PM, Achim Schneider wrote: > >>> Answer #2: > >>> > >>> Because you can't write > >>> > >>> f x = case x of > >>> [] -> [1] > >>> -> sort.nub > >> > >> But why not? > >> > > Because arities aren't lifted to the longest argument list. > > I think you lost the point of my question... > I'm glad you are capable of ever so nobly assigning the purest imaginable motives to me. You are a true inspiration. > >> Treating case as syntax sugar for a higher-order > >> function, so that all binding occurrences of lambdas in the > >> unsugared code are associated with lambdas, is a good thing, and > >> offers a natural way of desugaring the above, one case at a time. > >> > > What about > > > > f x = [1] > > f - = sort.nub > > > > ? > > > > You could also do things like > > > > f - x = (foo x).bar > > > > with it. No more rewriting of pointfree code because of added > > arguments... > > So `-' as a pattern means `implicitly apply the RHS to whatever this > pattern matches'? I like it. > Yes. I suppose _> is a better idea, or something else beginning with _, as the rest of the characters could be functions. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From droundy at darcs.net Mon Jan 14 12:56:56 2008 From: droundy at darcs.net (David Roundy) Date: Mon Jan 14 12:50:15 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False In-Reply-To: <51AF6510-6CC0-4D8A-94AA-D704CE47510A@fastmail.fm> References: <20080110212434.07e18eb8@solaris.tower> <20080110202724.GO28763@darcs.net> <20080110214153.46ad3395@solaris.tower> <20080110205220.GR28763@darcs.net> <20080110220408.47186b19@solaris.tower> <87k5mgsm31.fsf@nmd9999.imr.no> <20080111145420.1c82c377@solaris.tower> <20080111170335.GH27808@darcs.net> <20080111191247.55ab360d@solaris.tower> <51AF6510-6CC0-4D8A-94AA-D704CE47510A@fastmail.fm> Message-ID: <20080114175654.GT27808@darcs.net> On Fri, Jan 11, 2008 at 07:10:20PM -0800, Jonathan Cast wrote: > On 11 Jan 2008, at 10:12 AM, Achim Schneider wrote: > > >David Roundy wrote: > > > >>Prelude> let x=1e-300/1e300 > >>Prelude> x > >>0.0 > >>Prelude> x/x > >>NaN > >> > >>The "true" answer here is that x/x == 1.0 (not 0 or +Infinity), but > >>there's no way for the computer to know this, so it's NaN. > > Didn't catch this the first time around, but: only to a physicist. I don't understand what you're saying below. Do you mean that the "true" answer is not 1.0, or that it's not reasonable for the computer to call it NaN? Since 1.0 is the answer you get for high-precision computations, it's hard to see how you can argue that it's a wrong answer. > (I mean no disrespect to the author of darcs, but nevertheless the > point stands). Back in the real world, 0 / 0 may be defined > arbitrarily, or left undefined. (Defining it breaks the wonderful > property that, if lim (xn) = x, lim (yn) = y, and x/y = z, then lim > (xn / yn) = z. This is considered a Bad Thing by real > mathematicians). In fact, in integration theory 0 * inf = 0 for > certain 'multiplications', which gives the lie to 0 / 0. -- David Roundy Department of Physics Oregon State University From bos at serpentine.com Mon Jan 14 13:01:46 2008 From: bos at serpentine.com (Bryan O'Sullivan) Date: Mon Jan 14 12:55:07 2008 Subject: [Haskell-cafe] Computer Science Books using Haskell In-Reply-To: <7.0.1.0.0.20080114065433.01cf5470@ntlworld.com> References: <7.0.1.0.0.20080114065433.01cf5470@ntlworld.com> Message-ID: <478BA38A.9020005@serpentine.com> PR Stanley wrote: > Can the list recommend books that use Haskell - or any FP language but > preferably Haskell - to illustrate the principles of compilers and/or > algorithms? Try Andrew Appel's "Modern Compiler Implementation in ML" http://www.cs.princeton.edu/~appel/modern/ml/ which, as it uses SML for everything, should translate quite readily to Haskell. Has the Haskell Program Coverage tool been integrated into Cabal? That is, is there anything like "runhaskell Setup.hs coverage" to generate a coverage report? Thanks, Greg -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080114/aece67f3/attachment.htm From dons at galois.com Mon Jan 14 13:17:28 2008 From: dons at galois.com (Don Stewart) Date: Mon Jan 14 13:10:51 2008 Subject: [Haskell-cafe] cabal and hpc? In-Reply-To: <1f3dc80d0801141012x6699216fu80e102c77b2d8e66@mail.gmail.com> References: <1f3dc80d0801141012x6699216fu80e102c77b2d8e66@mail.gmail.com> Message-ID: <20080114181728.GJ23179@scytale.galois.com> garious: > Has the Haskell Program Coverage tool been integrated into Cabal? That > is, is there anything like "runhaskell Setup.hs coverage" to generate a > coverage report? Not yet, but definitely on the todo list (its a variant of the test target, that would add -fhpc to each compile, so might be a bit tricky). Until then, you can hook hpc into your testsuite. I'd also recommend linking to the hpc coverage logs from your cabal file's 'description' field., until hackage can compute hpc results automatically. Bring on the code quality! -- Don From jgbailey at gmail.com Mon Jan 14 15:19:57 2008 From: jgbailey at gmail.com (Justin Bailey) Date: Mon Jan 14 15:13:17 2008 Subject: [Haskell-cafe] Getting frantic with FranTk In-Reply-To: References: Message-ID: On Jan 13, 2008 5:54 AM, Torsten Otto wrote: > Howdy, > > with a just-in-time-learning approach I managed to teach my class of > advanced high schoolers the basics of functional programming using > Haskell (I had only used Scheme before). Now to show them that Haskell That is awesome. I commend you. I only ever learned BASIC in school. > I have Hugs installed at /opt/local/bin/hugs in MacOS 10.4/10.5. What > do I do to get Hugs to recognize FranTk? I have downloaded it, but I > can't even get the demo to work, none of the imports can be found: I don't know much about Hugs and less about FranTk. You should probably verify that FranTk is still compatible with recent versions of Hugs. If they are, maybe try putting all the libraries in your current directory and then look for command line options to force hugs to look for them there? Justin -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080114/cb634575/attachment.htm From gwern0 at gmail.com Mon Jan 14 15:21:46 2008 From: gwern0 at gmail.com (gwern0@gmail.com) Date: Mon Jan 14 15:16:30 2008 Subject: [Haskell-cafe] Yi editor tutorial In-Reply-To: <478B64F2.5010608@nobugs.org> References: <478A91DD.1020403@nobugs.org> <20080114011833.GA10055@localhost> <478B64F2.5010608@nobugs.org> Message-ID: <20080114202146.GA30762@localhost> On 2008.01.14 13:34:42 +0000, Andrew Birkett scribbled 0.8K characters: > gwern0@gmail.com wrote: >> I'm going through them now, and I like them a lot. (Maybe I'll finally >> begin doing stuff with Yi!) >> Is there any particular reason you didn't put your tutorials on the >> Haskell wiki? I'd think they'd be good there. > > Cool, thanks. :-) > > I agree it'll be a good idea to move it to the wiki, and I'll do that soon. > On my own site, I can make lots of little changes locally and then > atomically (well, quickly at least!) rsync the new version up onto the > server. It makes life easier when I'm likely to change around the top > level structure. The wiki makes a lot of sense though, because it's > central and other people can extend the tutorial and fix bugs. I'd say editing a wiki is even easier. :) But if you want to wait until you've gotten it to a state where you're happy with it, that's good too. > It's also nice to be able to check the server logs and gauge interest too > (about 5000 hits since yesterday). > > Andrew True, but the interest won't last forever; so maybe after the Reddit links go quiescent? -- gwern rico Glock telex million propellants Warfare Ortega CNN 8182 Vauxhall -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080114/022e8a0b/attachment.bin From felipe.lessa at gmail.com Mon Jan 14 15:28:39 2008 From: felipe.lessa at gmail.com (Felipe Lessa) Date: Mon Jan 14 15:21:59 2008 Subject: [Haskell-cafe] Re: MonadPrompt + Gtk2Hs = ? In-Reply-To: References: Message-ID: On Jan 13, 2008 6:49 PM, apfelmus wrote: > K. Claessen. Poor man's concurrency monad. > http://www.cs.chalmers.se/~koen/pubs/jfp99-monad.ps > > P. Li, S. Zdancewic. Combining events and threads for scalable > network services. > http://www.seas.upenn.edu/~lipeng/homepage/papers/lz07pldi.pdf Two great papers! Thanks for pointing them out! > > Eventually this feature rang some bells: you can save not only when you > > want to undo, but also when you want to ask something to the user. > > Unfortunately, I still haven't come up with a nice higher order function > > that generalizes this work without reinventing Prompt on an isomorphic type. > > Oh, what kind of generalization do you have in mind? Leaking Prompt(..) in the export list to the GUI code seems wrong to me, I like 'runPromptM' because it hides the Prompt(..) data type from the user [module]. But after some rest I think I found a nice corresponding function: > contPromptM :: Monad m => (r -> m ()) > -> (forall a. p a -> (a -> m ()) -> m ()) > -> Prompt p r -> m () > contPromptM done _ (PromptDone r) = done r > contPromptM done cont (Prompt p c) = cont p (contPromptM done cont . c) This way all the Prompts get hidden so that 'lastAttempt' may be coded as > lastAttempt' :: AttemptCode > lastAttempt' showInfo entry button = guessGameNew >>= contPromptM done cont > where > cont :: forall a. GuessP a -> (a -> IO ()) -> IO () -- signature needed > cont (Print s) c = showInfo s >> c () > cont Guess c = do > mfix $ \cid -> > onClicked button $ do {signalDisconnect cid; > guess <- entryGetText entry; > c (read guess)} > return () > done attempts = showInfo $ "You took " ++ show attempts ++ " attempts." Nice and clean, and much better to read as well. Now the only question unanswered for me is if there are any relations between (forall a. p a -> (a -> m ()) -> m ()) -- from contPromptM and (ContT r m a -> (a -> m r) -> m r) -- from runContT besides the fact that both carry a continuation. I have a feeling that I am missing something clever here. Cheers, -- Felipe. From bf3 at telenet.be Mon Jan 14 15:58:35 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Mon Jan 14 15:51:56 2008 Subject: [Haskell-cafe] Strange GLFW linker problem on Linux Message-ID: <1200344315.3148.10.camel@localhost.localdomain> Because apparently GHC works much better on Linux than Windows, I switched to that platform. I'm currently trying Fedora 8. So now I'm completely alone in the dark: no experience with Haskell, no experience with Linux; I left decades of experience with Microsoft products behind me ;-) I tried compiling GFLW (used by SOE) and a Haskell test app on my laptop, and that worked fine. Then I installed Fedora on my desktop, installed all development tools, and GLFW (both the C library and Haskell wrapper) also compiled and linked fine, but when trying to link the test app to GLFW, I got linker errors (see below). It seems these symbols are defined in libXrandr, but I have both the binary as the devel package installed: [root@localhost dev]# yum list installed | grep Xrandr libXrandr.i386 1.2.2-1.fc8 installed libXrandr-devel.i386 1.2.2-1.fc8 installed So I have no idea what to do. The main difference between the laptop and desktop is that I installed the NVidia drivers on the desktop manually (first installed the kernel-devel package, and then downloaded and installed the linux driver from the nvidia website) Any hints? Thanks, Peter Linker errors reported by ghc --make Main.hs: /usr/local/lib/GLFW-0.1/ghc-6.8.2/libHSGLFW-0.1.a(x11_window.o): In function `_glfwPlatformRefreshWindowParams': x11_window.c:(.text+0x803): undefined reference to `XRRGetScreenInfo' x11_window.c:(.text+0x80d): undefined reference to `XRRConfigCurrentRate' x11_window.c:(.text+0x81b): undefined reference to `XRRFreeScreenConfigInfo' /usr/local/lib/GLFW-0.1/ghc-6.8.2/libHSGLFW-0.1.a(x11_window.o): In function `_glfwPlatformCloseWindow': x11_window.c:(.text+0xb7a): undefined reference to `XRRGetScreenInfo' x11_window.c:(.text+0xb9d): undefined reference to `XRRSetScreenConfig' x11_window.c:(.text+0xba6): undefined reference to `XRRFreeScreenConfigInfo' /usr/local/lib/GLFW-0.1/ghc-6.8.2/libHSGLFW-0.1.a(x11_window.o): In function `_glfwPlatformPollEvents': x11_window.c:(.text+0x115b): undefined reference to `XRRUpdateConfiguration' /usr/local/lib/GLFW-0.1/ghc-6.8.2/libHSGLFW-0.1.a(x11_window.o): In function `_glfwPlatformOpenWindow': x11_window.c:(.text+0x1fa5): undefined reference to `XRRSelectInput' /usr/local/lib/GLFW-0.1/ghc-6.8.2/libHSGLFW-0.1.a(x11_fullscreen.o): In function `_glfwPlatformGetVideoModes': x11_fullscreen.c:(.text+0x1ca): undefined reference to `XRRGetScreenInfo' x11_fullscreen.c:(.text+0x1db): undefined reference to `XRRConfigSizes' x11_fullscreen.c:(.text+0x219): undefined reference to `XRRFreeScreenConfigInfo' /usr/local/lib/GLFW-0.1/ghc-6.8.2/libHSGLFW-0.1.a(x11_fullscreen.o): In function `_glfwSetVideoModeMODE': x11_fullscreen.c:(.text+0x329): undefined reference to `XRRGetScreenInfo' x11_fullscreen.c:(.text+0x344): undefined reference to `XRRConfigCurrentConfiguration' x11_fullscreen.c:(.text+0x394): undefined reference to `XRRSetScreenConfigAndRate' x11_fullscreen.c:(.text+0x3ac): undefined reference to `XRRSetScreenConfig' /usr/local/lib/GLFW-0.1/ghc-6.8.2/libHSGLFW-0.1.a(x11_fullscreen.o): In function `_glfwGetClosestVideoMode': x11_fullscreen.c:(.text+0x3fa): undefined reference to `XRRGetScreenInfo' x11_fullscreen.c:(.text+0x408): undefined reference to `XRRConfigSizes' x11_fullscreen.c:(.text+0x48f): undefined reference to `XRRConfigRates' x11_fullscreen.c:(.text+0x4dc): undefined reference to `XRRFreeScreenConfigInfo' x11_fullscreen.c:(.text+0x512): undefined reference to `XRRFreeScreenConfigInfo' /usr/local/lib/GLFW-0.1/ghc-6.8.2/libHSGLFW-0.1.a(x11_fullscreen.o): In function `_glfwSetVideoModeMODE': x11_fullscreen.c:(.text+0x3be): undefined reference to `XRRFreeScreenConfigInfo' /usr/local/lib/GLFW-0.1/ghc-6.8.2/libHSGLFW-0.1.a(x11_init.o): In function `_glfwPlatformInit': x11_init.c:(.text+0xea): undefined reference to `XRRQueryExtension' collect2: ld returned 1 exit status From benukem at gmail.com Mon Jan 14 16:40:02 2008 From: benukem at gmail.com (B K) Date: Mon Jan 14 16:33:21 2008 Subject: [Haskell-cafe] First Israel Haskell Event Message-ID: <8ea9137a0801141340j34ba8958g213fe6af5e7a3fe0@mail.gmail.com> Hello all, A Haskell gathering will take place for the first time in Israel: Friday, January 18 2008 at 11:00 AM Village Green, 33 Jaffa Rd, (corner of Rivlin St), Jerusalem This will be an informal event where everyone can introduce themselves and talk about their thoughts on Haskell. Everyone and anyone are invited. If you are in the area then please stop by, and email me with any questions. Looking forward to an enlightening time, Benny From barsoap at web.de Mon Jan 14 16:45:27 2008 From: barsoap at web.de (Achim Schneider) Date: Mon Jan 14 16:39:02 2008 Subject: [Haskell-cafe] Re: Strange GLFW linker problem on Linux References: <1200344315.3148.10.camel@localhost.localdomain> Message-ID: <20080114224527.6923914d@solaris.tower> Peter Verswyvelen wrote: > Any hints? > Look at ghc --make -v and make sure that ghc uses the right -l and -L options when it calls the linker. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From ben.franksen at online.de Mon Jan 14 17:03:25 2008 From: ben.franksen at online.de (Ben Franksen) Date: Mon Jan 14 16:59:03 2008 Subject: [Haskell-cafe] Re: Re: Displaying # of reductions after eachcomputation in ghci? References: <20080108221155.GA3393@localhost.localdomain> Message-ID: Lennart Augustsson wrote: > What is a reduction anyway? I am not an expert but I thought in lambda calculus one has primitive rules for evaluation, e.g. beta reduction. So a reduction is a 'smallest step' in reducing an expression to normal form, no? Cheers Ben From t-otto-news at gmx.de Mon Jan 14 17:07:39 2008 From: t-otto-news at gmx.de (Torsten Otto) Date: Mon Jan 14 17:00:58 2008 Subject: [Haskell-cafe] Getting frantic with FranTk In-Reply-To: References: Message-ID: Thank you for the encouragement, Justin. Unfortunately I did try that. But it may also be where my basic understanding is missing: "the libraries" - do I have to somehow compile all the source or can I just use it? The source is Haskell, but it all comes with makefiles - are these for use with GHC or something more? I have a feeling I have to compile something somehow into some special location. I guess I'll just keep mucking around until I find a clue somewhere... All I know so far is how to use modules in Hugs which is enough for High School, but there is so much more out there... The Readme points out for the underlying Tcl: *** If on unix compile up the TclPrim.so library and run the tclexe script, with hugs as the argument program ie ../bin/tclexe hugs *** Ok, I can find tclexe, but how do I "compile up the TclPrim"? Probably pretty standard, I'm working on that (hints would still be appreciated...). I'm confused at the point where the demo imports FranTk allright, but then I've hunted the web for missing modules which left me with something else missing: Hugs> :l Demos.lhs ERROR "./Utils.hs" - Error while importing DLL "./Utils.so": dlopen(./Utils.so, 9): image not found Foreign.Marshal.Alloc> I don't begin to understand what this is telling me... If I get it to work, I'll put in on the Web for others to find. Torsten From t-otto-news at gmx.de Mon Jan 14 17:09:54 2008 From: t-otto-news at gmx.de (Torsten Otto) Date: Mon Jan 14 17:03:14 2008 Subject: [Haskell-cafe] Haskell and GUI Message-ID: Seeing my woes with FranTk - what else is out there that people use if a (simple) GUI is desired for a Haskell app? Just a few textboxes and a button or two would do me. Thanks in advance! Regards, Torsten From sebastian.sylvan at gmail.com Mon Jan 14 17:16:25 2008 From: sebastian.sylvan at gmail.com (Sebastian Sylvan) Date: Mon Jan 14 17:09:44 2008 Subject: [Haskell-cafe] Haskell and GUI In-Reply-To: References: Message-ID: <3d96ac180801141416i2298ed3cg8d447d907f363e68@mail.gmail.com> On Jan 14, 2008 10:09 PM, Torsten Otto wrote: > Seeing my woes with FranTk - what else is out there that people use if > a (simple) GUI is desired for a Haskell app? Just a few textboxes and > a button or two would do me. > > Thanks in advance! > > I like wxHaskell. It seems that GTK2HS is more active though, but I never did manage to install it on windows. -- Sebastian Sylvan +44(0)7857-300802 UIN: 44640862 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080114/6fd84920/attachment.htm From ndmitchell at gmail.com Mon Jan 14 17:16:56 2008 From: ndmitchell at gmail.com (Neil Mitchell) Date: Mon Jan 14 17:10:16 2008 Subject: [Haskell-cafe] Haskell and GUI In-Reply-To: References: Message-ID: <404396ef0801141416ubf5f0c9wfa995beb771ecf78@mail.gmail.com> Hi Torsten, > Seeing my woes with FranTk - what else is out there that people use if > a (simple) GUI is desired for a Haskell app? Just a few textboxes and > a button or two would do me. Gtk2hs in GHC: http://www.haskell.org/gtk2hs/ Thanks Neil From duncan.coutts at worc.ox.ac.uk Mon Jan 14 17:23:30 2008 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Mon Jan 14 17:16:51 2008 Subject: [Haskell-cafe] Getting frantic with FranTk In-Reply-To: References: Message-ID: <1200349410.5639.91.camel@localhost> On Sun, 2008-01-13 at 14:54 +0100, Torsten Otto wrote: > Howdy, > > with a just-in-time-learning approach I managed to teach my class of > advanced high schoolers the basics of functional programming using > Haskell (I had only used Scheme before). Now to show them that Haskell > is not a weirdo esoteric command line only language, I thought I'd end > the class with spoken output (easy enough with the System module and > "say" in Mac OS) and a GUI for input using FranTk. Honestly, if you could get FranTk to work I'd be very impressed. My impression is that it is extremely bitrotted. I would suggest trying one of the other GUI libs that has seen some maintenance this century. (I'm not joking - http://haskell.org/FranTk/ says it works with ghc-4.04 which was released in 1999) That also probably means using ghc rather than hugs since most of the modern GUI libs only work with ghc. The only exception is HGL, which is rumoured to still work wit hugs (though again it has seen little to no maintenance in recent years). So I'd recommend the new SOE, OpenGL, Gtk2Hs or wxHaskell. All of those come with some demos you can show off. SOE and OpenGL are purely for doing drawings and animation (OpenGL is 3D of course). The other two are full blown GUI toolkits. http://haskell.org/soe http://haskell.org/haskellwiki/Opengl http://haskell.org/gtk2hs http://wxhaskell.sourceforge.net/ Duncan From apfelmus at quantentunnel.de Mon Jan 14 17:27:19 2008 From: apfelmus at quantentunnel.de (apfelmus) Date: Mon Jan 14 17:20:46 2008 Subject: [Haskell-cafe] Re: MonadPrompt + Gtk2Hs = ? In-Reply-To: References: Message-ID: Felipe Lessa wrote: > apfelmus wrote: >> Oh, what kind of generalization do you have in mind? > > Leaking Prompt(..) in the export list to the GUI code seems wrong to > me, I like 'runPromptM' because it hides the Prompt(..) data type from > the user [module]. But after some rest I think I found a nice > corresponding function: > >> contPromptM :: Monad m => (r -> m ()) >> -> (forall a. p a -> (a -> m ()) -> m ()) >> -> Prompt p r -> m () >> contPromptM done _ (PromptDone r) = done r >> contPromptM done cont (Prompt p c) = cont p (contPromptM done cont . c) > > This way all the Prompts get hidden so that 'lastAttempt' may be coded as > >> lastAttempt' :: AttemptCode >> lastAttempt' showInfo entry button = guessGameNew >>= contPromptM done cont >> where >> cont :: forall a. GuessP a -> (a -> IO ()) -> IO () -- signature needed >> cont (Print s) c = showInfo s >> c () >> cont Guess c = do >> mfix $ \cid -> >> onClicked button $ do {signalDisconnect cid; >> guess <- entryGetText entry; >> c (read guess)} >> return () >> done attempts = showInfo $ "You took " ++ show attempts ++ " attempts." > > Nice and clean, and much better to read as well. The type of contPromptM is even more general than that: casePromptOf' :: (r -> f b) -> (forall a,b. p a -> (a -> f b) -> f b) -> Prompt p r -> f b casePromptOf' done cont (PromptDone r) = done r casePromptOf' done cont (Prompt p c ) = cont p (casePromptOf' done cont . c) In other words, it's (almost) the case expression / dual for the Prompt data type. So, only exporting this function and not the Prompt constructors is like exporting only either :: (a -> c) -> (b -> c) -> Either a b -> c instead of Left and Right for pattern matching. This way, you can do (simulated) pattern matching with them, but may not use them for construction. Which is probably what you want here. Except that there is a subtle difference, namely that c in Prompt p c has type c :: a -> Prompt p r whereas the argument to casePromptOf' expects it as c' = casePromptOf' done cont . c :: a -> f b This means that not exporting constructors could reduce the number of programs that are possible to implement, but I can't (dis-)prove it. (That's basically the question at the end of ). Of course, you can just change the argument type to (forall a,b. p a -> (a -> Prompt p b) -> f b) for the full flexibility. > Now the only question unanswered for me is if there are any > relations between > > (forall a. p a -> (a -> m ()) -> m ()) -- from contPromptM > > and > > (ContT r m a -> (a -> m r) -> m r) -- from runContT > > besides the fact that both carry a continuation. I have a feeling that > I am missing something clever here. The link to ContT m a = (forall b . (a -> m b) -> m b) is apparent in the case of casePromptOf' and is no surprise: you can omit p a and Prompt p r entirely and implement them directly as continuations (thereby loosing the ability to use it with different m, which would defeat the whole point here.) See also Implementing the State Monad. http://article.gmane.org/gmane.comp.lang.haskell.cafe/31486 for the details. Regards, apfelmus From apfelmus at quantentunnel.de Mon Jan 14 17:35:22 2008 From: apfelmus at quantentunnel.de (apfelmus) Date: Mon Jan 14 17:28:57 2008 Subject: [Haskell-cafe] Re: Displaying # of reductions after eachcomputation in ghci? In-Reply-To: References: <20080108221155.GA3393@localhost.localdomain> Message-ID: Ben Franksen wrote: > Lennart Augustsson wrote: >> What is a reduction anyway? > > I am not an expert but I thought in lambda calculus one has primitive rules > for evaluation, e.g. beta reduction. So a reduction is a 'smallest step' in > reducing an expression to normal form, no? Yes and no, a single beta reduction step like (\x.c(d(e(f(x))))) g => c(d(e(f(g)))) may take 5 steps in some reduction strategies since you have to walk down the expression tree to find the variable and replace it with its value. In the end, seconds are a better measure for time :) Regards, apfelmus From ben.franksen at online.de Mon Jan 14 18:02:32 2008 From: ben.franksen at online.de (Ben Franksen) Date: Mon Jan 14 17:58:08 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <87fxx4slcy.fsf@nmd9999.imr.no> <200801111456.05819.g9ks157k@acme.softbase.org> Message-ID: jerzy.karczmarczuk@info.unicaen.fr wrote: > Wolfgang Jeltsch wrote: >> My impression is that staying close to math is good from a software >> technology point of view. And it has the advantage of less confusion >> for the user. > > What does it mean "close to math"? > How close? Does math raise exceptions upon the division by zero? > Does *MATH* answer the question what is: (0/0)==(0/0) ? Nope! Exactly. So why try to give an answer in Haskell? MATH says: the expression 0/0 is undefined, thus comparing (0/0)==(0/0) is undefined, too. I would expect Haskell to say the same. Cheers Ben From paul at cogito.org.uk Mon Jan 14 18:14:56 2008 From: paul at cogito.org.uk (Paul Johnson) Date: Mon Jan 14 18:08:19 2008 Subject: [Haskell-cafe] QuickCheck properties: export or not? Message-ID: <478BECF0.1070206@cogito.org.uk> I was recently sent a patch for my Ranged Sets library which exported all the QuickCheck properties. I'd left them unexported on the grounds that they clutter up the documentation (although simplified versions are included in the documentation) and you can easily run them with the standard "quickcheck" script. The contributor, gwern0@gmail.com suggested an explicit test harness instead. I'm not unduly bothered one way or the other, but I thought I'd ask the community: what is the best practice here? Paul. From dons at galois.com Mon Jan 14 18:16:33 2008 From: dons at galois.com (Don Stewart) Date: Mon Jan 14 18:09:58 2008 Subject: [Haskell-cafe] QuickCheck properties: export or not? In-Reply-To: <478BECF0.1070206@cogito.org.uk> References: <478BECF0.1070206@cogito.org.uk> Message-ID: <20080114231633.GA25718@scytale.galois.com> paul: > I was recently sent a patch for my Ranged Sets library which exported > all the QuickCheck properties. I'd left them unexported on the grounds > that they clutter up the documentation (although simplified versions are > included in the documentation) and you can easily run them with the > standard "quickcheck" script. The contributor, gwern0@gmail.com > suggested an explicit test harness instead. > > I'm not unduly bothered one way or the other, but I thought I'd ask the > community: what is the best practice here? Most libs seem to include an external Properties.hs or similar file. The only tension there is how much do you need to test thoroughly. You might still end up exporting more than you wish to. -- Don From ndmitchell at gmail.com Mon Jan 14 18:28:24 2008 From: ndmitchell at gmail.com (Neil Mitchell) Date: Mon Jan 14 18:21:44 2008 Subject: [Haskell-cafe] QuickCheck properties: export or not? In-Reply-To: <478BECF0.1070206@cogito.org.uk> References: <478BECF0.1070206@cogito.org.uk> Message-ID: <404396ef0801141528v14c14b38jb6665e97ba817335@mail.gmail.com> Hi > standard "quickcheck" script. The contributor, gwern0@gmail.com > suggested an explicit test harness instead. Unless you have a test harness (ideally through Cabal), the properties will go out of sync, and you'll forget to run them. Tests are good, they should be able to be invoked as standard. Every time I've *not* done a test harness, and then relied on manually remembering things or putting them in the documentation, it has gone wrong very quickly! Thanks Neil From dons at galois.com Mon Jan 14 18:31:39 2008 From: dons at galois.com (Don Stewart) Date: Mon Jan 14 18:25:01 2008 Subject: [Haskell-cafe] QuickCheck properties: export or not? In-Reply-To: <404396ef0801141528v14c14b38jb6665e97ba817335@mail.gmail.com> References: <478BECF0.1070206@cogito.org.uk> <404396ef0801141528v14c14b38jb6665e97ba817335@mail.gmail.com> Message-ID: <20080114233139.GB25718@scytale.galois.com> ndmitchell: > Hi > > > standard "quickcheck" script. The contributor, gwern0@gmail.com > > suggested an explicit test harness instead. > > Unless you have a test harness (ideally through Cabal), the properties > will go out of sync, and you'll forget to run them. Tests are good, > they should be able to be invoked as standard. Every time I've *not* > done a test harness, and then relied on manually remembering things or > putting them in the documentation, it has gone wrong very quickly! I usually have a main = runTests file, and then use darcs to ensure the tests are up to date: $ cat _darcs/prefs/prefs test ghc -no-recomp -Onot -fasm -itests tests/Unit.hs --make -odir /tmp && tests/Unit darcs will run the testsuite, and it needs to pass, before a commit will be accepted. We do a similar thing for xmonad. The test command to run on every commit can be set via, darcs setpref test "my test command" -- Don From jerzy.karczmarczuk at info.unicaen.fr Mon Jan 14 19:29:50 2008 From: jerzy.karczmarczuk at info.unicaen.fr (jerzy.karczmarczuk@info.unicaen.fr) Date: Mon Jan 14 19:23:09 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <87fxx4slcy.fsf@nmd9999.imr.no> <200801111456.05819.g9ks157k@acme.softbase.org> Message-ID: Ben Franksen writes: > jerzy.karczmarczuk@info.unicaen.fr wrote: ... >> Does *MATH* answer the question what is: (0/0)==(0/0) ? Nope! > > Exactly. So why try to give an answer in Haskell? MATH says: the > expression 0/0 is undefined, thus comparing (0/0)==(0/0) is undefined, > too. I would expect Haskell to say the same. I don't know whether you are serious, or you are pulling my leg... Let's suppose that it is serious. When math says that something is undefined, in my little brain I understand that there is no answer. NO answer. Is this the "undefined" you want to have? The bottom non-termination? Now, this is obviously the *worst* possible reaction of the system, the IEEE indefinite is much better, at least you know what had happened. Would you propose the non-termination as the issue of all "errors", such as negative argument to the real sqrt, etc? Well, as you wish... But don't write medical software, please... Jerzy Karczmarczuk From barsoap at web.de Mon Jan 14 19:43:25 2008 From: barsoap at web.de (Achim Schneider) Date: Mon Jan 14 19:36:52 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <87fxx4slcy.fsf@nmd9999.imr.no> <200801111456.05819.g9ks157k@acme.softbase.org> Message-ID: <20080115014325.461fa869@solaris.tower> jerzy.karczmarczuk@info.unicaen.fr wrote: > When math says that something is undefined, in my little brain I > understand that there is no answer. > NO answer. > Math doesn't say that something is undefined, but tells you that you did something that's illegal, i.e. impossible, in the system you're working with. Trying to divide by zero is like trying to break out of a mental asylum with a banana: It's neither a good tool to fight your way free, as well as using it will get you back into the asylum, by system-inherent laws. The mathematically right, and only really sane way to handle such things is not to do them at all, which would change Haskell's semantics rather drastically. There just is no unsafePerformMath :: Math a -> a. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From tom.davie at gmail.com Mon Jan 14 20:10:30 2008 From: tom.davie at gmail.com (Thomas Davie) Date: Mon Jan 14 20:05:10 2008 Subject: [Haskell-cafe] Haskell and GUI In-Reply-To: References: Message-ID: <003DBC4B-3B26-4073-A038-EA948B9EEB68@gmail.com> There's also the HOC (Haskell Objective-C bridge), which lets you use Apple's Cocoa APIs. Bob On 14 Jan 2008, at 22:09, Torsten Otto wrote: > Seeing my woes with FranTk - what else is out there that people use > if a (simple) GUI is desired for a Haskell app? Just a few textboxes > and a button or two would do me. > > Thanks in advance! > > Regards, > Torsten > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From jerzy.karczmarczuk at info.unicaen.fr Mon Jan 14 20:22:38 2008 From: jerzy.karczmarczuk at info.unicaen.fr (jerzy.karczmarczuk@info.unicaen.fr) Date: Mon Jan 14 20:15:57 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <20080115014325.461fa869@solaris.tower> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <87fxx4slcy.fsf@nmd9999.imr.no> <200801111456.05819.g9ks157k@acme.softbase.org> <20080115014325.461fa869@solaris.tower> Message-ID: Achim Schneider writes: > jerzy.karczmarczuk@info.unicaen.fr wrote: > >> When math says that something is undefined, in my little brain I >> understand that there is no answer. > Math doesn't say that something is undefined, but tells you that you > did something that's illegal, i.e. impossible, in the system you're > working with. Yeah, sure. Thanks God, we have on this list a fellow who gets direct telephone calls from her Majesty the Queen Mathematics. And knows better. Go tell to all people who use the word 'undefined' in math that they are stupid. At least, more stupid than you. http://mathworld.wolfram.com/Undefined.html http://en.wikipedia.org/wiki/Defined_and_undefined http://mathforum.org/library/drmath/view/53336.html http://encarta.msn.com/encyclopedia_761568582/Calculus_(mathematics).html etc. Jerzy Karczmarczuk From lrpalmer at gmail.com Mon Jan 14 20:37:26 2008 From: lrpalmer at gmail.com (Luke Palmer) Date: Mon Jan 14 20:30:44 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <87fxx4slcy.fsf@nmd9999.imr.no> <200801111456.05819.g9ks157k@acme.softbase.org> Message-ID: <7ca3f0160801141737u142f7f53l8432ce4ac3ae9310@mail.gmail.com> On Jan 15, 2008 12:29 AM, wrote: > Ben Franksen writes: > > > jerzy.karczmarczuk@info.unicaen.fr wrote: > ... > >> Does *MATH* answer the question what is: (0/0)==(0/0) ? Nope! > > > > Exactly. So why try to give an answer in Haskell? MATH says: the > > expression 0/0 is undefined, thus comparing (0/0)==(0/0) is undefined, > > too. I would expect Haskell to say the same. > > I don't know whether you are serious, or you are pulling my leg... > Let's suppose that it is serious. > > When math says that something is undefined, in my little brain I understand > that there is no answer. > NO answer. I'm not sure if I'm agreeing or disagreeing with you here. Depends on exactly what you mean by no answer. When I was a TA for calculus 2, students were presented with something like the following problem: Find the limit: lim (sin x / x) x->0 And proceeding, they would reduce this to: sin 0 / 0 0 / 0 Look in the book that said "0/0 is undefined", and write "undefined" on the paper as if that were the answer. For the calculus uninclined (I figure that is a vast minority on this list), the answer is 1. In that case, undefined meant "you did the problem wrong". And the error was precisely when they wrote 0 on the bottom of the division sign. To me, when math says "undefined"... let me stop there. Math doesn't say "undefined". Instead, when mathematicians say "undefined", they usually mean not that the question has no answer, but that the question you're asking doesn't even make sense as a question. For example, division is only defined when the denominator is not 0. Asking what the answer to "0/0" is is like asking "what happens when I move the king across the board in chess?". That operation doesn't even make sense with those arguments. However, Haskell is not blessed (cursed?) with dependent types, so it is forced to answer such questions even though they don't make sense. But looking to math (at least with a classical interpretation of numbers) is just not going to work. Personally, I loathe the existence of NaN and +-Infinity in floating point types. Someone here made an enlightinging point encouraging us to think of floating point numbers not as numbers but as intervals. That makes me slightly more okay with the infinities, but NaN still bugs me. I'd prefer an error: Haskell's way of saying "you did the problem wrong". That would be most useful in the kinds of things I do with floating point numbers (games). But there are probably other areas where the IEEE semantics are more useful. Well... that paragraph was just a long-winded way of saying "I have an opinion, but I don't think it's very important...". Luke From barsoap at web.de Mon Jan 14 22:09:56 2008 From: barsoap at web.de (Achim Schneider) Date: Mon Jan 14 22:03:32 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <87fxx4slcy.fsf@nmd9999.imr.no> <200801111456.05819.g9ks157k@acme.softbase.org> <20080115014325.461fa869@solaris.tower> Message-ID: <20080115040956.6c808216@solaris.tower> jerzy.karczmarczuk@info.unicaen.fr wrote: > Achim Schneider writes: > > > jerzy.karczmarczuk@info.unicaen.fr wrote: > > > >> When math says that something is undefined, in my little brain I > >> understand that there is no answer. > > > Math doesn't say that something is undefined, but tells you that you > > did something that's illegal, i.e. impossible, in the system you're > > working with. > > Yeah, sure. > > Thanks God, we have on this list a fellow who gets direct telephone > calls from her Majesty the Queen Mathematics. And knows better. > Go tell to all people who use the word 'undefined' in math that they > are stupid. At least, more stupid than you. > That's funny, you just proved that I am more stupid than myself, as I use the term. For things that are illegal or impossible in the system I'm working with. It's not that I posted it because I didn't agree with what you said. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From john at repetae.net Mon Jan 14 22:17:32 2008 From: john at repetae.net (John Meacham) Date: Mon Jan 14 22:10:50 2008 Subject: [Haskell-cafe] fast fractional part of floating point number - modf? In-Reply-To: References: Message-ID: <20080115031732.GA874@momenergy.repetae.net> On Sun, Jan 13, 2008 at 01:08:49AM +0100, Henning Thielemann wrote: > Is there a fast and reliable way to compute the fraction of a floating > point number? no, and this has bothered me to the point I consider it a bug in the language spec that all 'rounding' style functions give back an integral type. These sort of operations are often used on floating point values when you want the same type out you put in, and in particular you want it to handle things like infinities and nan's properly which the conversion through integral does not (plus, these usually coorespond to a single machine instruction so are more 'primitive' in a sense and thus better building blocks for a RealFrac class). To alleviate this I added the following to the RealFrac class in jhc -- TODO Doubles class (Real a, Fractional a) => RealFrac a where .... ... -- new stuff added by jhc properFractionf :: a -> (a,a) truncatef, roundf :: a -> a ceilingf, floorf :: a -> a truncatef x = m where (m,_) = properFractionf x roundf x = fromInteger (round x) ceilingf x = if r > 0 then n + 1 else n where (n,r) = properFractionf x floorf x = if r < 0 then n - 1 else n where (n,r) = properFractionf x the meaning should be clear, they perform the same operation as their non f counterparts but maintain the same type. John -- John Meacham - ?repetae.net?john? From ryani.spam at gmail.com Mon Jan 14 23:08:15 2008 From: ryani.spam at gmail.com (Ryan Ingram) Date: Mon Jan 14 23:01:33 2008 Subject: [Haskell-cafe] Re: MonadPrompt + Gtk2Hs = ? In-Reply-To: References: Message-ID: <2f9b2d30801142008g275988fep4e23e0643a5b6669@mail.gmail.com> On Jan 14, 2008 2:28 PM, Felipe Lessa wrote: > > lastAttempt' :: AttemptCode > > lastAttempt' showInfo entry button = guessGameNew >>= contPromptM done cont > > where > > cont :: forall a. GuessP a -> (a -> IO ()) -> IO () -- signature needed > > cont (Print s) c = showInfo s >> c () > > cont Guess c = do > > mfix $ \cid -> > > onClicked button $ do {signalDisconnect cid; > > guess <- entryGetText entry; > > c (read guess)} > > return () > > done attempts = showInfo $ "You took " ++ show attempts ++ " attempts." Excellent work; I love it. I'll definitely have to give this a try when I get back from vacation. I'd been wondering what the best way to interface with GUI code is and it's nice to have a sample to work from. -- ryan From jonathanccast at fastmail.fm Mon Jan 14 23:28:25 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Mon Jan 14 23:21:46 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False In-Reply-To: <20080114175654.GT27808@darcs.net> References: <20080110212434.07e18eb8@solaris.tower> <20080110202724.GO28763@darcs.net> <20080110214153.46ad3395@solaris.tower> <20080110205220.GR28763@darcs.net> <20080110220408.47186b19@solaris.tower> <87k5mgsm31.fsf@nmd9999.imr.no> <20080111145420.1c82c377@solaris.tower> <20080111170335.GH27808@darcs.net> <20080111191247.55ab360d@solaris.tower> <51AF6510-6CC0-4D8A-94AA-D704CE47510A@fastmail.fm> <20080114175654.GT27808@darcs.net> Message-ID: On 14 Jan 2008, at 9:56 AM, David Roundy wrote: > On Fri, Jan 11, 2008 at 07:10:20PM -0800, Jonathan Cast wrote: >> On 11 Jan 2008, at 10:12 AM, Achim Schneider wrote: >> >>> David Roundy wrote: >>> >>>> Prelude> let x=1e-300/1e300 >>>> Prelude> x >>>> 0.0 >>>> Prelude> x/x >>>> NaN >>>> >>>> The "true" answer here is that x/x == 1.0 (not 0 or +Infinity), but >>>> there's no way for the computer to know this, so it's NaN. Ah. My apologies. Must remember to read first, then flame... You are right that, in Ratio Integer, you get this result. But you can't get that answer in Double. jcc From s.clover at gmail.com Tue Jan 15 00:17:17 2008 From: s.clover at gmail.com (Sterling Clover) Date: Tue Jan 15 00:10:39 2008 Subject: [Haskell-cafe] Re: [Haskell] ANNOUNCE: HStringTemplate -- An Elegant, Functional, Nifty Templating Engine for Haskell In-Reply-To: <20080114080940.GL20928@scytale.galois.com> References: <89B71013-9550-4E1F-91DD-A4ABD532F2F1@gmail.com> <20080114080940.GL20928@scytale.galois.com> Message-ID: <404294C0-74A2-488B-B047-BC52BA4901EE@gmail.com> I'm absolutely planning to get it up there, but it needs a bit more work first. Just today, gwern sent a bunch of very nice patches that cleaned up some -Wall messages, and fixed a build issue with 6.8. And then, thanks to an email from Martin L?tke, I realized that I had foolishly not exported a function to query groups, because I was too worried about functions to compose them! So yeah, letting your baby out into the world is a bit scary, but everyone's been quite helpful and supportive so far, and hopefully I'll feel ready to get it on hackage in the next week or two. (Of course, after that, I'm now puzzling over the best typesafe ways to represent html entity encoding and url escaping, planning to pull together some more documentation on all the loveliness of the stringtemplate grammar, there are more quickcheck properties to be written, you know.. the usual. :-) ) --S On Jan 14, 2008, at 3:09 AM, Don Stewart wrote: > s.clover: >> HStringTemplate is a port of Terrence Parr?s lovely StringTemplate >> (http://www.stringtemplate.org) engine to Haskell. >> >> It is available, cabalized, at: >> darcs get http://code.haskell.org/HStringTemplate/ > > Looks very useful! Will this be on hackage.haskell.org soon? > > I can't wait to: > > cabal install HStringTemplate > > :) > > -- Don From lennart at augustsson.net Tue Jan 15 00:18:43 2008 From: lennart at augustsson.net (Lennart Augustsson) Date: Tue Jan 15 00:12:01 2008 Subject: [Haskell-cafe] Re: Re: Displaying # of reductions after eachcomputation in ghci? In-Reply-To: References: <20080108221155.GA3393@localhost.localdomain> Message-ID: In lambda calculus you can take a beta reduction as the step. But Haskell is not normally implemented by lambda calculus so you have to pick something else. There are measures of reduction that you can come up with but they will vary, e.g., by compiler, optimization level, etc. I think time is a much more interesting measure, since that's what you really care about in the end. On Jan 14, 2008 2:03 PM, Ben Franksen wrote: > Lennart Augustsson wrote: > > What is a reduction anyway? > > I am not an expert but I thought in lambda calculus one has primitive > rules > for evaluation, e.g. beta reduction. So a reduction is a 'smallest step' > in > reducing an expression to normal form, no? > > Cheers > Ben > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080114/6a504fcc/attachment.htm From adam.smyczek at gmail.com Tue Jan 15 00:28:20 2008 From: adam.smyczek at gmail.com (Adam Smyczek) Date: Tue Jan 15 00:21:41 2008 Subject: [Haskell-cafe] ErrorT and catchError question Message-ID: Hi, I'm trying to use ErrorT transformer based on Don Stewart's Shell example: http://cgi.cse.unsw.edu.au/~dons/blog/2007/03/10#programmable-semicolons It's probably a trivial question, but I cannot figure out how to implement the catchError function in: instance MonadError String Shell where throwError = error . ("Shell failed: "++) catchError l h = ??? Thanks for help, Adam From allbery at ece.cmu.edu Tue Jan 15 00:33:51 2008 From: allbery at ece.cmu.edu (Brandon S. Allbery KF8NH) Date: Tue Jan 15 00:27:11 2008 Subject: [Haskell-cafe] ErrorT and catchError question In-Reply-To: References: Message-ID: <4C532956-1EA1-45DA-A64B-FAACE7DDCDFE@ece.cmu.edu> On Jan 15, 2008, at 0:28 , Adam Smyczek wrote: > It's probably a trivial question, but I cannot figure out > how to implement the catchError function in: > > instance MonadError String Shell where > throwError = error . ("Shell failed: "++) > catchError l h = ??? Take a look at Control.Exception.catch for starters. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH From dbenbenn at gmail.com Tue Jan 15 00:35:21 2008 From: dbenbenn at gmail.com (David Benbennick) Date: Tue Jan 15 00:28:40 2008 Subject: [Haskell-cafe] QuickCheck properties: export or not? In-Reply-To: <478BECF0.1070206@cogito.org.uk> References: <478BECF0.1070206@cogito.org.uk> Message-ID: I think that type classes with nontrivial requirements should export QuickCheck properties that test those requirements. For example, the Data.Monoid module (http://haskell.org/ghc/docs/latest/html/libraries/base/Data-Monoid.html) could export properties that check the monoid laws (for an Arbitrary Monoid with Eq). That would serve as a formal specification of the requirements, and allow any user to check that their implementation is right. -- I'm doing Science and I'm still alive. From lemming at henning-thielemann.de Tue Jan 15 01:40:03 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Tue Jan 15 01:33:27 2008 Subject: [Haskell-cafe] fast fractional part of floating point number - modf? In-Reply-To: <20080115031732.GA874@momenergy.repetae.net> References: <20080115031732.GA874@momenergy.repetae.net> Message-ID: On Mon, 14 Jan 2008, John Meacham wrote: > On Sun, Jan 13, 2008 at 01:08:49AM +0100, Henning Thielemann wrote: > > Is there a fast and reliable way to compute the fraction of a floating > > point number? > > no, and this has bothered me to the point I consider it a bug in the > language spec that all 'rounding' style functions give back an integral > type. I find returning an Integral is appropriate. The type expresses perfectly what kind of values you can expect. Sure, there should be some optimization rule like fromInteger (round x) = roundf x . However, the 'fraction' function gets a fraction and returns a fraction and doesn't care about the type of the integer part. As I see this is also missing from your RealFrac class extension. From jerzy.karczmarczuk at info.unicaen.fr Tue Jan 15 03:14:55 2008 From: jerzy.karczmarczuk at info.unicaen.fr (jerzy.karczmarczuk@info.unicaen.fr) Date: Tue Jan 15 03:08:14 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? In-Reply-To: <7ca3f0160801141737u142f7f53l8432ce4ac3ae9310@mail.gmail.com> References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <87fxx4slcy.fsf@nmd9999.imr.no> <200801111456.05819.g9ks157k@acme.softbase.org> <7ca3f0160801141737u142f7f53l8432ce4ac3ae9310@mail.gmail.com> Message-ID: Luke Palmer dialog with myself: > On Jan 15, 2008 12:29 AM, wrote: >> When math says that something is undefined, in my little brain I >> understand that there is no answer. > I'm not sure if I'm agreeing or disagreeing with you here. Depends on > exactly what you mean by no answer. Yes, this is a doctrinal problem. Since *any* concrete reaction, e.g., an error message is a kind of answer, the only - unusable as it is - way of not providing it is to fail the termination... > When I was a TA for calculus 2, students were presented with something > like the following problem: > Find the limit: > lim (sin x / x) > x->0 > And proceeding, they would reduce this to: > sin 0 / 0 > 0 / 0 > Look in the book that said "0/0 is undefined", and write "undefined" > on the paper as if that were the answer. > For the calculus uninclined (I figure that is a vast minority on this > list), the answer is 1. In that case, undefined meant "you did the > problem wrong". And the error was precisely when they wrote 0 on the > bottom of the division sign. What I see faulty here is that your students were not given, or could not grasp the only "serious" word in the problem statement, the word *limit*. In engineering, physics, etc., sometimes math is conveyed a bit approxima- tively, swallowing some touchy points, and relying on intuition. This is unavoidable, question of time. I taught math to physics students a bit and there is no free lunch here. But a true mathematician lecturing to genuine math students *here* makes the things clear as crystal. And what I learnt then was exactly that: undefined means no answer. I may be wrong, but it is possible that in such "state of spirit" of the Creators the Haskell <> object arose into "being". Whether you say that: > Instead, when mathematicians say "undefined", they usually mean not > that the question has no answer, but that the question you're asking > doesn't even make sense as a question. - or use such words as "illegal", "forbidden", etc., this is a question of philosophy more than math. At least: semantics. For Leibniz (or his eternal foe, Spinoza) it could even belong to ethics... We, or whoever might speculate until the solution of the non-termination problem whether math forbids anything, or what is the sense of a question, or the sense of the sense. Mathematicians I crossed in my life (plenty of them; same building...), at least some of them, *did* say that undefined means no answer. Your example with the King on the chessboard goes along the doctrine professed by Achim S., "forbidding" something. But this word, "legality", etc. is a juridic term, something not so meaningful in math. OK, you are forbidden to try 0/0. But you DO. So what? You claim that math doesn't say "undefined", mathematicians do, etc. Now, does MATH say "Hey! there is no sense in what you are doing!"? But math as an abstract domain, does it have "built-in" the notion of sense neither. You say: "you are out of system/sense". I say "you get no answer". I believe that my standpoint is more operational. > Personally, I loathe the existence of NaN and +-Infinity in floating > point types. I conclude that you live far from the numeric world. But I was raised as physicist, and without them, the implementation of several algorithms would be extremely difficult. > Someone here made an enlightinging point encouraging us to think of > floating point numbers not as numbers but as intervals. That makes me > slightly more okay with the infinities, but NaN still bugs me. > I'd prefer an error: Haskell's way of saying "you > did the problem wrong". That would be most useful in the kinds of > things I do with floating point numbers (games). But there are probably > other areas where the IEEE semantics are more useful. Once more, last time... The interval interpretation is a bit pulled out of thin air. It might be thought of, as the last bit rounding has sth. to do with "fuzzy" arith., but I don't think that this is the issue. I believe that if we wanted to be as close to math as we would be happy with, the only way is to extend the typing of numbers. There are numbers, and there are NaNs and infinities. PERFECTLY decent objects, with concrete representations (or families of). The arith. ops may generate those types, and if applied to them, the disease propagates. Simple as that. For many, many numerical library procedures which use automatic search through some domains, for vectorized computations, etc., bombing is almost as bad as non-termination. It provides you gratuitously with a waste of time. Absolutely inacceptable for engineering reasons. In games it might happen as well, when, e.g., a collision handling module finds a pathological geometrical situation, with a singularity so close that math bombs. Then, a possible solution is to output /some/ random value, and not break the game. In other words., accept NaNs and infinities, and do with them what your program requires. YOU take the responsability of raising an exception, not the system. Jerzy Karczmarczuk From felipe.lessa at gmail.com Tue Jan 15 04:55:07 2008 From: felipe.lessa at gmail.com (Felipe Lessa) Date: Tue Jan 15 04:48:25 2008 Subject: [Haskell-cafe] Re: MonadPrompt + Gtk2Hs = ? In-Reply-To: References: Message-ID: On Jan 14, 2008 8:27 PM, apfelmus wrote: > The type of contPromptM is even more general than that: > > casePromptOf' :: (r -> f b) > -> (forall a,b. p a -> (a -> f b) -> f b) > -> Prompt p r -> f b > casePromptOf' done cont (PromptDone r) = done r > casePromptOf' done cont (Prompt p c ) = cont p (casePromptOf' done cont . c) (I guess the forall b inside 'cont' is a typo?) Actually, it can be as general as casePromptOf :: (r -> b) -> (forall a. p a -> (a -> b) -> b) -> Prompt p r -> b casePromptOf done cont (PromptDone r) = done r casePromptOf done cont (Prompt p c ) = cont p (casePromptOf done cont . c) =) And, just for the record, runPromptAgain :: Monad m => (forall a. p a -> m a) -> Prompt p r -> m r runPromptAgain f = casePromptOf return ((>>=) . f) > The link to ContT m a = (forall b . (a -> m b) -> m b) is apparent in > the case of casePromptOf' and is no surprise: you can omit p a and > Prompt p r entirely and implement them directly as continuations > (thereby loosing the ability to use it with different m, which would > defeat the whole point here.) See also > > Implementing the State Monad. > http://article.gmane.org/gmane.comp.lang.haskell.cafe/31486 > > for the details. I've read that e-mail when it was sent but didn't understand it fully. I guess now I'm in a better condition, but I still have a lot to learn about these little warm, fuzzy things. Actually, the more I see, the less I understand why some people are afraid of them... it must really be the name 'monad'. Thanks for all the help guys! Next I'll try to reproduce the freezes I was getting with my first forkIO approach. Cheers, -- Felipe. From dekudekuplex at yahoo.com Tue Jan 15 05:02:34 2008 From: dekudekuplex at yahoo.com (Benjamin L. Russell) Date: Tue Jan 15 04:55:51 2008 Subject: Any publication date for The Little Haskeller? [Was: Re: [Haskell-cafe] Computer Science Books using Haskell] In-Reply-To: <7.0.1.0.0.20080114065433.01cf5470@ntlworld.com> Message-ID: <408520.30380.qm@web30206.mail.mud.yahoo.com> Speaking of computer science books using Haskell, does anybody know when will a Haskell version of The Little Schemer, or anything equivalent, be published? It seems strange that The Little MLer is out, but not The Little Haskeller. Benjamin L. Russell --- PR Stanley wrote: > Hi > Can the list recommend books that use Haskell - or > any FP language > but preferably Haskell - to illustrate the > principles of compilers > and/or algorithms? > I think most of you would understand if I said that > I'd prefer FP > code instead of funny math symbols that don't > translate into ANSI > characters with the current OCR technology, unless, > of course, you > know of a book available in latex code. > Rather than rushing straight to Google I thought I'd > first draw on > the wealth of knowledge that exists on this list. > Cheers > Paul > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From dekudekuplex at yahoo.com Tue Jan 15 05:08:59 2008 From: dekudekuplex at yahoo.com (Benjamin L. Russell) Date: Tue Jan 15 05:02:17 2008 Subject: Any publication date for Structure and Interpretation of Functional Computer Programs? [Was: Re: [Haskell-cafe] Computer Science Books using Haskell] In-Reply-To: <7.0.1.0.0.20080114065433.01cf5470@ntlworld.com> Message-ID: <255387.27554.qm@web30208.mail.mud.yahoo.com> Alternatively, again speaking of computer science books using Haskell, does anybody know when will a Haskell version of Structure and Interpretation of Computer Programs, or anything of the same scope, be published? It seems strange that Concepts, Techniques, and Models of Computer Programming is out using Mozart/Oz, but apparently nothing of equivalent scope using Haskell. Ideally, the book should cover roughly the same scope of topics as SICP or CTM, but with a declarative ("What is?"), rather than an imperative ("How to?"), approach. Benjamin L. Russell --- PR Stanley wrote: > Hi > Can the list recommend books that use Haskell - or > any FP language > but preferably Haskell - to illustrate the > principles of compilers > and/or algorithms? > I think most of you would understand if I said that > I'd prefer FP > code instead of funny math symbols that don't > translate into ANSI > characters with the current OCR technology, unless, > of course, you > know of a book available in latex code. > Rather than rushing straight to Google I thought I'd > first draw on > the wealth of knowledge that exists on this list. > Cheers > Paul > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From dekudekuplex at yahoo.com Tue Jan 15 05:09:37 2008 From: dekudekuplex at yahoo.com (Benjamin L. Russell) Date: Tue Jan 15 05:02:54 2008 Subject: Any publication date for Structure and Interpretation of Functional Computer Programs? [Was: Re: [Haskell-cafe] Computer Science Books using Haskell] In-Reply-To: <7.0.1.0.0.20080114065433.01cf5470@ntlworld.com> Message-ID: <241467.35796.qm@web30211.mail.mud.yahoo.com> Alternatively, again speaking of computer science books using Haskell, does anybody know when will a Haskell version of Structure and Interpretation of Computer Programs, or anything of the same scope, be published? It seems strange that Concepts, Techniques, and Models of Computer Programming is out using Mozart/Oz, but apparently nothing of equivalent scope using Haskell. Ideally, the book should cover roughly the same scope of topics as SICP or CTM, but with a declarative ("What is?"), rather than an imperative ("How to?"), approach. Benjamin L. Russell --- PR Stanley wrote: > Hi > Can the list recommend books that use Haskell - or > any FP language > but preferably Haskell - to illustrate the > principles of compilers > and/or algorithms? > I think most of you would understand if I said that > I'd prefer FP > code instead of funny math symbols that don't > translate into ANSI > characters with the current OCR technology, unless, > of course, you > know of a book available in latex code. > Rather than rushing straight to Google I thought I'd > first draw on > the wealth of knowledge that exists on this list. > Cheers > Paul > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From haskell at list.mightyreason.com Tue Jan 15 06:04:38 2008 From: haskell at list.mightyreason.com (ChrisK) Date: Tue Jan 15 05:58:06 2008 Subject: [Haskell-cafe] Re: \_ -> not equivalent to const $ In-Reply-To: <7ca3f0160801101454g27267cd4qdbe3b93300b30a56@mail.gmail.com> References: <7ca3f0160801101454g27267cd4qdbe3b93300b30a56@mail.gmail.com> Message-ID: Luke Palmer wrote: > In attempting to devise a variant of cycle which did not keep its > argument alive (for the purpose of cycle [1::Int..]), I came across > this peculiar behavior: > > import Debug.Trace > > cycle' :: (a -> [b]) -> [b] > cycle' xs = xs undefined ++ cycle' xs > > >> take 20 $ cycle' (const $ 1:2:3:4:trace "x" 5:[]) > [1,2,3,4,x > 5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5] > > Nuts. Oh, but wait: > >> take 20 $ cycle' (\_ -> 1:2:3:4:trace "x" 5:[]) > [1,2,3,4,x > 5,1,2,3,4,x > 5,1,2,3,4,x > 5,1,2,3,4,x > 5] > > Hey, it worked! > > Can someone explain what the heck is going on here? > > Luke (\_ -> 1:2:3:4:trace "x" 5:[]) literally could mean your second program, but... the 1:2:3:4:trace "x" 5:[] does not depend on the _ argument, and so it can be lifted outside the (\_ -> ... ) and lazily evaluated once and shared between calls. Optimization in ghc do this for you. The definition "const x = (\_ -> x)" binds 'x' outside of the _ argument, so 'x' is obviously outside (\_ -> ...) and will be lazily evaluated once and shared. I see that making the binding and sharing explicit in >> take 20 $ cycle' (let x = 1:2:3:4:trace "x" 5:[] in (\_ -> x)) > [1,2,3,4,x > 5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5] behaves like const. And pushing the binding inside the (\_ -> ...) >> take 20 $ cycle' (\_ -> let x = 1:2:3:4:trace "x" 5:[] in x) > [1,2,3,4,x > 5,1,2,3,4,x > 5,1,2,3,4,x > 5,1,2,3,4,x > 5] behaves like your second example. -- Chris From barsoap at web.de Tue Jan 15 06:24:52 2008 From: barsoap at web.de (Achim Schneider) Date: Tue Jan 15 06:18:20 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <87fxx4slcy.fsf@nmd9999.imr.no> <200801111456.05819.g9ks157k@acme.softbase.org> <7ca3f0160801141737u142f7f53l8432ce4ac3ae9310@mail.gmail.com> Message-ID: <20080115122452.6f276e75@solaris.tower> jerzy.karczmarczuk@info.unicaen.fr wrote: > Your example with the King on the chessboard goes along the doctrine > professed by Achim S., "forbidding" something. But this word, > "legality", etc. is a juridic term, something not so meaningful in > math. OK, you are forbidden to try 0/0. But you DO. So what? > You claim that math doesn't say "undefined", mathematicians do, etc. > Now, does MATH say "Hey! there is no sense in what you are doing!"? > But math as an abstract domain, does it have "built-in" the notion of > sense neither. You say: "you are out of system/sense". I say "you get > no answer". I believe that my standpoint is more operational. > I believe it's basically the same point. Legal, btw, is meant along the lines of "it is not allowed for an apple to reinterpret gravity and fly into earth's orbit". Natural, not human-made law. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From levi.stephen at optusnet.com.au Tue Jan 15 06:29:03 2008 From: levi.stephen at optusnet.com.au (Levi Stephen) Date: Tue Jan 15 06:22:25 2008 Subject: [Haskell-cafe] First go at reactive programming Message-ID: <478C98FF.2060903@optusnet.com.au> Hi, Listed below is my first experiment with reactive programming. It is a simple web server written using the Data.Reactive[1] library. The intended interface is given by the runHttpServer function, so the remainder is intended to be internal. I'd be happy to hear comments on any parts of this, but am particularly interested in the following: 1. Is this kind of code what is intended from reactive programming? 2a. I'm not sure about passing the (Handle,...) tuple around. Is there a way to avoid this? 2b. I'm not sure of the best place to handle possible socket exceptions 2c. I'd like to be able to pass a function of type Event Request -> Event Response to runHttpServer, so that reactive programming could be used throughout client code also, but the (Handle,...) tuples seem to be getting in the way. 3. I have a feeling there's a clearer way to write responseSend. Thanks, Levi [1] http://www.haskell.org/haskellwiki/Reactive module Main where import Control.Applicative import Control.Arrow ((&&&),(>>>)) import Control.Concurrent import Control.Monad import Data.Reactive import Network.BSD import Network.HTTP import Network import System.IO import Text.XHtml.Strict type RequestHandler = Request -> Response main = runHttpServer helloWorldHandler helloWorldHandler :: RequestHandler helloWorldHandler _ = Response (2,0,0) "" [] $ prettyHtml helloWorldDoc helloWorldDoc = header << thetitle << "Hello World" +++ body << h1 << "Hello World" runHttpServer r = socketServer >>= runE . handleConnection r socketServer :: IO (Event Handle) socketServer = withSocketsDo $ do (e,snk) <- mkEventShow "Server" sock <- listenOn (PortNumber 8080) forkIO $ forever $ acceptConnection sock $ snk return e handleConnection :: RequestHandler -> Event Handle -> Event (IO ()) handleConnection r = handleToRequest >>> runRequestHandler r >>> responseSend handleToRequest :: Event Handle -> Event (Handle, IO (Result Request)) handleToRequest e = fmap (id &&& receiveHTTP) e responseSend :: Event (Handle, IO (Result Response)) -> Event (IO ()) responseSend e = fmap (\(h,rsp) -> rsp >>= either (putStrLn . show) (respondHTTP h) >> close h) e runRequestHandler :: RequestHandler -> Event (Handle, IO (Result Request)) -> Event (Handle, IO (Result Response)) runRequestHandler r e = fmap hrToHr e where rqhdl :: Result Request -> Result Response rqhdl rq = bindE rq (Right . r) hrToHr :: (Handle, IO (Result Request)) -> (Handle, IO (Result Response)) hrToHr (h,req) = (h, liftA rqhdl req) acceptConnection s k = accept s >>= \(h,_,_) -> forkIO $ k h instance Stream Handle where readLine h = hGetLine h >>= \l -> return $ Right $ l ++ "\n" readBlock h n = replicateM n (hGetChar h) >>= return . Right writeBlock h s = mapM_ (hPutChar h) s >>= return . Right close = hClose From john at repetae.net Tue Jan 15 07:08:03 2008 From: john at repetae.net (John Meacham) Date: Tue Jan 15 07:01:22 2008 Subject: [Haskell-cafe] fast fractional part of floating point number - modf? In-Reply-To: References: <20080115031732.GA874@momenergy.repetae.net> Message-ID: <20080115120803.GA9240@momenergy.repetae.net> On Tue, Jan 15, 2008 at 07:40:03AM +0100, Henning Thielemann wrote: > > On Mon, 14 Jan 2008, John Meacham wrote: > > > On Sun, Jan 13, 2008 at 01:08:49AM +0100, Henning Thielemann wrote: > > > Is there a fast and reliable way to compute the fraction of a floating > > > point number? > > > > no, and this has bothered me to the point I consider it a bug in the > > language spec that all 'rounding' style functions give back an integral > > type. > > I find returning an Integral is appropriate. The type expresses perfectly > what kind of values you can expect. Sure, there should be some > optimization rule like > fromInteger (round x) = roundf x . it is not that it isn't appropriate, it is that is isn't that useful nor is it equivalent. roundf NaN -> NaN fromInteger $ round NaN -> error roundf -0 -> -0 fromInteger $ round -0 -> 0 and how about fromInteger $ ceil (the highest represpentable number in a Double) you go from a 64 bit primitive value to one that takes up a substantial amount of memory when expressed as an Integer and back again. All of these tricky corner cases have been thought out by the IEEE. more importantly, all these things have well defined meanings in IEEE floating point specfications and they cannot be followed in haskell due to the integral constraint. Floating point numbers are odd beasts, we must be careful with them. John -- John Meacham - ?repetae.net?john? From bulat.ziganshin at gmail.com Tue Jan 15 07:28:02 2008 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Tue Jan 15 07:21:42 2008 Subject: [Haskell-cafe] Haskell and GUI In-Reply-To: References: Message-ID: <1823036741.20080115152802@gmail.com> Hello Torsten, Tuesday, January 15, 2008, 1:09:54 AM, you wrote: > Seeing my woes with FranTk - what else is out there that people use if > a (simple) GUI is desired for a Haskell app? Just a few textboxes and > a button or two would do me. i've read Gtk2Hs tutorial[1] and developed first version of GUI for my program in 1 day [1] http://darcs.haskell.org/gtk2hs/docs/tutorial/Tutorial_Port/index.xhtml -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From gale at sefer.org Tue Jan 15 08:27:46 2008 From: gale at sefer.org (Yitzchak Gale) Date: Tue Jan 15 08:21:03 2008 Subject: [Haskell-cafe] Haskell and GUI In-Reply-To: References: Message-ID: <2608b8a80801150527n40e0d347i7e8049b54a824a44@mail.gmail.com> Hi Torsten, Here is something I use in GTK2HS when teaching beginners: http://hpaste.org/5017 Hope this helps, Yitz From gale at sefer.org Tue Jan 15 08:46:34 2008 From: gale at sefer.org (Yitzchak Gale) Date: Tue Jan 15 08:39:52 2008 Subject: [Haskell-cafe] Haskell and GUI In-Reply-To: <2608b8a80801150527n40e0d347i7e8049b54a824a44@mail.gmail.com> References: <2608b8a80801150527n40e0d347i7e8049b54a824a44@mail.gmail.com> Message-ID: <2608b8a80801150546r6f2c7afau53d1a08167ead253@mail.gmail.com> btw, if you use GTK2HS on the Mac, don't forget to start up X Windows support, and run "export DISPLAY=:0.0" in your terminal window, before you run your program. X Windows is usually in Applications/Utilities, but only if you installed it manually from the Mac OS X discs, it is not installed by default. Good news - Gtk2 now has native support for the Mac, so you probably won't need to run X starting with the next version of GTK2HS. Regard, Yitz From marco-oweber at gmx.de Tue Jan 15 08:57:52 2008 From: marco-oweber at gmx.de (Marc Weber) Date: Tue Jan 15 08:51:11 2008 Subject: [Haskell-cafe] jumping to code every and anywhere : what about installing tagfile and source ? In-Reply-To: <20080114005700.GC26840@gmx.de> References: <20080114005700.GC26840@gmx.de> Message-ID: <20080115135752.GA31704@gmx.de> Maybe it's better to ask ghc to include location information into the iface files? Then you can get the right file depending on your imports.. Marc From wss at Cs.Nott.AC.UK Tue Jan 15 11:10:44 2008 From: wss at Cs.Nott.AC.UK (Wouter Swierstra) Date: Tue Jan 15 11:12:51 2008 Subject: [Haskell-cafe] Haskell and GUI In-Reply-To: References: Message-ID: <00C0E6A4-AF74-4FAA-929F-9B9400DFCD0B@cs.nott.ac.uk> Hi Torsten, If you really only want a simple GUI - I seem to recall you're on a Mac - you might even be able to get away with the AppleScript bindings: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/AppleScript-0.1.3 There are an example of a simple textfield GUI in the examples directory. Hope this helps, Wouter This message has been checked for viruses but the contents of an attachment may still contain software viruses, which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation. From haskell at list.mightyreason.com Tue Jan 15 12:22:58 2008 From: haskell at list.mightyreason.com (ChrisK) Date: Tue Jan 15 12:16:24 2008 Subject: [Haskell-cafe] Re: Haskell and GUI In-Reply-To: <2608b8a80801150546r6f2c7afau53d1a08167ead253@mail.gmail.com> References: <2608b8a80801150527n40e0d347i7e8049b54a824a44@mail.gmail.com> <2608b8a80801150546r6f2c7afau53d1a08167ead253@mail.gmail.com> Message-ID: <478CEBF2.1040400@list.mightyreason.com> The advice below is for Mac OS X 10.4 and below. Starting with Mac OS X 10.5 (Leopard) the DISPLAY is set for you by the operating system. Mine is currently "/tmp/launch-sQZXQV/:0" which looks very strange because it is used to cause the launchd daemon to start the X server on demand (i.e. lazily). Yitzchak Gale wrote: > btw, if you use GTK2HS on the Mac, don't forget to > start up X Windows support, and run "export DISPLAY=:0.0" > in your terminal window, before you run your program. > X Windows is usually in Applications/Utilities, but only > if you installed it manually from the Mac OS X discs, > it is not installed by default. > > Good news - Gtk2 now has native support for the > Mac, so you probably won't need to run X starting > with the next version of GTK2HS. > > Regard, > Yitz -- Chris From immanuel.normann at googlemail.com Tue Jan 15 12:53:10 2008 From: immanuel.normann at googlemail.com (Immanuel Normann) Date: Tue Jan 15 12:46:33 2008 Subject: [Haskell-cafe] haskelldb basic documentation needed Message-ID: <92952f860801150953q79a66166o5e5ff27fb37ee91d@mail.gmail.com> with the release update haskelldb-0.9 -> haskelldb-0.10 several things have changed. Unfortunately the API documentation does not give enough information in generall. Is there any additional uptodate documentation around? In particular the fundamental function "connect" hast a new signature: *connect* :: (forall m a . MonadIOm => [( String, String)] -> (Database-> m a) -> m a) I don't know what pairs of strings this function needs. The API description is to unspecific: The connectfunction takes some driver specific name, value pairs use to setup the > database connection, and a database action to run. What are the specific name value pairs needed (for a connection to a mysql db )? Immanuel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080115/6f9740ec/attachment.htm From conal at conal.net Tue Jan 15 14:42:45 2008 From: conal at conal.net (Conal Elliott) Date: Tue Jan 15 14:36:03 2008 Subject: [Haskell-cafe] Haskell and GUI In-Reply-To: References: Message-ID: If you can get wxHaskell installed & working, you could try Phooey and/or TV. Both are described on the Haskell wiki and available via darcs and Hackage. On Jan 14, 2008 2:09 PM, Torsten Otto wrote: > Seeing my woes with FranTk - what else is out there that people use if > a (simple) GUI is desired for a Haskell app? Just a few textboxes and > a button or two would do me. > > Thanks in advance! > > Regards, > Torsten > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080115/5c470e41/attachment.htm From jgbailey at gmail.com Tue Jan 15 16:44:28 2008 From: jgbailey at gmail.com (Justin Bailey) Date: Tue Jan 15 16:37:45 2008 Subject: [Haskell-cafe] haskelldb basic documentation needed In-Reply-To: <92952f860801150953q79a66166o5e5ff27fb37ee91d@mail.gmail.com> References: <92952f860801150953q79a66166o5e5ff27fb37ee91d@mail.gmail.com> Message-ID: 2008/1/15 Immanuel Normann : > I don't know what pairs of strings this function needs. The API > description is to unspecific: > > The connect function takes some driver specific name, value pairs use to > > setup the database connection, and a database action to run. > > > What are the specific name value pairs needed (for a connection to a mysql > db )? > Immanuel Your best bet is to download the appropriate drivers - either haskelld-hdbc-mysql or haskelldb-hsql-mysql. If you get the haskelldb sources via darcs, you can also look in the test directory to see how the connections are established. In my specific case, I am using PostgreSQL and by login function looks like this: -- ^ Returns a function which can log into the database and perform operations. login :: MonadIO m => String -> Int -> String -> String -> String -> (Database -> m a) -> m a login server port user password dbname = postgresqlConnect [("host", server), ("port", show port), ("user", user), ("password", password), ("dbname", dbname)] > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080115/2363a53a/attachment.htm From agl at imperialviolet.org Tue Jan 15 18:23:59 2008 From: agl at imperialviolet.org (Adam Langley) Date: Tue Jan 15 18:17:15 2008 Subject: [Haskell-cafe] Re: ANN: A triple of new packages for talking tothe outside world In-Reply-To: <20080110184521.GA17906@scytale.galois.com> References: <396556a20801071037t1b66e444u52abe1d934b7f902@mail.gmail.com> <396556a20801081226l5ebf5062p685a80c6aac6ba41@mail.gmail.com> <1199885578.7279.119.camel@localhost> <117f2cc80801091425l41b73ea3uddda3d91ba9405e7@mail.gmail.com> <20080109234352.3ee84d4a@solaris.tower> <20080110010123.GF18915@darcs.net> <396556a20801091725p4a2dbf8aw3117a568b807c195@mail.gmail.com> <20080110184521.GA17906@scytale.galois.com> Message-ID: <396556a20801151523t314797atb40fa26688c6ec6@mail.gmail.com> On Jan 10, 2008 10:45 AM, Don Stewart wrote: > That's pretty much what we envisaged as the approach to take. > Monad transformers adding some bit-buffer state over Get/Put. For anyone who's still reading this thread... I've just uploaded[1] binary-strict 0.2.1 which includes Data.Binary.Strict.BitGet - a Get like monad which works by the bit. I'm afraid that Haddock 2 is choaking on {-# UNPACK #-}, so I don't have the HTML documentation to point to. (And I thought that Haddock 2 was going to fix all those parsing issues :( - hopefully I'm just doing something stupid). [1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/binary-strict-0.2.1 AGL -- Adam Langley agl@imperialviolet.org http://www.imperialviolet.org 650-283-9641 From dons at galois.com Tue Jan 15 18:26:47 2008 From: dons at galois.com (Don Stewart) Date: Tue Jan 15 18:20:09 2008 Subject: [Haskell-cafe] Re: ANN: A triple of new packages for talking tothe outside world In-Reply-To: <396556a20801151523t314797atb40fa26688c6ec6@mail.gmail.com> References: <396556a20801081226l5ebf5062p685a80c6aac6ba41@mail.gmail.com> <1199885578.7279.119.camel@localhost> <117f2cc80801091425l41b73ea3uddda3d91ba9405e7@mail.gmail.com> <20080109234352.3ee84d4a@solaris.tower> <20080110010123.GF18915@darcs.net> <396556a20801091725p4a2dbf8aw3117a568b807c195@mail.gmail.com> <20080110184521.GA17906@scytale.galois.com> <396556a20801151523t314797atb40fa26688c6ec6@mail.gmail.com> Message-ID: <20080115232647.GD30040@scytale.galois.com> agl: > On Jan 10, 2008 10:45 AM, Don Stewart wrote: > > That's pretty much what we envisaged as the approach to take. > > Monad transformers adding some bit-buffer state over Get/Put. > > For anyone who's still reading this thread... > > I've just uploaded[1] binary-strict 0.2.1 which includes > Data.Binary.Strict.BitGet - a Get like monad which works by the bit. > I'm afraid that Haddock 2 is choaking on {-# UNPACK #-}, so I don't > have the HTML documentation to point to. (And I thought that Haddock 2 > was going to fix all those parsing issues :( - hopefully I'm just > doing something stupid). > > [1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/binary-strict-0.2.1 Ok. That's awesome. I guess if you do all the TODOs for Binary like this, we should merge the code back in :) From agl at imperialviolet.org Tue Jan 15 19:05:49 2008 From: agl at imperialviolet.org (Adam Langley) Date: Tue Jan 15 18:59:05 2008 Subject: [Haskell-cafe] Re: ANN: A triple of new packages for talking tothe outside world In-Reply-To: <20080115232647.GD30040@scytale.galois.com> References: <396556a20801081226l5ebf5062p685a80c6aac6ba41@mail.gmail.com> <1199885578.7279.119.camel@localhost> <117f2cc80801091425l41b73ea3uddda3d91ba9405e7@mail.gmail.com> <20080109234352.3ee84d4a@solaris.tower> <20080110010123.GF18915@darcs.net> <396556a20801091725p4a2dbf8aw3117a568b807c195@mail.gmail.com> <20080110184521.GA17906@scytale.galois.com> <396556a20801151523t314797atb40fa26688c6ec6@mail.gmail.com> <20080115232647.GD30040@scytale.galois.com> Message-ID: <396556a20801151605y602e9781kdda7a771416b0b8@mail.gmail.com> On Jan 15, 2008 3:26 PM, Don Stewart wrote: > Ok. That's awesome. I guess if you do all the TODOs for Binary like > this, we should merge the code back in :) Well, at the moment I'm pretty unhappy with the amount of code duplication required both within binary-strict and between binary and binary-strict. I think this code needs a whole lot of restructuring (maybe a bit of TH for generating the common bits). I'll get to that when it appears that the API seems reasonable. AGL -- Adam Langley agl@imperialviolet.org http://www.imperialviolet.org 650-283-9641 From ndmitchell at gmail.com Tue Jan 15 20:01:48 2008 From: ndmitchell at gmail.com (Neil Mitchell) Date: Tue Jan 15 19:55:03 2008 Subject: [Haskell-cafe] Re: ANN: A triple of new packages for talking tothe outside world In-Reply-To: <396556a20801151605y602e9781kdda7a771416b0b8@mail.gmail.com> References: <396556a20801081226l5ebf5062p685a80c6aac6ba41@mail.gmail.com> <117f2cc80801091425l41b73ea3uddda3d91ba9405e7@mail.gmail.com> <20080109234352.3ee84d4a@solaris.tower> <20080110010123.GF18915@darcs.net> <396556a20801091725p4a2dbf8aw3117a568b807c195@mail.gmail.com> <20080110184521.GA17906@scytale.galois.com> <396556a20801151523t314797atb40fa26688c6ec6@mail.gmail.com> <20080115232647.GD30040@scytale.galois.com> <396556a20801151605y602e9781kdda7a771416b0b8@mail.gmail.com> Message-ID: <404396ef0801151701r64b97023y981e8bd3f95f3e24@mail.gmail.com> Hi > (maybe a bit of TH for generating the common bits) That would be bad. Then you'll have gone from Data.Binary being portable code, to being GHC specific code, and I will cry.... :'-( CPP is a good way to common stuff up in a portable way - I've used it in FilePath. There is nearly no end to the amount of crazy CPP hackery you can use to refactor stuff. Thanks Neil From adam.smyczek at gmail.com Tue Jan 15 22:05:57 2008 From: adam.smyczek at gmail.com (Adam Smyczek) Date: Tue Jan 15 21:59:18 2008 Subject: [Haskell-cafe] ErrorT and catchError question In-Reply-To: <4C532956-1EA1-45DA-A64B-FAACE7DDCDFE@ece.cmu.edu> References: <4C532956-1EA1-45DA-A64B-FAACE7DDCDFE@ece.cmu.edu> Message-ID: Ups, resend, first response did not make into the list. On Jan 14, 2008, at 9:33 PM, Brandon S. Allbery KF8NH wrote: > > On Jan 15, 2008, at 0:28 , Adam Smyczek wrote: > >> It's probably a trivial question, but I cannot figure out >> how to implement the catchError function in: >> >> instance MonadError String Shell where >> throwError = error . ("Shell failed: "++) >> catchError l h = ??? > > Take a look at Control.Exception.catch for starters. No, did not help and going over the source code of Control.Monad.Error did not help as well. Does someone have other tips for me? Thanks, Adam > -- > brandon s. allbery [solaris,freebsd,perl,pugs,haskell] > allbery@kf8nh.com > system administrator [openafs,heimdal,too many hats] > allbery@ece.cmu.edu > electrical and computer engineering, carnegie mellon university > KF8NH > > From monnier at iro.umontreal.ca Tue Jan 15 22:30:36 2008 From: monnier at iro.umontreal.ca (Stefan Monnier) Date: Tue Jan 15 22:23:59 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <87fxx4slcy.fsf@nmd9999.imr.no> <200801111456.05819.g9ks157k@acme.softbase.org> <7ca3f0160801141737u142f7f53l8432ce4ac3ae9310@mail.gmail.com> Message-ID: > Yes, this is a doctrinal problem. Since *any* concrete reaction, e.g., an > error message is a kind of answer, the only - unusable as it is - way of > not providing it is to fail the termination... You can just disallow the call, using the type system. Not that it's always easy or practical either, mind you. Stefan From agl at imperialviolet.org Tue Jan 15 22:33:26 2008 From: agl at imperialviolet.org (Adam Langley) Date: Tue Jan 15 22:26:42 2008 Subject: [Haskell-cafe] Re: ANN: A triple of new packages for talking tothe outside world In-Reply-To: <404396ef0801151701r64b97023y981e8bd3f95f3e24@mail.gmail.com> References: <396556a20801081226l5ebf5062p685a80c6aac6ba41@mail.gmail.com> <117f2cc80801091425l41b73ea3uddda3d91ba9405e7@mail.gmail.com> <20080109234352.3ee84d4a@solaris.tower> <20080110010123.GF18915@darcs.net> <396556a20801091725p4a2dbf8aw3117a568b807c195@mail.gmail.com> <20080110184521.GA17906@scytale.galois.com> <396556a20801151523t314797atb40fa26688c6ec6@mail.gmail.com> <20080115232647.GD30040@scytale.galois.com> <396556a20801151605y602e9781kdda7a771416b0b8@mail.gmail.com> <404396ef0801151701r64b97023y981e8bd3f95f3e24@mail.gmail.com> Message-ID: <396556a20801151933h6a1b16f0m385dd3b70b30080c@mail.gmail.com> On Jan 15, 2008 5:01 PM, Neil Mitchell wrote: > That would be bad. Then you'll have gone from Data.Binary being > portable code, to being GHC specific code, and I will cry.... :'-( Ok, no TH ;) AGL -- Adam Langley agl@imperialviolet.org http://www.imperialviolet.org 650-283-9641 From allbery at ece.cmu.edu Tue Jan 15 22:34:42 2008 From: allbery at ece.cmu.edu (Brandon S. Allbery KF8NH) Date: Tue Jan 15 22:27:59 2008 Subject: [Haskell-cafe] ErrorT and catchError question In-Reply-To: References: <4C532956-1EA1-45DA-A64B-FAACE7DDCDFE@ece.cmu.edu> Message-ID: <420DB5D8-0DDC-4A99-A138-CD20FEE630B8@ece.cmu.edu> On Jan 15, 2008, at 22:05 , Adam Smyczek wrote: > Ups, resend, first response did not make into the list. > On Jan 14, 2008, at 9:33 PM, Brandon S. Allbery KF8NH wrote: > >> >> On Jan 15, 2008, at 0:28 , Adam Smyczek wrote: >> >>> It's probably a trivial question, but I cannot figure out >>> how to implement the catchError function in: >>> >>> instance MonadError String Shell where >>> throwError = error . ("Shell failed: "++) >>> catchError l h = ??? >> >> Take a look at Control.Exception.catch for starters. > > No, did not help and > going over the source code of Control.Monad.Error did not > help as well. Does someone have other tips for me? Perhaps you could explain what you're looking for? Your typeclass doesn't tell us anything about the semantics. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH From adam.smyczek at gmail.com Tue Jan 15 22:54:11 2008 From: adam.smyczek at gmail.com (Adam Smyczek) Date: Tue Jan 15 22:47:29 2008 Subject: [Haskell-cafe] ErrorT and catchError question In-Reply-To: <420DB5D8-0DDC-4A99-A138-CD20FEE630B8@ece.cmu.edu> References: <4C532956-1EA1-45DA-A64B-FAACE7DDCDFE@ece.cmu.edu> <420DB5D8-0DDC-4A99-A138-CD20FEE630B8@ece.cmu.edu> Message-ID: <5B29CDAD-6B55-48AC-A9CF-C5CFC8E4F212@gmail.com> On Jan 15, 2008, at 7:34 PM, Brandon S. Allbery KF8NH wrote: > > On Jan 15, 2008, at 22:05 , Adam Smyczek wrote: > >> Ups, resend, first response did not make into the list. >> On Jan 14, 2008, at 9:33 PM, Brandon S. Allbery KF8NH wrote: >> >>> >>> On Jan 15, 2008, at 0:28 , Adam Smyczek wrote: >>> >>>> It's probably a trivial question, but I cannot figure out >>>> how to implement the catchError function in: >>>> >>>> instance MonadError String Shell where >>>> throwError = error . ("Shell failed: "++) >>>> catchError l h = ??? >>> >>> Take a look at Control.Exception.catch for starters. >> >> No, did not help and >> going over the source code of Control.Monad.Error did not >> help as well. Does someone have other tips for me? > > Perhaps you could explain what you're looking for? Your typeclass > doesn't tell us anything about the semantics. The type declaration: newtype Loader a = Loader { load :: ErrorT String IO a } deriving (Functor, Monad, MonadIO) instance MonadError String Loader where throwError = error . ("Error: " ++) l `catchError` h = ??? how do I implement this ??? -- Example usage data Attribute = Attribute { a_name :: Name, a_value :: Value } deriving Show -- Find a required attribute by name and throw an -- exception it if does not exist findRequired :: Name -> [Attribute] -> Loader Attribute findRequired n as = case find (\a -> a_name a == n) as of Just a -> return a Nothing -> throwError $ "Missing required '" ++ n ++ "' attribute!" -- I would like to use catchException for -- findOptional and provide default value -- if findRequired fails findOptional :: Name -> [Attribute] -> Value -> Loader Attribute findOptional n as defaultValue = catchError (findRequired n as) (\_ -> return $ Attribute n defaultValue) As you probably can see on this code, I'm a haskell newbie and open for all tips how to improve this code. Thanks, Adam > -- > brandon s. allbery [solaris,freebsd,perl,pugs,haskell] > allbery@kf8nh.com > system administrator [openafs,heimdal,too many hats] > allbery@ece.cmu.edu > electrical and computer engineering, carnegie mellon university > KF8NH > > From jonathanccast at fastmail.fm Tue Jan 15 23:07:38 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Tue Jan 15 23:00:57 2008 Subject: [Haskell-cafe] ErrorT and catchError question In-Reply-To: <5B29CDAD-6B55-48AC-A9CF-C5CFC8E4F212@gmail.com> References: <4C532956-1EA1-45DA-A64B-FAACE7DDCDFE@ece.cmu.edu> <420DB5D8-0DDC-4A99-A138-CD20FEE630B8@ece.cmu.edu> <5B29CDAD-6B55-48AC-A9CF-C5CFC8E4F212@gmail.com> Message-ID: <6B1DC497-676F-405E-9371-CBE68C19C213@fastmail.fm> On 15 Jan 2008, at 7:54 PM, Adam Smyczek wrote: > > On Jan 15, 2008, at 7:34 PM, Brandon S. Allbery KF8NH wrote: > >> >> On Jan 15, 2008, at 22:05 , Adam Smyczek wrote: >> >>> Ups, resend, first response did not make into the list. >>> On Jan 14, 2008, at 9:33 PM, Brandon S. Allbery KF8NH wrote: >>> >>>> >>>> On Jan 15, 2008, at 0:28 , Adam Smyczek wrote: >>>> >>>>> It's probably a trivial question, but I cannot figure out >>>>> how to implement the catchError function in: >>>>> >>>>> instance MonadError String Shell where >>>>> throwError = error . ("Shell failed: "++) >>>>> catchError l h = ??? >>>> >>>> Take a look at Control.Exception.catch for starters. >>> >>> No, did not help and >>> going over the source code of Control.Monad.Error did not >>> help as well. Does someone have other tips for me? >> >> Perhaps you could explain what you're looking for? Your typeclass >> doesn't tell us anything about the semantics. > > The type declaration: > > newtype Loader a = Loader > { load :: ErrorT String IO a } > deriving (Functor, Monad, MonadIO) > > instance MonadError String Loader where > throwError = error . ("Error: " ++) I don't think this is what you want; you're throwing away the benefit of using ErrorT. You probably want throwError = Loader . throwError > l `catchError` h = ??? how do I implement this ??? l `catchError` h = Loader (load l `catchError` load . h) jcc From ninegua at gmail.com Tue Jan 15 23:32:54 2008 From: ninegua at gmail.com (Paul L) Date: Tue Jan 15 23:26:09 2008 Subject: [Haskell-cafe] ANN: GLFW-0.3 released Message-ID: <856033f20801152032y64b9ecadka637a4bfa2433bd7@mail.gmail.com> GLFW is a Haskell module for GLFW OpenGL framework. It provides an alternative to GLUT for OpenGL based Haskell programs. The current 0.3 version is for download from hackageDB at: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/GLFW-0.3 Same as the previous 0.2 version it requires Cabal 1.2 or later for installation (which comes as default in GHC 6.8 or later). The installation is now conforming to the standard Cabal steps. New addition is the Haddock documentation for all interface functions. There is also a sample program to demonstrate its usage on the Haskell wiki site for GLFW: http://haskell.org/haskellwiki/GLFW Any feedbacks is welcome! I've only tested it on a limited number of platforms + GHC combinations, so if you have installation issue, please let me know. Thank you! -- Regards, Paul Liu Yale Haskell Group http://www.haskell.org/yale From adam.smyczek at gmail.com Tue Jan 15 23:53:53 2008 From: adam.smyczek at gmail.com (Adam Smyczek) Date: Tue Jan 15 23:47:12 2008 Subject: [Haskell-cafe] ErrorT and catchError question In-Reply-To: <6B1DC497-676F-405E-9371-CBE68C19C213@fastmail.fm> References: <4C532956-1EA1-45DA-A64B-FAACE7DDCDFE@ece.cmu.edu> <420DB5D8-0DDC-4A99-A138-CD20FEE630B8@ece.cmu.edu> <5B29CDAD-6B55-48AC-A9CF-C5CFC8E4F212@gmail.com> <6B1DC497-676F-405E-9371-CBE68C19C213@fastmail.fm> Message-ID: <617547BB-4A98-451A-9954-41ED902FDCD4@gmail.com> On Jan 15, 2008, at 8:07 PM, Jonathan Cast wrote: > On 15 Jan 2008, at 7:54 PM, Adam Smyczek wrote: > >> >> On Jan 15, 2008, at 7:34 PM, Brandon S. Allbery KF8NH wrote: >> >>> >>> On Jan 15, 2008, at 22:05 , Adam Smyczek wrote: >>> >>>> Ups, resend, first response did not make into the list. >>>> On Jan 14, 2008, at 9:33 PM, Brandon S. Allbery KF8NH wrote: >>>> >>>>> >>>>> On Jan 15, 2008, at 0:28 , Adam Smyczek wrote: >>>>> >>>>>> It's probably a trivial question, but I cannot figure out >>>>>> how to implement the catchError function in: >>>>>> >>>>>> instance MonadError String Shell where >>>>>> throwError = error . ("Shell failed: "++) >>>>>> catchError l h = ??? >>>>> >>>>> Take a look at Control.Exception.catch for starters. >>>> >>>> No, did not help and >>>> going over the source code of Control.Monad.Error did not >>>> help as well. Does someone have other tips for me? >>> >>> Perhaps you could explain what you're looking for? Your >>> typeclass doesn't tell us anything about the semantics. >> >> The type declaration: >> >> newtype Loader a = Loader >> { load :: ErrorT String IO a } >> deriving (Functor, Monad, MonadIO) >> >> instance MonadError String Loader where >> throwError = error . ("Error: " ++) > > I don't think this is what you want; you're throwing away the > benefit of using ErrorT. You probably want > > throwError = Loader . throwError > >> l `catchError` h = ??? how do I implement this ??? > > l `catchError` h = Loader (load l `catchError` load . h) > Thanks Jonathan, this is exactly what I was looking for and I got the concept of ErrorT now, I think. > jcc > From dekudekuplex at yahoo.com Wed Jan 16 00:22:45 2008 From: dekudekuplex at yahoo.com (Benjamin L. Russell) Date: Wed Jan 16 00:16:00 2008 Subject: [Haskell-cafe] High-readibility version of "CONS should not evaluate its arguments?" Message-ID: <219364.63773.qm@web30202.mail.mud.yahoo.com> While reading the paper "A History of Haskell: Being Lazy With Class" (Paul Hudak, John Hughes, Simon Peyton Jones, Philip Wadler: The Third ACM SIGPLAN History of Programming Languages Conference (HOPL-III) San Diego, California, June 9-10, 2007) (http://research.microsoft.com/~simonpj/papers/history-of-haskell/history.pdf), I came across a reference (in Part I, Section 2.1: The Call of Laziness) to the paper ""CONS should not evaluate its arguments" (D. P. Friedman and D. S. Wise, in Automata, Languages, and Programming, S. Michaelson and R. Milner, Eds. Edinburgh: Edinburgh University Press, 1976, pp. 257-284), and looked for a highly readable version. However, all I could come across was Technical Report TR44 at the Indiana Department of Computer Science, at http://www.cs.indiana.edu/cgi-bin/techreports/TRNNN.cgi?trnum=TR44. This version appears as small, light typewritten type on horizontally placed double pages, and is very hard to read. Does anybody know where I can find a version of this paper with higher readability? From dekudekuplex at yahoo.com Wed Jan 16 01:54:08 2008 From: dekudekuplex at yahoo.com (Benjamin L. Russell) Date: Wed Jan 16 01:47:22 2008 Subject: [Haskell-cafe] Yi editor tutorial In-Reply-To: <478A91DD.1020403@nobugs.org> Message-ID: <753062.19697.qm@web30212.mail.mud.yahoo.com> Your Yi editor tutorial looks like a fascinating idea, but I use Mac OS X (10.2.8 Jaguar, soon to be upgraded to 10.5.x Leopard) at home, and Windows XP at work, while your tutorial is based on Ubuntu and the bash shell. A few questions: 1) Do you have any versions of your Yi tutorial for Mac OS X or Windows XP; if not, are there any plans for such tutorials in the future? 2) On your tutorial top page (http://nobugs.org/developer/yi/), you mentioned that you had first learned Haskell in 2001 from _The Haskell School of Expression_ by Paul Hudak. I also tried studying that book, and found it very interesting (especially with its focus on multimedia examples), but unfortunately got stuck on an exercise in Chapter 2 that required trigonometry, which I had forgotten from lack of use and didn't have time to review. Also, I wanted to study it online, and had purchased the book (and thus paid the licensing fee), but was unable to find an online version. Do you have any suggestions for online books with the same flavor that require less domain-specific knowledge; alternatively, do you have any suggestions for online material that precisely covers the domain-specific knowledge assumed by that book? Benjamin L. Russell --- Andrew Birkett wrote: > Hi, > > I've recently started using Yi, the haskell editor. > I found it slightly > non-trivial to get started, so I've written up my > installation method > and a "beginners guide" tutorial which I hope will > be of interest to > other people who'd like to try Yi. It lives at: > > http://nobugs.org/developer/yi/ > > Let me know if it's useful or if you have > suggestions (to andy@nobugs.org) > > Andrew > -- > - http://www.nobugs.org - > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From dons at galois.com Wed Jan 16 02:08:52 2008 From: dons at galois.com (Don Stewart) Date: Wed Jan 16 02:04:51 2008 Subject: [Haskell-cafe] hmp3 1.4: ncurses mp3 player in Haskell Message-ID: <20080116070852.GB31112@scytale.galois.com> 4 years after its original release, and with almost daily use, I'm pleased to announce a new release of hmp3, the Haskell mp3 player. The goal of this project was a more stable, resize-friendly mp3 player for the console, that didn't compromise on efficiency or the user interface. This release, version 1.4, introduces pcre support for searching for tracks and albums, and improves support for ghc 6.8. Install: $ cabal install hmp3 Hackage: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hmp3 Homepage: http://www.cse.unsw.edu.au/~dons/hmp3.html Repos: http://code.haskell.org/~dons/code/hmp3 Cheers, Don --- Take direct action against bad code: program Haskell! From conal at conal.net Wed Jan 16 02:19:04 2008 From: conal at conal.net (Conal Elliott) Date: Wed Jan 16 02:12:20 2008 Subject: [Haskell-cafe] First go at reactive programming In-Reply-To: <478C98FF.2060903@optusnet.com.au> References: <478C98FF.2060903@optusnet.com.au> Message-ID: Hi Levi, Delightful! I'd been hoping for a networking-related use of Reactive. I made a few tweaks to clean up the code: * Factored the fmap out of handleConnection, handleToRequest, runRequestHandler r, and responseSend, to simplify their interfaces/semantics (no more events). * Used (second.fmap) in runRequestHandler in place of explicit manipulation. Then factored it out into handleConnection, to simplify interface/semantics (no more pair/IO). * Added a few type signatures. * Replaced (putStrLn . show) with print in responseSend. Let's play some more with improving on the handle-passing. Meanwhile, new version below. I bet we can make it more functional/elegant, isolating the IO from a simple & pure core. For instance, the pattern of accepting connections and then dialoging on each one smells very like what I have in mind for the (functional) Event monad. Cheers, - Conal module Main where import Control.Applicative import Control.Arrow (second,(&&&),(>>>)) import Control.Concurrent import Control.Monad import Data.Reactive import Network.BSD import Network.HTTP import Network import System.IO import Text.XHtml.Strict type RequestHandler = Request -> Response main = runHttpServer helloWorldHandler helloWorldHandler :: RequestHandler helloWorldHandler _ = Response (2,0,0) "" [] $ prettyHtml helloWorldDoc helloWorldDoc = header << thetitle << "Hello World" +++ body << h1 << "Hello World" runHttpServer :: RequestHandler -> IO a runHttpServer r = socketServer >>= runE . fmap (handleConnection r) socketServer :: IO (Event Handle) socketServer = withSocketsDo $ do (e,snk) <- mkEventShow "Server" sock <- listenOn (PortNumber 8080) forkIO $ forever $ acceptConnection sock $ snk return e handleConnection :: RequestHandler -> Handle -> IO () handleConnection r = handleToRequest >>> (second.fmap) (runRequestHandler r) >>> responseSend handleToRequest :: Handle -> (Handle, IO (Result Request)) handleToRequest = id &&& receiveHTTP runRequestHandler :: RequestHandler -> Result Request -> Result Response runRequestHandler r rq = rq `bindE` (Right . r) responseSend :: (Handle, IO (Result Response)) -> IO () responseSend (h,rsp) = rsp >>= either print (respondHTTP h) >> close h acceptConnection :: Socket -> (Handle -> IO ()) -> IO ThreadId acceptConnection s k = accept s >>= \(h,_,_) -> forkIO $ k h instance Stream Handle where readLine h = hGetLine h >>= \l -> return $ Right $ l ++ "\n" readBlock h n = replicateM n (hGetChar h) >>= return . Right writeBlock h s = mapM_ (hPutChar h) s >>= return . Right close = hClose On Jan 15, 2008 3:29 AM, Levi Stephen wrote: > Hi, > > Listed below is my first experiment with reactive programming. It is a > simple web server written using the Data.Reactive[1] library. The > intended interface is given by the runHttpServer function, so the > remainder is intended to be internal. > > I'd be happy to hear comments on any parts of this, but am particularly > interested in the following: > > 1. Is this kind of code what is intended from reactive programming? > 2a. I'm not sure about passing the (Handle,...) tuple around. Is there a > way to avoid this? > 2b. I'm not sure of the best place to handle possible socket exceptions > 2c. I'd like to be able to pass a function of type Event Request -> > Event Response to runHttpServer, so that reactive programming could be > used throughout client code also, but the (Handle,...) tuples seem to be > getting in the way. > 3. I have a feeling there's a clearer way to write responseSend. > > Thanks, > Levi > > [1] http://www.haskell.org/haskellwiki/Reactive > > module Main where > > import Control.Applicative > import Control.Arrow ((&&&),(>>>)) > import Control.Concurrent > import Control.Monad > > import Data.Reactive > > import Network.BSD > import Network.HTTP > import Network > > import System.IO > > import Text.XHtml.Strict > > type RequestHandler = Request -> Response > > main = runHttpServer helloWorldHandler > > helloWorldHandler :: RequestHandler > helloWorldHandler _ = Response (2,0,0) "" [] $ prettyHtml helloWorldDoc > > helloWorldDoc = header << thetitle << "Hello World" > +++ body << h1 << "Hello World" > > runHttpServer r = socketServer >>= runE . handleConnection r > > socketServer :: IO (Event Handle) > socketServer = withSocketsDo $ do > (e,snk) <- mkEventShow "Server" > sock <- listenOn (PortNumber 8080) > forkIO $ forever $ acceptConnection sock $ snk > return e > > handleConnection :: RequestHandler -> Event Handle -> Event (IO ()) > handleConnection r = handleToRequest >>> runRequestHandler r >>> > responseSend > > > handleToRequest :: Event Handle -> Event (Handle, IO (Result Request)) > handleToRequest e = fmap (id &&& receiveHTTP) e > > responseSend :: Event (Handle, IO (Result Response)) -> Event (IO ()) > responseSend e = fmap (\(h,rsp) -> rsp >>= either (putStrLn . show) > (respondHTTP h) >> close h) e > > runRequestHandler :: RequestHandler -> Event (Handle, IO (Result > Request)) -> Event (Handle, IO (Result Response)) > runRequestHandler r e = fmap hrToHr e > where > rqhdl :: Result Request -> Result Response > rqhdl rq = bindE rq (Right . r) > hrToHr :: (Handle, IO (Result Request)) -> (Handle, IO (Result > Response)) > hrToHr (h,req) = (h, liftA rqhdl req) > > acceptConnection s k = accept s >>= \(h,_,_) -> forkIO $ k h > > instance Stream Handle where > readLine h = hGetLine h >>= \l -> return $ Right $ l ++ "\n" > readBlock h n = replicateM n (hGetChar h) >>= return . Right > writeBlock h s = mapM_ (hPutChar h) s >>= return . Right > close = hClose > > > > > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080115/ab10d9cc/attachment-0001.htm From apfelmus at quantentunnel.de Wed Jan 16 04:08:20 2008 From: apfelmus at quantentunnel.de (apfelmus) Date: Wed Jan 16 04:01:44 2008 Subject: [Haskell-cafe] Re: Simulating client server communication with recursive monads In-Reply-To: <006901c857de$f460cd00$dd226700$@de> References: <004601c85709$f4d74550$de85cff0$@de> <005401c857a3$1f32d550$5d987ff0$@de> <478D0448.2050907@list.mightyreason.com> <006901c857de$f460cd00$dd226700$@de> Message-ID: <478DC984.9080106@quantentunnel.de> [redirected to haskell-cafe] Jan Stranik wrote: > Do you know what is the theoretical foundation for having mfix process > side-effects in the lexical order as opposed to execution order? > Could you point me to some papers, if you know of any off top your head? http://www.cse.ogi.edu/pacsoft/projects/rmb/ Regards, apfelmus From duncan.coutts at worc.ox.ac.uk Wed Jan 16 04:49:49 2008 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Wed Jan 16 04:44:02 2008 Subject: [Haskell-cafe] Re: [Haskell] ANN: GLFW-0.3 released In-Reply-To: <856033f20801152032y64b9ecadka637a4bfa2433bd7@mail.gmail.com> References: <856033f20801152032y64b9ecadka637a4bfa2433bd7@mail.gmail.com> Message-ID: <1200476989.5639.144.camel@localhost> On Tue, 2008-01-15 at 23:32 -0500, Paul L wrote: > GLFW is a Haskell module for GLFW OpenGL framework. It provides an > alternative to GLUT for OpenGL based Haskell programs. > > The current 0.3 version is for download from hackageDB at: > http://hackage.haskell.org/cgi-bin/hackage-scripts/package/GLFW-0.3 Well done on getting another release out. It's available in the Gentoo's Haskell overlay already :-) > Same as the previous 0.2 version it requires Cabal 1.2 or later for > installation (which comes as default in GHC 6.8 or later). The > installation is now conforming to the standard Cabal steps. > > New addition is the Haddock documentation for all interface functions. > There is also a sample program to demonstrate its usage on the Haskell > wiki site for GLFW: > http://haskell.org/haskellwiki/GLFW > > Any feedbacks is welcome! I've only tested it on a limited number of > platforms + GHC combinations, so if you have installation issue, > please let me know. Thank you! You bundle all the GLFW source code. Some systems have the C library already available as a dynamic library. For gentoo for example we would prefer to use the existing glfw package than statically linking in another copy. This would be a good application of configurations, something like: flag system-glfw description: Use the the system GLFW C library. Otherwise use the bundled copy. default: False Library ... if flag(system-glfw) extra-libraries: glfw else ... Duncan From lemming at henning-thielemann.de Wed Jan 16 04:57:27 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Wed Jan 16 04:50:53 2008 Subject: [Haskell-cafe] Properties of optimizer rule application? In-Reply-To: <47830A3B.7040401@cse.unsw.edu.au> References: <20080103192002.GF4775@scytale.galois.com> <47830A3B.7040401@cse.unsw.edu.au> Message-ID: Reading various papers and the Wiki about GHC optimizer rules I got the impression that there are not much properties I can rely on and I wonder how I can write a reliable fusion framework with this constraint. I read about the strategy to replace functions early by fusable implementations and replace them back to fast low-level implementation if fusion was not possible. However, can I rely on the back-translation if I have no warranty that the corresponding rule is applied? Is there some warranty that rules are applied as long as applicable rules are available or is the optimizer free to decide that it worked enough for today? I see several phases with a fixed number of iterations in the output of -ddump-simpl-iterations. Is there some idea behind these phases or is the structure and number rather arbitrary? If there is only a fixed number of simplifier runs, how can I rely on complete fusion of arbitrary large expressions? At some place I read that the order of application of rules is arbitrary. I like to have some warranty that more special rules are applied before more general rules. That is, if rule X is applicable whereever Y is applicable then Y shall be tried before X. This is currently not assured, right? Another text passage tells that the simplification is inside-out expressions. Such a direction would make the design of rules definitely easier. Having both directions, maybe alternating in the runs of the simplifier, would be also nice. I could then design transforms of the kind: toFastStructure . slowA . slowB . slowC . slowWithNoFastCounterpart fastA . toFastStructure . slowB . slowC . slowWithNoFastCounterpart fastA . fastB . toFastStructure . slowC . slowWithNoFastCounterpart fastA . fastB . fastC . toFastStructure . slowWithNoFastCounterpart fastA . fastBC . toFastStructure . slowWithNoFastCounterpart fastABC . toFastStructure . slowWithNoFastCounterpart On the one hand the inner of functions may not be available to fusion, if the INLINE pragma is omitted. As far as I know inlining may take place also without the INLINE pragma, but I have no warranty. Can I rely on functions being inlined with INLINE pragma? Somewhere I read that functions are not inlined if there is still an applicable rule that uses the function on the left-hand side. Altogether I'm uncertain how inlining is interleaved with rule application. It was said, that rules are just alternative function definitions. In this sense a function definition with INLINE is a more aggressively used simplifier rule, right? On the other hand if I set the INLINE pragma then the inner of the function is not fused. If this would be the case, I could guide the optimizer to fuse several sub-expressions before others. Say, doubleMap f g = map f . map g could be fused to doubleMap f g = map (f . g) and then this fused version can be fused further in the context of the caller. The current situation seems to be that {-# INLINE doubleMap #-} switches off local fusion and allows global fusion, whereas omitting the INLINE pragma switches on local fusion and disallows global fusion. How can I have both of them? From bsinclai at turing.une.edu.au Wed Jan 16 06:02:40 2008 From: bsinclai at turing.une.edu.au (Ben Sinclair) Date: Wed Jan 16 05:55:56 2008 Subject: [Haskell-cafe] libmpd-haskell RFC Message-ID: <20080116110239.GA18843@mephistopheles> Hello all, If anybody has already used libmpd-haskell (the darcs repo version) or would like to look over it I would appreciate their comments. Thanks, Ben http://turing.une.edu.au/~bsinclai/code/libmpd-haskell/ -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080116/e6e4a2d7/attachment.bin From simonpj at microsoft.com Wed Jan 16 06:32:25 2008 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Wed Jan 16 06:25:39 2008 Subject: [Haskell-cafe] Properties of optimizer rule application? In-Reply-To: References: <20080103192002.GF4775@scytale.galois.com> <47830A3B.7040401@cse.unsw.edu.au> Message-ID: <638ABD0A29C8884A91BC5FB5C349B1C315A53A4FE9@EA-EXMSG-C334.europe.corp.microsoft.com> GHC has one main mechanism for controlling the application of rules, namely simplifier "phases". You can say "apply this rule only after phase N" or "apply this rule only before phase N". Similarly for INLINE pragmas. The manual describes this in detail. I urge against relying on "top-down" or "bottom-up" guarantees, because they are fragile: if you miss a single opportunity to apply rule A, then rule B may kick in; but a later inlining or other simplification might make rule A applicable. Phases are the way to go. That said, GHC has much too rigid a notion of phases at the moment. There are precisely 3, namely 2 then 1 then 0, and that does not give enough control. Really we should let you give arbitrary names to phases, express constraints (A must be before B), and run a constraint solver to map phase names to a linear ordering. The current system is horribly non-modular. There's scope for an intern project here. Simon | -----Original Message----- | From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Henning Thielemann | Sent: 16 January 2008 09:57 | To: Haskell Cafe | Subject: [Haskell-cafe] Properties of optimizer rule application? | | | Reading various papers and the Wiki about GHC optimizer rules I got the | impression that there are not much properties I can rely on and I wonder | how I can write a reliable fusion framework with this constraint. | I read about the strategy to replace functions early by fusable | implementations and replace them back to fast low-level implementation if | fusion was not possible. However, can I rely on the back-translation if I | have no warranty that the corresponding rule is applied? Is there some | warranty that rules are applied as long as applicable rules are available | or is the optimizer free to decide that it worked enough for today? | I see several phases with a fixed number of iterations in the output of | -ddump-simpl-iterations. Is there some idea behind these phases or is the | structure and number rather arbitrary? If there is only a fixed number of | simplifier runs, how can I rely on complete fusion of arbitrary large | expressions? | At some place I read that the order of application of rules is arbitrary. | I like to have some warranty that more special rules are applied before | more general rules. That is, if rule X is applicable whereever Y is | applicable then Y shall be tried before X. This is currently not assured, | right? | Another text passage tells that the simplification is inside-out | expressions. Such a direction would make the design of rules definitely | easier. Having both directions, maybe alternating in the runs of the | simplifier, would be also nice. I could then design transforms of the | kind: | toFastStructure . slowA . slowB . slowC . slowWithNoFastCounterpart | fastA . toFastStructure . slowB . slowC . slowWithNoFastCounterpart | fastA . fastB . toFastStructure . slowC . slowWithNoFastCounterpart | fastA . fastB . fastC . toFastStructure . slowWithNoFastCounterpart | fastA . fastBC . toFastStructure . slowWithNoFastCounterpart | fastABC . toFastStructure . slowWithNoFastCounterpart | | On the one hand the inner of functions may not be available to fusion, if | the INLINE pragma is omitted. As far as I know inlining may take place | also without the INLINE pragma, but I have no warranty. Can I rely on | functions being inlined with INLINE pragma? Somewhere I read that | functions are not inlined if there is still an applicable rule that uses | the function on the left-hand side. Altogether I'm uncertain how inlining | is interleaved with rule application. It was said, that rules are just | alternative function definitions. In this sense a function definition with | INLINE is a more aggressively used simplifier rule, right? | On the other hand if I set the INLINE pragma then the inner of the | function is not fused. If this would be the case, I could guide the | optimizer to fuse several sub-expressions before others. Say, | doubleMap f g = map f . map g | could be fused to | doubleMap f g = map (f . g) | and then this fused version can be fused further in the context of the | caller. The current situation seems to be that {-# INLINE doubleMap #-} | switches off local fusion and allows global fusion, whereas omitting the | INLINE pragma switches on local fusion and disallows global fusion. How | can I have both of them? | _______________________________________________ | Haskell-Cafe mailing list | Haskell-Cafe@haskell.org | http://www.haskell.org/mailman/listinfo/haskell-cafe From rl at cse.unsw.edu.au Wed Jan 16 07:34:47 2008 From: rl at cse.unsw.edu.au (Roman Leshchinskiy) Date: Wed Jan 16 07:28:07 2008 Subject: [Haskell-cafe] Re: Properties of optimizer rule application? In-Reply-To: References: <20080103192002.GF4775@scytale.galois.com> <47830A3B.7040401@cse.unsw.edu.au> Message-ID: <478DF9E7.30204@cse.unsw.edu.au> Henning Thielemann wrote: > Reading various papers and the Wiki about GHC optimizer rules I got the > impression that there are not much properties I can rely on and I wonder > how I can write a reliable fusion framework with this constraint. That depends on your definition of reliable. You can't have a framework which fuses everything that can be fused but then, I don't think that's even theoretically possible. You can, however, have a framework which does a pretty good job. > I read about the strategy to replace functions early by fusable > implementations and replace them back to fast low-level implementation if > fusion was not possible. However, can I rely on the back-translation if I > have no warranty that the corresponding rule is applied? Is there some > warranty that rules are applied as long as applicable rules are available > or is the optimizer free to decide that it worked enough for today? > I see several phases with a fixed number of iterations in the output of > -ddump-simpl-iterations. Is there some idea behind these phases or is the > structure and number rather arbitrary? If there is only a fixed number of > simplifier runs, how can I rely on complete fusion of arbitrary large > expressions? In general, you can't. You can control the number of simplifier phases with -fsimplifier-phases (in the HEAD only) and the number of iterations in each phase with -fmax-simplifier-iterations. That said, there are other things that break fusion (such as code getting between two functions you want to fuse). Again, you can only try to make your framework good enough; it'll never be perfect. > At some place I read that the order of application of rules is arbitrary. > I like to have some warranty that more special rules are applied before > more general rules. That is, if rule X is applicable whereever Y is > applicable then Y shall be tried before X. This is currently not assured, > right? IIRC, ghc tries more specific rules first but that's somewhat unreliable. You can make rule X inactive in simplifier phase 2, however. Then, only rule Y will be tried in phase 2; both rules will be tried in subsequent phases. I suspect, though, that ordering requirements on rules might indicate a problem in the design of the fusion framework. I think they are best avoided. > Another text passage tells that the simplification is inside-out > expressions. Such a direction would make the design of rules definitely > easier. Having both directions, maybe alternating in the runs of the > simplifier, would be also nice. I could then design transforms of the > kind: > toFastStructure . slowA . slowB . slowC . slowWithNoFastCounterpart > fastA . toFastStructure . slowB . slowC . slowWithNoFastCounterpart > fastA . fastB . toFastStructure . slowC . slowWithNoFastCounterpart > fastA . fastB . fastC . toFastStructure . slowWithNoFastCounterpart > fastA . fastBC . toFastStructure . slowWithNoFastCounterpart > fastABC . toFastStructure . slowWithNoFastCounterpart Again, I don't think you really want to rely on the order of simplification. For your example, you only need the following rules: toFastStructure (slow{A|B|C} x) = fast{A|B|C} (toFastStructure x) fastB (fastC x) = fastBC x fastA (fastBC x) = fastABC x They do not require any specific traversal order. > On the one hand the inner of functions may not be available to fusion, if > the INLINE pragma is omitted. As far as I know inlining may take place > also without the INLINE pragma, but I have no warranty. Can I rely on > functions being inlined with INLINE pragma? No. The inliner still uses heuristic to determine if inlining really is beneficial. If you want to be sure, use rewrite rules. > Somewhere I read that > functions are not inlined if there is still an applicable rule that uses > the function on the left-hand side. Altogether I'm uncertain how inlining > is interleaved with rule application. It was said, that rules are just > alternative function definitions. In this sense a function definition with > INLINE is a more aggressively used simplifier rule, right? No, rules are "more aggressive" since they are applied unconditionally. > On the other hand if I set the INLINE pragma then the inner of the > function is not fused. If this would be the case, I could guide the > optimizer to fuse several sub-expressions before others. Say, > doubleMap f g = map f . map g > could be fused to > doubleMap f g = map (f . g) > and then this fused version can be fused further in the context of the > caller. The current situation seems to be that {-# INLINE doubleMap #-} > switches off local fusion and allows global fusion, whereas omitting the > INLINE pragma switches on local fusion and disallows global fusion. How > can I have both of them? If you say {-# INLINE doubleMap #-}, you really expect doubleMap to be inlined and never to be called explicitly; therefore, you don't really care too much what actually happens to it. You can, however, do something like: {-# NOINLINE doubleMap #-} doubleMap f g = map f . map g -- will be fused {-# RULES "doubleMap" forall f g. doubleMap f g = map f . map g #-} This makes sure that the rhs of doubleMap will be optimised for those cases when the rule doesn't fire (e.g., when doubleMap is applied to less than two arguments). Roman From lemming at henning-thielemann.de Wed Jan 16 08:52:35 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Wed Jan 16 08:45:50 2008 Subject: [Haskell-cafe] Properties of optimizer rule application? In-Reply-To: <638ABD0A29C8884A91BC5FB5C349B1C315A53A4FE9@EA-EXMSG-C334.europe.corp.microsoft.com> References: <20080103192002.GF4775@scytale.galois.com> <47830A3B.7040401@cse.unsw.edu.au> <638ABD0A29C8884A91BC5FB5C349B1C315A53A4FE9@EA-EXMSG-C334.europe.corp.microsoft.com> Message-ID: On Wed, 16 Jan 2008, Simon Peyton-Jones wrote: > GHC has one main mechanism for controlling the application of rules, > namely simplifier "phases". You can say "apply this rule only after > phase N" or "apply this rule only before phase N". Similarly for INLINE > pragmas. The manual describes this in detail. Indeed. But since it does not mention the number of phases, nor the number of iterations per phase, nor what actually is performed per iteration, this appeared to me to be an internal issue of GHC which should not be relied on. > I urge against relying on "top-down" or "bottom-up" guarantees, because > they are fragile: if you miss a single opportunity to apply rule A, then > rule B may kick in; but a later inlining or other simplification might > make rule A applicable. Phases are the way to go. I see. > That said, GHC has much too rigid a notion of phases at the moment. > There are precisely 3, namely 2 then 1 then 0, and that does not give enough control. What about the 'gentle' phase in the dump ? > Really we should let you give arbitrary names to phases, express > constraints (A must be before B), and run a constraint solver to map > phase names to a linear ordering. Sounds like a topological sort. Reminds me on precedence control of infix operators. It seems to me that you have something more sophisticated already in mind. What you sketch would allow application specific code to defer optimization rules from the standard libraries. E.g. I could write rules for lists that are designed for my application and that can be applied without interference from Data.List. When no more of my rules can be applied, then Data.List rules can fuse the rest. It's interesting how to integrate this in the Haskell language. When you want to state "phase A before phase B" you may have to refer to phases defined in other modules. You have to be able to import them from other modules, and you cannot use the regular 'import' syntax, since phase identifiers are not part of Haskell language. Maybe you must enclose those imports in pragmas, too. You need new module dependency checking, since more dependencies can be introduced when optimization is switched on or you have to restrict phase import to modules that are imported anyway. {-# RULES import qualified Data.List as List #-} > There's scope for an intern project here. I could take the opportunity. From gwern0 at gmail.com Wed Jan 16 10:57:20 2008 From: gwern0 at gmail.com (gwern0@gmail.com) Date: Wed Jan 16 10:52:55 2008 Subject: [Haskell-cafe] Yi editor tutorial In-Reply-To: <753062.19697.qm@web30212.mail.mud.yahoo.com> References: <478A91DD.1020403@nobugs.org> <753062.19697.qm@web30212.mail.mud.yahoo.com> Message-ID: <20080116155720.GA24691@localhost> On 2008.01.15 22:54:08 -0800, "Benjamin L. Russell" scribbled 1.8K characters: > Your Yi editor tutorial looks like a fascinating idea, > but I use Mac OS X (10.2.8 Jaguar, soon to be upgraded > to 10.5.x Leopard) at home, and Windows XP at work, > while your tutorial is based on Ubuntu and the bash > shell. > > A few questions: > > 1) Do you have any versions of your Yi tutorial for > Mac OS X or Windows XP; if not, are there any plans > for such tutorials in the future? I suspect you would have a hard time running on Windows XP: the cabal file currently declares a dependency on 'unix' because the VTY interface needs it, and also because the Dired module needs System.Posix.Users (to look up file owners). So at the very least you'd need to edit those out. > 2) On your tutorial top page > (http://nobugs.org/developer/yi/), you mentioned that > you had first learned Haskell in 2001 from _The > Haskell School of Expression_ by Paul Hudak. I also > tried studying that book, and found it very > interesting (especially with its focus on multimedia > examples), but unfortunately got stuck on an exercise > in Chapter 2 that required trigonometry, which I had > forgotten from lack of use and didn't have time to > review. Also, I wanted to study it online, and had > purchased the book (and thus paid the licensing fee), > but was unable to find an online version. Do you have > any suggestions for online books with the same flavor > that require less domain-specific knowledge; > alternatively, do you have any suggestions for online > material that precisely covers the domain-specific > knowledge assumed by that book? > > Benjamin L. Russell -- gwern NAVCM Area51 M.P.R.I. Misawa Manfurov CACI Internet rapnel W3 HF -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080116/686cf6cd/attachment.bin From bit at mutantlemon.com Wed Jan 16 12:03:27 2008 From: bit at mutantlemon.com (Bit Connor) Date: Wed Jan 16 11:56:44 2008 Subject: [Haskell-cafe] ANNOUNCE: HStringTemplate -- An Elegant, Functional, Nifty Templating Engine for Haskell In-Reply-To: <89B71013-9550-4E1F-91DD-A4ABD532F2F1@gmail.com> References: <89B71013-9550-4E1F-91DD-A4ABD532F2F1@gmail.com> Message-ID: <6205bd290801160903p4aa56a6em1c54d473dd9be883@mail.gmail.com> On Jan 14, 2008 9:47 AM, Sterling Clover wrote: > HStringTemplate is a port of Terrence Parr's lovely StringTemplate > (http://www.stringtemplate.org) engine to Haskell. > > It is available, cabalized, at: > darcs get http://code.haskell.org/HStringTemplate/ Template systems have been a crucial missing part of Haskell web development. I am very happy to hear about this project, and will definitely be looking at this in the near future! Thanks, Bit From apfelmus at quantentunnel.de Wed Jan 16 12:04:25 2008 From: apfelmus at quantentunnel.de (apfelmus) Date: Wed Jan 16 11:57:54 2008 Subject: [Haskell-cafe] Re: MonadPrompt + Gtk2Hs = ? In-Reply-To: References: Message-ID: Felipe Lessa wrote: > apfelmus wrote: >> The type of contPromptM is even more general than that: >> >> casePromptOf' :: (r -> f b) >> -> (forall a,b. p a -> (a -> f b) -> f b) >> -> Prompt p r -> f b >> casePromptOf' done cont (PromptDone r) = done r >> casePromptOf' done cont (Prompt p c ) = cont p (casePromptOf' done cont . c) > > (I guess the forall b inside 'cont' is a typo?) No, it's intentional and not less general than > casePromptOf :: (r -> b) > -> (forall a. p a -> (a -> b) -> b) > -> Prompt p r -> b > casePromptOf done cont (PromptDone r) = done r > casePromptOf done cont (Prompt p c ) = cont p (casePromptOf done cont . c) since we can use data Const c b = Const { unConst :: c } and set f = (Const b) yielding casePromptOf :: forall p,c. (r -> c) -> (forall a. p a -> (a -> c) -> c) -> Prompt p r -> c casePromptOf return bind = unConst . casePromptOf' (Const . return) bind' where bind' :: forall a,b. p a -> (a -> Const c b) -> Const c b bind' p c = Const $ bind p (unConst . c) In other words, casePromptOf can be defined with casePromptOf' and a clever choice of f . > And, just for the record, > > runPromptAgain :: Monad m => (forall a. p a -> m a) -> Prompt p r -> m r > runPromptAgain f = casePromptOf return ((>>=) . f) I thought that casePromptOf would not be general enough to write this very definition runPromptAgain' f = casePromptOf' return ((>>=) . f) that's why I used a type constructor f b instead, with f = m the monad in mind. The difference is basically that the (>>=) in runPromptAgain' is expected to be polymorphic (>>=) :: forall b. m a -> (a -> m b) -> m b whereas the (>>=) in runPromptAgain is specialized to the final type m r of runPromptAgain , i.e. (>>=) :: m a -> (a -> m r) -> m r Unfortunately, I failed to realize that casePromptOf is in turn not less general than casePromptOf' rendering my approach pretty useless :) I mean, if the second argument in casePromptOf' :: (r -> f c) -> (forall a,b. p a -> (a -> f b) -> f b) -> Prompt p r -> f c is polymorphic, we can certainly plug it into casePromptOf :: (r -> f c) -> (forall a. p a -> (a -> f c) -> f c) -> Prompt p r -> f c and thus define casePromptOf' in terms of casePromptOf : casePromptOf' return bind = casePromptOf return bind The above equivalence of a type constructor f and a simple type c in certain cases applies to the continuation monad, too. I mean that ContT r m a is equivalent to Cont (m r) a and even ContT' m a is equivalent to forall r. Cont (m r) a for the more type safe version data ContT' m a = ContT' (forall r. (a -> m r) -> m r) So, it's pretty clear that ContT isn't really a monad transformer since m doesn't need to be a monad at all. Put differently, the Control.Monad.Cont module needs some cleanup since type synonyms type ContT r m a = Cont (m r) a type ContT' m a = forall r. Cont (m r) a (or newtypes for type classery) are enough. Regards, apfelmus From magnus at therning.org Wed Jan 16 12:40:32 2008 From: magnus at therning.org (Magnus Therning) Date: Wed Jan 16 12:33:48 2008 Subject: [Haskell-cafe] HPC of several modules? Message-ID: How do I get reports on coverage of all modules in a program? The documentation I've found http://blog.unsafeperformio.com/?p=18 and http://www.haskell.org/ghc/docs/latest/html/users_guide/hpc.html both do coverage of a single module. Going the naive route of first making sure there are no compiled modules in my source tree (i.e. removing all .o and .hi files) then running 'ghc --make -fhpc MyTool.hs' succeeds in building the program, and I get a MyTool.tix and a .mix file in .hpc/ for each module after running it, but how do I get 'hpc' to produce reports containing more than just Main? 'hpc6 markup MyTool' includes only Main 'hpc6 markup MyTool Main My.Module' includes only Main 'hpc6 markup MyTool My.Module' results in an error: Writing: hpc_index.html hpc6: Prelude.foldr1: empty list None of the arguments shown by 'hpc6 help markup' stands out as a clear candidate either... 'hpc6 report --per-module MyTool' generates this: ---------- 80% expressions used (386/479) 100% boolean coverage (0/0) 100% guards (0/0) 100% 'if' conditions (0/0) 100% qualifiers (0/0) 100% alternatives used (0/0) 100% local declarations used (0/0) 100% top-level declarations used (17/17) Where are my other modules??? Any and all help is appreciated. /M -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080116/df912ece/attachment.htm From ndmitchell at gmail.com Wed Jan 16 12:51:03 2008 From: ndmitchell at gmail.com (Neil Mitchell) Date: Wed Jan 16 12:44:19 2008 Subject: [Haskell-cafe] HPC of several modules? In-Reply-To: References: Message-ID: <404396ef0801160951i7b4555e3j6ec80b2cc03b734c@mail.gmail.com> Hi > and .hi files) then running 'ghc --make -fhpc MyTool.hs' succeeds in That's all I do. > 'hpc6 markup MyTool' includes only Main I do: hpc markup MyTool.tix Then it all Just Works (TM). What is hpc6? I am using the version supplied with GHC 6.8. Thanks Neil From jules at jellybean.co.uk Wed Jan 16 12:54:05 2008 From: jules at jellybean.co.uk (Jules Bean) Date: Wed Jan 16 12:47:20 2008 Subject: [Haskell-cafe] Yi editor tutorial In-Reply-To: <753062.19697.qm@web30212.mail.mud.yahoo.com> References: <753062.19697.qm@web30212.mail.mud.yahoo.com> Message-ID: <478E44BD.2010508@jellybean.co.uk> First of all, Andrew: Thanks! That was really interesting. Benjamin L. Russell wrote: > Your Yi editor tutorial looks like a fascinating idea, > but I use Mac OS X (10.2.8 Jaguar, soon to be upgraded > to 10.5.x Leopard) at home, and Windows XP at work, > while your tutorial is based on Ubuntu and the bash > shell. > > A few questions: > > 1) Do you have any versions of your Yi tutorial for > Mac OS X or Windows XP; if not, are there any plans > for such tutorials in the future? Didn't look to me very ubuntu specific. I bet it would work out very similarly on OS X. WinXP is something else, as gwern observed.... J From vigalchin at gmail.com Wed Jan 16 13:27:37 2008 From: vigalchin at gmail.com (Galchin Vasili) Date: Wed Jan 16 13:20:50 2008 Subject: [Haskell-cafe] Poisx select support Message-ID: <5ae4f2ba0801161027n2632375i1f8edc2fe24a35c5@mail.gmail.com> Hello, In the ghc libraries directory I can't find the Haskell .hs/.lhsthat implements Posix select. ?? I found Select.c. Regards, Vasili -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080116/1f2c837f/attachment.htm From dons at galois.com Wed Jan 16 14:32:59 2008 From: dons at galois.com (Don Stewart) Date: Wed Jan 16 14:26:16 2008 Subject: [Haskell-cafe] Poisx select support In-Reply-To: <5ae4f2ba0801161027n2632375i1f8edc2fe24a35c5@mail.gmail.com> References: <5ae4f2ba0801161027n2632375i1f8edc2fe24a35c5@mail.gmail.com> Message-ID: <20080116193259.GA4629@scytale.galois.com> vigalchin: > Hello, > > In the ghc libraries directory I can't find the Haskell > .hs/.lhsthat implements Posix select. ?? I found Select.c. In Control.Concurrent forkIO threadDelay threadWaitRead threadWaitWrite The thread primitives are implemented in terms of select, and give you a cleaner interface. Also, with Control.Concurrent.STM. atomically orElse retry You can have threads wait on one of a series of alternative events. Using STM, you'll be able to compose blocks of such code, which you can't do with select. -- Don From vigalchin at gmail.com Wed Jan 16 15:09:31 2008 From: vigalchin at gmail.com (Galchin Vasili) Date: Wed Jan 16 15:02:45 2008 Subject: [Haskell-cafe] Poisx select support In-Reply-To: <20080116193259.GA4629@scytale.galois.com> References: <5ae4f2ba0801161027n2632375i1f8edc2fe24a35c5@mail.gmail.com> <20080116193259.GA4629@scytale.galois.com> Message-ID: <5ae4f2ba0801161209x5ab3535bh57ef28ab62ac891@mail.gmail.com> Hi Don, Sorry ..I wasn't clear enough.I am trying to determine from the Haskell FFI doc what datatype to use in order to model C's "void *", e.g. for mmap http://www.opengroup.org/onlinepubs/000095399/functions/mmap.html Regards, Vasili On 1/16/08, Don Stewart wrote: > > vigalchin: > > Hello, > > > > In the ghc libraries directory I can't find the Haskell > > .hs/.lhsthat implements Posix select. ?? I found Select.c. > > In Control.Concurrent > > forkIO > threadDelay > threadWaitRead > threadWaitWrite > > The thread primitives are implemented in terms of select, and give you a > cleaner interface. > > Also, with Control.Concurrent.STM. > > atomically > orElse > retry > > You can have threads wait on one of a series of alternative events. > Using STM, you'll be able to compose blocks of such code, which you > can't do with select. > > -- Don > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080116/ed81c74d/attachment.htm From dons at galois.com Wed Jan 16 15:14:01 2008 From: dons at galois.com (Don Stewart) Date: Wed Jan 16 15:07:16 2008 Subject: [Haskell-cafe] Poisx select support In-Reply-To: <5ae4f2ba0801161209x5ab3535bh57ef28ab62ac891@mail.gmail.com> References: <5ae4f2ba0801161027n2632375i1f8edc2fe24a35c5@mail.gmail.com> <20080116193259.GA4629@scytale.galois.com> <5ae4f2ba0801161209x5ab3535bh57ef28ab62ac891@mail.gmail.com> Message-ID: <20080116201401.GE4629@scytale.galois.com> vigalchin: > Hi Don, > > Sorry ..I wasn't clear enough.I am trying to determine from the > Haskell FFI doc what datatype to use in order to model C's "void *", e.g. > for mmap > [1]http://www.opengroup.org/onlinepubs/000095399/functions/mmap.html > > Regards, Vasili In the System.IO.Posix.MMap module, mmap is imported as: foreign import ccall unsafe "hs_bytestring_mmap.h hs_bytestring_mmap" c_mmap :: CSize -> CInt -> IO (Ptr Word8) foreign import ccall unsafe "hs_bytestring_mmap.h munmap" c_munmap :: Ptr Word8 -> CSize -> IO CInt You can see the full binding to mmap here: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/bytestring-mmap Cheers, Don From lemming at henning-thielemann.de Wed Jan 16 15:28:53 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Wed Jan 16 15:22:58 2008 Subject: [Haskell-cafe] ANNOUNCE: Haddock version 2.0.0.0 In-Reply-To: References: Message-ID: On Tue, 8 Jan 2008, David Waern wrote: > Changes in version 2.0.0.0: > > * The GHC API is used as the front-end It's great to see this progress in Haddock. However, is Haddock now more difficult to port than before? Is there some bug- and feature request tracker for Haddock? I only know of http://www.haskell.org/haskellwiki/Haddock/Development_ideas and the first big point seems to be finished now. I like to have the following enhancements: * Optionally show qualifications of identifiers, that is print "Sequence.map" rather than "map", "Music.T" rather than just "T". The option for haddock could be --qualification QUAL QUAL=none (default) strip off qualification (just "map") QUAL=orig show the identifiers as they are written in the module (e.g. "map" or "List.map") QUAL=full show all identifiers with full qualification (Data.List.map) Actually I tried to implement it by myself in the old Haddock, but I could not precisely identify the place, where the qualification is removed. * Documentation of arguments of type constructors other than 'top level' arrows. E.g. T (a {- ^ arg -} -> b {- ^ result -} ) (a {- ^ arg -} -> b {- ^ result -} ) -> c (a {- ^ x coord -}, b {- ^ y coord -}) -> c It's probably difficult to format properly in HTML. From vigalchin at gmail.com Wed Jan 16 15:36:49 2008 From: vigalchin at gmail.com (Galchin Vasili) Date: Wed Jan 16 15:30:02 2008 Subject: [Haskell-cafe] Poisx select support In-Reply-To: <20080116201401.GE4629@scytale.galois.com> References: <5ae4f2ba0801161027n2632375i1f8edc2fe24a35c5@mail.gmail.com> <20080116193259.GA4629@scytale.galois.com> <5ae4f2ba0801161209x5ab3535bh57ef28ab62ac891@mail.gmail.com> <20080116201401.GE4629@scytale.galois.com> Message-ID: <5ae4f2ba0801161236i23f8e92dpe47ed3149553e884@mail.gmail.com> Hi Don, I am looking at the code for ghc-6.8.2 but don't see the mmap support. Is this newly wriiten by you? I would also like to help round out the Posix functionality in Haskell. Is there an accurate list of what needs to be done given the fact that maybe some work is in progress but not "checked in"? Thank you, Vasili On 1/16/08, Don Stewart wrote: > > vigalchin: > > Hi Don, > > > > Sorry ..I wasn't clear enough.I am trying to determine from the > > Haskell FFI doc what datatype to use in order to model C's "void *", > e.g. > > for mmap > > [1]http://www.opengroup.org/onlinepubs/000095399/functions/mmap.html > > > > Regards, Vasili > > In the System.IO.Posix.MMap module, mmap is imported as: > > foreign import ccall unsafe "hs_bytestring_mmap.h hs_bytestring_mmap" > c_mmap :: CSize -> CInt -> IO (Ptr Word8) > > foreign import ccall unsafe "hs_bytestring_mmap.h munmap" > c_munmap :: Ptr Word8 -> CSize -> IO CInt > > You can see the full binding to mmap here: > > > http://hackage.haskell.org/cgi-bin/hackage-scripts/package/bytestring-mmap > > Cheers, > Don > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080116/acf9fb96/attachment.htm From dons at galois.com Wed Jan 16 15:40:22 2008 From: dons at galois.com (Don Stewart) Date: Wed Jan 16 15:33:37 2008 Subject: [Haskell-cafe] Poisx select support In-Reply-To: <5ae4f2ba0801161236i23f8e92dpe47ed3149553e884@mail.gmail.com> References: <5ae4f2ba0801161027n2632375i1f8edc2fe24a35c5@mail.gmail.com> <20080116193259.GA4629@scytale.galois.com> <5ae4f2ba0801161209x5ab3535bh57ef28ab62ac891@mail.gmail.com> <20080116201401.GE4629@scytale.galois.com> <5ae4f2ba0801161236i23f8e92dpe47ed3149553e884@mail.gmail.com> Message-ID: <20080116204022.GG4629@scytale.galois.com> vigalchin: > Hi Don, > > I am looking at the code for ghc-6.8.2 but don't see the mmap > support. Is this newly wriiten by you? I would also like to help round out > the Posix functionality in Haskell. Is there an accurate list of what > needs to be done given the fact that maybe some work is in progress but > not "checked in"? > > Thank you, Vasili Code isn't generally checked into ghc 6.8.2, or the base libraries. Instead, new projects are distributed via hackage.haskell.org. It is like CPAN for Haskell, if you're familiar with CPAN. The mmap bytestring package is available there, for example. For improving POSIX support in general, careful patches to the 'unix' library would be the best way: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/unix If something you need is missing from there, write it as a patch against the darcs repository for `unix', http://darcs.haskell.org/packages/unix/, and submit it to libraries@haskell.org for inclusion in the next release of that library. -- Don From bf3 at telenet.be Wed Jan 16 15:45:43 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Wed Jan 16 15:38:56 2008 Subject: [Haskell-cafe] Data constructors versus types Message-ID: <1200516343.4222.13.camel@localhost.localdomain> I know nothing about theoretical computer science, but I was wondering if it possible to forget about types, and just keep the concept of data constructors, and have an analyzer determine correctness of the code and "staticness" of the data? Basically this is what SCHEME does no? Doesn't SCHEME have static whole program analyzers to remove the overhead of the "symbol tags" and check correctness of a program (Stalin, Petit-Scheme, ...)? What are to pros/contras? Thank you, Peter From dons at galois.com Wed Jan 16 15:50:56 2008 From: dons at galois.com (Don Stewart) Date: Wed Jan 16 15:44:14 2008 Subject: [Haskell-cafe] Data constructors versus types In-Reply-To: <1200516343.4222.13.camel@localhost.localdomain> References: <1200516343.4222.13.camel@localhost.localdomain> Message-ID: <20080116205056.GH4629@scytale.galois.com> bf3: > I know nothing about theoretical computer science, but I was wondering > if it possible to forget about types, and just keep the concept of data > constructors, and have an analyzer determine correctness of the code and > "staticness" of the data? The analysis would be type inference and checking. -- Don From lemming at henning-thielemann.de Wed Jan 16 15:56:53 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Wed Jan 16 15:50:10 2008 Subject: [Haskell-cafe] Re: Properties of optimizer rule application? In-Reply-To: <478DF9E7.30204@cse.unsw.edu.au> References: <20080103192002.GF4775@scytale.galois.com> <47830A3B.7040401@cse.unsw.edu.au> <478DF9E7.30204@cse.unsw.edu.au> Message-ID: On Wed, 16 Jan 2008, Roman Leshchinskiy wrote: > Henning Thielemann wrote: > > Reading various papers and the Wiki about GHC optimizer rules I got the > > impression that there are not much properties I can rely on and I wonder > > how I can write a reliable fusion framework with this constraint. > > That depends on your definition of reliable. You can't have a framework > which fuses everything that can be fused but then, I don't think that's > even theoretically possible. At least I expect that it fuses greedily and does not stop as long as rules are applicable. Thinking of intermediate fusable function replacements, I can be sure that rules are invoked that prevent me from making things worse by optimization attempts. > > I read about the strategy to replace functions early by fusable > > implementations and replace them back to fast low-level implementation if > > fusion was not possible. However, can I rely on the back-translation if I > > have no warranty that the corresponding rule is applied? Is there some > > warranty that rules are applied as long as applicable rules are available > > or is the optimizer free to decide that it worked enough for today? > > I see several phases with a fixed number of iterations in the output of > > -ddump-simpl-iterations. Is there some idea behind these phases or is the > > structure and number rather arbitrary? If there is only a fixed number of > > simplifier runs, how can I rely on complete fusion of arbitrary large > > expressions? > > In general, you can't. To give a precise example: If I have a sequence of 'map's map f0 . map f1 . ... . map fn then there is some length where this is no longer collapsed to a single 'map'? However then I wonder, how it is possible to make the compiler to go into an infinite loop by the rule "loop" forall x,y. f x y = f y x as stated in the GHC manual: http://haskell.org/ghc/docs/latest/html/users_guide/rewrite-rules.html I'm still uncertain how much is done in one iteration in one phase, since there seems to be several rules that can fire in one iteration. > You can control the number of simplifier phases with -fsimplifier-phases > (in the HEAD only) and the number of iterations in each phase with > -fmax-simplifier-iterations. Good to know. > That said, there are other things that break fusion (such as code > getting between two functions you want to fuse). Again, you can only try > to make your framework good enough; it'll never be perfect. It would be nice to have a flag which alters the rule application order of the compiler randomly in order to see whether the fusion framework implicitly relies on a particular behaviour of the current compiler version. > > Another text passage tells that the simplification is inside-out > > expressions. Such a direction would make the design of rules definitely > > easier. Having both directions, maybe alternating in the runs of the > > simplifier, would be also nice. I could then design transforms of the > > kind: > > toFastStructure . slowA . slowB . slowC . slowWithNoFastCounterpart > > fastA . toFastStructure . slowB . slowC . slowWithNoFastCounterpart > > fastA . fastB . toFastStructure . slowC . slowWithNoFastCounterpart > > fastA . fastB . fastC . toFastStructure . slowWithNoFastCounterpart > > fastA . fastBC . toFastStructure . slowWithNoFastCounterpart > > fastABC . toFastStructure . slowWithNoFastCounterpart > > Again, I don't think you really want to rely on the order of > simplification. For your example, you only need the following rules: > > toFastStructure (slow{A|B|C} x) = fast{A|B|C} (toFastStructure x) > fastB (fastC x) = fastBC x > fastA (fastBC x) = fastABC x > > They do not require any specific traversal order. Ok, this was a bad example. Try this one: project . project . foo with the rules project (project x) = project x project (foo x) = projectFoo x Both rules can be applied to the expression, but you get one fusion more, if you use the first one first. Let me guess, in order to solve that, I should restrict the first rule to an earlier phase than the second rule. Thanks for the detailed answer and thanks to the busy people who have created the optimizer and who have written all the papers and Wiki pages for making use of this feature. I don't know another language where it is possible to control the optimizer in this way. From igloo at earth.li Wed Jan 16 16:05:07 2008 From: igloo at earth.li (Ian Lynagh) Date: Wed Jan 16 15:58:23 2008 Subject: [Haskell-cafe] Poisx select support In-Reply-To: <20080116204022.GG4629@scytale.galois.com> References: <5ae4f2ba0801161027n2632375i1f8edc2fe24a35c5@mail.gmail.com> <20080116193259.GA4629@scytale.galois.com> <5ae4f2ba0801161209x5ab3535bh57ef28ab62ac891@mail.gmail.com> <20080116201401.GE4629@scytale.galois.com> <5ae4f2ba0801161236i23f8e92dpe47ed3149553e884@mail.gmail.com> <20080116204022.GG4629@scytale.galois.com> Message-ID: <20080116210507.GA22372@matrix.chaos.earth.li> On Wed, Jan 16, 2008 at 12:40:22PM -0800, Donald Bruce Stewart wrote: > > If something you need is missing from there, write it as a patch against > the darcs repository for `unix', > http://darcs.haskell.org/packages/unix/, and submit it to > libraries@haskell.org for inclusion in the next release of that library. Please note that patches for the unix library should follow the library submissions process: http://www.haskell.org/haskellwiki/Library_submissions Thanks Ian From droundy at darcs.net Wed Jan 16 16:14:22 2008 From: droundy at darcs.net (David Roundy) Date: Wed Jan 16 16:07:36 2008 Subject: [Haskell-cafe] Re: [darcs-devel] announcing darcs 2.0.0pre2 In-Reply-To: <477CC2EC.2030302@microsoft.com> References: <20071216211722.GI11101@darcs.net> <47666BA0.2080408@microsoft.com> <20071221143254.GO11036@darcs.net> <477CC2EC.2030302@microsoft.com> Message-ID: <20080116211419.GR27808@darcs.net> On Thu, Jan 03, 2008 at 11:11:40AM +0000, Simon Marlow wrote: > > Anyhow, could you retry this test with the above change in methodology, > > and let me know if (a) the pull is still slow the first time and (b) if > > it's much faster the second time (after the reverse unpull/pull)? > > I think I've done it in both directions now, and it got faster, but still > much slower than darcs1: > > $ time darcs2 unpull --from-tag 2007-09-25 -a > Finished unpulling. > 58.68s real 50.64s user 6.36s system 97% darcs2 unpull --from-tag > 2007-09-25 -a > $ time darcs2 pull -a ../ghc-darcs2 > Pulling from "../ghc-darcs2"... > Finished pulling and applying. > 53.28s real 44.62s user 7.10s system 97% darcs2 pull -a ../ghc-darcs2 > > This is still an order of magnitude slower than darcs1 for the same > operation. (these times are now on the local filesystem, BTW) I've recently found the problem leading to this slowdown (I believe) and get about an order-of-magnitude improvement in the speed of a pull of 400 patches in the ghc repository. It turned out to be an issue that scaled with the size (width) of the repository, not with the number of patches (which had been the obvious suspect), which was causing trouble when applying to the pristine cache. At this point, darcs-2 outperforms darcs-1 on most tests that I've tried, so it'd be a good time to find some more performance problems, if you can... and I don't doubt that there are more out there. -- David Roundy Department of Physics Oregon State University From barsoap at web.de Wed Jan 16 16:20:28 2008 From: barsoap at web.de (Achim Schneider) Date: Wed Jan 16 16:14:10 2008 Subject: [Haskell-cafe] Re: Data constructors versus types References: <1200516343.4222.13.camel@localhost.localdomain> Message-ID: <20080116222028.4b2f3413@solaris.tower> Peter Verswyvelen wrote: > I know nothing about theoretical computer science, but I was wondering > if it possible to forget about types, and just keep the concept of > data constructors, and have an analyzer determine correctness of the > code and "staticness" of the data? > > Basically this is what SCHEME does no? Doesn't SCHEME have static > whole program analyzers to remove the overhead of the "symbol tags" > and check correctness of a program (Stalin, Petit-Scheme, ...)? > > What are to pros/contras? > Basically, it's a matter of taste, and how much of the checking can be done at compile-time... which gets quite involved and O(big), if all you have is (tagged) lists with type information. And, yes, Stalin manages to specialize a -> a functions to Int -> Int to make numerical code as fast or faster than C, but so does GHC. Plus a GHC build may allow you to get a coffee, Stalin allows you to go shopping, watch a movie and then go on vacation. That is because, in general, you can't forget about the type of your data, you need it in some way or the other to do anything with it. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From barsoap at web.de Wed Jan 16 16:30:11 2008 From: barsoap at web.de (Achim Schneider) Date: Wed Jan 16 16:23:32 2008 Subject: [Haskell-cafe] Re: Data constructors versus types References: <1200516343.4222.13.camel@localhost.localdomain> <20080116222028.4b2f3413@solaris.tower> Message-ID: <20080116223011.1ddb4b6f@solaris.tower> Achim Schneider wrote: > And, yes, Stalin manages to specialize a -> a functions to Int -> Int > to make numerical code as fast or faster than C, but so does GHC. > That is, seen formally, quite fuzzy. I'm going to be beaten for it. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From lane at downstairspeople.org Wed Jan 16 16:33:48 2008 From: lane at downstairspeople.org (Christopher Lane Hinson) Date: Wed Jan 16 16:27:03 2008 Subject: [Haskell-cafe] HPC of several modules? In-Reply-To: <404396ef0801160951i7b4555e3j6ec80b2cc03b734c@mail.gmail.com> References: <404396ef0801160951i7b4555e3j6ec80b2cc03b734c@mail.gmail.com> Message-ID: > What is hpc6? I am using the version supplied with GHC 6.8. This is just hpc on debian/ubuntu systems, where all the binaries have symlinks that append a version number. ghc6.8 on debian doesn't provide hpc without the 6. I just reportbugged this. --Lane From bf3 at telenet.be Wed Jan 16 16:56:03 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Wed Jan 16 16:49:18 2008 Subject: [Haskell-cafe] Re: Data constructors versus types In-Reply-To: <20080116222028.4b2f3413@solaris.tower> References: <1200516343.4222.13.camel@localhost.localdomain> <20080116222028.4b2f3413@solaris.tower> Message-ID: <1200520564.4222.52.camel@localhost.localdomain> Thank you for explaining. I was wondering if the same syntax could be used somehow (not in Haskell, in some theoretical language), I mean use an annotation to tell the compiler that a "type-tag" should be determined at compile time and not at runtime, otherwise -> error So eg // Runtime tag, aka data constructor foo (Int n) = ... // Compile tag, aka type foo (>Int< n) = ... Might not make any sense... You're talking about O(big)... But wasn't the C language in some way succesful because on the hardware at that time other much nicer languages (e.g. LISP) were just way too slow? Or was this just O(n) times slower? IMHO: Shouldn't concepts that are conceptually the same (in this case, "giving meaning/adding constraints to bits of data" ) at runtime and compile time look very similar in the language? Most languages require completely different syntax and code when you want something to be lazy versus strict. Haskell doesn't, you can just add an annotation if you want it to be strict, no much rewriting is required. However, if I want to change a runtime data constructor definition (and code) into a compiletime type, then I can rewrite all of my code basically. That is not the case in SCHEME as far as I understand it. On Wed, 2008-01-16 at 22:20 +0100, Achim Schneider wrote: > Peter Verswyvelen wrote: > > > I know nothing about theoretical computer science, but I was wondering > > if it possible to forget about types, and just keep the concept of > > data constructors, and have an analyzer determine correctness of the > > code and "staticness" of the data? > > > > Basically this is what SCHEME does no? Doesn't SCHEME have static > > whole program analyzers to remove the overhead of the "symbol tags" > > and check correctness of a program (Stalin, Petit-Scheme, ...)? > > > > What are to pros/contras? > > > Basically, it's a matter of taste, and how much of the checking can be > done at compile-time... which gets quite involved and O(big), if all > you have is (tagged) lists with type information. > > And, yes, Stalin manages to specialize a -> a functions to Int -> Int > to make numerical code as fast or faster than C, but so does GHC. > > Plus a GHC build may allow you to get a coffee, Stalin allows you to go > shopping, watch a movie and then go on vacation. > > That is because, in general, you can't forget about the type of your > data, you need it in some way or the other to do anything with it. > From bf3 at telenet.be Wed Jan 16 17:04:44 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Wed Jan 16 16:57:57 2008 Subject: [Haskell-cafe] Compiling Blobs Message-ID: <1200521084.4222.56.camel@localhost.localdomain> I'm trying to build http://www.cs.york.ac.uk/fp/darcs/Blobs using GHC 6.8.2. It looks like a good Haskell program to learn from. So far I managed to modify the source code so it makes use of the new HaXML libraries, and after a lot of hacking I could build and link to wxHaskell, but my app crashes (I do get a window however, woohoo) Maybe someone else managed already? Thanks, Peter From dominic.steinitz at blueyonder.co.uk Wed Jan 16 17:41:05 2008 From: dominic.steinitz at blueyonder.co.uk (Dominic Steinitz) Date: Wed Jan 16 17:34:25 2008 Subject: [Haskell-cafe] Re: ANN: A triple of new packages for talking tothe outside world References: <396556a20801071037t1b66e444u52abe1d934b7f902@mail.gmail.com> <396556a20801081226l5ebf5062p685a80c6aac6ba41@mail.gmail.com> <1199885578.7279.119.camel@localhost> <117f2cc80801091425l41b73ea3uddda3d91ba9405e7@mail.gmail.com> <20080109234352.3ee84d4a@solaris.tower> <20080110010123.GF18915@darcs.net> <396556a20801091725p4a2dbf8aw3117a568b807c195@mail.gmail.com> <20080110184521.GA17906@scytale.galois.com> <396556a20801151523t314797atb40fa26688c6ec6@mail.gmail.com> Message-ID: Adam Langley imperialviolet.org> writes: > > On Jan 10, 2008 10:45 AM, Don Stewart galois.com> wrote: > > That's pretty much what we envisaged as the approach to take. > > Monad transformers adding some bit-buffer state over Get/Put. > > For anyone who's still reading this thread... > > I've just uploaded[1] binary-strict 0.2.1 which includes > Data.Binary.Strict.BitGet - a Get like monad which works by the bit. > I'm afraid that Haddock 2 is choaking on {-# UNPACK #-}, so I don't > have the HTML documentation to point to. (And I thought that Haddock 2 > was going to fix all those parsing issues :( - hopefully I'm just > doing something stupid). > > [1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/binary-strict-0.2.1 > > AGL > Thanks for taking the time on this. The old NewBinary had NewBinary.Binary.getBits :: NewBinary.Binary.BinHandle -> Int -> IO GHC.Word.Word8 which allowed you to do things like tlv_ bin = do tagValueVal <- getBits bin 5 tagConstructionVal <- getBits bin 1 tagTypeVal <- getBits bin 2 I'm sure I'm wrong but putting bits into [Bool] doesn't look very efficient. Of course, NewBinary didn't address what happened for n >= 8. Some possibilities are a) not allowing more than 8 b) returning [Word8] or c) (which I thought was where we'd go) a ByteString with some sort of padding. Dominic. From david.waern at gmail.com Wed Jan 16 18:04:48 2008 From: david.waern at gmail.com (David Waern) Date: Wed Jan 16 17:58:00 2008 Subject: [Haskell-cafe] ANNOUNCE: Haddock version 2.0.0.0 In-Reply-To: References: Message-ID: 2008/1/16, Henning Thielemann : > > On Tue, 8 Jan 2008, David Waern wrote: > > > Changes in version 2.0.0.0: > > > > * The GHC API is used as the front-end > > It's great to see this progress in Haddock. However, is Haddock now more > difficult to port than before? Haddock is already ported to the GHC API, the wiki-page needs updating. > Is there some bug- and feature request > tracker for Haddock? I only know of > http://www.haskell.org/haskellwiki/Haddock/Development_ideas > and the first big point seems to be finished now. There is no bug-tracker yet. When community.haskell.org provides Trac, we might use that. For now, we're using the TODO file in the darcs repo (code.haskell.org/haddock). > I like to have the following enhancements: > > * Optionally show qualifications of identifiers, that is print > "Sequence.map" rather than "map", "Music.T" rather than just "T". The > option for haddock could be > --qualification QUAL > QUAL=none (default) strip off qualification (just "map") > QUAL=orig show the identifiers as they are written in the module (e.g. "map" or "List.map") > QUAL=full show all identifiers with full qualification (Data.List.map) > Actually I tried to implement it by myself in the old Haddock, but I > could not precisely identify the place, where the qualification is > removed. > > * Documentation of arguments of type constructors other than 'top level' arrows. E.g. > T (a {- ^ arg -} -> b {- ^ result -} ) > (a {- ^ arg -} -> b {- ^ result -} ) -> c > (a {- ^ x coord -}, b {- ^ y coord -}) -> c > It's probably difficult to format properly in HTML. > I've added these to the TODO file. Thanks, David From barsoap at web.de Wed Jan 16 18:31:38 2008 From: barsoap at web.de (Achim Schneider) Date: Wed Jan 16 18:25:00 2008 Subject: [Haskell-cafe] Re: Data constructors versus types References: <1200516343.4222.13.camel@localhost.localdomain> <20080116222028.4b2f3413@solaris.tower> <1200520564.4222.52.camel@localhost.localdomain> Message-ID: <20080117003138.74bc13a4@solaris.tower> Peter Verswyvelen wrote: > Thank you for explaining. > > I was wondering if the same syntax could be used somehow (not in > Haskell, in some theoretical language), I mean use an annotation to > tell the compiler that a "type-tag" should be determined at compile > time and not at runtime, otherwise -> error > > So eg > > // Runtime tag, aka data constructor > foo (Int n) = ... > > // Compile tag, aka type > foo (>Int< n) = ... > > Might not make any sense... > ghc --ddump-simpl and assure that your values get unboxed... > You're talking about O(big)... But wasn't the C language in some way > succesful because on the hardware at that time other much nicer > languages (e.g. LISP) were just way too slow? Or was this just O(n) > times slower? > Compiler technology also wasn't as advanced as now, Stalin can't compile even small programs under say 5 minutes... compare this to e.g. TurboPascal, which afair uses three passes: Parsing, Error Reporting, Code Generation, it was similar with C compilers back then. Lisp was fast on lisp machines, where it is the same as what C is to Neumann-Architectures: An assembler. I'm not at all sure about the specific O's involved, but I guess it's quite easy to get to NP-complete if you want to do really much without much information. > IMHO: Shouldn't concepts that are conceptually the same (in this case, > "giving meaning/adding constraints to bits of data" ) at runtime and > compile time look very similar in the language? Most languages require > completely different syntax and code when you want something to be > lazy versus strict. Haskell doesn't, you can just add an annotation > if you want it to be strict, no much rewriting is required. However, > if I want to change a runtime data constructor definition (and code) > into a compiletime type, then I can rewrite all of my code basically. > That is not the case in SCHEME as far as I understand it. > Scheme knows no types but the builtins like INT or PAIR or LIST or SYMBOL and so on. Even if you distinguish say ('complex 1 2) from ('vec3 1 2 3) , the compiler in general won't stop you from passing these things into the wrong functions. It doesn't even know that a function is passed a "LIST (QUOTEDSYMBOL INT INT)" or "LIST (QUOTEDSYMBOL INT INT INT)", it just sees a pair, in both cases. Lisp is actually not really meant to be compiled, but interpreted. The nice thing is that it doesn't need more than a handful of primitives, a list parser and heap manager/garbage collector and evaluator, which all can be implemented in under 1000 lines of C. Things get more involved with get/cc, but then how many C programmers ever heard of setjmp... on top of my head, one set of possible primitives is quote lambda set! succ pred cond. you can then start by defining define by (set! 'define (lambda (sym f) (set! sym f))) There's the wizard book and Graham's Ansi Common Lisp if you're interested in how cheap lisp actually is. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From jerzy.karczmarczuk at info.unicaen.fr Wed Jan 16 18:58:19 2008 From: jerzy.karczmarczuk at info.unicaen.fr (jerzy.karczmarczuk@info.unicaen.fr) Date: Wed Jan 16 18:51:33 2008 Subject: [Haskell-cafe] Re: Data constructors versus types In-Reply-To: <20080117003138.74bc13a4@solaris.tower> References: <1200516343.4222.13.camel@localhost.localdomain> <20080116222028.4b2f3413@solaris.tower> <1200520564.4222.52.camel@localhost.localdomain> <20080117003138.74bc13a4@solaris.tower> Message-ID: Achim Schneider writes: > Lisp is actually not really meant to be compiled, but interpreted. The > nice thing is that it doesn't need more than a handful of primitives, a > list parser and heap manager/garbage collector and evaluator, which all > can be implemented in under 1000 lines of C. Things get more involved > with get/cc, but then how many C programmers ever heard of setjmp... Would you mind stopping to spread dubious truths? Certainly, Lisp processors started with simple eval/apply interpreters, since they were easy to construct, but compilers, their name is Legion! Look at CMU Common Lisp compiler. GNU CLISP compiler Lisp Works compiler Allegro compiler ... There are also Lisp->C translators. The result is of course compiled. CLiCC, this is a German (Kiel) product. Perhaps not so far from you. Where did you read that Lisp is not meant to be compiled, for goodness' sake!? Jerzy Karczmarczuk From rl at cse.unsw.edu.au Wed Jan 16 19:10:44 2008 From: rl at cse.unsw.edu.au (Roman Leshchinskiy) Date: Wed Jan 16 19:04:19 2008 Subject: [Haskell-cafe] Re: Properties of optimizer rule application? In-Reply-To: References: <20080103192002.GF4775@scytale.galois.com> <47830A3B.7040401@cse.unsw.edu.au> <478DF9E7.30204@cse.unsw.edu.au> Message-ID: <478E9D04.8030002@cse.unsw.edu.au> Henning Thielemann wrote: > > To give a precise example: If I have a sequence of 'map's > map f0 . map f1 . ... . map fn > then there is some length where this is no longer collapsed to a single > 'map'? No. After applying a rule, the simplifier optimises the result of the rewriting. This means that with (map f (map g x) = map (f . g) x), map f (map g (map h xs)) is first rewritten to map (f . g) (map h xs) and the immediately to map (f . g . h) xs Rewriting does not shift the "focus" of the simplifier. > project . project . foo > with the rules > project (project x) = project x > project (foo x) = projectFoo x > > Both rules can be applied to the expression, but you get one fusion more, > if you use the first one first. Let me guess, in order to solve that, I > should restrict the first rule to an earlier phase than the second rule. That's one possibility. It would be vastly preferable, however, to add the rule project (projectFoo x) = projectFoo x In general, you want your rewrite system to be confluent. I suspect that non-confluence always indicates a design problem. This is within one set of rules, of course - explicitly staged things like "rewriting back" of stuff which didn't fuse are different. Roman From mail at joachim-breitner.de Wed Jan 16 19:21:49 2008 From: mail at joachim-breitner.de (Joachim Breitner) Date: Wed Jan 16 19:15:03 2008 Subject: [Haskell-cafe] Haskell-Support in Ohloh Message-ID: <1200529309.3822.33.camel@otto.ehbuehl.net> Hi, I?m only margianlly involved or up to date there, but still some might have missed this: Ohloh has begun to release their tools, starting with ohcount, their tool to measure code and comments lines: http://labs.ohloh.net/ohcount/ They explicitly write that they want haskell support, and the oldest open bug report on their page is about this: http://labs.ohloh.net/ohcount/ticket/205 So if anyone feels like programming some ruby (I guess they want it to be in that language as well) and wants to give the haskell community a chance for wider audience, give it a shot. Greetings, Joachim -- Joachim "nomeata" Breitner mail: mail@joachim-breitner.de | ICQ# 74513189 | GPG-Key: 4743206C JID: nomeata@joachim-breitner.de | http://www.joachim-breitner.de/ Debian Developer: nomeata@debian.org -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Dies ist ein digital signierter Nachrichtenteil Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080117/1c4c4b25/attachment.bin From dons at galois.com Wed Jan 16 19:26:36 2008 From: dons at galois.com (Don Stewart) Date: Wed Jan 16 19:19:50 2008 Subject: [Haskell-cafe] Haskell-Support in Ohloh In-Reply-To: <1200529309.3822.33.camel@otto.ehbuehl.net> References: <1200529309.3822.33.camel@otto.ehbuehl.net> Message-ID: <20080117002636.GK4629@scytale.galois.com> mail: > Hi, > > I?m only margianlly involved or up to date there, but still some might > have missed this: > > Ohloh has begun to release their tools, starting with ohcount, their > tool to measure code and comments lines: > > http://labs.ohloh.net/ohcount/ > > They explicitly write that they want haskell support, and the oldest > open bug report on their page is about this: > > http://labs.ohloh.net/ohcount/ticket/205 > > So if anyone feels like programming some ruby (I guess they want it to > be in that language as well) and wants to give the haskell community a > chance for wider audience, give it a shot. > Oh, great! I've been waiting for this. It's annoying having xmonad classified as a C/C++ project (and sjanssen and I as C/C++ developers!) http://www.ohloh.net/projects/6869?p=xmonad Ohloh Summary * Mostly written in C/C++ * Extremely well-commented source code So what we need is a) darcs support (so we don't have to convert repos to git), and b) a haskell lexer. Then all the haskell projects can get analysed, linked to , etc, -- and made more visible to the general open source world. -- Don From graham.fawcett at gmail.com Wed Jan 16 20:19:24 2008 From: graham.fawcett at gmail.com (Graham Fawcett) Date: Wed Jan 16 20:12:37 2008 Subject: [Haskell-cafe] ANNOUNCE: HStringTemplate -- An Elegant, Functional, Nifty Templating Engine for Haskell In-Reply-To: <89B71013-9550-4E1F-91DD-A4ABD532F2F1@gmail.com> References: <89B71013-9550-4E1F-91DD-A4ABD532F2F1@gmail.com> Message-ID: On Jan 14, 2008 2:47 AM, Sterling Clover wrote: > HStringTemplate is a port of Terrence Parr's lovely StringTemplate > (http://www.stringtemplate.org) engine to Haskell. This is very cool. Your docs describe a function, cacheSTGroup: cacheSTGroup :: Int -> STGen a -> STGen a Given an integral amount of seconds and a group, returns a group cached for that span of time. Does not cache "misses." How does this work without breaking referential transparency? Shouldn't it be in the IO monad if it is time-dependent? Graham From allbery at ece.cmu.edu Wed Jan 16 20:21:14 2008 From: allbery at ece.cmu.edu (Brandon S. Allbery KF8NH) Date: Wed Jan 16 20:14:27 2008 Subject: [Haskell-cafe] Re: Data constructors versus types In-Reply-To: References: <1200516343.4222.13.camel@localhost.localdomain> <20080116222028.4b2f3413@solaris.tower> <1200520564.4222.52.camel@localhost.localdomain> <20080117003138.74bc13a4@solaris.tower> Message-ID: <71B99E99-5324-4EC1-85BB-A318C434839D@ece.cmu.edu> On Jan 16, 2008, at 18:58 , jerzy.karczmarczuk@info.unicaen.fr wrote: > Achim Schneider writes: >> Lisp is actually not really meant to be compiled, but interpreted. >> The >> > Would you mind stopping to spread dubious truths? > Certainly, Lisp processors started with simple eval/apply > interpreters, > since they were easy to construct, but compilers, their name is > Legion! He is correct given that he almost certainly means "was not originally meant to be compiled" --- and please, spare us the obvious pedantry. Also, you might want to take a close look at your public persona as exposed on this list. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH From agl at imperialviolet.org Wed Jan 16 20:33:41 2008 From: agl at imperialviolet.org (Adam Langley) Date: Wed Jan 16 20:26:53 2008 Subject: [Haskell-cafe] Re: ANN: A triple of new packages for talking tothe outside world In-Reply-To: References: <396556a20801071037t1b66e444u52abe1d934b7f902@mail.gmail.com> <1199885578.7279.119.camel@localhost> <117f2cc80801091425l41b73ea3uddda3d91ba9405e7@mail.gmail.com> <20080109234352.3ee84d4a@solaris.tower> <20080110010123.GF18915@darcs.net> <396556a20801091725p4a2dbf8aw3117a568b807c195@mail.gmail.com> <20080110184521.GA17906@scytale.galois.com> <396556a20801151523t314797atb40fa26688c6ec6@mail.gmail.com> Message-ID: <396556a20801161733i409573b5y26693e633d92ae8e@mail.gmail.com> On Jan 16, 2008 2:41 PM, Dominic Steinitz wrote: > tlv_ bin = > do tagValueVal <- getBits bin 5 > tagConstructionVal <- getBits bin 1 > tagTypeVal <- getBits bin 2 > > I'm sure I'm wrong but putting bits into [Bool] doesn't look very efficient. Of > course, NewBinary didn't address what happened for n >= 8. Some possibilities > are a) not allowing more than 8 b) returning [Word8] or c) (which I thought was > where we'd go) a ByteString with some sort of padding. BitGet is just an API RFC at the moment, so I'm just describing it here - not trying to justify it. In BitGet there's getAsWord[8|16|32|64] which take a number of bits ($n$) and returns the next $n$ bits in the bottom of a Word$x$. Thus, getAsWord8 is what you call getBits and, if you had a 48 bit number, you could use getAsWord64 and the bottom 48-bits of the resulting Word64 would be what you want. Equally, asking for more than $x$ bits when calling getAsWord$x$ is a mistake, however I don't check for it in the interest of speed. There are also get[Left|Right]ByteString which return the next $n$ bits in a ByteString of Word8's. The padding is either at the end of the last byte (left aligned) or at the beginning of the first byte (right aligned). If you did want a [Bool], you could use: bits <- sequence $ take n $ repeat getBit AGL -- Adam Langley agl@imperialviolet.org http://www.imperialviolet.org 650-283-9641 From gwern0 at gmail.com Wed Jan 16 20:31:20 2008 From: gwern0 at gmail.com (gwern0@gmail.com) Date: Wed Jan 16 20:27:51 2008 Subject: [Haskell-cafe] Re: Data constructors versus types In-Reply-To: References: <1200516343.4222.13.camel@localhost.localdomain> <20080116222028.4b2f3413@solaris.tower> <1200520564.4222.52.camel@localhost.localdomain> <20080117003138.74bc13a4@solaris.tower> Message-ID: <20080117013120.GB11540@localhost> On 2008.01.17 00:58:19 +0100, jerzy.karczmarczuk@info.unicaen.fr scribbled 0.9K characters: > Achim Schneider writes: >> Lisp is actually not really meant to be compiled, but interpreted. The >> nice thing is that it doesn't need more than a handful of primitives, a >> list parser and heap manager/garbage collector and evaluator, which all >> can be implemented in under 1000 lines of C. Things get more involved >> with get/cc, but then how many C programmers ever heard of setjmp... > > Would you mind stopping to spread dubious truths? > Certainly, Lisp processors started with simple eval/apply interpreters, > since they were easy to construct, but compilers, their name is Legion! > Look at CMU Common Lisp compiler. > GNU CLISP compiler > Lisp Works compiler > Allegro compiler > ... ... > Jerzy Karczmarczuk I don't think it's a dubious truth. Apparently a lot of Lisps (like Maclisp or Interlisp, I hear) had a situation where the semantics of a program could differ depending on whether it was compiled or interpreted, and Scheme and Common Lisp made a point of trying to avoid that. In _Introduction to Common Lisp_, we read: "Most Lisp implementations are internally inconsistent in that by default the interpreter and compiler may assign different semantics to correct programs. This semantic difference stems primarily from the fact that the interpreter assumes all variables to be dynamically scoped, whereas the compiler assumes all variables to be local unless explicitly directed otherwise. This difference has been the usual practice in Lisp for the sake of convenience and efficiency but can lead to very subtle bugs. The definition of Common Lisp avoids such anomalies by explicitly requiring the interpreter and compiler to impose identical semantics on correct programs so far as possible." Given that it was designed as interpreted, compilation was motivated by efficiency concerns, and interpreted techniques differed from compiled techniques (and in a way that would allow you to redefine and change more stuff on the fly), I think it's a reasonable case to say that many Lisps - like all the ones before Scheme and CL - were meant to be interpreted and not so much compiled. -- gwern NATIA DIA Burns espionage 97 utopia orthodox Meade cond SOCIMI -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080116/2cf27855/attachment.bin From mmitar at gmail.com Wed Jan 16 21:16:48 2008 From: mmitar at gmail.com (Mitar) Date: Wed Jan 16 21:10:00 2008 Subject: [Haskell-cafe] 0/0 > 1 == False In-Reply-To: References: Message-ID: Hi! On Jan 11, 2008 7:30 AM, Cristian Baboi wrote: > NaN is not 'undefined' Why not? What is a semantic difference? I believe Haskell should use undefined instead of NaN for all operations which are mathematically undefined (like 0/0). NaN should be used in a languages which does not support such nice Haskell features. Because if Haskell would use undefined such error would propagate itself to higher levels of computations, with NaN it does not. if bigComputation > 1 then ... else ... Would be evaluating else semantically correct if bigComputation returns NaN? No, it is not. With undefined this is correctly (not)evaluated. Mitar From ryani.spam at gmail.com Wed Jan 16 21:25:01 2008 From: ryani.spam at gmail.com (Ryan Ingram) Date: Wed Jan 16 21:18:13 2008 Subject: [Haskell-cafe] Re: [Haskell] Simulating client server communication with recursive monads In-Reply-To: <004601c85709$f4d74550$de85cff0$@de> References: <004601c85709$f4d74550$de85cff0$@de> Message-ID: <2f9b2d30801161825w5c47688av6194433c99bead0e@mail.gmail.com> (redirected to haskell-cafe) mfix is "value" recursion, not "effect" recursion. It allows you to "tie-the-knot" with data being constructed recursively even in a monadic context. When you are using the Writer monad like this, the bind operation between statements in a "do" construct is just ++. "simulation" in your message is > simulation:: Writer [String] () > simulation = mdo > a <- server cr > cr <- client $ take 10 a > return () This is really just the following: > simulation :: Writer [String] () > simulation = Writer result where > ( a, a_out ) = runWriter (server cr) > ( cr, cr_out ) = runWriter (client $ take 10 a) > result = ( (), a_out ++ cr_out ) With "mdo" you are allowed to have the values refer to each other; the right hand side of "( a, a_out ) = ..." can refer to "cr" and vice versa. But there's no way to follow the thread of computation between the server and the client with this style. -- ryan From derek.a.elkins at gmail.com Wed Jan 16 20:30:42 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Wed Jan 16 21:26:13 2008 Subject: [Haskell-cafe] 0/0 > 1 == False In-Reply-To: References: Message-ID: <1200533442.5657.7.camel@derek-laptop> On Thu, 2008-01-17 at 03:16 +0100, Mitar wrote: > Hi! > > On Jan 11, 2008 7:30 AM, Cristian Baboi wrote: > > NaN is not 'undefined' > > Why not? What is a semantic difference? I believe Haskell should use > undefined instead of NaN for all operations which are mathematically > undefined (like 0/0). NaN should be used in a languages which does not > support such nice Haskell features. Because if Haskell would use > undefined such error would propagate itself to higher levels of > computations, with NaN it does not. > > if bigComputation > 1 > then ... > else ... > > Would be evaluating else semantically correct if bigComputation > returns NaN? No, it is not. With undefined this is correctly > (not)evaluated. For the love of Pete, floating point numbers are not real numbers. 0/0 is mathematically defined for floating point numbers to be NaN. If you don't want to use IEEE floating point numbers, use a different type as was suggested early in this thread. From felipe.lessa at gmail.com Wed Jan 16 21:50:45 2008 From: felipe.lessa at gmail.com (Felipe Lessa) Date: Wed Jan 16 21:43:57 2008 Subject: [Haskell-cafe] 0/0 > 1 == False In-Reply-To: <1200533442.5657.7.camel@derek-laptop> References: <1200533442.5657.7.camel@derek-laptop> Message-ID: On Jan 16, 2008 11:30 PM, Derek Elkins wrote: > For the love of Pete, floating point numbers are not real numbers. 0/0 > is mathematically defined for floating point numbers to be NaN. If you > don't want to use IEEE floating point numbers, use a different type as > was suggested early in this thread. In fact, you can be happy just by using Rational Prelude> 0/0 :: Rational *** Exception: Ratio.%: zero denominator or creating a newtype newtype ZeroUndef a = Z {unZ :: a} instance Eq a => Eq (ZeroUndef a) where Z a == Z b = a == b Z a /= Z b = a /= b instance Show a => Show (ZeroUndef a) where ... instance Num a => Num (ZeroUndef a) where ... instance Fractional a => Fractional (ZeroUndef a) where ... Z a / Z 0 = error "..." Z a / Z b = Z (a / b) .... so that ZeroUndef Double, ZeroUndef Float, ZeroUndef Matrix and all friends do work like you want. -- Felipe. From ok at cs.otago.ac.nz Wed Jan 16 22:19:44 2008 From: ok at cs.otago.ac.nz (Richard A. O'Keefe) Date: Wed Jan 16 22:12:59 2008 Subject: [Haskell-cafe] Re: Data constructors versus types In-Reply-To: <1200520564.4222.52.camel@localhost.localdomain> References: <1200516343.4222.13.camel@localhost.localdomain> <20080116222028.4b2f3413@solaris.tower> <1200520564.4222.52.camel@localhost.localdomain> Message-ID: On 17 Jan 2008, at 10:56 am, Peter Verswyvelen wrote: > You're talking about O(big)... But wasn't the C language in some way > succesful because on the hardware at that time other much nicer > languages (e.g. LISP) were just way too slow? Or was this just O(n) > times slower? No. C was designed as a Systems Implementation Language (there were lots of SILs) with the following advantages: (1) tolerable code from a fairly naive compiler (the PDP-11 UNIX V7 C compiler did a little optimisation, but not very much; function entry/ exit was done using calls to library support routines in order to save space, so every function call involved *three* hardware-level function calls; I speeded up a text editor by about 20% by replacing just two tiny functions by hand- written assembler, and it was this function call overhead that was saved) (2) tolerably compact code; a fairly useful library of stuff that you didn't actually have to use (again, said text editor got a notable space saving by *not* using any C stdio stuff at all, not using any floating point stuff at all, and not even linking, let alone calling, malloc()) (3) fairly direct mapping between language and machine so the "performance model" you had to keep in your head was simple (4) a fair degree of portability between compilers (although the PC world spoiled this to some extent). Lisp *performance* compared with C was always O(1) and sometimes excellent; I have had Scheme code running faster than C. It was the memory footprint caused by Lisp's comparatively large library (possibly even including the compiler) always being there in full, and the (largely imaginary) cost of garbage collection which scared people off. It is intensely annoying to an old Lisp hacker to see Java succeeding despite being worse at just about everything Lisp was ever criticised for. But in fairness, the other thing was that before the advent of Common Lisp, every Lisp was different. Develop in MacLisp and you could forget about delivering in Interlisp, and vice versa. This is why, although I actually have Lazy ML on my machine still, I dropped it for Haskell. From ok at cs.otago.ac.nz Wed Jan 16 22:38:54 2008 From: ok at cs.otago.ac.nz (Richard A. O'Keefe) Date: Wed Jan 16 22:33:23 2008 Subject: [Haskell-cafe] Re: Data constructors versus types In-Reply-To: <20080117003138.74bc13a4@solaris.tower> References: <1200516343.4222.13.camel@localhost.localdomain> <20080116222028.4b2f3413@solaris.tower> <1200520564.4222.52.camel@localhost.localdomain> <20080117003138.74bc13a4@solaris.tower> Message-ID: On 17 Jan 2008, at 12:31 pm, Achim Schneider wrote: > Lisp is actually not really meant to be compiled, but interpreted. The "classic" Lisp is Lisp 1.5. The Lisp 1.5 Programmer's Manual, published in I think 1961, contains "Appendix D: The Lisp Compiler". If I'm reading appendix G correctly, the compiler was under 4000 words of storage. > The > nice thing is that it doesn't need more than a handful of > primitives, a > list parser and heap manager/garbage collector and evaluator, which > all > can be implemented in under 1000 lines of C. Things get more involved > with get/cc, but then how many C programmers ever heard of setjmp... I have no idea what get/cc might be, unless it is a mistake for call/cc, but that's Scheme, not Lisp. "Classic" Lisp stack management wasn't really any harder than Pascal stack management (in part because classic Lisps were still struggling to get closures right). From stevelihn at gmail.com Wed Jan 16 23:36:41 2008 From: stevelihn at gmail.com (Steve Lihn) Date: Wed Jan 16 23:29:52 2008 Subject: [Haskell-cafe] haskelldb basic documentation needed In-Reply-To: References: <92952f860801150953q79a66166o5e5ff27fb37ee91d@mail.gmail.com> Message-ID: For mysql (via HDBC),some documentation is available here. But it is rather going through HDBC-ODBC-mysql. It is a bit complex than you would normally expect with mysql. http://en.wikibooks.org/wiki/Haskell/Database 2008/1/15 Justin Bailey : > 2008/1/15 Immanuel Normann : > > > I don't know what pairs of strings this function needs. The API > description is to unspecific: > > > > > > > The connect function takes some driver specific name, value pairs use to > setup the database connection, and a database action to run. > > > > > > What are the specific name value pairs needed (for a connection to a mysql > db )? > > Immanuel > > Your best bet is to download the appropriate drivers - either > haskelld-hdbc-mysql or haskelldb-hsql-mysql. If you get the haskelldb > sources via darcs, you can also look in the test directory to see how the > connections are established. > > In my specific case, I am using PostgreSQL and by login function looks like > this: > > -- ^ Returns a function which can log into the database and perform > operations. > login :: MonadIO m => String -> Int -> String -> String -> String -> > (Database -> m a) -> m a > login server port user password dbname = postgresqlConnect [("host", > server), > ("port", show port), > ("user", user), > ("password", password), > ("dbname", dbname)] > > > > > _______________________________________________ > > 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 > > From sjanssen at cse.unl.edu Thu Jan 17 01:25:37 2008 From: sjanssen at cse.unl.edu (Spencer Janssen) Date: Thu Jan 17 01:19:31 2008 Subject: [Haskell-cafe] Poisx select support In-Reply-To: <5ae4f2ba0801161209x5ab3535bh57ef28ab62ac891@mail.gmail.com> References: <5ae4f2ba0801161027n2632375i1f8edc2fe24a35c5@mail.gmail.com> <20080116193259.GA4629@scytale.galois.com> <5ae4f2ba0801161209x5ab3535bh57ef28ab62ac891@mail.gmail.com> Message-ID: <20080117062537.GA15810@presario> On Wed, Jan 16, 2008 at 02:09:31PM -0600, Galchin Vasili wrote: > Hi Don, > > Sorry ..I wasn't clear enough.I am trying to determine from the > Haskell FFI doc what datatype to use in order to model C's "void *", e.g. > for mmap http://www.opengroup.org/onlinepubs/000095399/functions/mmap.html > > Regards, Vasili For C's "void *", I'd use "Ptr ()". Cheers, Spencer Janssen From bos at serpentine.com Thu Jan 17 01:29:45 2008 From: bos at serpentine.com (Bryan O'Sullivan) Date: Thu Jan 17 01:22:56 2008 Subject: [Haskell-cafe] Poisx select support In-Reply-To: <20080117062537.GA15810@presario> References: <5ae4f2ba0801161027n2632375i1f8edc2fe24a35c5@mail.gmail.com> <20080116193259.GA4629@scytale.galois.com> <5ae4f2ba0801161209x5ab3535bh57ef28ab62ac891@mail.gmail.com> <20080117062537.GA15810@presario> Message-ID: <478EF5D9.7060600@serpentine.com> Spencer Janssen wrote: > For C's "void *", I'd use "Ptr ()". "Ptr a" seems to be more usual, and hews closer to the idea that it's a pointer to an opaque value. References: <1200516343.4222.13.camel@localhost.localdomain> <20080116222028.4b2f3413@solaris.tower> <1200520564.4222.52.camel@localhost.localdomain> <20080117003138.74bc13a4@solaris.tower> Message-ID: <1200555178.2777.17.camel@localhost.localdomain> > ghc --ddump-simpl and assure that your values get unboxed... I was not really talking about boxed/unboxed values, that's another issue I think. What I was talking about is more related to the work of Neil Mitchell and Colin Runciman in their static checker for pattern matching http://www-users.cs.york.ac.uk/~ndm/downloads/paper-unfailing_haskell_a_static_checker_for_pattern_matching-24_sep_2005.pdf For example, if we would have a language that only knows "bits" as datatype, together with data constructors (tagging the bits): data Number = Int Bits#32 | Float Bits#32 (Int x) + (Int y) = Int (primAddInt32 x y) (Float x) + (Float y) = Int (primAddFloat32 x y) etc (1) Would a sufficiently smart compiler be able to eliminate the tagging overhead at runtime? Answer: yes? (2) Would such a language be just as statically safe as Haskell? Answer: I guess so? (3) What would the complexity of the compiler given a code size? of n? Answer: O(???) (4) Would it be possible to create an incremental compiler that would reduce the complexity from say quadratic to linear or constant? On very old computers I worked with great incremental C assemblers and linkers, where the time needed to recompile/relink was mostly proportional to the amount of changes one did. I guess current compilers are so complex that making them incremental would be insane? Thank you, Peter > > > You're talking about O(big)... But wasn't toxbboxhe C language in some way > > succesful because on the hardware at that time other much nicer > > languages (e.g. LISP) were just way too slow? Or was this just O(n) > > times slower? > > > Compiler technology also wasn't as advanced as now, Stalin can't > compile even small programs under say 5 minutes... compare this to e.g. > TurboPascal, which afair uses three passes: Parsing, Error Reporting, > Code Generation, it was similar with C compilers back then. > > Lisp was fast on lisp machines, where it is the same as what C is to > Neumann-Architectures: An assembler. > > I'm not at all sure about the specific O's involved, but I guess it's > quite easy to get to NP-complete if you want to do really much without > much information. > > > > IMHO: Shouldn't concepts that are conceptually the same (in this case, > > "giving meaning/adding constraints to bits of data" ) at runtime and > > compile time look very similar in the language? Most languages require > > completely different syntax and code when you want something to be > > lazy versus strict. Haskell doesn't, you can just add an annotation > > if you want it to be strict, no much rewriting is required. However, > > if I want to change a runtime data constructor definition (and code) > > into a compiletime type, then I can rewrite all of my code basically. > > That is not the case in SCHEME as far as I understand it. > > > Scheme knows no types but the builtins like INT or PAIR or LIST or > SYMBOL and so on. Even if you distinguish say > > ('complex 1 2) > from > ('vec3 1 2 3) > > , the compiler in general won't stop you from passing these things into > the wrong functions. It doesn't even know that a function is passed a > "LIST (QUOTEDSYMBOL INT INT)" or "LIST (QUOTEDSYMBOL INT INT INT)", it > just sees a pair, in both cases. > > Lisp is actually not really meant to be compiled, but interpreted. The > nice thing is that it doesn't need more than a handful of primitives, a > list parser and heap manager/garbage collector and evaluator, which all > can be implemented in under 1000 lines of C. Things get more involved > with get/cc, but then how many C programmers ever heard of setjmp... > > on top of my head, one set of possible primitives is > > quote lambda set! succ pred cond. > > you can then start by defining define by > > (set! 'define (lambda (sym f) (set! sym f))) > > There's the wizard book and Graham's Ansi Common Lisp if you're > interested in how cheap lisp actually is. > From anton at appsolutions.com Thu Jan 17 02:43:45 2008 From: anton at appsolutions.com (Anton van Straaten) Date: Thu Jan 17 02:34:57 2008 Subject: [Haskell-cafe] Re: Data constructors versus types In-Reply-To: <20080117013120.GB11540@localhost> References: <1200516343.4222.13.camel@localhost.localdomain> <20080116222028.4b2f3413@solaris.tower> <1200520564.4222.52.camel@localhost.localdomain> <20080117003138.74bc13a4@solaris.tower> <20080117013120.GB11540@localhost> Message-ID: <478F0731.3030505@appsolutions.com> gwern0@gmail.com wrote: > On 2008.01.17 00:58:19 +0100, jerzy.karczmarczuk@info.unicaen.fr scribbled 0.9K characters: >> Achim Schneider writes: >>> Lisp is actually not really meant to be compiled, but interpreted. ... >> Would you mind stopping to spread dubious truths? ... > I don't think it's a dubious truth. It's about as accurate as saying "Television is actually not really meant to be color, but black and white". From simonpj at microsoft.com Thu Jan 17 03:35:02 2008 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Thu Jan 17 03:28:14 2008 Subject: [Haskell-cafe] Re: Properties of optimizer rule application? In-Reply-To: References: <20080103192002.GF4775@scytale.galois.com> <47830A3B.7040401@cse.unsw.edu.au> <478DF9E7.30204@cse.unsw.edu.au> Message-ID: <638ABD0A29C8884A91BC5FB5C349B1C315A53A546C@EA-EXMSG-C334.europe.corp.microsoft.com> | Ok, this was a bad example. Try this one: | project . project . foo | with the rules | project (project x) = project x | project (foo x) = projectFoo x | | Both rules can be applied to the expression, but you get one fusion more, | if you use the first one first. Let me guess, in order to solve that, I | should restrict the first rule to an earlier phase than the second rule. As you point out, this set of rules is not confluent: project (project foo) can reduce to ---> project (projectFoo x) or to ---> projectFoo x depending on the order of application. The conventional solution is not to apply the rules very carefully (which is extremely hard in general), but rather to "complete" the rules, by adding project (projectFoo x) = projectFoo x Now it doesn't matter which order you apply them in. You can do this by hand, although it'd be quite a nice thing to automate it in GHC. | To give a precise example: If I have a sequence of 'map's | map f0 . map f1 . ... . map fn | then there is some length where this is no longer collapsed to a single | 'map'? (a) GHC tries to do as much as possible in a single iteration of the simplifer; I think it uses an outermost-first strategy for this. (b) For each phase it runs the simplifier until nothing changes, or a maximum of N times, where N is settable by a command-line-flag -fmax-simplifier-iterations. After N it stops running that phase, even if the simplification has not terminated. | However then I wonder, how it is possible to make the compiler to | go into an infinite loop by the rule | | "loop" forall x,y. f x y = f y x Yes, it's possible. Remember (a) does "as much as possible", which in your rule means rather a lot. In this thread Roman and I have described stuff that isn't in the manual. Henning, would you feel like elaborating the Wiki page http://haskell.org/haskellwiki/GHC/Using_rules (which already has a lot of info) to reflect what you've learned? That way it's preserved for others. thanks Simon From levi.stephen at optusnet.com.au Thu Jan 17 04:54:14 2008 From: levi.stephen at optusnet.com.au (Levi Stephen) Date: Thu Jan 17 04:47:37 2008 Subject: [Haskell-cafe] First go at reactive programming In-Reply-To: References: <478C98FF.2060903@optusnet.com.au> Message-ID: <478F25C6.6020306@optusnet.com.au> Hi, Below is a version that was aimed at getting rid of the (Handle,IO (Request a)) tuples and as a result made it easier to remove the IO monad from some types, but I don't think it removed it completely from any methods. module Main where import Control.Applicative import Control.Concurrent import Control.Monad import Data.Reactive import Network.BSD import Network.HTTP import Network import System.IO import Text.XHtml.Strict type RequestHandler = Request -> Response main = runHttpServer helloWorldHandler helloWorldHandler :: RequestHandler helloWorldHandler = Response (2,0,0) "" [] . prettyHtml . helloWorldDoc helloWorldDoc :: Request -> Html helloWorldDoc rq = header << thetitle << "Hello World" +++ body << (h1 << "Hello World" +++ p << show rq) runHttpServer :: RequestHandler -> IO a runHttpServer r = socketServer >>= runE . fmap (handleConnection r) socketServer :: IO (Event Handle) socketServer = withSocketsDo $ do (e,snk) <- mkEventShow "Server" sock <- listenOn (PortNumber 8080) forkIO $ forever $ acceptConnection sock $ snk return e handleConnection :: Handle -> RequestHandler -> IO () handleConnection h r = handleToRequest h >>= responseSend h . runRequestHandler r handleToRequest :: Handle -> IO (Result Request) handleToRequest = receiveHTTP runRequestHandler :: RequestHandler -> Result Request -> Result Response runRequestHandler r rq = rq `bindE` (Right . r) responseSend :: Handle -> Result Response -> IO () responseSend h rsp = either print (respondHTTP h) rsp >> close h acceptConnection :: Socket -> (Handle -> IO ()) -> IO ThreadId acceptConnection s k = accept s >>= \(h,_,_) -> forkIO $ k h instance Stream Handle where readLine h = hGetLine h >>= \l -> return $ Right $ l ++ "\n" readBlock h n = replicateM n (hGetChar h) >>= return . Right writeBlock h s = mapM_ (hPutChar h) s >>= return . Right close = hClose From simonmarhaskell at gmail.com Thu Jan 17 05:01:27 2008 From: simonmarhaskell at gmail.com (Simon Marlow) Date: Thu Jan 17 04:54:41 2008 Subject: [Haskell-cafe] Re: announcing darcs 2.0.0pre2 In-Reply-To: <20080116211419.GR27808@darcs.net> References: <20071216211722.GI11101@darcs.net> <47666BA0.2080408@microsoft.com> <20071221143254.GO11036@darcs.net> <477CC2EC.2030302@microsoft.com> <20080116211419.GR27808@darcs.net> Message-ID: <478F2777.2080205@microsoft.com> David Roundy wrote: > On Thu, Jan 03, 2008 at 11:11:40AM +0000, Simon Marlow wrote: >>> Anyhow, could you retry this test with the above change in methodology, >>> and let me know if (a) the pull is still slow the first time and (b) if >>> it's much faster the second time (after the reverse unpull/pull)? >> I think I've done it in both directions now, and it got faster, but still >> much slower than darcs1: >> >> $ time darcs2 unpull --from-tag 2007-09-25 -a >> Finished unpulling. >> 58.68s real 50.64s user 6.36s system 97% darcs2 unpull --from-tag >> 2007-09-25 -a >> $ time darcs2 pull -a ../ghc-darcs2 >> Pulling from "../ghc-darcs2"... >> Finished pulling and applying. >> 53.28s real 44.62s user 7.10s system 97% darcs2 pull -a ../ghc-darcs2 >> >> This is still an order of magnitude slower than darcs1 for the same >> operation. (these times are now on the local filesystem, BTW) > > I've recently found the problem leading to this slowdown (I believe) and > get about an order-of-magnitude improvement in the speed of a pull of 400 > patches in the ghc repository. It turned out to be an issue that scaled > with the size (width) of the repository, not with the number of patches > (which had been the obvious suspect), which was causing trouble when > applying to the pristine cache. > > At this point, darcs-2 outperforms darcs-1 on most tests that I've tried, > so it'd be a good time to find some more performance problems, if you > can... and I don't doubt that there are more out there. Certainly a lot faster, nice work! Though it's still not as fast as darcs-1 here. New figures: $ time darcs2 unpull --from-tag 2007-09-25 -a Finished unpulling. 18.83s real 15.27s user 1.53s system 89% darcs2 unpull --from-tag 2007-09-25 -a $ time darcs2 pull ../ghc-darcs2-other -a Finished pulling and applying. 10.38s real 7.69s user 1.50s system 88% darcs2 pull ../ghc-darcs2-other - I repeated the darcs-1 timings for comparison: $ time darcs unpull --from-tag 2007-09-25 -a Finished unpulling. 8.04s real 7.14s user 0.90s system 99% darcs unpull --from-tag 2007-09-25 -a $ time darcs pull ~/ghc-HEAD -a Finished pulling and applying. 7.90s real 4.90s user 0.98s system 74% darcs pull ~/ghc-HEAD -a In this case darcs-1 is pulling more patches (530 vs. 400), because I'm using the latest GHC HEAD repo. Also the darcs-1 repository being pulled from is on a different, NFS mounted, filesystem, whereas the darcs-2 timings were made using repos on the same local filesystem. In all cases I tried things a few times to let caches etc. fill up. Can you repeat these? Cheers, Simon From magnus at therning.org Thu Jan 17 06:26:22 2008 From: magnus at therning.org (Magnus Therning) Date: Thu Jan 17 06:19:34 2008 Subject: [Haskell-cafe] HPC of several modules? In-Reply-To: <404396ef0801160951i7b4555e3j6ec80b2cc03b734c@mail.gmail.com> References: <404396ef0801160951i7b4555e3j6ec80b2cc03b734c@mail.gmail.com> Message-ID: On 1/16/08, Neil Mitchell wrote: > > Hi > > > and .hi files) then running 'ghc --make -fhpc MyTool.hs' succeeds in > > That's all I do. > > > 'hpc6 markup MyTool' includes only Main > > I do: > > hpc markup MyTool.tix Hmm, I wonder what I was doing yesterday. Maybe I didn't clean things up properly. Today things seem to work properly. /M -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080117/8ab96683/attachment.htm From roma at ro-che.info Thu Jan 17 06:28:31 2008 From: roma at ro-che.info (Roman Cheplyaka) Date: Thu Jan 17 06:21:57 2008 Subject: [Haskell-cafe] libmpd-haskell RFC In-Reply-To: <20080116110239.GA18843@mephistopheles> References: <20080116110239.GA18843@mephistopheles> Message-ID: <20080117112831.GA5167@home.ro-che.info> * Ben Sinclair [2008-01-16 22:02:40+1100] > If anybody has already used libmpd-haskell (the darcs repo version) > or would like to look over it I would appreciate their comments. > > Thanks, > Ben > > http://turing.une.edu.au/~bsinclai/code/libmpd-haskell/ I'd like to use it in xmonad extension to control MPD, but since all extensions live in one package (XMonadContrib), adding new dependencies is discouraged, so I chose ad-hoc solution using netcat. -- Roman I. Cheplyaka :: http://ro-che.info/ ...being in love is totally punk rock... -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 307 bytes Desc: Digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080117/0384b142/attachment.bin From magnus at therning.org Thu Jan 17 06:43:59 2008 From: magnus at therning.org (Magnus Therning) Date: Thu Jan 17 06:37:17 2008 Subject: [Haskell-cafe] ghc6.8: hiding uninstalled package? Message-ID: This might seem like a silly question, but what's the reasoning behind the following behaviour? % ghc-pkg list dataenc /usr/lib/ghc-6.8.2/package.conf: % ghc --make -hide-package dataenc -isrc UT.hs ghc-6.8.2: unknown package: dataenc Hiding an uninstalled package doesn't seem to warrant failing compilation! /M -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080117/4c2475b0/attachment.htm From jlareyes at cybercia.com Thu Jan 17 08:00:23 2008 From: jlareyes at cybercia.com (=?us-ascii?Q?Jose_Luis_Reyes_F.?=) Date: Thu Jan 17 07:53:39 2008 Subject: [Haskell-cafe] Hamming's Problem Message-ID: <003f01c85908$edbf5950$c93e0bf0$@com> Hi, In exercise 2 of http://www.walenz.org/Dijkstra/page0145.html we need to write a function that holds (1) The value 1 is in the sequence (2) If x and y are in the sequence, so is f(x,y), where f has the properties a. f(x,y) > x b. (y1 > y2) => (f(x,y1)>f(x,y2)) This is a solution for this problem, but an inefficient one hammingff :: [Integer] hammingff = 1 : merge [ h x y | x <- hammingff, y <- hammingff ] [ h x y | y <- hammingff, x <- hammingff ] h x y = 2*x+3*y merge :: (Ord a) => [a] -> [a] -> [a] merge [] xs = xs merge ys [] = ys merge (x:xs) (y:ys) = case compare x y of LT -> x : merge xs (y:ys) GT -> y : merge (x:xs) ys EQ -> x : merge xs ys anybody has a better solution?. Thanks Jose -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080117/d7114d31/attachment.htm From g9ks157k at acme.softbase.org Thu Jan 17 09:09:28 2008 From: g9ks157k at acme.softbase.org (Wolfgang Jeltsch) Date: Thu Jan 17 09:08:34 2008 Subject: [Haskell-cafe] Haskell and GUI In-Reply-To: References: Message-ID: <200801171509.28774.g9ks157k@acme.softbase.org> Am Dienstag, 15. Januar 2008 20:42 schrieb Conal Elliott: > If you can get wxHaskell installed & working, you could try Phooey and/or > TV. Both are described on the Haskell wiki and available via darcs and > Hackage. And they have the interesting property of being a functional approach to GUI programming (similar to FranTk). Most of the other Haskell GUI toolkits are imperative in nature. And now my shameless plug: If you can get Gtk2Hs installed and working, you could try Grapefruit which is also a functional library. In addition to GUIs, it also supports animated graphics. At the moment, it?s main downside is that it supports only a small set of widgets (buttons, labels, edit fields and boxes). See . Best wishes, Wolfgang From ithika at gmail.com Thu Jan 17 09:22:12 2008 From: ithika at gmail.com (Dougal Stanton) Date: Thu Jan 17 09:15:22 2008 Subject: [Haskell-cafe] Filter by several predicates at once Message-ID: <2d3641330801170622j1ec06c30xc074304513725b93@mail.gmail.com> Are the functions > passall, passany :: [a -> Bool] -> a -> Bool > passall ps v = and $ map ($v) ps > passany ps v = or $ map ($v) ps or something similar defined anywhere? Such that one can write > filter (passany tests) [0..10] > filter (passall tests) [0..10] where > tests = [>5, odd] Or is there a better way of filtering by several predicates for each value without using > filter p3 . filter p2 . filter p1 or > filter (\v -> p1 v && p2 v && p3 v) vs Cheers, D -- Dougal Stanton dougal@dougalstanton.net // http://www.dougalstanton.net From ndmitchell at gmail.com Thu Jan 17 09:27:39 2008 From: ndmitchell at gmail.com (Neil Mitchell) Date: Thu Jan 17 09:20:49 2008 Subject: [Haskell-cafe] Filter by several predicates at once In-Reply-To: <2d3641330801170622j1ec06c30xc074304513725b93@mail.gmail.com> References: <2d3641330801170622j1ec06c30xc074304513725b93@mail.gmail.com> Message-ID: <404396ef0801170627l31b47108vc62137b55c20a443@mail.gmail.com> Hi > > passall, passany :: [a -> Bool] -> a -> Bool > > passall ps v = and $ map ($v) ps > > passany ps v = or $ map ($v) ps > > or something similar defined anywhere? Such that one can write Don't think so. One thing I have often wanted is something like: or1 a b x = a x || b x or2 a b x y = a x y || b x y Then you can do: filter ((>5) `or1` odd) [0..10] filter ((>5) `and1` odd) [0..10] You can imagine that or1 could get a symbol such as ||#, and or2 could perhaps be ||## (if # wasn't already really overloaded) Thanks Neil From isaacdupree at charter.net Thu Jan 17 09:46:20 2008 From: isaacdupree at charter.net (Isaac Dupree) Date: Thu Jan 17 09:39:24 2008 Subject: [Haskell-cafe] Filter by several predicates at once In-Reply-To: <404396ef0801170627l31b47108vc62137b55c20a443@mail.gmail.com> References: <2d3641330801170622j1ec06c30xc074304513725b93@mail.gmail.com> <404396ef0801170627l31b47108vc62137b55c20a443@mail.gmail.com> Message-ID: <478F6A3C.7020001@charter.net> Neil Mitchell wrote: > Hi > >>> passall, passany :: [a -> Bool] -> a -> Bool >>> passall ps v = and $ map ($v) ps >>> passany ps v = or $ map ($v) ps >> or something similar defined anywhere? Such that one can write nearly; using Prelude: passall ps v = all ($v) ps passany ps v = any ($v) ps > One thing I have often wanted is something like: > > or1 a b x = a x || b x > or2 a b x y = a x y || b x y yep, there's the idea of putting Bools in a typeclass that allows you to (||) functions-returning-Bool-class-instance for example, which I haven't used much but seems like a good idea (though potentially confusing, especially if the Prelude-Bool-specific names are reused) ~Isaac From jmvilaca at di.uminho.pt Thu Jan 17 09:51:46 2008 From: jmvilaca at di.uminho.pt (=?ISO-8859-1?Q?Miguel_Vila=E7a?=) Date: Thu Jan 17 09:45:04 2008 Subject: [Haskell-cafe] Re: Compiling Blobs In-Reply-To: <1200521084.4222.56.camel@localhost.localdomain> References: <1200521084.4222.56.camel@localhost.localdomain> Message-ID: <478F6B82.4030900@di.uminho.pt> Peter Verswyvelen wrote: > I'm trying to build http://www.cs.york.ac.uk/fp/darcs/Blobs using GHC > 6.8.2. It looks like a good Haskell program to learn from. > > So far I managed to modify the source code so it makes use of the new > HaXML libraries, and after a lot of hacking I could build and link to > wxHaskell, but my app crashes (I do get a window however, woohoo) > > Maybe someone else managed already? > > Thanks, > Peter > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > Hi Peter, I have Blobs compiling and running in my machine. Its an Kubuntu Gutsy with GHC 6.6.1 and HaXml 1.19.SOMETHING (I'm using a repository version but not yet the current one) This implies some minor changes that I've as local patches, that I can send to you as soon as I find how to get a file per patch from the repository. The big issue is always to be able to get wxHaskell compiled and working properly. I'm currently using a recent (1 or 2 weeks old) version of wxHaskell from its official repository (darcs get http://darcs.haskell.org/wxhaskell) and wxGTK 2.6.3 You can find more information in INblobs (INblobs is done on top of Bblobs) webpage : http://haskell.di.uminho.pt/jmvilaca/INblobs/ or in the wxHaskell mailing list wxhaskell-users@lists.sourceforge.net What versions of wxWidgets are you using and in which platform? best Miguel Vilaca From scook0 at gmail.com Thu Jan 17 10:01:41 2008 From: scook0 at gmail.com (Stuart Cook) Date: Thu Jan 17 09:54:51 2008 Subject: [Haskell-cafe] Filter by several predicates at once In-Reply-To: <478F6A3C.7020001@charter.net> References: <2d3641330801170622j1ec06c30xc074304513725b93@mail.gmail.com> <404396ef0801170627l31b47108vc62137b55c20a443@mail.gmail.com> <478F6A3C.7020001@charter.net> Message-ID: <49b351060801170701r38dce1f9y4a44eabf5951364d@mail.gmail.com> On Jan 18, 2008 1:46 AM, Isaac Dupree wrote: > Neil Mitchell wrote: > > Hi > > > >>> passall, passany :: [a -> Bool] -> a -> Bool > >>> passall ps v = and $ map ($v) ps > >>> passany ps v = or $ map ($v) ps > >> or something similar defined anywhere? Such that one can write > > nearly; using Prelude: > passall ps v = all ($v) ps > passany ps v = any ($v) ps See also , which would let you define passall = swing all passany = swing any Whether that's any better than the pointwise version is up to you. Stuart From ithika at gmail.com Thu Jan 17 10:11:01 2008 From: ithika at gmail.com (Dougal Stanton) Date: Thu Jan 17 10:11:03 2008 Subject: [Haskell-cafe] Filter by several predicates at once In-Reply-To: <49b351060801170701r38dce1f9y4a44eabf5951364d@mail.gmail.com> References: <2d3641330801170622j1ec06c30xc074304513725b93@mail.gmail.com> <404396ef0801170627l31b47108vc62137b55c20a443@mail.gmail.com> <478F6A3C.7020001@charter.net> <49b351060801170701r38dce1f9y4a44eabf5951364d@mail.gmail.com> Message-ID: <2d3641330801170711l4cee861cx6d7287a8c77a206a@mail.gmail.com> On 17/01/2008, Stuart Cook wrote: > On Jan 18, 2008 1:46 AM, Isaac Dupree wrote: > > nearly; using Prelude: > > passall ps v = all ($v) ps > > passany ps v = any ($v) ps Yes, thanks Isaac. That should have been obvious, argh... > > passall = swing all > passany = swing any > > Whether that's any better than the pointwise version is up to you. I think in this case I will use the explicit version, because I wouldn't remember how swing worked. What is the motivation for the name? ;-) (Do I want to hear the answer...?) D -- Dougal Stanton dougal@dougalstanton.net // http://www.dougalstanton.net From dons at galois.com Thu Jan 17 11:56:14 2008 From: dons at galois.com (Don Stewart) Date: Thu Jan 17 11:56:25 2008 Subject: [Haskell-cafe] libmpd-haskell RFC In-Reply-To: <20080117112831.GA5167@home.ro-che.info> References: <20080116110239.GA18843@mephistopheles> <20080117112831.GA5167@home.ro-che.info> Message-ID: <20080117165614.GC10397@scytale.galois.com> roma: > * Ben Sinclair [2008-01-16 22:02:40+1100] > > If anybody has already used libmpd-haskell (the darcs repo version) > > or would like to look over it I would appreciate their comments. > > > > Thanks, > > Ben > > > > http://turing.une.edu.au/~bsinclai/code/libmpd-haskell/ > > I'd like to use it in xmonad extension to control MPD, but since all > extensions live in one package (XMonadContrib), adding new dependencies > is discouraged, so I chose ad-hoc solution using netcat. > We could have multiple extension packages (i.e. xmonadcontrib-network) for things that touch the network. -- Don From roma at ro-che.info Thu Jan 17 12:02:19 2008 From: roma at ro-che.info (Roman Cheplyaka) Date: Thu Jan 17 12:02:47 2008 Subject: [Haskell-cafe] libmpd-haskell RFC In-Reply-To: <20080117165614.GC10397@scytale.galois.com> References: <20080116110239.GA18843@mephistopheles> <20080117112831.GA5167@home.ro-che.info> <20080117165614.GC10397@scytale.galois.com> Message-ID: <20080117170219.GA8125@home.ro-che.info> * Don Stewart [2008-01-17 08:56:14-0800] > roma: > > * Ben Sinclair [2008-01-16 22:02:40+1100] > > > If anybody has already used libmpd-haskell (the darcs repo version) > > > or would like to look over it I would appreciate their comments. > > > > > > Thanks, > > > Ben > > > > > > http://turing.une.edu.au/~bsinclai/code/libmpd-haskell/ > > > > I'd like to use it in xmonad extension to control MPD, but since all > > extensions live in one package (XMonadContrib), adding new dependencies > > is discouraged, so I chose ad-hoc solution using netcat. > > > > We could have multiple extension packages (i.e. xmonadcontrib-network) > for things that touch the network. It doesn't really matter -- I hardly imagine amarok user who would agree to fetch&build libmpd-haskell in order to use some other network-related extension. -- Roman I. Cheplyaka :: http://ro-che.info/ ...being in love is totally punk rock... -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 307 bytes Desc: Digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080117/1e701d55/attachment.bin From barsoap at web.de Thu Jan 17 12:07:56 2008 From: barsoap at web.de (Achim Schneider) Date: Thu Jan 17 12:08:14 2008 Subject: [Haskell-cafe] Re: Data constructors versus types References: <1200516343.4222.13.camel@localhost.localdomain> <20080116222028.4b2f3413@solaris.tower> <1200520564.4222.52.camel@localhost.localdomain> <20080117003138.74bc13a4@solaris.tower> <20080117013120.GB11540@localhost> <478F0731.3030505@appsolutions.com> Message-ID: <20080117180756.4fe89dba@solaris.tower> Anton van Straaten wrote: > gwern0@gmail.com wrote: > > On 2008.01.17 00:58:19 +0100, jerzy.karczmarczuk@info.unicaen.fr > > scribbled 0.9K characters: > >> Achim Schneider writes: > >>> Lisp is actually not really meant to be compiled, but > >>> interpreted. > ... > >> Would you mind stopping to spread dubious truths? > ... > > I don't think it's a dubious truth. > > It's about as accurate as saying "Television is actually not really > meant to be color, but black and white". > Yes, that about fits... the chroma data still has only half the resolution of luminosity. In fact, it wasn't even meant to be a programming language, just a calculus. But still, I should have written "was meant" not "is meant". -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From barsoap at web.de Thu Jan 17 12:11:46 2008 From: barsoap at web.de (Achim Schneider) Date: Thu Jan 17 12:15:05 2008 Subject: [Haskell-cafe] Re: Data constructors versus types References: <1200516343.4222.13.camel@localhost.localdomain> <20080116222028.4b2f3413@solaris.tower> <1200520564.4222.52.camel@localhost.localdomain> <20080117003138.74bc13a4@solaris.tower> Message-ID: <20080117181146.54f252e0@solaris.tower> "Richard A. O'Keefe" wrote: > I have no idea what get/cc might be, unless it is a mistake for > call/cc, but that's Scheme, not Lisp. > Erm... yes. I guess it's the part of call/cc that gets the continuation before calling it. Actually, I shouldn't be talking about stuff that was used before I was even planned... -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From trebla at vex.net Thu Jan 17 13:08:58 2008 From: trebla at vex.net (Albert Y. C. Lai) Date: Thu Jan 17 13:09:03 2008 Subject: [Haskell-cafe] ghc6.8: hiding uninstalled package? In-Reply-To: References: Message-ID: <478F99BA.9070200@vex.net> Magnus Therning wrote: > This might seem like a silly question, but what's the reasoning behind > the following behaviour? > > % ghc-pkg list dataenc > /usr/lib/ghc-6.8.2/package.conf: > % ghc --make -hide-package dataenc -isrc UT.hs > ghc-6.8.2 : unknown package: dataenc > > Hiding an uninstalled package doesn't seem to warrant failing compilation! "I cannot find it, therefore I cannot hide it"? XD The following is fairly widely accepted behaviour: $ rm phd-thsies rm: cannot remove `phd-thsies': No such file or directory If a file is absent and you want it absent, is that an error? (Now you might get into a long thread debating whether deletion is analogous to hiding...) If I want to hide or delete something, and the computer can't find that something, it may be because I have a typo. If the computer remains silent about it, I fail to hide or delete the true thing. I want to delete phd-thesis, but I typed phd-thsies, and I appreciate the error report. If I fail to delete phd-thesis, at worst more people read it and be enlightened :) but if I fail to hide a package and I don't know about it, the ensuing problems will be much more mysterious. From magnus at therning.org Thu Jan 17 13:24:00 2008 From: magnus at therning.org (Magnus Therning) Date: Thu Jan 17 13:24:09 2008 Subject: [Haskell-cafe] ghc6.8: hiding uninstalled package? In-Reply-To: <478F99BA.9070200@vex.net> References: <478F99BA.9070200@vex.net> Message-ID: On 1/17/08, Albert Y. C. Lai wrote: > > Magnus Therning wrote: > > This might seem like a silly question, but what's the reasoning behind > > the following behaviour? > > > > % ghc-pkg list dataenc > > /usr/lib/ghc-6.8.2/package.conf: > > % ghc --make -hide-package dataenc -isrc UT.hs > > ghc-6.8.2 : unknown package: dataenc > > > > Hiding an uninstalled package doesn't seem to warrant failing > compilation! > > "I cannot find it, therefore I cannot hide it"? XD > > The following is fairly widely accepted behaviour: > > $ rm phd-thsies > rm: cannot remove `phd-thsies': No such file or directory > > If a file is absent and you want it absent, is that an error? > > (Now you might get into a long thread debating whether deletion is > analogous to hiding...) > > If I want to hide or delete something, and the computer can't find that > something, it may be because I have a typo. If the computer remains > silent about it, I fail to hide or delete the true thing. I want to > delete phd-thesis, but I typed phd-thsies, and I appreciate the error > report. If I fail to delete phd-thesis, at worst more people read it and > be enlightened :) but if I fail to hide a package and I don't know about > it, the ensuing problems will be much more mysterious. Fair enough. I stumbled on this behaviour because I was writing a makefile for my unit/quickcheck tests. I need to make sure that the correct module is used, hence I need to hide it if it's installed. I ended up with the following in order to work around the issue: ifeq (,$(shell ghc-pkg list dataenc | grep dataenc)) GHCOPTS = -fhpc -isrc else GHCOPTS = -fhpc -hide-package dataenc -isrc endif % : %.hs ghc --make $(GHCOPTS) $< Is there a better way to do it? /M -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080117/683a9c47/attachment.htm From clifford.beshers at gmail.com Thu Jan 17 13:42:51 2008 From: clifford.beshers at gmail.com (Clifford Beshers) Date: Thu Jan 17 13:43:00 2008 Subject: [Haskell-cafe] libmpd-haskell RFC In-Reply-To: <20080116110239.GA18843@mephistopheles> References: <20080116110239.GA18843@mephistopheles> Message-ID: <6841b9520801171042o770d4f1v96570a45d6ff24c@mail.gmail.com> A comment on documentation. I find it very frustrating when libraries are described as an interface to X, where X is often an acronym that has multiple definitions on the web. Lots of clicking got me to 'Music Player Demon', but no further description or links. Just a little more information, say in a top-level README and/or the Haddock docs would be greatly appreciated. 2008/1/16 Ben Sinclair : > Hello all, > If anybody has already used libmpd-haskell (the darcs repo version) > or would like to look over it I would appreciate their comments. > > Thanks, > Ben > > http://turing.une.edu.au/~bsinclai/code/libmpd-haskell/ > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.6 (GNU/Linux) > > iD8DBQFHjeRPDo+byWtWM/kRApQhAJ9eMVQR+Bd5hgmsXSF9rRvVCS8ZxACg15rl > FuRALK8V7ArBSxR9FvTYUr4= > =d97o > -----END PGP SIGNATURE----- > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080117/8da131d9/attachment.htm From cs-haskell at protempore.net Thu Jan 17 13:59:21 2008 From: cs-haskell at protempore.net (Calvin Smith) Date: Thu Jan 17 13:59:23 2008 Subject: [Haskell-cafe] Hamming's Problem In-Reply-To: <003f01c85908$edbf5950$c93e0bf0$@com> References: <003f01c85908$edbf5950$c93e0bf0$@com> Message-ID: <478FA589.7060802@protempore.net> The author of Pugs (Perl6 implemented in Haskell) gives a nice solution to the problem of generating the Hamming numbers in the following interview: http://www.perl.com/pub/a/2005/09/08/autrijus-tang.html?page=last From dominic.steinitz at blueyonder.co.uk Thu Jan 17 14:05:55 2008 From: dominic.steinitz at blueyonder.co.uk (Dominic Steinitz) Date: Thu Jan 17 14:06:13 2008 Subject: [Haskell-cafe] Re: ANN: A triple of new packages for talking tothe outside world References: <396556a20801071037t1b66e444u52abe1d934b7f902@mail.gmail.com> <1199885578.7279.119.camel@localhost> <117f2cc80801091425l41b73ea3uddda3d91ba9405e7@mail.gmail.com> <20080109234352.3ee84d4a@solaris.tower> <20080110010123.GF18915@darcs.net> <396556a20801091725p4a2dbf8aw3117a568b807c195@mail.gmail.com> <20080110184521.GA17906@scytale.galois.com> <396556a20801151523t314797atb40fa26688c6ec6@mail.gmail.com> <396556a20801161733i409573b5y26693e633d92ae8e@mail.gmail.com> Message-ID: Adam Langley imperialviolet.org> writes: > > BitGet is just an API RFC at the moment, so I'm just describing it > here - not trying to justify it. > > In BitGet there's getAsWord[8|16|32|64] which take a number of bits ($n$) and > returns the next $n$ bits in the bottom of a Word$x$. Thus, getAsWord8 is what > you call getBits and, if you had a 48 bit number, you could use getAsWord64 and > the bottom 48-bits of the resulting Word64 would be what you want. > > Equally, asking for more than $x$ bits when calling getAsWord$x$ is a mistake, > however I don't check for it in the interest of speed. > > There are also get[Left|Right]ByteString which return the next $n$ bits in a > ByteString of Word8's. The padding is either at the end of the last byte (left > aligned) or at the beginning of the first byte (right aligned). > Ok so I should be doing something like this. I'm not clear what happens if you are reading from a socket and not all the input has arrived but I'll think about that over the weekend. Another thought: could e.g. getRightByteString be in the IO monad and then I don't have to run the Get(?) monad? Or is that a really stupid question? Dominic. import qualified Data.ByteString as B import Data.Word import IO import qualified Data.Binary.Strict.BitGet as BG test = do h <- openFile "foobarbaz" ReadMode b <- B.hGetContents h let ebms = test2 b case ebms of Left s -> return s Right bms -> return (concat ((map (show . B.unpack) bms))) test1 = do bm1 <- BG.getRightByteString 2 bm2 <- BG.getRightByteString 2 return [bm1,bm2] test2 bs = BG.runBitGet bs test1 From bf3 at telenet.be Thu Jan 17 14:10:28 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Thu Jan 17 14:10:31 2008 Subject: [Haskell-cafe] Re: Compiling Blobs In-Reply-To: <478F6B82.4030900@di.uminho.pt> References: <1200521084.4222.56.camel@localhost.localdomain> <478F6B82.4030900@di.uminho.pt> Message-ID: <1200597028.2993.6.camel@localhost.localdomain> Hi Miguel! Thanks for the reply! Yes, I also took the latest darcs version of wxHaskell, HaXml 1.19.2, and polyparse. I had to do some minor tweaks to the Blobs source code (mainly Text.Parse stuff, no big deal really). I used wxGTK 2.6.4, --with-opengl and --disable-sharing (otherwise I got link errors when linking Blobs). However I'm using GHC 6.8.2 on Fedora 8. BTW what do you think is the best distro for doing Haskell development? Now I just switched from Windows to Linux, so this is all very very new to me. However I do like the Linux way of settings things up, so I'm planning to dig a bit deeper in the Linux world. Not easy because I know a lot about Windows development, so giving that up is hard. I'll take a look at the website you mentioned. The fact to you have it running gives me confidance it is possible :) Cheers, Peter On Thu, 2008-01-17 at 14:51 +0000, Miguel Vila?a wrote: > Peter Verswyvelen wrote: > > I'm trying to build http://www.cs.york.ac.uk/fp/darcs/Blobs using GHC > > 6.8.2. It looks like a good Haskell program to learn from. > > > > So far I managed to modify the source code so it makes use of the new > > HaXML libraries, and after a lot of hacking I could build and link to > > wxHaskell, but my app crashes (I do get a window however, woohoo) > > > > Maybe someone else managed already? > > > > Thanks, > > Peter > > > > > > _______________________________________________ > > Haskell-Cafe mailing list > > Haskell-Cafe@haskell.org > > http://www.haskell.org/mailman/listinfo/haskell-cafe > > > Hi Peter, > I have Blobs compiling and running in my machine. > Its an Kubuntu Gutsy with GHC 6.6.1 and HaXml 1.19.SOMETHING (I'm using > a repository version but not yet the current one) > This implies some minor changes that I've as local patches, that I can > send to you as soon as I find how to get a file per patch from the > repository. > > The big issue is always to be able to get wxHaskell compiled and working > properly. > I'm currently using a recent (1 or 2 weeks old) version of wxHaskell > from its official repository (darcs get > http://darcs.haskell.org/wxhaskell) and wxGTK 2.6.3 > > You can find more information in INblobs (INblobs is done on top of > Bblobs) webpage : http://haskell.di.uminho.pt/jmvilaca/INblobs/ > or in the wxHaskell mailing list wxhaskell-users@lists.sourceforge.net > > What versions of wxWidgets are you using and in which platform? > > best > Miguel Vilaca > From bf3 at telenet.be Thu Jan 17 14:16:06 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Thu Jan 17 14:16:08 2008 Subject: [Haskell-cafe] Re: Data constructors versus types In-Reply-To: <478F0731.3030505@appsolutions.com> References: <1200516343.4222.13.camel@localhost.localdomain> <20080116222028.4b2f3413@solaris.tower> <1200520564.4222.52.camel@localhost.localdomain> <20080117003138.74bc13a4@solaris.tower> <20080117013120.GB11540@localhost> <478F0731.3030505@appsolutions.com> Message-ID: <1200597366.2993.10.camel@localhost.localdomain> > It's about as accurate as saying "Television is actually not really > meant to be color, but black and white". Funny, but that is actually correct, since both NTSC and PAL did a lot of tricks to carry color information using the same infrastructure as black and white TVs :) Of course that will soon be over when we all go digital, then we have jaggies and blockies because of over-compression :) Okay, ooooooooff topic. Cheers, Peter From bf3 at telenet.be Thu Jan 17 14:19:42 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Thu Jan 17 14:19:45 2008 Subject: [Haskell-cafe] Re: Compiling Blobs In-Reply-To: <1200597028.2993.6.camel@localhost.localdomain> References: <1200521084.4222.56.camel@localhost.localdomain> <478F6B82.4030900@di.uminho.pt> <1200597028.2993.6.camel@localhost.localdomain> Message-ID: <1200597582.2993.13.camel@localhost.localdomain> Sorry guys, this email also got in my personal email box, I did not mention to send this to the cafe. And with this message this is double spam, duh. On Thu, 2008-01-17 at 20:10 +0100, Peter Verswyvelen wrote: > Hi Miguel! > > Thanks for the reply! > > Yes, I also took the latest darcs version of wxHaskell, HaXml 1.19.2, > and polyparse. > > I had to do some minor tweaks to the Blobs source code (mainly > Text.Parse stuff, no big deal really). > > I used wxGTK 2.6.4, --with-opengl and --disable-sharing (otherwise I got > link errors when linking Blobs). > > However I'm using GHC 6.8.2 on Fedora 8. BTW what do you think is the > best distro for doing Haskell development? > > Now I just switched from Windows to Linux, so this is all very very new > to me. However I do like the Linux way of settings things up, so I'm > planning to dig a bit deeper in the Linux world. Not easy because I know > a lot about Windows development, so giving that up is hard. > > I'll take a look at the website you mentioned. > > The fact to you have it running gives me confidance it is possible :) > > Cheers, > Peter > > > On Thu, 2008-01-17 at 14:51 +0000, Miguel Vila?a wrote: > > Peter Verswyvelen wrote: > > > I'm trying to build http://www.cs.york.ac.uk/fp/darcs/Blobs using GHC > > > 6.8.2. It looks like a good Haskell program to learn from. > > > > > > So far I managed to modify the source code so it makes use of the new > > > HaXML libraries, and after a lot of hacking I could build and link to > > > wxHaskell, but my app crashes (I do get a window however, woohoo) > > > > > > Maybe someone else managed already? > > > > > > Thanks, > > > Peter > > > > > > > > > _______________________________________________ > > > Haskell-Cafe mailing list > > > Haskell-Cafe@haskell.org > > > http://www.haskell.org/mailman/listinfo/haskell-cafe > > > > > Hi Peter, > > I have Blobs compiling and running in my machine. > > Its an Kubuntu Gutsy with GHC 6.6.1 and HaXml 1.19.SOMETHING (I'm using > > a repository version but not yet the current one) > > This implies some minor changes that I've as local patches, that I can > > send to you as soon as I find how to get a file per patch from the > > repository. > > > > The big issue is always to be able to get wxHaskell compiled and working > > properly. > > I'm currently using a recent (1 or 2 weeks old) version of wxHaskell > > from its official repository (darcs get > > http://darcs.haskell.org/wxhaskell) and wxGTK 2.6.3 > > > > You can find more information in INblobs (INblobs is done on top of > > Bblobs) webpage : http://haskell.di.uminho.pt/jmvilaca/INblobs/ > > or in the wxHaskell mailing list wxhaskell-users@lists.sourceforge.net > > > > What versions of wxWidgets are you using and in which platform? > > > > best > > Miguel Vilaca > > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From bulat.ziganshin at gmail.com Thu Jan 17 13:00:55 2008 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Jan 17 14:48:13 2008 Subject: [Haskell-cafe] Filter by several predicates at once In-Reply-To: <478F6A3C.7020001@charter.net> References: <2d3641330801170622j1ec06c30xc074304513725b93@mail.gmail.com> <404396ef0801170627l31b47108vc62137b55c20a443@mail.gmail.com> <478F6A3C.7020001@charter.net> Message-ID: <1258835474.20080117210055@gmail.com> Hello Isaac, Thursday, January 17, 2008, 5:46:20 PM, you wrote: > yep, there's the idea of putting Bools in a typeclass that allows you to > (||) functions-returning-Bool-class-instance for example, which I > haven't used much but seems like a good idea (though potentially > confusing, especially if the Prelude-Bool-specific names are reused) -- Datatypes having default values class Defaults a where defaultValue :: a instance Defaults () where defaultValue = () instance Defaults Bool where defaultValue = False instance Defaults [a] where defaultValue = [] instance Defaults (a->a) where defaultValue = id instance Defaults (Maybe a) where defaultValue = Nothing instance Defaults (a->IO a) where defaultValue = return instance Defaults a => Defaults (IO a) where defaultValue = return defaultValue instance Num a => Defaults a where defaultValue = 0 -- Datatypes that can be checked for default value class TestDefaultValue a where isDefaultValue :: a -> Bool instance TestDefaultValue Bool where isDefaultValue = not instance TestDefaultValue [a] where isDefaultValue = null instance Num a => TestDefaultValue a where isDefaultValue = (==0) infixr 3 &&& infixr 2 ||| a ||| b | isDefaultValue a = b | otherwise = a a &&& b | isDefaultValue a = defaultValue | otherwise = b my code contains countless examples of using these funcs: 1. here it is used to conditionally include options in cmdline: ["rar", "x", arcname]++ (isAddDir &&& ["-ad"])++ (arcdir &&& files &&& ["-ap"++arcdir])++... 2. here it is used to get list of files where current directory may be specified as "": files <- dirList (dirName ||| ".") 3. here it is used to show file basename or full path if basename is empty: putStr (takeBaseName file ||| file) 4. here it's used for conditional code execution: do opt_debug command &&& testMalloc ... 5. here it is used to additionally print amount of bad sectors if it's non-zero: putStrLn$ show recoverable_sectors++" recoverable errors "++ (bad_sectors &&& " and "++show bad_sectors++" bad sectors") 6. here it's used to create tempfile in current directory unless temporary directory was explicitly specified in --tempdir option let filename = (opt_tempdir command ||| ".") "$$temp$$" 7. here it is use to apply additional reorder step to sorted list only if --reorder option was specified sorted_diskfiles <- (opt_reorder command &&& reorder) (sort_files command diskfiles) (reorder has type [String] -> IO [String]) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From jerzy.karczmarczuk at info.unicaen.fr Thu Jan 17 15:27:03 2008 From: jerzy.karczmarczuk at info.unicaen.fr (jerzy.karczmarczuk@info.unicaen.fr) Date: Thu Jan 17 15:27:07 2008 Subject: [Haskell-cafe] Re: Data constructors versus types In-Reply-To: <20080117180756.4fe89dba@solaris.tower> References: <1200516343.4222.13.camel@localhost.localdomain> <20080116222028.4b2f3413@solaris.tower> <1200520564.4222.52.camel@localhost.localdomain> <20080117003138.74bc13a4@solaris.tower> <20080117013120.GB11540@localhost> <478F0731.3030505@appsolutions.com> <20080117180756.4fe89dba@solaris.tower> Message-ID: Achim Schneider continues to comment the Lisp history: > In fact, it wasn't even meant to be a programming language, just a > calculus. There is comprehensive German article (in English), by Herbert Stoyan, on this historical issue: http://www8.informatik.uni-erlangen.de/html/lisp/histlit1.html Stoyan reminds a - currently - not so obvious truth, that something like functional paradigmatics was not so popular at that time, the second half of fifties, beginning of sixties. People reasoned rather in terms of algorithms, and McCarthy was no exception. Let's cite Stoyan: "To come back to functional programming, it is an important fact that McCarthy as mathematician was familiar with some formal mathematical languages but did not have a deep, intimate understanding of all their details. McCarthy himself has stressed this fact (23). His aim was to use the mathematical formalismus as languages and not as calculi. This is the root of the historical fact that he never took the Lambda-Calculus conversion rules as a sound basis for LISP implementation." So, I believe it is not so briliant an idea to confound the Church calculus with Lisp! We have also the text of the Master himself, available on-line: http://www-formal.stanford.edu/jmc/history/lisp/lisp.html The chapter on the "prehistory": http://www-formal.stanford.edu/jmc/history/lisp/node2.html#SECTION0002000000 0000000000 begins: "My desire for an algebraic list processing language for artificial intelligence work on the IBM 704 computer arose in the summer of 1956 during the Dartmouth Summer Research Project on Artificial Intelligence which was the first organized study of AI. During this meeting, Newell, Shaw and Simon described IPL 2, a list processing language for Rand Corporation's JOHNNIAC..." So, sorry, but McCarthy since the very beginning thought about making a usable computer language, not a "calculus". When discussing the evolution of FLPL, the *third* point mentions Church for the first time: "c. To use functions as arguments, one needs a notation for functions, and it seemed natural to use the -notation of Church (1941). I didn't understand the rest of his book, so I wasn't tempted to try to implement his more general mechanism for defining functions. Church used higher order functionals instead of using conditional expressions. ..." See also the article of Paul Graham: http://lib.store.yahoo.net/lib/paulgraham/jmc.ps ======= Before somebody once more accuses me of pedantry, or says publicly here that I am aggressive towards people: You know that spreading half-truths, and also plain rubbish on Internet is extremely easy. Wherever you look, you find plenty of occasions to err, it suffices to put yourself in a mode of a dead person from the movie "The sixth sense" of M. Night Shyamalan, with Bruce Willis, and Haley Joel Osment. The boy says to the other main personage (unaware of his own condition) that "dead people see only what they WANT to see"... And somehow the false information spreads easier than the true one. THIS list, which, independently of the freedom to chat about anything, is still targeted at serious comp. sci. problems, and I think that the fact that somebody is young and inexperienced, is not a justification to make false claims, just because this and that had XXX years less than myself in order to read some easily available texts. Of course, anybody may say "dubious truths", I am ashamed of myself, but from time to time I explode. Sorry about this. Jerzy Karczmarczuk From agl at imperialviolet.org Thu Jan 17 15:36:46 2008 From: agl at imperialviolet.org (Adam Langley) Date: Thu Jan 17 15:36:49 2008 Subject: [Haskell-cafe] Re: ANN: A triple of new packages for talking tothe outside world In-Reply-To: References: <396556a20801071037t1b66e444u52abe1d934b7f902@mail.gmail.com> <117f2cc80801091425l41b73ea3uddda3d91ba9405e7@mail.gmail.com> <20080109234352.3ee84d4a@solaris.tower> <20080110010123.GF18915@darcs.net> <396556a20801091725p4a2dbf8aw3117a568b807c195@mail.gmail.com> <20080110184521.GA17906@scytale.galois.com> <396556a20801151523t314797atb40fa26688c6ec6@mail.gmail.com> <396556a20801161733i409573b5y26693e633d92ae8e@mail.gmail.com> Message-ID: <396556a20801171236w522a6012s2592164a7cc9daaa@mail.gmail.com> On Jan 17, 2008 11:05 AM, Dominic Steinitz wrote: > I'm not clear what happens if you > are reading from a socket and not all the input has arrived but I'll think > about that over the weekend. At the moment, BitGet deals with strict ByteStrings only. One could use it within a standard Get monad by getting a strict ByteString from the lazy input. I believe that lazy ByteStrings got fixed a while back so that reading from a socket doesn't block reading a whole block. (i.e. if you trickle data, byte by byte, to a socket a lazy ByteString should return a spine of 1 byte strict ByteStrings.) A fully lazy BitGet would also be possible, of course, I've just not written it yet ;) > Adam Langley imperialviolet.org> writes: > Another thought: could e.g. getRightByteString be in the IO monad and then I > don't have to run the Get(?) monad? Or is that a really stupid question? If it were in the IO monad, I guess that you're suggesting that it read from a handle? If that were the case, the remainder of the last byte would have to be discarded because one can only read whole bytes from a Handle and there's no mechanism for pushing back into it. It's certainly possible to do, but I think a quick wrapper around a BitGet would be the way to do it. If it's particually desirable I can add it, although I'll admit that it seems a bit odd and I'm wondering what your use case is. Cheers AGL -- Adam Langley agl@imperialviolet.org http://www.imperialviolet.org 650-283-9641 From anton at appsolutions.com Thu Jan 17 15:51:14 2008 From: anton at appsolutions.com (Anton van Straaten) Date: Thu Jan 17 15:49:10 2008 Subject: [Haskell-cafe] Re: Data constructors versus types In-Reply-To: References: <1200516343.4222.13.camel@localhost.localdomain> <20080116222028.4b2f3413@solaris.tower> <1200520564.4222.52.camel@localhost.localdomain> <20080117003138.74bc13a4@solaris.tower> <20080117013120.GB11540@localhost> <478F0731.3030505@appsolutions.com> <20080117180756.4fe89dba@solaris.tower> Message-ID: <478FBFC2.4050007@appsolutions.com> jerzy.karczmarczuk@info.unicaen.fr wrote: > [McCarthy's] aim was to use the mathematical > formalismus as languages and not as calculi. This is the root of > the historical fact that he never took the Lambda-Calculus conversion > rules as a sound basis for LISP implementation." > So, I believe it is not so briliant an idea to confound the Church calculus > with Lisp! It's difficult to extricate the two, as Lisp & McCarthy's experience shows. The decision to use lambda notation without the accompanying semantics would have been fine if Lisp had not also had first-class functions. But with first-class functions, and without lexical scoping semantics, Lisp suffered from scoping bugs which were only resolved once Lisp's 'lambda' was changed to follow Church's semantics, as Sussman and Steele originally did for Scheme. When CL adopted lexical scoping, it was seen as a choice, but it wasn't really much of a choice. The choice was between continuing with a fundamentally buggy language and working around those bugs somehow, or fixing it by adopting Church's lexical scoping rules. > Wherever you look, you find plenty of occasions to > err, it suffices to put yourself in a mode of a dead person from the > movie "The sixth sense" of M. Night Shyamalan, with Bruce Willis, and > Haley Joel Osment. I see dead languages... Anton From isaacdupree at charter.net Thu Jan 17 15:55:24 2008 From: isaacdupree at charter.net (Isaac Dupree) Date: Thu Jan 17 15:55:23 2008 Subject: [Haskell-cafe] Re: Compiling Blobs In-Reply-To: <1200597028.2993.6.camel@localhost.localdomain> References: <1200521084.4222.56.camel@localhost.localdomain> <478F6B82.4030900@di.uminho.pt> <1200597028.2993.6.camel@localhost.localdomain> Message-ID: <478FC0BC.6090101@charter.net> Peter Verswyvelen wrote: > However I'm using GHC 6.8.2 on Fedora 8. BTW what do you think is the > best distro for doing Haskell development? they all suck if you want to be able to try/use the latest stuff, in my experience; just install a GHC and cabal stuff in your home directory (you can install more than one GHC-version there if you want to test things with multiple versions...). There's a semi-good reason for this: distros don't like to package broken things, and usually something breaks with each different version of GHC, but not necessarily something you're relying on, and as you're doing Haskell development you may be able to help fix it. so that is, you compile (configure) things with --prefix=$HOME (or --prefix=$HOME/unix or so if you don't like your home-directory being cluttered with names like "bin", "lib" etc.). and when using cabal you also, if it's a system-wide-installed ghc, need to give --user when configuring. And then you add "whatever-you-put-for-prefix/bin" to your path, e.g. in ~/.bashrc adding PATH="$HOME/bin:$PATH" so that the programs (ghc, happy, alex, xmonad, whatever) will be found if you want to run them. Did I leave anything important out? now, there might be a distro system that actually worked well for this. Maybe in a couple years and once cabal-install is reasonably stable, some unconventional distro like GoboLinux or NixOS might meet my standards :-) ~Isaac From barsoap at web.de Thu Jan 17 16:40:10 2008 From: barsoap at web.de (Achim Schneider) Date: Thu Jan 17 16:40:25 2008 Subject: [Haskell-cafe] Re: Data constructors versus types References: <1200516343.4222.13.camel@localhost.localdomain> <20080116222028.4b2f3413@solaris.tower> <1200520564.4222.52.camel@localhost.localdomain> <20080117003138.74bc13a4@solaris.tower> <20080117013120.GB11540@localhost> <478F0731.3030505@appsolutions.com> <20080117180756.4fe89dba@solaris.tower> Message-ID: <20080117224010.37b2b5a0@solaris.tower> jerzy.karczmarczuk@info.unicaen.fr wrote: > [...] > I heard it somewhere trustworthy. Instinctively, I would guess somewhere into the direction of Graham, but I'm not sure at all. On the other hand, you can be absolutely sure that I didn't get it off the next warez-board nor from Bill Gates. The Story, afaicr, went along the lines of "Professor writes something for a cool paper about some calculus, student gets hold of it, implements it and completely baffles the professor, he didn't ever dare to think about letting that one run on a computer". It might be one of those apples that didn't fall off trees while Newton had his idea about gravity, but then it's a complete, nice story with a nice morale on its own. After all, lisp's history isn't as important for me than its semantics, and everything I read about it was kind of accidental, it just wasn't uninteresting enough to skip. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From cetin.sert at gmail.com Thu Jan 17 16:52:27 2008 From: cetin.sert at gmail.com (Cetin Sert) Date: Thu Jan 17 16:53:08 2008 Subject: [Haskell-cafe] Reflection.Emit in Haskell Message-ID: As a .NET (C#/F#) programmer learning Haskell, I would love to know the best online sources about run-time compilation etc. like Reflection.Emit in .NET. I am making heavy use of this .NET API to compile customized (regular-expressions-) FSAs at run-time and want to learn how I might achieve the same in Haskell. Book or online article references specific to this issue will be highly appreciated ^_^ Best Regards, Cetin Sert INF 521, 4-6-2 69120 Heidelberg Germany http://www.corsis.de -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080117/9bcc68be/attachment.htm From garious at gmail.com Thu Jan 17 19:39:31 2008 From: garious at gmail.com (Greg Fitzgerald) Date: Thu Jan 17 19:39:33 2008 Subject: [Haskell-cafe] shootout using 6.6? Message-ID: <1f3dc80d0801171639u13b26081icb9da54c93b065b3@mail.gmail.com> http://shootout.alioth.debian.org/gp4/haskell.php Anyone know if the Language Shootout is actually using GHC 6.6 or is that a typo? Thanks, Greg -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080117/769b0964/attachment.htm From dons at galois.com Thu Jan 17 19:41:09 2008 From: dons at galois.com (Don Stewart) Date: Thu Jan 17 19:41:17 2008 Subject: [Haskell-cafe] shootout using 6.6? In-Reply-To: <1f3dc80d0801171639u13b26081icb9da54c93b065b3@mail.gmail.com> References: <1f3dc80d0801171639u13b26081icb9da54c93b065b3@mail.gmail.com> Message-ID: <20080118004109.GP10636@scytale.galois.com> garious: > [1]http://shootout.alioth.debian.org/gp4/haskell.php > > Anyone know if the Language Shootout is actually using GHC 6.6 or is that > a typo? It's using 6.6 till the gentoo 6.8 package is more widely distributed. From dons at galois.com Thu Jan 17 22:02:52 2008 From: dons at galois.com (Don Stewart) Date: Thu Jan 17 22:03:02 2008 Subject: [Haskell-cafe] STM in F# Message-ID: <20080118030252.GA12719@scytale.galois.com> http://cs.hubfs.net/blogs/hell_is_other_languages/archive/2008/01/16/4565.aspx I imagine this can only ease the process of learning Haskell, and broaden the base of possible Haskellers, as more people on using .NET stuff become familiar with modern typed FP. -- Don From jonathanccast at fastmail.fm Thu Jan 17 22:30:02 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Thu Jan 17 22:30:05 2008 Subject: [Haskell-cafe] STM in F# In-Reply-To: <20080118030252.GA12719@scytale.galois.com> References: <20080118030252.GA12719@scytale.galois.com> Message-ID: <3640C189-0191-49A3-BA42-71DCF6DEB0C9@fastmail.fm> On 17 Jan 2008, at 7:02 PM, Don Stewart wrote: > http://cs.hubfs.net/blogs/hell_is_other_languages/archive/ > 2008/01/16/4565.aspx > > I imagine this can only ease the process of learning Haskell, and > broaden the base of possible Haskellers, as more people on using .NET > stuff become familiar with modern typed FP. Indeed, these days I think the main advantage of Haskell is not the feature set (the same features can be used nicely in Perl (well, nicely for Perl), or not-so-nicely in Python), but rather, the fact that Haskell is *designed* for such things, so it's syntax makes things that are verbose in Perl or Python natural. jcc From prionic at gmx.de Fri Jan 18 00:23:27 2008 From: prionic at gmx.de (=?UTF-8?B?TWFydGluIEzDvHRrZQ==?=) Date: Fri Jan 18 00:15:14 2008 Subject: [Haskell-cafe] Reflection.Emit in Haskell In-Reply-To: References: Message-ID: <479037CF.5010300@gmx.de> Cetin Sert schrieb: > > As a .NET (C#/F#) programmer learning Haskell, I would love to know > the best online sources about run-time compilation etc. like > Reflection.Emit in .NET. I am making heavy use of this .NET API to > compile customized (regular-expressions-) FSAs at run-time and want to > learn how I might achieve the same in Haskell. Book or online article > references specific to this issue will be highly appreciated ^_^ > I am not familiar with C# but I think what you looking for is the GHC api which allows you to compile haskell expressions at runtime. Look for metaplug on hackage (http://hackage.haskell.org/cgi-bin/hackage-scripts/package/metaplug-0.1.1). In its source you ll find an example on how to use the api. You may of course use metaplug itself. I must warn you though that the GHC api is not the best documented and maintained. Currently (ghc 6.8.1) f.i. it seems that reloading modules is broken. The most official docu is here: http://www.haskell.org/haskellwiki/GHC/As_a_library. regards, Martin -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080118/bf1e165c/attachment.htm From s.clover at gmail.com Fri Jan 18 00:55:24 2008 From: s.clover at gmail.com (Sterling Clover) Date: Fri Jan 18 00:55:32 2008 Subject: [Haskell-cafe] ANNOUNCE: HStringTemplate -- An Elegant, Functional, Nifty Templating Engine for Haskell In-Reply-To: References: <89B71013-9550-4E1F-91DD-A4ABD532F2F1@gmail.com> Message-ID: <920EA66C-EAE7-45E1-BE11-09441B262E69@gmail.com> Graham, I'm sort of playing fast and loose with referential transparency here, as I actually am with stringTemplateFileGroup as well. They both use unsafeIO to do what they want, and in corner cases could give silly, though not dangerous results (i.e., in the sense of being hazardous to your program, these calls are substantially less worrisome than head). stringTemplateFileGroup could conceivably be in IO, if it was strict in reading all the files in the directory it was passed, but cacheSTGroup would force every access to a group to take place in IO, which would make the library somewhat of a pain to work with. My semi-justification for this is that its referentially- transparent-enough for most use cases, in that just about the only thing one would be doing with a StringTemplate result would be outputting it again in some form anyway. In my experience, being able to "hot-edit" templates for a live app is a key benefit of a templating system, and forcing everything into IO to get that seems like an undue burden on end-users. On the other hand, I'm also open to implementing an IO API that's safe and renaming the current functions to something somewhat scarier, or moving both them and their IO equivs to distinct modules so that end users could choose which to import. A number of options seem reasonable here. --Sterl. (btw, I fixed the typo you emailed me about in the repo, and also made a few other changes I documented at http:// fmapfixreturn.wordpress.com/) On Jan 16, 2008, at 8:19 PM, Graham Fawcett wrote: > On Jan 14, 2008 2:47 AM, Sterling Clover wrote: >> HStringTemplate is a port of Terrence Parr's lovely StringTemplate >> (http://www.stringtemplate.org) engine to Haskell. > > This is very cool. > > Your docs describe a function, cacheSTGroup: > > cacheSTGroup :: Int -> STGen a -> STGen a > Given an integral amount of seconds and a group, returns a group > cached for that span of time. Does not cache "misses." > > How does this work without breaking referential transparency? > Shouldn't it be in the IO monad if it is time-dependent? > > Graham From bf3 at telenet.be Fri Jan 18 01:21:20 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Fri Jan 18 01:21:15 2008 Subject: [Haskell-cafe] Reflection.Emit in Haskell In-Reply-To: <479037CF.5010300@gmx.de> References: <479037CF.5010300@gmx.de> Message-ID: <47904560.2090708@telenet.be> That would be possible, but wouldn't Template Haskell also be an option? Peter Martin L?tke wrote: > Cetin Sert schrieb: >> >> As a .NET (C#/F#) programmer learning Haskell, I would love to know >> the best online sources about run-time compilation etc. like >> Reflection.Emit in .NET. I am making heavy use of this .NET API to >> compile customized (regular-expressions-) FSAs at run-time and want >> to learn how I might achieve the same in Haskell. Book or online >> article references specific to this issue will be highly appreciated ^_^ >> > I am not familiar with C# but I think what you looking for is the GHC > api which allows you to compile haskell expressions at runtime. Look > for metaplug on hackage > (http://hackage.haskell.org/cgi-bin/hackage-scripts/package/metaplug-0.1.1). > In its source you ll find an example on how to use the api. You may of > course use metaplug itself. I must warn you though that the GHC api is > not the best documented and maintained. Currently (ghc 6.8.1) f.i. it > seems that reloading modules is broken. > The most official docu is here: > http://www.haskell.org/haskellwiki/GHC/As_a_library. > > regards, > Martin > ------------------------------------------------------------------------ > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080118/5e3c19ee/attachment.htm From bf3 at telenet.be Fri Jan 18 01:32:21 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Fri Jan 18 01:32:15 2008 Subject: [Haskell-cafe] STM in F# In-Reply-To: <3640C189-0191-49A3-BA42-71DCF6DEB0C9@fastmail.fm> References: <20080118030252.GA12719@scytale.galois.com> <3640C189-0191-49A3-BA42-71DCF6DEB0C9@fastmail.fm> Message-ID: <479047F5.6000704@telenet.be> Reminds me of a song, "I'm dreaming of a ... dotnet Haskell..." I find it such a petty no real work seems to be done on that. Okay, the performance might not be optimal. Okay, you might have two huge frameworks that overlap. Okay, using the .NET stuff would mean some kind of automatic IO monadic wrapper generator, but surely with the .NET reflection support, this would be possible. But look at the advantages... Of course Haskell is a research language, and "avoid success at all cost" is the goal. But unfortunately, IMHO Haskell does make a lot of sense, so... Ah well, I should stop nagging about this :-) Jonathan Cast wrote: > On 17 Jan 2008, at 7:02 PM, Don Stewart wrote: > >> http://cs.hubfs.net/blogs/hell_is_other_languages/archive/2008/01/16/4565.aspx >> >> >> I imagine this can only ease the process of learning Haskell, and >> broaden the base of possible Haskellers, as more people on using .NET >> stuff become familiar with modern typed FP. > > Indeed, these days I think the main advantage of Haskell is not the > feature set (the same features can be used nicely in Perl (well, > nicely for Perl), or not-so-nicely in Python), but rather, the fact > that Haskell is *designed* for such things, so it's syntax makes > things that are verbose in Perl or Python natural. > > jcc > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > From derek.a.elkins at gmail.com Fri Jan 18 01:39:52 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Fri Jan 18 02:40:30 2008 Subject: [Haskell-cafe] STM in F# In-Reply-To: <479047F5.6000704@telenet.be> References: <20080118030252.GA12719@scytale.galois.com> <3640C189-0191-49A3-BA42-71DCF6DEB0C9@fastmail.fm> <479047F5.6000704@telenet.be> Message-ID: <1200638392.5676.0.camel@derek-laptop> On Fri, 2008-01-18 at 07:32 +0100, Peter Verswyvelen wrote: > Reminds me of a song, "I'm dreaming of a ... dotnet Haskell..." > > I find it such a petty no real work seems to be done on that. No one is stopping you. From bulat.ziganshin at gmail.com Thu Jan 17 17:39:02 2008 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Fri Jan 18 02:45:56 2008 Subject: [Haskell-cafe] Reflection.Emit in Haskell In-Reply-To: References: Message-ID: <15910202182.20080118013902@gmail.com> Hello Cetin, Friday, January 18, 2008, 12:52:27 AM, you wrote: > As a .NET (C#/F#) programmer learning Haskell, I would love to know > the best online sources about run-time compilation etc. like hs-plugins (unix-only afair), and GHC-as-a-library > Reflection.Emit in .NET. I am making heavy use of this .NET API to > compile customized (regular-expressions-) FSAs at run-time and want > to learn how I might achieve the same in Haskell. Book or online > article references specific to this issue will be highly appreciated ^_^ it was Runtime_Compilation page on old Haskell wiki, written by Andrew Bromage and me. in short, some form of run-time compilation works without actual compiling code. in particular, RegEx package compiles regexps on the fly. my own program includes very simple variant of run-time compiled regexps: -- Compiled regexp Example data RegExpr = RE_End -- "" | RE_Anything -- "*" | RE_AnyStr RegExpr -- '*':"bc*" | RE_FromEnd RegExpr -- '*':"bc" | RE_AnyChar RegExpr -- '?':"bc" | RE_Char Char RegExpr -- 'a':"bc" -- |Compile string representation of regexpr into RegExpr compile_RE s = case s of "" -> RE_End "*" -> RE_Anything '*':cs | cs `contains` '*' -> RE_AnyStr (compile_RE cs) | otherwise -> RE_FromEnd (compile_RE$ reverse s) '?':cs -> RE_AnyChar (compile_RE cs) c :cs -> RE_Char c (compile_RE cs) -- |Check match of string s with regexpr re match_RE re s = case re of RE_End -> null s RE_Anything -> True RE_AnyStr r -> any (match_RE r) (tails s) RE_FromEnd r -> match_RE r (reverse s) RE_AnyChar r -> case s of "" -> False _:xs -> match_RE r xs RE_Char c r -> case s of "" -> False x:xs -> x==c && match_RE r xs -- |Check match of string s with regexpr re, represented as string match re {-s-} = match_RE (compile_RE re) {-s-} actually, you will not find anything unusual here. the code for matching with RegExpr is just constructed at runtime (as tree of closures) which makes matching quite efficient -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From apfelmus at quantentunnel.de Fri Jan 18 03:52:17 2008 From: apfelmus at quantentunnel.de (apfelmus) Date: Fri Jan 18 03:52:31 2008 Subject: [Haskell-cafe] Re: Reflection.Emit in Haskell In-Reply-To: <15910202182.20080118013902@gmail.com> References: <15910202182.20080118013902@gmail.com> Message-ID: Bulat Ziganshin wrote: > it was Runtime_Compilation page on old Haskell wiki, written by Andrew > Bromage and me. in short, some form of run-time compilation works > without actual compiling code. > > -- |Check match of string s with regexpr re > match_RE re s = case re of > RE_End -> null s > RE_Anything -> True > RE_AnyStr r -> any (match_RE r) (tails s) > RE_FromEnd r -> match_RE r (reverse s) > RE_AnyChar r -> case s of > "" -> False > _:xs -> match_RE r xs > RE_Char c r -> case s of > "" -> False > x:xs -> x==c && match_RE r xs > > -- |Check match of string s with regexpr re, represented as string > match re {-s-} = match_RE (compile_RE re) {-s-} > > > actually, you will not find anything unusual here. the code for > matching with RegExpr is just constructed at runtime (as tree of > closures) which makes matching quite efficient I doubt that this works as intendend, I think you have to explicitly fist the lambdas into the case expression: match_RE r = case r of RE_End -> null RE_Anything -> const True RE_AnyStr r -> let re = match_RE r in \s -> any re (tails s) RE_FromEnd r -> let re = match_RE r in re . reverse RE_AnyChar r -> let re = match_RE r in \s -> case s of "" -> False _:xs -> re xs RE_Char c r -> let re = match_RE r in \s -> case s of "" -> False x:xs -> x==c && re r xs This way, every match_RE r will evaluated to the function corresponding to r and the result will be shared. In your code, match_RE r s will be "run-time compile" the regex matcher for each string s again and again. Regards, apfelmus From apfelmus at quantentunnel.de Fri Jan 18 04:01:58 2008 From: apfelmus at quantentunnel.de (apfelmus) Date: Fri Jan 18 04:02:11 2008 Subject: [Haskell-cafe] Re: STM in F# In-Reply-To: <20080118030252.GA12719@scytale.galois.com> References: <20080118030252.GA12719@scytale.galois.com> Message-ID: Don Stewart wrote: > http://cs.hubfs.net/blogs/hell_is_other_languages/archive/2008/01/16/4565.aspx > > I imagine this can only ease the process of learning Haskell, and > broaden the base of possible Haskellers, as more people on using .NET > stuff become familiar with modern typed FP. There's a reason the STM monad hatched in Haskell: how does the above STM in F# handle side-effects like launchMissile ? Regards, apfelmus From ketil+haskell at ii.uib.no Fri Jan 18 04:59:06 2008 From: ketil+haskell at ii.uib.no (Ketil Malde) Date: Fri Jan 18 04:59:18 2008 Subject: [Haskell-cafe] Re: STM in F# In-Reply-To: (apfelmus@quantentunnel.de's message of "Fri\, 18 Jan 2008 10\:01\:58 +0100") References: <20080118030252.GA12719@scytale.galois.com> Message-ID: <87bq7jqwt1.fsf@nmd9999.imr.no> apfelmus writes: >> I imagine this can only ease the process of learning Haskell, and >> broaden the base of possible Haskellers, as more people on using .NET >> stuff become familiar with modern typed FP. > There's a reason the STM monad hatched in Haskell: how does the above > STM in F# handle side-effects like launchMissile ? If you read the comments at the bottom, it seems it does not. Expect an arbitrary number of missiles (although the final effect of destroying the target city will perhaps be the same). -k -- If I haven't seen further, it is by standing in the footprints of giants From njbartlett at gmail.com Fri Jan 18 05:05:49 2008 From: njbartlett at gmail.com (Neil Bartlett) Date: Fri Jan 18 05:06:03 2008 Subject: [Haskell-cafe] Re: STM in F# In-Reply-To: References: <20080118030252.GA12719@scytale.galois.com> Message-ID: <2C5BA7A0-CB38-4674-B915-1A2F16018870@gmail.com> On 18 Jan 2008, at 09:01, apfelmus wrote: > Don Stewart wrote: >> http://cs.hubfs.net/blogs/hell_is_other_languages/archive/2008/01/16/4565.aspx >> I imagine this can only ease the process of learning Haskell, and >> broaden the base of possible Haskellers, as more people on using .NET >> stuff become familiar with modern typed FP. > > There's a reason the STM monad hatched in Haskell: how does the > above STM in F# handle side-effects like launchMissile ? It is presumably handled the same way that all such things are handled in non-pure or imperative languages... a dire warning in the documentation not to do this. - Neil From duncan.coutts at worc.ox.ac.uk Fri Jan 18 05:24:54 2008 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Fri Jan 18 05:27:04 2008 Subject: [Haskell-cafe] shootout using 6.6? In-Reply-To: <20080118004109.GP10636@scytale.galois.com> References: <1f3dc80d0801171639u13b26081icb9da54c93b065b3@mail.gmail.com> <20080118004109.GP10636@scytale.galois.com> Message-ID: <1200651894.5639.238.camel@localhost> On Thu, 2008-01-17 at 16:41 -0800, Don Stewart wrote: > garious: > > [1]http://shootout.alioth.debian.org/gp4/haskell.php > > > > Anyone know if the Language Shootout is actually using GHC 6.6 or is that > > a typo? > > It's using 6.6 till the gentoo 6.8 package is more widely distributed. Note that ghc-6.8.2 is in gentoo now and has been for a few weeks. There's no reason not to use it. Duncan From jules at jellybean.co.uk Fri Jan 18 05:29:24 2008 From: jules at jellybean.co.uk (Jules Bean) Date: Fri Jan 18 05:29:24 2008 Subject: [Haskell-cafe] ANNOUNCE: HStringTemplate -- An Elegant, Functional, Nifty Templating Engine for Haskell In-Reply-To: References: <89B71013-9550-4E1F-91DD-A4ABD532F2F1@gmail.com> Message-ID: <47907F84.2080605@jellybean.co.uk> [removed haskell@ from the cc: list, which I think is conventional if discussion continues] Graham Fawcett wrote: > On Jan 14, 2008 2:47 AM, Sterling Clover wrote: >> HStringTemplate is a port of Terrence Parr's lovely StringTemplate >> (http://www.stringtemplate.org) engine to Haskell. > > This is very cool. > > Your docs describe a function, cacheSTGroup: > > cacheSTGroup :: Int -> STGen a -> STGen a > Given an integral amount of seconds and a group, returns a group > cached for that span of time. Does not cache "misses." > > How does this work without breaking referential transparency? > Shouldn't it be in the IO monad if it is time-dependent? If the result is always the same, but only efficiency varies, then you could argue it's still referentially transparent. Of course, if the result isn't always the same (template file could be changed underneath you) then it isn't... the list is already aware of my views on behind-the-scenes lazy IO :) Jules From bulat.ziganshin at gmail.com Fri Jan 18 02:52:05 2008 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Fri Jan 18 05:35:25 2008 Subject: [Haskell-cafe] Reflection.Emit in Haskell In-Reply-To: <47904560.2090708@telenet.be> References: <479037CF.5010300@gmx.de> <47904560.2090708@telenet.be> Message-ID: <1568747753.20080118105205@gmail.com> Hello Peter, Friday, January 18, 2008, 9:21:20 AM, you wrote: > > That would be possible, but wouldn't Template Haskell also be an option? TH is just macroprocessor. it does nothing at runtime -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From t-otto-news at gmx.de Fri Jan 18 03:32:37 2008 From: t-otto-news at gmx.de (Torsten Otto) Date: Fri Jan 18 06:13:38 2008 Subject: [Haskell-cafe] Haskell and GUI In-Reply-To: <200801171509.28774.g9ks157k@acme.softbase.org> References: <200801171509.28774.g9ks157k@acme.softbase.org> Message-ID: Gee, wizzz, folks. Thank you all for the many hints. I can't say yet which one I'll dive into but I'm in good spirits about Haskell and GUI now. I like the idea of a functional approach and I don't need extensive GUIs either, so Grapefruit just added another candidate... Using the Cocoa API or AppleScript bindings is very slick (I'll look into that), but I think I'd rather have a platform independent solution for my class. I'll do my best to post a beginners tutorial on the web where it may be found, but it'll likely be in German. I will definitely continue to recommend Haskell to my colleagues. Thanks again for your support, Torsten Am 17.01.2008 um 15:09 schrieb Wolfgang Jeltsch: > Am Dienstag, 15. Januar 2008 20:42 schrieb Conal Elliott: >> If you can get wxHaskell installed & working, you could try Phooey >> and/or >> TV. Both are described on the Haskell wiki and available via darcs >> and >> Hackage. > > And they have the interesting property of being a functional > approach to GUI > programming (similar to FranTk). Most of the other Haskell GUI > toolkits are > imperative in nature. > > And now my shameless plug: If you can get Gtk2Hs installed and > working, you > could try Grapefruit which is also a functional library. In > addition to > GUIs, it also supports animated graphics. At the moment, it?s main > downside > is that it supports only a small set of widgets (buttons, labels, > edit fields > and boxes). See . > > Best wishes, > Wolfgang > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From bulat.ziganshin at gmail.com Fri Jan 18 05:45:28 2008 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Fri Jan 18 07:07:31 2008 Subject: [Haskell-cafe] Re: Reflection.Emit in Haskell In-Reply-To: References: <15910202182.20080118013902@gmail.com> Message-ID: <356871187.20080118134528@gmail.com> Hello apfelmus, Friday, January 18, 2008, 11:52:17 AM, you wrote: > I doubt that this works as intendend, I think you have to explicitly > fist the lambdas into the case expression: thank you. it was written in this style initially. then i rewrote it believing in GHC power but don't really checked results -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bertram.felgenhauer at googlemail.com Fri Jan 18 07:35:44 2008 From: bertram.felgenhauer at googlemail.com (Bertram Felgenhauer) Date: Fri Jan 18 07:36:02 2008 Subject: [Haskell-cafe] Hamming's Problem In-Reply-To: <003f01c85908$edbf5950$c93e0bf0$@com> References: <003f01c85908$edbf5950$c93e0bf0$@com> Message-ID: <20080118123544.GA4270@zombie.inf.tu-dresden.de> Jose Luis Reyes F. wrote: > Hi, > > In exercise 2 of http://www.walenz.org/Dijkstra/page0145.html we need to > write a function that holds > > (1) The value 1 is in the sequence > (2) If x and y are in the sequence, so is f(x,y), where f has the > properties > a. f(x,y) > x > b. (y1 > y2) => (f(x,y1)>f(x,y2)) > > This is a solution for this problem, but an inefficient one > > hammingff :: [Integer] > hammingff = 1 : merge [ h x y | x <- hammingff, y <- hammingff ] > [ h x y | y <- hammingff, x <- hammingff ] That's not sufficient. In fact, because hammingff is an infinite sequence, this is equivalent to hammingff = 1 : merge [ h (head hammingff) y | y <- hammingff ] [ h x (head hammingff) | x <- hammingff ] > h x y = 2*x+3*y [snip merge function] Indeed, the first few terms of hammingff are [1,5,13,17,29], and the value h 5 5 = 25 is missing. > anybody has a better solution?. I have some ideas, but maybe you want to work on a correct solution first? Btw, with your choice of h, the result list will contain all natural numbers that are not divisible by 3 and are = 1 (mod 4). Evaluating the first n elements of that list will require O(n^2) evaluations of h. Bertram From Christian.Maeder at dfki.de Fri Jan 18 07:55:14 2008 From: Christian.Maeder at dfki.de (Christian Maeder) Date: Fri Jan 18 07:55:15 2008 Subject: [Haskell-cafe] functional graphs Message-ID: <4790A1B2.7030901@dfki.de> Hi, Given a complete graph as a list of nodes whose edge labels are given by a function over two nodes: data CGraph a b = CGraph [a] (a -> a -> b) Can I define an instance for the fgl Graph class? import Data.Graph.Inductive.Graph instance Graph CGraph where empty = CGraph [] -- and now? I had no idea how to define empty (except using undefined). I thought of requiring a context for the node labels of type a, but this type is not mentioned in the class header. So it looked to me like the impossibility to define sets (requiring an Ord) as monads. (i.e. instance Monad Data.Set.Set) Any working proposals for my graph problem? Cheers Christian From ithika at gmail.com Fri Jan 18 08:26:43 2008 From: ithika at gmail.com (Dougal Stanton) Date: Fri Jan 18 08:26:44 2008 Subject: [Haskell-cafe] Hamming's Problem In-Reply-To: <20080118123544.GA4270@zombie.inf.tu-dresden.de> References: <003f01c85908$edbf5950$c93e0bf0$@com> <20080118123544.GA4270@zombie.inf.tu-dresden.de> Message-ID: <2d3641330801180526i1c443932i23863500483185ce@mail.gmail.com> On 18/01/2008, Bertram Felgenhauer wrote: > I have some ideas, but maybe you want to work on a correct solution > first? There is an implementation on the wikipedia article for Haskell: hamming = 1 : map (2*) hamming `merge` map (3*) hamming `merge` map (5*) hamming where merge (x:xs) (y:ys) | x < y = x : xs `merge` (y:ys) | x > y = y : (x:xs) `merge` ys | otherwise = x : xs `merge` ys -- Dougal Stanton dougal@dougalstanton.net // http://www.dougalstanton.net From bertram.felgenhauer at googlemail.com Fri Jan 18 09:09:04 2008 From: bertram.felgenhauer at googlemail.com (Bertram Felgenhauer) Date: Fri Jan 18 09:09:12 2008 Subject: [Haskell-cafe] Re: MonadPrompt + Gtk2Hs = ? In-Reply-To: References: Message-ID: <20080118140904.GB4270@zombie.inf.tu-dresden.de> apfelmus wrote: > Felipe Lessa wrote: >> casePromptOf :: (r -> b) >> -> (forall a. p a -> (a -> b) -> b) >> -> Prompt p r -> b >> casePromptOf done cont (PromptDone r) = done r >> casePromptOf done cont (Prompt p c ) = cont p (casePromptOf done cont . c) [is just as general as] > casePromptOf' :: (r -> f c) > -> (forall a,b. p a -> (a -> f b) -> f b) > -> Prompt p r -> f c That's nice. So let's implement Prompt differently, using casePromptOf as a template: > newtype Prompt p r = Prompt { > runP :: forall b . (r -> b) -> (forall a . p a -> (a -> b) -> b) -> b > } We can define a Monad instance easily enough: > instance Monad (Prompt p) where > return a = Prompt $ \done _ -> done a > f >>= g = Prompt $ \done prm -> runP f (\x -> runP (g x) done prm) prm prompt can be implemented as follows: > instance MonadPrompt (Prompt p) where > prompt p = \done prm -> prm p done And finally define some handy functions for running it, > runPromptC :: (r -> b) -> (forall a . p a -> (a -> b) -> b) > -> Prompt p r -> b > runPromptC ret prm p = runP p ret prm (runPromptC is just a different name for casePromptOf) > runPromptM :: Monad m => (forall a . p a -> m a) > -> Prompt p r -> m r > runPromptM prm = runPromptC return (\p cont -> prm p >>= cont) The interesting point here is that by working with continuations, we could eliminate the recursive call of (>>=) in its own implementation, curing the quadratic slowdown for left associative uses of (>>=). enjoy, Bertram P.S. I've written a small peg solitaire game using Prompt and gtk2hs, available from http://int-e.home.tlink.de/haskell/solitaire.tar.gz Maybe it's interesting to somebody. From j.vimal at gmail.com Fri Jan 18 10:33:44 2008 From: j.vimal at gmail.com (Vimal) Date: Fri Jan 18 10:33:43 2008 Subject: [Haskell-cafe] An idea - Feasibility and effort Message-ID: Hi Haskellers, This semester, I am having a software engineering course. I always wanted to do something significant in Haskell. This is probably an opportunity that I can utilize. I have the following ideas, with inspiration from various sources. Please let me know your views/ideas on them. If you feel you are experienced enough, do warn me if the idea might not be feasible to implement! I will have about half a month for getting the Software Requirement Specification ready, and ~ 1 month of time for coding. Idea 1: A Traceroute visualizer. I saw the video on the London Haskell Group on how to create a game in Haskell, and loved the "rotating earth" part of the game. (Space Invaders or something like that). Combine the earth (with a Google earth touch) with a traceroute backend and animate packet routing via different cities live on the screen. I like this idea. More of a fun project than a useful one. Probably Haskell isnt a good language to implement it, but as they say, one should never think about moulding a project to suit the language you code in. Idea 2: A module that generates optimum (in some sense) set of instructions for a given (pure, functional) expression. So, this basically involves concepts like * avoiding recalculating common subexpressions (expression-tree matching?), * register allocation (assuming a finite supply of registers, modeling as graph colouring), * Term rewriting I am just quoting some terms there, I may be wrong. but this might be a project that Haskell might help me beautifully model and execute. I would like to have some opinion on the complexity of the project ideas that I have in mind. Thanks, -- Vimal Indian Institute of Technology Madras Chennai India From byorgey at gmail.com Fri Jan 18 11:05:39 2008 From: byorgey at gmail.com (Brent Yorgey) Date: Fri Jan 18 11:05:39 2008 Subject: [Haskell-cafe] Re: STM in F# In-Reply-To: <87bq7jqwt1.fsf@nmd9999.imr.no> References: <20080118030252.GA12719@scytale.galois.com> <87bq7jqwt1.fsf@nmd9999.imr.no> Message-ID: <22fcbd520801180805i76f1377fj330b1a02a54d0957@mail.gmail.com> On Jan 18, 2008 4:59 AM, Ketil Malde wrote: > apfelmus writes: > > >> I imagine this can only ease the process of learning Haskell, and > >> broaden the base of possible Haskellers, as more people on using .NET > >> stuff become familiar with modern typed FP. > > > There's a reason the STM monad hatched in Haskell: how does the above > > STM in F# handle side-effects like launchMissile ? > > If you read the comments at the bottom, it seems it does not. Expect > an arbitrary number of missiles (although the final effect of > destroying the target city will perhaps be the same). > That's only because launchMissile is idempotent. -Brent -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080118/1d6a869b/attachment.htm From s.clover at gmail.com Fri Jan 18 11:08:44 2008 From: s.clover at gmail.com (Sterling Clover) Date: Fri Jan 18 11:08:44 2008 Subject: [Haskell-cafe] Re: STM in F# In-Reply-To: <22fcbd520801180805i76f1377fj330b1a02a54d0957@mail.gmail.com> References: <20080118030252.GA12719@scytale.galois.com> <87bq7jqwt1.fsf@nmd9999.imr.no> <22fcbd520801180805i76f1377fj330b1a02a54d0957@mail.gmail.com> Message-ID: B-but, (and here's the ironic part), launchMissile is only idempotent it the missile is atomic. --S 2008/1/18 Brent Yorgey : > > On Jan 18, 2008 4:59 AM, Ketil Malde wrote: > > > apfelmus writes: > > > > >> I imagine this can only ease the process of learning Haskell, and > > >> broaden the base of possible Haskellers, as more people on using .NET > > >> stuff become familiar with modern typed FP. > > > > > There's a reason the STM monad hatched in Haskell: how does the above > > > STM in F# handle side-effects like launchMissile ? > > > > If you read the comments at the bottom, it seems it does not. Expect > > an arbitrary number of missiles (although the final effect of > > destroying the target city will perhaps be the same). > > > > That's only because launchMissile is idempotent. > > -Brent > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080118/2cdd6ae5/attachment.htm From bf3 at telenet.be Fri Jan 18 11:33:41 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Fri Jan 18 11:33:44 2008 Subject: [Haskell-cafe] STM in F# In-Reply-To: <1200638392.5676.0.camel@derek-laptop> References: <20080118030252.GA12719@scytale.galois.com> <3640C189-0191-49A3-BA42-71DCF6DEB0C9@fastmail.fm> <479047F5.6000704@telenet.be> <1200638392.5676.0.camel@derek-laptop> Message-ID: <1200674021.2805.4.camel@localhost.localdomain> On Fri, 2008-01-18 at 00:39 -0600, Derek Elkins wrote: > On Fri, 2008-01-18 at 07:32 +0100, Peter Verswyvelen wrote: > > Reminds me of a song, "I'm dreaming of a ... dotnet Haskell..." > > > > I find it such a petty no real work seems to be done on that. > > No one is stopping you. Well yes, lack of time and knowledge :-) And oh yeah, I also forget my RSI ;-) From jgbailey at gmail.com Fri Jan 18 11:49:30 2008 From: jgbailey at gmail.com (Justin Bailey) Date: Fri Jan 18 11:49:29 2008 Subject: [Haskell-cafe] Re: [Haskell] ANNOUNCE: HStringTemplate -- An Elegant, Functional, Nifty Templating Engine for Haskell In-Reply-To: <89B71013-9550-4E1F-91DD-A4ABD532F2F1@gmail.com> References: <89B71013-9550-4E1F-91DD-A4ABD532F2F1@gmail.com> Message-ID: On Jan 13, 2008 11:47 PM, Sterling Clover wrote: > HStringTemplate is a port of Terrence Parr's lovely StringTemplate > (http://www.stringtemplate.org) engine to Haskell. Reading about the original library, I'm impressed. Can you add some examples to your darcs repository showing how to use your library? Or do you have some posted somewhere? Justin From ccshan at post.harvard.edu Fri Jan 18 11:44:49 2008 From: ccshan at post.harvard.edu (Chung-chieh Shan) Date: Fri Jan 18 12:00:13 2008 Subject: [Haskell-cafe] Re: Hamming's Problem References: <003f01c85908$edbf5950$c93e0bf0$@com> <20080118123544.GA4270@zombie.inf.tu-dresden.de> <2d3641330801180526i1c443932i23863500483185ce@mail.gmail.com> Message-ID: <1l1765-b9o.ln1@mantle.rutgers.edu> Calvin Smith wrote: > The author of Pugs (Perl6 implemented in Haskell) gives a nice solution > to the problem of generating the Hamming numbers in the following interview: > http://www.perl.com/pub/a/2005/09/08/autrijus-tang.html?page=last Dougal Stanton wrote: > There is an implementation on the wikipedia article for Haskell: Note that Dijkstra's two exercises are not the same as Hamming's original problem. I recommend the exercises! -- Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig One thing that UNIX does not need is more features. It is successful in part because it has a small number of good ideas that work well together. Merely adding features does not make it easier for users to do things -- it just makes the manual thicker. -- Rob Pike, Brian W. Kernighan, 1983. From jim at sdf-eu.org Fri Jan 18 13:19:13 2008 From: jim at sdf-eu.org (Jim Burton) Date: Fri Jan 18 13:19:17 2008 Subject: [Haskell-cafe] problem building array package Message-ID: <1200680353.5324.25.camel@unicorn> Building array from cabal with ghc6.6: ~/array-0.1.0.0$ runhaskell Setup.hs configure Configuring array-0.1.0.0... ~/array-0.1.0.0$ runhaskell Setup.hs build Preprocessing library array-0.1.0.0... Building array-0.1.0.0... [ 1 of 10] Compiling Data.Array.Base ( Data/Array/Base.hs, dist/build/Data/Array/Base.o ) Data/Array/Base.hs:391:23: Not in scope: `Arr.numElements' Data/Array/Base.hs:1067:35: Not in scope: `ArrST.numElementsSTArray' Data/Array/Base.hs:1079:51: Not in scope: `ArrST.numElementsSTArray' Any ideas why? Thanks, Jim From igouy2 at yahoo.com Fri Jan 18 13:30:25 2008 From: igouy2 at yahoo.com (Isaac Gouy) Date: Fri Jan 18 13:30:25 2008 Subject: [Haskell-cafe] shootout using 6.6? Message-ID: <414204.72997.qm@web60516.mail.yahoo.com> Duncan Coutts wrote > Note that ghc-6.8.2 is in gentoo now and has been for a few weeks. > There's no reason not to use it. Cool! It shall be done! Mea culpa - when I was considering building ghc from source I seem to have unmerged ghc, so ghc-6.8.2 didn't show up in the portage updates. ____________________________________________________________________________________ Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs From tretriluxana.s at gmail.com Fri Jan 18 16:57:27 2008 From: tretriluxana.s at gmail.com (Sukit Tretriluxana) Date: Fri Jan 18 16:57:26 2008 Subject: [Haskell-cafe] One-line haskell program with GHC Message-ID: <8252533f0801181357s50a1bf89y3dbb1253005521a4@mail.gmail.com> Hi, I don't know if it's been asked before. I just wonder if GHC supports some sort of one-liner program that can be specify right as the argument to either ghci or runghc program. In perl, they have something like perl *-e* 'print "Hello"' Do we have similar thing with GHC? Thanks, Ed -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080118/83891efc/attachment.htm From clifford.beshers at gmail.com Fri Jan 18 17:00:33 2008 From: clifford.beshers at gmail.com (Clifford Beshers) Date: Fri Jan 18 17:00:31 2008 Subject: [Haskell-cafe] One-line haskell program with GHC In-Reply-To: <8252533f0801181357s50a1bf89y3dbb1253005521a4@mail.gmail.com> References: <8252533f0801181357s50a1bf89y3dbb1253005521a4@mail.gmail.com> Message-ID: <6841b9520801181400w11dc1a95t66d671ccd796169a@mail.gmail.com> 2008/1/18 Sukit Tretriluxana : > Hi, > > I don't know if it's been asked before. I just wonder if GHC supports some > sort of one-liner program that can be specify right as the argument to > either ghci or runghc program. In perl, they have something like > > perl *-e* 'print "Hello"' > > Do we have similar thing with GHC? ghc -e 'putStrLn "Yes, we do."' -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080118/af17ed63/attachment.htm From tretriluxana.s at gmail.com Fri Jan 18 17:04:26 2008 From: tretriluxana.s at gmail.com (Sukit Tretriluxana) Date: Fri Jan 18 17:04:23 2008 Subject: [Haskell-cafe] One-line haskell program with GHC In-Reply-To: <6841b9520801181400w11dc1a95t66d671ccd796169a@mail.gmail.com> References: <8252533f0801181357s50a1bf89y3dbb1253005521a4@mail.gmail.com> <6841b9520801181400w11dc1a95t66d671ccd796169a@mail.gmail.com> Message-ID: <8252533f0801181404m69c9ea2ag99b1701c683c7895@mail.gmail.com> Thanks a lot! I thought that option resided in ghci or runghc apps. On Jan 18, 2008 2:00 PM, Clifford Beshers wrote: > 2008/1/18 Sukit Tretriluxana : > > > Hi, > > > > I don't know if it's been asked before. I just wonder if GHC supports > > some sort of one-liner program that can be specify right as the argument to > > either ghci or runghc program. In perl, they have something like > > > > perl *-e* 'print "Hello"' > > > > Do we have similar thing with GHC? > > > > ghc -e 'putStrLn "Yes, we do."' > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080118/5e401380/attachment.htm From thomas.dubuisson at gmail.com Fri Jan 18 18:14:22 2008 From: thomas.dubuisson at gmail.com (Thomas DuBuisson) Date: Fri Jan 18 18:10:44 2008 Subject: [Haskell-cafe] Control.Concurrent.STM.old? Message-ID: <1200698062.3374.5.camel@localhost> Does the 'old' function referenced in the SPJ and Tim Harris data invariants paper stil exist? It is of type STM a -> STM a and allowed invariants to compare old TVar values with new ones. I can't find it in any of the Haddocks or the code (and the 'check' funciton is not commented in the Haddock). Tom From felipe.lessa at gmail.com Fri Jan 18 18:15:30 2008 From: felipe.lessa at gmail.com (Felipe Lessa) Date: Fri Jan 18 18:15:28 2008 Subject: [Haskell-cafe] Re: [Haskell] Ancient, but still having fun In-Reply-To: <638ABD0A29C8884A91BC5FB5C349B1C315A55284CA@EA-EXMSG-C334.europe.corp.microsoft.com> References: <638ABD0A29C8884A91BC5FB5C349B1C315A55284CA@EA-EXMSG-C334.europe.corp.microsoft.com> Message-ID: [redirecting to haskell-cafe] On Jan 18, 2008 9:07 PM, Simon Peyton-Jones wrote: > It's Friday 18 January 2008, which makes it my 50th birthday. Happy birthday, Simon! =) Also, you're not ancient at all, and I don't doubt that you'll continue to provide essential contributions to all the Haskell community. > Suddenly Haskell is cool. It seems it's difficult to avoid success at all costs hehe... -- Felipe. From droundy at darcs.net Fri Jan 18 18:22:55 2008 From: droundy at darcs.net (David Roundy) Date: Fri Jan 18 18:22:53 2008 Subject: [Haskell-cafe] threads + IORefs = Segmentation fault? Message-ID: <20080118232255.GF6197@darcs.net> Hi all, I'm working on some new progress-reporting code for darcs, and am getting segmentation faults! :( The code uses threads + an IORef global variable to do this (with lots of unsafePerformIO). So my question for the gurus who know more about this than I do: is this safe? I thought it would be, because only one thread ever modifies the IORef, and the others only read it. I don't really care if they read a correct value, as long as they don't segfault. The code (to summarize) looks like: {-# NOINLINE _progressData #-} _progressData :: IORef (Map String ProgressData) _progressData = unsafePerformIO $ newIORef empty updateProgressData :: String -> (ProgressData -> ProgressData) -> IO () updateProgressData k f = when (progressMode) $ modifyIORef _progressData (adjust f k) setProgressData :: String -> ProgressData -> IO () setProgressData k p = when (progressMode) $ modifyIORef _progressData (insert k p) getProgressData :: String -> IO (Maybe ProgressData) getProgressData k = if progressMode then lookup k `fmap` readIORef _progressData else return Nothing The key function is beginTedious :: String -> IO () beginTedious k = do tid <- forkIO $ handleProgress k debugMessage $ "Beginning " ++ k setProgressData k $ ProgressData { sofar = 0, latest = Nothing, total = Nothing, handler = Just tid } which is called before an action that may be so tedious for our users that they need their day brightened by messages such as "Applying patch 137/1436". The handleProgress function alternates between threadDelay and reading the progress data to see whether any progress has been made and printing messages. Meanwhile the main thread calls functions that update _progressData. Anyhow, the point is that I'm getting segfaults, even after recompiling everything from scratch! Is this in fact that unsafe? Do I really need to switch to MVars, even though no locking is required? -- David Roundy Department of Physics Oregon State University From gwern0 at gmail.com Fri Jan 18 18:39:02 2008 From: gwern0 at gmail.com (gwern0@gmail.com) Date: Fri Jan 18 18:39:10 2008 Subject: [Haskell-cafe] One-line haskell program with GHC In-Reply-To: <8252533f0801181357s50a1bf89y3dbb1253005521a4@mail.gmail.com> References: <8252533f0801181357s50a1bf89y3dbb1253005521a4@mail.gmail.com> Message-ID: <20080118233902.GA11520@localhost> On 2008.01.18 13:57:27 -0800, Sukit Tretriluxana scribbled 1.3K characters: > Hi, > > I don't know if it's been asked before. I just wonder if GHC supports some sort of one-liner > program that can be specify right as the argument to either ghci or runghc program. In perl, > they have something like > > perl -e 'print "Hello"' > > Do we have similar thing with GHC? > > Thanks, > Ed http://www.joachim-breitner.de/blog/archives/156-Haskell-on-the-Command-Line.html http://haskell.org/haskellwiki/Simple_Unix_tools http://www.haskell.org/pipermail/haskell-cafe/2007-March/023035.html or http://groups.google.com/group/fa.haskell/browse_thread/thread/e948ff0ad4d7c0c9/241dca1a802c68bb -- gwern hope Coderpunks sigvoice .45 sabana MI5 CISSP Digicash b Tyrell -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080118/9000ba77/attachment.bin From dons at galois.com Fri Jan 18 19:06:27 2008 From: dons at galois.com (Don Stewart) Date: Fri Jan 18 19:06:33 2008 Subject: [Haskell-cafe] shootout using 6.6? In-Reply-To: <414204.72997.qm@web60516.mail.yahoo.com> References: <414204.72997.qm@web60516.mail.yahoo.com> Message-ID: <20080119000627.GC11353@scytale.galois.com> igouy2: > Duncan Coutts wrote > > > Note that ghc-6.8.2 is in gentoo now and has been for a few weeks. > > There's no reason not to use it. > > Cool! It shall be done! Great. Do let us know when its available. A couple of benchmarks will need to be tweaked in light of library changes. I'm also hoping to see good speedups for constructor-matching heavy programs like binary-trees. -- Don From hc-erikd at mega-nerd.com Fri Jan 18 19:47:05 2008 From: hc-erikd at mega-nerd.com (Erik de Castro Lopo) Date: Fri Jan 18 19:47:06 2008 Subject: [Haskell-cafe] library to read/write audio files In-Reply-To: <9979e72e0712110914g7698adeeq9d659c07cd61b2c0@mail.gmail.com> References: <9979e72e0712110914g7698adeeq9d659c07cd61b2c0@mail.gmail.com> Message-ID: <20080119114705.099c988c.hc-erikd@mega-nerd.com> Sorry, I missed this when it first came through, I was travelling in Europe. I'm also mainly a lurker on this list as my functional language of choice is actually Ocaml, but I've been wanting to learn Haskell for some time. John Lato wrote: > I originally intended to use Erik de Castro Lopo's excellent > libsndfile Thank you. > This library is far from complete. Firstly, only the wave format is > implemented (and incompletely). I really do ask you to reconsider this. Even just parsing the WAVE file format is a *HUGE* undertaking if you intend to support everything that is actually in the specs as well as handle all the horribly broken WAVE files produced by many commercial products. Cheers, Erik -- ----------------------------------------------------------------- Erik de Castro Lopo ----------------------------------------------------------------- "Men never do evil so completely and cheerfully as when they do it from religious conviction." -- Blaise Pascal, mathematician, 1670 From dons at galois.com Fri Jan 18 19:50:24 2008 From: dons at galois.com (Don Stewart) Date: Fri Jan 18 19:50:29 2008 Subject: [Haskell-cafe] library to read/write audio files In-Reply-To: <20080119114705.099c988c.hc-erikd@mega-nerd.com> References: <9979e72e0712110914g7698adeeq9d659c07cd61b2c0@mail.gmail.com> <20080119114705.099c988c.hc-erikd@mega-nerd.com> Message-ID: <20080119005024.GD11353@scytale.galois.com> hc-erikd: > > > I originally intended to use Erik de Castro Lopo's excellent > > libsndfile > > Thank you. > > > This library is far from complete. Firstly, only the wave format is > > implemented (and incompletely). > > I really do ask you to reconsider this. Even just parsing the WAVE > file format is a *HUGE* undertaking if you intend to support > everything that is actually in the specs as well as handle all the > horribly broken WAVE files produced by many commercial products. > > Cheers, > Erik I agree with Erik. It makes more sense to bind to a recognised library, so that the developer effort isn't wasted duplicating complex functionality. Unless there's a serious robustness/safety/functionality argument to be made for doing it purely in Haskell, just write a binding instead, and move on to problems we can better apply Haskell's strengths to. -- Don From hc-erikd at mega-nerd.com Fri Jan 18 19:50:59 2008 From: hc-erikd at mega-nerd.com (Erik de Castro Lopo) Date: Fri Jan 18 19:50:57 2008 Subject: [Haskell-cafe] library to read/write audio files In-Reply-To: <2EB27CFC-7405-4A81-8770-C1E6BF721A4A@k-hornz.de> References: <9979e72e0712110914g7698adeeq9d659c07cd61b2c0@mail.gmail.com> <2EB27CFC-7405-4A81-8770-C1E6BF721A4A@k-hornz.de> Message-ID: <20080119115059.a68290c1.hc-erikd@mega-nerd.com> Stefan Kersten wrote: > incidentally, i've been working on libsndfile bindings the last few > days; here's the darcs repository: > > http://darcs.k-hornz.de/cgi-bin/darcsweb.cgi?r=hsndfile;a=summary > > it's not quite finished yet, but if you're interested you could have > a look at the interface and make suggestions. maybe both projects > could benefit from each other? i personally don't see much advantages > in _not_ using libsndfile underneath ... Well done Stefan. Let me know how it goes. I am in the process (have been for some time, but then got distracted) of doing Ocaml bindings to libsndfile. Cheers, Erik -- ----------------------------------------------------------------- Erik de Castro Lopo ----------------------------------------------------------------- "C++ is a language strongly optimized for liars and people who go by guesswork and ignorance." -- Erik Naggum From igouy2 at yahoo.com Fri Jan 18 20:11:21 2008 From: igouy2 at yahoo.com (Isaac Gouy) Date: Fri Jan 18 20:11:19 2008 Subject: [Haskell-cafe] shootout using 6.6? In-Reply-To: <20080119000627.GC11353@scytale.galois.com> Message-ID: <377009.5676.qm@web60518.mail.yahoo.com> --- Don Stewart wrote: > igouy2: > > Duncan Coutts wrote > > > > > Note that ghc-6.8.2 is in gentoo now and has been for a few > weeks. > > > There's no reason not to use it. > > > > Cool! It shall be done! > > Great. Do let us know when its available. A couple of benchmarks > will need to be tweaked in light of library changes. > > I'm also hoping to see good speedups for constructor-matching > heavy programs like binary-trees. Yes that was a good speed up :-) otoh there are several failing programs... http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=ghc&lang2=ghc ____________________________________________________________________________________ Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs From dons at galois.com Fri Jan 18 20:23:59 2008 From: dons at galois.com (Don Stewart) Date: Fri Jan 18 20:24:01 2008 Subject: [Haskell-cafe] shootout using 6.6? In-Reply-To: <377009.5676.qm@web60518.mail.yahoo.com> References: <20080119000627.GC11353@scytale.galois.com> <377009.5676.qm@web60518.mail.yahoo.com> Message-ID: <20080119012359.GA12910@scytale.galois.com> igouy2: > > --- Don Stewart wrote: > > > igouy2: > > > Duncan Coutts wrote > > > > > > > Note that ghc-6.8.2 is in gentoo now and has been for a few > > weeks. > > > > There's no reason not to use it. > > > > > > Cool! It shall be done! > > > > Great. Do let us know when its available. A couple of benchmarks > > will need to be tweaked in light of library changes. > > > > I'm also hoping to see good speedups for constructor-matching > > heavy programs like binary-trees. > > Yes that was a good speed up :-) > > otoh there are several failing programs... > > http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=ghc&lang2=ghc > > Thanks for all your efforts here Isaac! Yay, constructor specialisation! http://shootout.alioth.debian.org/gp4/benchmark.php?test=binarytrees&lang=all Looks like there's a few regressions, and a few failures. We can coordinate fixes on the wiki, http://haskell.org/haskellwiki/Shootout Cheers, Don From ben.franksen at online.de Fri Jan 18 20:31:13 2008 From: ben.franksen at online.de (Ben Franksen) Date: Fri Jan 18 20:33:40 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <87fxx4slcy.fsf@nmd9999.imr.no> <200801111456.05819.g9ks157k@acme.softbase.org> Message-ID: jerzy.karczmarczuk@info.unicaen.fr wrote: > Ben Franksen writes: >> jerzy.karczmarczuk@info.unicaen.fr wrote: > ... >>> Does *MATH* answer the question what is: (0/0)==(0/0) ? Nope! >> >> Exactly. So why try to give an answer in Haskell? MATH says: the >> expression 0/0 is undefined, thus comparing (0/0)==(0/0) is undefined, >> too. I would expect Haskell to say the same. > > I don't know whether you are serious, or you are pulling my leg... > Let's suppose that it is serious. > > When math says that something is undefined, in my little brain I > understand that there is no answer. > NO answer. Oh, come on. You know very well what I am talking about. Defined or undefined is always relative to a set of axioms/laws that we usually take for granted. Division by zero is left undefined (in the sense of 'not defined') for a reason: there is no way to define it without breaking some laws. E.g. A one-point compactification of the real line is a nice thing but it breaks total (global) ordering (and certain algebraic laws, IIRC). I knwo of no mathematical theory that includes a NaN. > Is this the "undefined" you want to have? The bottom non-termination? In practice, it will be an exception. > Now, > this is obviously the *worst* possible reaction of the system, the IEEE > indefinite is much better, at least you know what had happened. It depends. An unsigned Infinity is ok if you are willing to concede that odering is local only and not total. I.e. to every number there is an open interval enclosing it on which the order is total, but it is not (necessarily) total globally. Two (signed) infinities are ok if you are willing to give up more laws. > Would you propose the non-termination as the issue of all "errors", such > as negative argument to the real sqrt, etc? What do you suppose is the answer to head [] ? What makes you think this is a less defined value, compared to, say, 0/0? > Well, as you wish... But don't write medical software, please... For medical software, somewhere at the end of the calculation there will be some effect to the outside world, if only to display the calculated value. Every pure calculation will eventually be called from the IO monad, where we can catch the exception. What is the advantage of letting the pure calculation continue while it is almost sure that the result will be Nan (=Not a Nan ;) anyway? In the end it won't make a big difference whether the 'undefined' result is due to a (cought) exception or due to a Nan result. I think the exception is cleaner, though. Cheers Ben From ben.franksen at online.de Fri Jan 18 20:38:24 2008 From: ben.franksen at online.de (Ben Franksen) Date: Fri Jan 18 20:40:43 2008 Subject: [Haskell-cafe] Re: Why purely in haskell? References: <65055d7c0801090640y5dbc1a8fn77cb3de141499c93@mail.gmail.com> <87fxx4slcy.fsf@nmd9999.imr.no> <200801111456.05819.g9ks157k@acme.softbase.org> <7ca3f0160801141737u142f7f53l8432ce4ac3ae9310@mail.gmail.com> Message-ID: jerzy.karczmarczuk@info.unicaen.fr wrote: >> Personally, I loathe the existence of NaN and +-Infinity in floating >> point types. > > I conclude that you live far from the numeric world. But I was raised as > physicist, and without them, the implementation of several algorithms > would be extremely difficult. Hm. Can you give an example? (A web link, maybe to a paper or some, such would be enough). I am asking because I am used to calculating with infinity from integration theory where the rationale is similar: formulation of most of the basic theorems would loose a lot of its elegance if the 'infinite case' had to be handled explicitly. Cheers Ben From jonathanccast at fastmail.fm Fri Jan 18 21:24:05 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Fri Jan 18 21:24:06 2008 Subject: [Haskell-cafe] One-line haskell program with GHC In-Reply-To: <6841b9520801181400w11dc1a95t66d671ccd796169a@mail.gmail.com> References: <8252533f0801181357s50a1bf89y3dbb1253005521a4@mail.gmail.com> <6841b9520801181400w11dc1a95t66d671ccd796169a@mail.gmail.com> Message-ID: <2EC85BB6-A9D8-4948-AAB8-FD2AB033E64B@fastmail.fm> On 18 Jan 2008, at 2:00 PM, Clifford Beshers wrote: > 2008/1/18 Sukit Tretriluxana : > Hi, > > I don't know if it's been asked before. I just wonder if GHC > supports some sort of one-liner program that can be specify right > as the argument to either ghci or runghc program. In perl, they > have something like > > perl -e 'print "Hello"' > > Do we have similar thing with GHC? > > > ghc -e 'putStrLn "Yes, we do."' Although, unlike perl, you don't have to say print explicitly if you don't need it: ghc -e '"This works great!"' jcc -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080118/a0ecf642/attachment.htm From ben.franksen at online.de Fri Jan 18 21:31:23 2008 From: ben.franksen at online.de (Ben Franksen) Date: Fri Jan 18 21:33:44 2008 Subject: [Haskell-cafe] Re: Re: 0/0 > 1 == False References: <20080110220408.47186b19@solaris.tower> <87k5mgsm31.fsf@nmd9999.imr.no> <20080111145420.1c82c377@solaris.tower> <20080111170335.GH27808@darcs.net> <20080111191247.55ab360d@solaris.tower> <51AF6510-6CC0-4D8A-94AA-D704CE47510A@fastmail.fm> <20080112082519.4e7d81f2@solaris.tower> <200801120920.m0C9KXdT009948@mi1.bluebottle.com> <20080112104517.411627aa@solaris.tower> <20080112112432.674dcaff@solaris.tower> <200801121127.m0CBRX3E023254@mi0.bluebottle.com> Message-ID: Kalman Noel wrote: > Achim Schneider wrote: >> Actually, lim( 0 ) * lim( inf ) isn't anything but equals one, and >> the anything is defined to one (or, rather, is _one_ anything) to be >> able to use the abstraction. It's a bit like the difference between >> eight pens and a box of pens. If someone knows how to properly >> formalise n = 1, please speak up. > > Sorry if I still don't follow at all. Here is how I understand (i. e. > have learnt) lim notation, with n ? N, a_n ? R. (Excuse my poor > terminology, I have to translate this in my mind from German maths > language ;-). My point of posting this is that I don't see how to > accommodate the lim notation as I know it with your term. The limit of > infinity? What is the limit of infinity, and why should I multiplicate > it with 0? Why should I get 1? > > (1) lim a_n = a (where a ? R) > (2) lim a_n = ? > (3) lim a_n = ? ? > (4) lim { x ? x0 } f(x) = y (where f is a function into R) > > (1) means that the sequence of reals a_n converges towards a. > > (2) means that the sequence does not converge, because you can > always find a value that is /larger/ than what you hoped might > be the limit. > > (3) means that the sequence does not converge, because you can > always find a value that is /smaller/ than what you hoped might > be the limit. > > (4) means that for any sequence of reals (x_n ? dom f) converging > towards x0, we have lim f(x_n) = y. For this equation again, we > have the three cases above. (2) usually rather mean that for each positive limit A there is a number N such that a_N > A for /all/ n > N. An analogous definition hold for (3). Your definition of (2) is usually termed as '(a_n) contains a subsequence that tends toward +infinity'. Cheers Ben+ From ben.franksen at online.de Fri Jan 18 21:33:39 2008 From: ben.franksen at online.de (Ben Franksen) Date: Fri Jan 18 21:40:04 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False References: Message-ID: Benja Fallenstein wrote: > On Jan 10, 2008 9:22 AM, Mitar wrote: >> I understand that proper mathematical behavior would be that as 0/0 is >> mathematically undefined that 0/0 cannot be even compared to 1. > > My understanding is that common mathematical practice is that > comparing an undefined value to anything (including itself) always > yields false; "x /= x" is sometimes used to formalize "x is > undefined." In Mathematics one usually avoids comparing undefined values. If one does the result is undefined, too, of course. IOW, the whole calculation is worthless scribble. Cheers Ben From j.vimal at gmail.com Fri Jan 18 22:15:37 2008 From: j.vimal at gmail.com (Vimal) Date: Fri Jan 18 22:15:34 2008 Subject: [Haskell-cafe] problem building array package In-Reply-To: <1200680353.5324.25.camel@unicorn> References: <1200680353.5324.25.camel@unicorn> Message-ID: > Data/Array/Base.hs:391:23: Not in scope: `Arr.numElements' > > Data/Array/Base.hs:1067:35: > Not in scope: `ArrST.numElementsSTArray' > > Data/Array/Base.hs:1079:51: > Not in scope: `ArrST.numElementsSTArray' > > I had the same problem with ghc-6.6. It works with ghc-6.8.2. -- Vimal From stevelihn at gmail.com Fri Jan 18 22:40:48 2008 From: stevelihn at gmail.com (Steve Lihn) Date: Fri Jan 18 22:40:46 2008 Subject: [Haskell-cafe] need help for cabal-install Message-ID: Hi, I just got cabal-install working. However, I have a problem using it. My GHC is installed in a user-specific location, so when I do the Cabal dance, I have to specfiy "Setup configure --prefix=$HOME/ghc". Now with "cabal install", I can not figure out where to specify the --prefix. Cabal always complains "failed to install package". Help is appreciated. Steve From stevelihn at gmail.com Fri Jan 18 22:58:15 2008 From: stevelihn at gmail.com (Steve Lihn) Date: Fri Jan 18 22:58:16 2008 Subject: [Haskell-cafe] First go at reactive programming In-Reply-To: <478F25C6.6020306@optusnet.com.au> References: <478C98FF.2060903@optusnet.com.au> <478F25C6.6020306@optusnet.com.au> Message-ID: Tried to install reactive-0.2 on GHC-6.6, but failed. Building reactive-0.2... src/Data/Reactive.hs:1:13: cannot parse LANGUAGE pragma Is the package for GHC 6.8? Is there an older version (0.0?) for GHC 6.6 that I can play with your example? (Or advise how to hack that file to get it work on 6.6) Thanks, Steve From cjb at laptop.org Fri Jan 18 23:44:16 2008 From: cjb at laptop.org (Chris Ball) Date: Fri Jan 18 23:39:14 2008 Subject: [Haskell-cafe] Re: need help for cabal-install In-Reply-To: (Steve Lihn's message of "Fri, 18 Jan 2008 22:40:48 -0500") References: Message-ID: <86ve5qzaov.fsf@pullcord.laptop.org> Hi Steve, > Now with "cabal install", I can not figure out where to specify the > --prefix. Cabal always complains "failed to install package". I think you're just missing a "--user": $ cabal install --prefix=$HOME --user foo - Chris. -- Chris Ball From sjanssen at cse.unl.edu Sat Jan 19 00:11:24 2008 From: sjanssen at cse.unl.edu (Spencer Janssen) Date: Sat Jan 19 00:12:07 2008 Subject: [Haskell-cafe] problem building array package In-Reply-To: <1200680353.5324.25.camel@unicorn> References: <1200680353.5324.25.camel@unicorn> Message-ID: <20080119051124.GA28223@presario> On Fri, Jan 18, 2008 at 06:19:13PM +0000, Jim Burton wrote: > Building array from cabal with ghc6.6: > > ~/array-0.1.0.0$ runhaskell Setup.hs configure > Configuring array-0.1.0.0... > ~/array-0.1.0.0$ runhaskell Setup.hs build > Preprocessing library array-0.1.0.0... > Building array-0.1.0.0... > [ 1 of 10] Compiling Data.Array.Base ( Data/Array/Base.hs, > dist/build/Data/Array/Base.o ) > > Data/Array/Base.hs:391:23: Not in scope: `Arr.numElements' > > Data/Array/Base.hs:1067:35: > Not in scope: `ArrST.numElementsSTArray' > > Data/Array/Base.hs:1079:51: > Not in scope: `ArrST.numElementsSTArray' > > > Any ideas why? Thanks, > > Jim The array package isn't needed for GHC 6.6, as Data.Array.* is included in the base package. Cheers, Spencer Janssen From conal at conal.net Sat Jan 19 01:31:07 2008 From: conal at conal.net (Conal Elliott) Date: Sat Jan 19 01:31:05 2008 Subject: [Haskell-cafe] First go at reactive programming In-Reply-To: References: <478C98FF.2060903@optusnet.com.au> <478F25C6.6020306@optusnet.com.au> Message-ID: Hi Steve, Thanks for letting me know about the LANGUAGE problem. Yes, I used 6.8-friendly (6.6-unfriendly) LANGUAGE pragmas. In retrospect, probably not such a great idea, since there seem to be many folks still on 6.6. I just changed the sources (commenting out the LANGUAGE pragmas and inserting -fglasgow-exts pragmas), darcs-pushed, and put a new version (0.3) on hackage. Please give it another try. Cheers, - Conal On Jan 18, 2008 7:58 PM, Steve Lihn wrote: > Tried to install reactive-0.2 on GHC-6.6, but failed. > > Building reactive-0.2... > src/Data/Reactive.hs:1:13: cannot parse LANGUAGE pragma > > Is the package for GHC 6.8? Is there an older version (0.0?) for GHC > 6.6 that I can play with your example? (Or advise how to hack that > file to get it work on 6.6) > > Thanks, > Steve > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080118/ce166cbc/attachment.htm From kalman.noel at bluebottle.com Sat Jan 19 05:46:10 2008 From: kalman.noel at bluebottle.com (Kalman Noel) Date: Sat Jan 19 05:46:15 2008 Subject: [Haskell-cafe] Re: Re: 0/0 > 1 == False In-Reply-To: References: <20080111145420.1c82c377@solaris.tower> <20080111170335.GH27808@darcs.net> <20080111191247.55ab360d@solaris.tower> <51AF6510-6CC0-4D8A-94AA-D704CE47510A@fastmail.fm> <20080112082519.4e7d81f2@solaris.tower> <200801120920.m0C9KXdT009948@mi1.bluebottle.com> <20080112104517.411627aa@solaris.tower> <20080112112432.674dcaff@solaris.tower> <200801121127.m0CBRX3E023254@mi0.bluebottle.com> Message-ID: <200801191050.m0JAo95h016973@mi0.bluebottle.com> Ben Franksen wrote: > Kalman Noel wrote: > > (2) lim a_n = ? [...] > > (2) means that the sequence does not converge, because you can > > always find a value that is /larger/ than what you hoped might > > be the limit. > > (2) usually rather mean that for each positive limit A there is a number N > such that a_N > A for /all/ n > N. You're right here. I tried to come up with a more wordy, informal description, but failed on that. > Your definition of (2) is usually termed as '(a_n) contains a subsequence > that tends toward +infinity'. May you elaborate? I don't see where a subsequence comes into play here. Kalman ---------------------------------------------------------------------- Get a free email account with anti spam protection. http://www.bluebottle.com/tag/2 From bf3 at telenet.be Sat Jan 19 07:27:47 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Sat Jan 19 07:27:49 2008 Subject: [Haskell-cafe] threads + IORefs = Segmentation fault? In-Reply-To: <20080118232255.GF6197@darcs.net> References: <20080118232255.GF6197@darcs.net> Message-ID: <1200745667.4032.3.camel@localhost.localdomain> Hi David, Which version of GHC are you using? I tried to recompile some GHC 6.6.1 progs using GHC 6.8.2 and I also got segfaults. I haven't figured out yet if this is because my changes to make it work with GHC 6.8.2 are incorrect, or if this is an issue with 6.8.2. Cheers, Peter On Fri, 2008-01-18 at 18:22 -0500, David Roundy wrote: > Hi all, > > I'm working on some new progress-reporting code for darcs, and am getting > segmentation faults! :( The code uses threads + an IORef global variable > to do this (with lots of unsafePerformIO). So my question for the gurus > who know more about this than I do: is this safe? I thought it would be, > because only one thread ever modifies the IORef, and the others only read > it. I don't really care if they read a correct value, as long as they > don't segfault. > > The code (to summarize) looks like: > > {-# NOINLINE _progressData #-} > _progressData :: IORef (Map String ProgressData) > _progressData = unsafePerformIO $ newIORef empty > > updateProgressData :: String -> (ProgressData -> ProgressData) -> IO () > updateProgressData k f = when (progressMode) $ modifyIORef _progressData (adjust f k) > > setProgressData :: String -> ProgressData -> IO () > setProgressData k p = when (progressMode) $ modifyIORef _progressData (insert k p) > > getProgressData :: String -> IO (Maybe ProgressData) > getProgressData k = if progressMode then lookup k `fmap` readIORef _progressData > else return Nothing > > The key function is > > beginTedious :: String -> IO () > beginTedious k = do tid <- forkIO $ handleProgress k > debugMessage $ "Beginning " ++ k > setProgressData k $ ProgressData { sofar = 0, > latest = Nothing, > total = Nothing, > handler = Just tid } > > which is called before an action that may be so tedious for our users that > they need their day brightened by messages such as "Applying patch > 137/1436". The handleProgress function alternates between threadDelay and > reading the progress data to see whether any progress has been made and > printing messages. Meanwhile the main thread calls functions that update > _progressData. > > Anyhow, the point is that I'm getting segfaults, even after recompiling > everything from scratch! Is this in fact that unsafe? Do I really need to > switch to MVars, even though no locking is required? From barsoap at web.de Sat Jan 19 08:01:19 2008 From: barsoap at web.de (Achim Schneider) Date: Sat Jan 19 08:01:30 2008 Subject: [Haskell-cafe] Re: threads + IORefs = Segmentation fault? References: <20080118232255.GF6197@darcs.net> Message-ID: <20080119140119.2239636c@solaris.tower> David Roundy wrote: > {-# NOINLINE _progressData #-} > _progressData :: IORef (Map String ProgressData) > _progressData = unsafePerformIO $ newIORef empty > > updateProgressData :: String > -> (ProgressData -> ProgressData) > -> IO () > updateProgressData k f = when (progressMode) $ modifyIORef > _progressData (adjust f k) > The question I'm asking myself is why you would want to modify a reference to an always empty Map, which would be the case if unsafePerformIO performs its action every time. If it doesnt' (and experience suggest that it doesn't, as does the faithful usage of {-# NOINLINE #-}, BUT YOU'LL NEVER, EVER, KNOW), I'm wondering why you don't create the IORef in beginTedious and pass it around. Possibly even with an implicit parameter. And, yes, without multiple writing threads locking is unnecessary, and mostly even with multiple writing threads, if they don't read, too. /me mandates the renaming of unsafePerformIO to iReallyReallyThoughtReallyHardAboutThisAndThereReallyIsNoDifferentWayThanToUseThisDreadedUnsafePerformIO. OTOH, I have no idea what causes the segfault. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From droundy at darcs.net Sat Jan 19 08:36:44 2008 From: droundy at darcs.net (David Roundy) Date: Sat Jan 19 08:36:40 2008 Subject: [Haskell-cafe] threads + IORefs = Segmentation fault? In-Reply-To: <1200745667.4032.3.camel@localhost.localdomain> References: <20080118232255.GF6197@darcs.net> <1200745667.4032.3.camel@localhost.localdomain> Message-ID: <20080119133643.GH6197@darcs.net> Using ghc 6.6, but I've since isolated the bug as being unrelated to the IORefs and threading, it was in an FFI binding that somehow never died until I was testing this new code. David On Sat, Jan 19, 2008 at 01:27:47PM +0100, Peter Verswyvelen wrote: > Hi David, > > Which version of GHC are you using? > > I tried to recompile some GHC 6.6.1 progs using GHC 6.8.2 and I also got > segfaults. I haven't figured out yet if this is because my changes to > make it work with GHC 6.8.2 are incorrect, or if this is an issue with > 6.8.2. > > Cheers, > Peter > > > On Fri, 2008-01-18 at 18:22 -0500, David Roundy wrote: > > Hi all, > > > > I'm working on some new progress-reporting code for darcs, and am getting > > segmentation faults! :( The code uses threads + an IORef global variable > > to do this (with lots of unsafePerformIO). So my question for the gurus > > who know more about this than I do: is this safe? I thought it would be, > > because only one thread ever modifies the IORef, and the others only read > > it. I don't really care if they read a correct value, as long as they > > don't segfault. > > > > The code (to summarize) looks like: > > > > {-# NOINLINE _progressData #-} > > _progressData :: IORef (Map String ProgressData) > > _progressData = unsafePerformIO $ newIORef empty > > > > updateProgressData :: String -> (ProgressData -> ProgressData) -> IO () > > updateProgressData k f = when (progressMode) $ modifyIORef _progressData (adjust f k) > > > > setProgressData :: String -> ProgressData -> IO () > > setProgressData k p = when (progressMode) $ modifyIORef _progressData (insert k p) > > > > getProgressData :: String -> IO (Maybe ProgressData) > > getProgressData k = if progressMode then lookup k `fmap` readIORef _progressData > > else return Nothing > > > > The key function is > > > > beginTedious :: String -> IO () > > beginTedious k = do tid <- forkIO $ handleProgress k > > debugMessage $ "Beginning " ++ k > > setProgressData k $ ProgressData { sofar = 0, > > latest = Nothing, > > total = Nothing, > > handler = Just tid } > > > > which is called before an action that may be so tedious for our users that > > they need their day brightened by messages such as "Applying patch > > 137/1436". The handleProgress function alternates between threadDelay and > > reading the progress data to see whether any progress has been made and > > printing messages. Meanwhile the main thread calls functions that update > > _progressData. > > > > Anyhow, the point is that I'm getting segfaults, even after recompiling > > everything from scratch! Is this in fact that unsafe? Do I really need to > > switch to MVars, even though no locking is required? > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe -- David Roundy Department of Physics Oregon State University From lennart at augustsson.net Sat Jan 19 08:46:38 2008 From: lennart at augustsson.net (Lennart Augustsson) Date: Sat Jan 19 08:46:35 2008 Subject: [Haskell-cafe] threads + IORefs = Segmentation fault? In-Reply-To: <20080119133643.GH6197@darcs.net> References: <20080118232255.GF6197@darcs.net> <1200745667.4032.3.camel@localhost.localdomain> <20080119133643.GH6197@darcs.net> Message-ID: You should use an MVar if you want it to be thread safe. On Jan 19, 2008 1:36 PM, David Roundy wrote: > Using ghc 6.6, but I've since isolated the bug as being unrelated to the > IORefs and threading, it was in an FFI binding that somehow never died > until I was testing this new code. > > David > > On Sat, Jan 19, 2008 at 01:27:47PM +0100, Peter Verswyvelen wrote: > > Hi David, > > > > Which version of GHC are you using? > > > > I tried to recompile some GHC 6.6.1 progs using GHC 6.8.2 and I also got > > segfaults. I haven't figured out yet if this is because my changes to > > make it work with GHC 6.8.2 are incorrect, or if this is an issue with > > 6.8.2. > > > > Cheers, > > Peter > > > > > > On Fri, 2008-01-18 at 18:22 -0500, David Roundy wrote: > > > Hi all, > > > > > > I'm working on some new progress-reporting code for darcs, and am > getting > > > segmentation faults! :( The code uses threads + an IORef global > variable > > > to do this (with lots of unsafePerformIO). So my question for the > gurus > > > who know more about this than I do: is this safe? I thought it would > be, > > > because only one thread ever modifies the IORef, and the others only > read > > > it. I don't really care if they read a correct value, as long as they > > > don't segfault. > > > > > > The code (to summarize) looks like: > > > > > > {-# NOINLINE _progressData #-} > > > _progressData :: IORef (Map String ProgressData) > > > _progressData = unsafePerformIO $ newIORef empty > > > > > > updateProgressData :: String -> (ProgressData -> ProgressData) -> IO > () > > > updateProgressData k f = when (progressMode) $ modifyIORef > _progressData (adjust f k) > > > > > > setProgressData :: String -> ProgressData -> IO () > > > setProgressData k p = when (progressMode) $ modifyIORef _progressData > (insert k p) > > > > > > getProgressData :: String -> IO (Maybe ProgressData) > > > getProgressData k = if progressMode then lookup k `fmap` readIORef > _progressData > > > else return Nothing > > > > > > The key function is > > > > > > beginTedious :: String -> IO () > > > beginTedious k = do tid <- forkIO $ handleProgress k > > > debugMessage $ "Beginning " ++ k > > > setProgressData k $ ProgressData { sofar = 0, > > > latest = > Nothing, > > > total = > Nothing, > > > handler = Just > tid } > > > > > > which is called before an action that may be so tedious for our users > that > > > they need their day brightened by messages such as "Applying patch > > > 137/1436". The handleProgress function alternates between threadDelay > and > > > reading the progress data to see whether any progress has been made > and > > > printing messages. Meanwhile the main thread calls functions that > update > > > _progressData. > > > > > > Anyhow, the point is that I'm getting segfaults, even after > recompiling > > > everything from scratch! Is this in fact that unsafe? Do I really need > to > > > switch to MVars, even though no locking is required? > > > > _______________________________________________ > > Haskell-Cafe mailing list > > Haskell-Cafe@haskell.org > > http://www.haskell.org/mailman/listinfo/haskell-cafe > > -- > David Roundy > Department of Physics > Oregon State University > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080119/7e6b75ac/attachment.htm From reinier.lamers at phil.uu.nl Sat Jan 19 09:12:52 2008 From: reinier.lamers at phil.uu.nl (Reinier Lamers) Date: Sat Jan 19 09:13:03 2008 Subject: [Haskell-cafe] Haskell-Support in Ohloh In-Reply-To: <1200529309.3822.33.camel@otto.ehbuehl.net> References: <1200529309.3822.33.camel@otto.ehbuehl.net> Message-ID: Op 17-jan-2008, om 1:21 heeft Joachim Breitner het volgende geschreven: > > They explicitly write that they want haskell support, and the oldest > open bug report on their page is about this: > > http://labs.ohloh.net/ohcount/ticket/205 > > So if anyone feels like programming some ruby (I guess they want it to > be in that language as well) and wants to give the haskell community a > chance for wider audience, give it a shot. I used this rainy saturday to make a patch. It only took three lines of Ruby or so, and some more work getting ohcount to build on my machine and to make some unit tests. I submitted the patch to their trac, http://labs.ohloh.net/ohcount/ticket/205 . Reinier From stevelihn at gmail.com Sat Jan 19 09:14:47 2008 From: stevelihn at gmail.com (Steve Lihn) Date: Sat Jan 19 09:14:55 2008 Subject: [Haskell-cafe] First go at reactive programming In-Reply-To: References: <478C98FF.2060903@optusnet.com.au> <478F25C6.6020306@optusnet.com.au> Message-ID: Reactive-0.3 seems to have a dependency on TypeCompose-0.3. Earlier version does not work (for lack of Data.Pair). This probably should be specified in Cabal file. I aslo fixed all the LANGUAGE problems and now encountered the following error in TypeCompose: [4 of 9] Compiling Control.Compose ( src/Control/Compose.hs, dist/build/Control/Compose.o ) src/Control/Compose.hs:561:0: parse error on input `deriving' I tried to restored the commented out "deriving Monoid" and got pass that. Not sure if that is right though. Back to reactive-0.3, I encountered: src/Data/Future.hs:60:27: Module `Control.Monad' does not export `forever' Forever is in the latest library, but not in my GHC 6.6. I am not sure how to get this fixed. Any suggestion? http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Monad.html Steve On Jan 19, 2008 1:31 AM, Conal Elliott wrote: > Hi Steve, > > Thanks for letting me know about the LANGUAGE problem. Yes, I used > 6.8-friendly (6.6-unfriendly) LANGUAGE pragmas. In retrospect, probably not > such a great idea, since there seem to be many folks still on 6.6. > > I just changed the sources (commenting out the LANGUAGE pragmas and > inserting -fglasgow-exts pragmas), darcs-pushed, and put a new version (0.3) > on hackage. Please give it another try. > > Cheers, - Conal > > > > On Jan 18, 2008 7:58 PM, Steve Lihn wrote: > > Tried to install reactive-0.2 on GHC-6.6, but failed. > > > > Building reactive-0.2... > > src/Data/Reactive.hs:1:13: cannot parse LANGUAGE pragma > > > > Is the package for GHC 6.8? Is there an older version (0.0?) for GHC > > 6.6 that I can play with your example? (Or advise how to hack that > > file to get it work on 6.6) > > > > Thanks, > > Steve > > > > From duncan.coutts at worc.ox.ac.uk Sat Jan 19 09:18:19 2008 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Sat Jan 19 09:18:18 2008 Subject: [Haskell-cafe] Re: need help for cabal-install In-Reply-To: <86ve5qzaov.fsf@pullcord.laptop.org> References: <86ve5qzaov.fsf@pullcord.laptop.org> Message-ID: <1200752299.5639.278.camel@localhost> On Fri, 2008-01-18 at 23:44 -0500, Chris Ball wrote: > Hi Steve, > > > Now with "cabal install", I can not figure out where to specify the > > --prefix. Cabal always complains "failed to install package". > > I think you're just missing a "--user": > > $ cabal install --prefix=$HOME --user foo The prefix can also be set in the $HOME/.cabal/config file. BTW, In the development version of cabal-install --user is the default and the default user prefix is $HOME/.cabal (though both can be changed in the config file). I'd also recommend anyone trying out cabal-install to ignore the old version on hackage and go straight for the development version. It's a tad harder to get installed since it also needs the development version of the Cabal lib, but it has so many issues fixed. darcs get --partial http://darcs.haskell.org/cabal cd cabal make setup ./setup configure --prefix=$HOME/.cabal --user ./setup build ./setup install cd .. darcs get --partial http://darcs.haskell.org/cabal-install cd cabal-install runghc Setup.hs configure --prefix=$HOME/.cabal --bindir=$HOME --user runghc Setup.hs build runghc Setup.hs install This assumes $HOME/bin is on your path and that you already have the zlib and HTTP packages installed. Then get the latest hackage package list with: cabal update For a quick guide see: cabal --help There's also bash command line completion support: source bash-completion/cabal Then give it a try. Report any complaints or requests in the hackage trac: http://hackage.haskell.org/trac/hackage/ Duncan From stevelihn at gmail.com Sat Jan 19 09:27:54 2008 From: stevelihn at gmail.com (Steve Lihn) Date: Sat Jan 19 09:27:52 2008 Subject: [Haskell-cafe] Re: need help for cabal-install In-Reply-To: <1200752299.5639.278.camel@localhost> References: <86ve5qzaov.fsf@pullcord.laptop.org> <1200752299.5639.278.camel@localhost> Message-ID: On Jan 19, 2008 9:18 AM, Duncan Coutts wrote: > > > > > I think you're just missing a "--user": > > > > $ cabal install --prefix=$HOME --user foo > > The prefix can also be set in the $HOME/.cabal/config file. > Syntax? Something like: prefix: /path/to/my/ghc ? > BTW, In the development version of cabal-install --user is the default > and the default user prefix is $HOME/.cabal (though both can be changed > in the config file). > Is this newer than 12 hours ago? I tried "cabal install --prefix=/path package" (without --user). That did not seem to work... Steve From stevelihn at gmail.com Sat Jan 19 09:30:42 2008 From: stevelihn at gmail.com (Steve Lihn) Date: Sat Jan 19 09:30:38 2008 Subject: [Haskell-cafe] Re: need help for cabal-install In-Reply-To: References: <86ve5qzaov.fsf@pullcord.laptop.org> <1200752299.5639.278.camel@localhost> Message-ID: Just tried to test drive another feature and got the nasty error: > cabal list Stack space overflow: current size 8388608 bytes. Use `+RTS -Ksize' to increase it. On Jan 19, 2008 9:27 AM, Steve Lihn wrote: > On Jan 19, 2008 9:18 AM, Duncan Coutts wrote: > > > > > > > > I think you're just missing a "--user": > > > > > > $ cabal install --prefix=$HOME --user foo > > > > The prefix can also be set in the $HOME/.cabal/config file. > > > > Syntax? Something like: prefix: /path/to/my/ghc ? > > > BTW, In the development version of cabal-install --user is the default > > and the default user prefix is $HOME/.cabal (though both can be changed > > in the config file). > > > > Is this newer than 12 hours ago? I tried "cabal install --prefix=/path > package" (without --user). That did not seem to work... > > Steve > From r.kelsall at millstream.com Sat Jan 19 10:18:37 2008 From: r.kelsall at millstream.com (Richard Kelsall) Date: Sat Jan 19 10:18:48 2008 Subject: [Haskell-cafe] shootout using 6.6? In-Reply-To: <20080119012359.GA12910@scytale.galois.com> References: <20080119000627.GC11353@scytale.galois.com> <377009.5676.qm@web60518.mail.yahoo.com> <20080119012359.GA12910@scytale.galois.com> Message-ID: <479214CD.10609@millstream.com> Don Stewart wrote: ... > Yay, constructor specialisation! > > http://shootout.alioth.debian.org/gp4/benchmark.php?test=binarytrees&lang=all > And it's nice to see GHC 6.8.2 is now nearly ten times faster than GCC for this benchmark : http://shootout.alioth.debian.org/gp4/benchmark.php?test=threadring&lang=all Scary to think how fast GHC might become in 6.10 :) Richard. From stevelihn at gmail.com Sat Jan 19 10:47:20 2008 From: stevelihn at gmail.com (Steve Lihn) Date: Sat Jan 19 10:47:17 2008 Subject: [Haskell-cafe] How best to make GHC 6.6 and 6.8 co-exist on one server/account Message-ID: Hi, It appears some of the latest hackages are moving towards 6.8 to take advantage of the new features, while quite a few remains at 6.6. The compatibility between the two versions has been problematic. I only have 6.6 installed, but now thinking to add 6.8 to my account (so I can switch between them, depending what works where). What is the best practice to make 6.8 co-exist with 6.6 ? Specific questions are: 1) I installed 6.6 under prefix=$HOME/ghc. If I install 6.8 to the same prefix, it will overwrite 6.6. Correct? How do I get around it? 2) I installed additional tools and packages under $HOME/htools using 6.6. (Which I begin to wonder if that is necessary.) Do I have to use a different directory for 6.8? I noticed that, for each package, the path is $HOME/htools/lib//ghc-6.6.1/ etc etc. It seems that 6.8 will create subdirectories, so they can co-exist peacefully. Correct? Thanks, Steve From duncan.coutts at worc.ox.ac.uk Sat Jan 19 10:53:32 2008 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Sat Jan 19 10:53:30 2008 Subject: [Haskell-cafe] Re: need help for cabal-install In-Reply-To: References: <86ve5qzaov.fsf@pullcord.laptop.org> <1200752299.5639.278.camel@localhost> Message-ID: <1200758012.5639.282.camel@localhost> On Sat, 2008-01-19 at 09:30 -0500, Steve Lihn wrote: > Just tried to test drive another feature and got the nasty error: > > > cabal list > Stack space overflow: current size 8388608 bytes. > Use `+RTS -Ksize' to increase it. Oops, silly error on my part. darcs pull and it's fixed. Duncan From duncan.coutts at worc.ox.ac.uk Sat Jan 19 11:02:17 2008 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Sat Jan 19 11:02:23 2008 Subject: [Haskell-cafe] Re: need help for cabal-install In-Reply-To: References: <86ve5qzaov.fsf@pullcord.laptop.org> <1200752299.5639.278.camel@localhost> Message-ID: <1200758537.5639.291.camel@localhost> On Sat, 2008-01-19 at 09:27 -0500, Steve Lihn wrote: > On Jan 19, 2008 9:18 AM, Duncan Coutts wrote: > > > > > > > > I think you're just missing a "--user": > > > > > > $ cabal install --prefix=$HOME --user foo > > > > The prefix can also be set in the $HOME/.cabal/config file. > > > > Syntax? Something like: prefix: /path/to/my/ghc ? Yes, but using ghc's path would be a really bad idea. Actually there's "user-prefix:" and "global-prefix:" for the prefixes to use when using --user or --global installs. > > BTW, In the development version of cabal-install --user is the default > > and the default user prefix is $HOME/.cabal (though both can be changed > > in the config file). > > > > Is this newer than 12 hours ago? I tried "cabal install --prefix=/path > package" (without --user). That did not seem to work... Remember, --user is default unless overridden by --global. So if you are trying to install as root that probably will not work since it'll probably have been built against packages that were in your user's package db but are not in your root users package db. We've not concentrated very much on global installs yet for cabal-install. We've been trying to make ordinary user installs "Just Work"tm. There was a bug a couple days ago where the prefix given on the command line was being overridden from the one given in the config file. That's now fixed. The command line overrides the saved config settings. So if it's still not working for you, you'll have to give more details. Details of what command you were using exactly and what the error message was. Duncan From duncan.coutts at worc.ox.ac.uk Sat Jan 19 11:12:27 2008 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Sat Jan 19 11:12:24 2008 Subject: [Haskell-cafe] How best to make GHC 6.6 and 6.8 co-exist on one server/account In-Reply-To: References: Message-ID: <1200759147.5639.302.camel@localhost> On Sat, 2008-01-19 at 10:47 -0500, Steve Lihn wrote: > Hi, > It appears some of the latest hackages are moving towards 6.8 to take > advantage of the new features, while quite a few remains at 6.6. The > compatibility between the two versions has been problematic. I only > have 6.6 installed, but now thinking to add 6.8 to my account (so I > can switch between them, depending what works where). It should all work. I've got 3 ghc versions installed. > What is the best practice to make 6.8 co-exist with 6.6 ? Specific > questions are: > 1) I installed 6.6 under prefix=$HOME/ghc. If I install 6.8 to the > same prefix, it will overwrite 6.6. Correct? How do I get around it? That could be ok. Check what the layout if $HOME/ghc is. If it looks like: bin/ lib/ lib/ghc-6.6/ then that's fine and you'll be able to install another ghc to the same prefix, since the sub-dirs are versioned. You'll end up with $HOME/bin/ghc being the latest ghc, and the older version available as $HOME/ghc/bin/ghc-6.6. > 2) I installed additional tools and packages under $HOME/htools using > 6.6. (Which I begin to wonder if that is necessary.) Do I have to use > a different directory for 6.8? I noticed that, for each package, the > path is $HOME/htools/lib//ghc-6.6.1/ etc etc. It seems > that 6.8 will create subdirectories, so they can co-exist peacefully. > Correct? Yes. The aim is to be able to have multiple haskell implementations, multiple versions of each haskell implementations and multiple versions of each library built for any/all haskell implementation/version and to have them all co-exist peacefully. Duncan From conal at conal.net Sat Jan 19 11:17:26 2008 From: conal at conal.net (Conal Elliott) Date: Sat Jan 19 11:17:23 2008 Subject: [Haskell-cafe] First go at reactive programming In-Reply-To: References: <478C98FF.2060903@optusnet.com.au> <478F25C6.6020306@optusnet.com.au> Message-ID: Thanks for the TypeCompose>=0.3 tip. I've fixed my local Reactive.cabal and will push at some point. Oh yeay -- I'd forgotten about the "deriving" change in 6.8 vs 6.6. Urg. I didn't realize that 'forever' isn't in 6.2. You can use the 6.8def: -- | @'forever' act@ repeats the action infinitely. forever :: (Monad m) => m a -> m () forever a = a >> forever a I'm wondering how hard to try to get these libs to work with both 6.6 and 6.8. My hope has been that people will switch to 6.8, but perhaps there are obstacles I don't know about. Is there something that keeps you from upgrading? - Conal On Jan 19, 2008 6:14 AM, Steve Lihn wrote: > Reactive-0.3 seems to have a dependency on TypeCompose-0.3. Earlier > version does not work (for lack of Data.Pair). This probably should be > specified in Cabal file. > > I aslo fixed all the LANGUAGE problems and now encountered the > following error in TypeCompose: > > [4 of 9] Compiling Control.Compose ( src/Control/Compose.hs, > dist/build/Control/Compose.o ) > src/Control/Compose.hs:561:0: parse error on input `deriving' > > I tried to restored the commented out "deriving Monoid" and got pass > that. Not sure if that is right though. Back to reactive-0.3, I > encountered: > > src/Data/Future.hs:60:27: > Module `Control.Monad' does not export `forever' > > Forever is in the latest library, but not in my GHC 6.6. I am not sure > how to get this fixed. Any suggestion? > > > http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Monad.html > > > Steve > > > On Jan 19, 2008 1:31 AM, Conal Elliott wrote: > > Hi Steve, > > > > Thanks for letting me know about the LANGUAGE problem. Yes, I used > > 6.8-friendly (6.6-unfriendly) LANGUAGE pragmas. In retrospect, probably > not > > such a great idea, since there seem to be many folks still on 6.6. > > > > I just changed the sources (commenting out the LANGUAGE pragmas and > > inserting -fglasgow-exts pragmas), darcs-pushed, and put a new version ( > 0.3) > > on hackage. Please give it another try. > > > > Cheers, - Conal > > > > > > > > On Jan 18, 2008 7:58 PM, Steve Lihn wrote: > > > Tried to install reactive-0.2 on GHC-6.6, but failed. > > > > > > Building reactive-0.2... > > > src/Data/Reactive.hs:1:13: cannot parse LANGUAGE pragma > > > > > > Is the package for GHC 6.8? Is there an older version (0.0?) for GHC > > > 6.6 that I can play with your example? (Or advise how to hack that > > > file to get it work on 6.6) > > > > > > Thanks, > > > Steve > > > > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080119/7c736fe0/attachment.htm From nornagon at gmail.com Sat Jan 19 11:59:20 2008 From: nornagon at gmail.com (Jeremy Apthorp) Date: Sat Jan 19 11:59:17 2008 Subject: [Haskell-cafe] Haskell-Support in Ohloh In-Reply-To: References: <1200529309.3822.33.camel@otto.ehbuehl.net> Message-ID: <14d615330801190859p2598782o2e3e6202f9005baf@mail.gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 20/01/2008, Reinier Lamers wrote: > > Op 17-jan-2008, om 1:21 heeft Joachim Breitner het volgende geschreven: > > > > They explicitly write that they want haskell support, and the oldest > > open bug report on their page is about this: > > > > http://labs.ohloh.net/ohcount/ticket/205 > > > > So if anyone feels like programming some ruby (I guess they want it to > > be in that language as well) and wants to give the haskell community a > > chance for wider audience, give it a shot. > I used this rainy saturday to make a patch. It only took three lines > of Ruby or so, and some more work getting ohcount to build on my > machine and to make some unit tests. I submitted the patch to their > trac, http://labs.ohloh.net/ohcount/ticket/205 . Is it just me or does that patch not actually include the line counting code..? Jeremy -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFHkixQ5plcd8tF/AQRAqQeAJ420viuL4fdi3EqvtRZkbTSoJsmQQCgkYqG oofypoHigdBzSNtM2xB1nw0= =3tv8 -----END PGP SIGNATURE----- From tphyahoo at gmail.com Sat Jan 19 12:05:06 2008 From: tphyahoo at gmail.com (Thomas Hartman) Date: Sat Jan 19 12:05:02 2008 Subject: [Haskell-cafe] functional graphs In-Reply-To: <910ddf450801190856r330be968u4c689a415c6225fd@mail.gmail.com> References: <4790A1B2.7030901@dfki.de> <910ddf450801190856r330be968u4c689a415c6225fd@mail.gmail.com> Message-ID: <910ddf450801190905i2d8c7c9doaf897a0e96d366e1@mail.gmail.com> I don't get where the graph edges (Node,Node) are specified. Do you just assume that every two nodes have an edge between them and calculate the edge label from the function? Also, is there a real world / motivating use for a graph defined this way? thomas. 2008/1/18, Christian Maeder : > Hi, > > Given a complete graph as a list of nodes whose edge labels are given by > a function over two nodes: > > data CGraph a b = CGraph [a] (a -> a -> b) > > Can I define an instance for the fgl Graph class? > > import Data.Graph.Inductive.Graph > > instance Graph CGraph where > empty = CGraph [] -- and now? > > I had no idea how to define empty (except using undefined). > > I thought of requiring a context for the node labels of type a, but this > type is not mentioned in the class header. So it looked to me like the > impossibility to define sets (requiring an Ord) as monads. (i.e. > instance Monad Data.Set.Set) > > Any working proposals for my graph problem? > > Cheers Christian > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From stevelihn at gmail.com Sat Jan 19 12:22:43 2008 From: stevelihn at gmail.com (Steve Lihn) Date: Sat Jan 19 12:22:41 2008 Subject: [Haskell-cafe] First go at reactive programming In-Reply-To: References: <478C98FF.2060903@optusnet.com.au> <478F25C6.6020306@optusnet.com.au> Message-ID: > -- | @'forever' act@ repeats the action infinitely. > forever :: (Monad m) => m a -> m () > forever a = a >> forever a Great. The code compiled successfully by inserting this in various places. > I'm wondering how hard to try to get these libs to work with both 6.6 and > 6.8. My hope has been that people will switch to 6.8, but perhaps there are > obstacles I don't know about. Is there something that keeps you from > upgrading? I am asking this question in another thread. The problem is -- I've got many modules compiled under 6.6, some with much agony. If I switch to 6.8, I have to recompile them again. Two issues I image: (1) It may take lots of effort to recompile all the modules. I have forgetten how I got around some of the modules! Too bad... Got to take notes next time... (2) If I got stuck in 6.8, it may not be easy to switch back. It does not appear straightforward to me. I'd like to hear how other people approach these issues before I jump into it. Don't want to break the working environment that I spent months to set up! -- Finally, get to test the Reactive sample code. (1) Levi's first post compiled successfully and worked like charm. Congrat. (2) Levi's second post did not compile. There is a type error... react.hs:33:65: Couldn't match expected type `Handle' against inferred type `RequestHandler' In the first argument of `handleConnection', namely `r' In the first argument of `fmap', namely `(handleConnection r)' In the second argument of `(.)', namely `fmap (handleConnection r)' Thanks. Steve From jon at ffconsultancy.com Sat Jan 19 12:30:50 2008 From: jon at ffconsultancy.com (Jon Harrop) Date: Sat Jan 19 12:37:23 2008 Subject: [Haskell-cafe] Throwback of inferred types Message-ID: <200801191730.50916.jon@ffconsultancy.com> Is it possible to get throwback of inferred types into Emacs or an IDE for Haskell? -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?e From gwern0 at gmail.com Sat Jan 19 12:38:58 2008 From: gwern0 at gmail.com (gwern0@gmail.com) Date: Sat Jan 19 12:39:23 2008 Subject: [Haskell-cafe] First go at reactive programming In-Reply-To: References: <478C98FF.2060903@optusnet.com.au> <478F25C6.6020306@optusnet.com.au> Message-ID: <20080119173858.GA19970@localhost> On 2008.01.19 12:22:43 -0500, Steve Lihn scribbled 1.5K characters: ... > I am asking this question in another thread. The problem is -- I've > got many modules compiled under 6.6, some with much agony. If I switch > to 6.8, I have to recompile them again. Two issues I image: > > (1) It may take lots of effort to recompile all the modules. I have > forgetten how I got around some of the modules! Too bad... Got to take > notes next time... These days, every package you'd want to install (with the exception of GHC, Darcs, and the large graphics toolkits) should be available on Hackage or at least in Cabalized form. If they aren't, then that's a bug or at least missing feature. The whole point of Cabal was so you don't have to take notes! > (2) If I got stuck in 6.8, it may not be easy to switch back. Well, uh, is that really a bad thing? Do you worry about device drivers 'because if I got stuck in the 2.x series of Linux kernels, it may not be easy to switch back [to 1.x]'? No; 6.8.x is the future. The older GHCs will fall behind, people will rightfully upgrade, things will bitrot, and so on. There's no real benefit to willfully using outdated software - the most painful parts of the 6.8.x upgrade are past. > It does not appear straightforward to me. I'd like to hear how other > people approach these issues before I jump into it. Don't want to > break the working environment that I spent months to set up! I began darcs send'ing patches for stuff broken by 6.8.x; by this point, all the major stuff I use is fixed, at least out of Darcs (although many packages are woefully outdated on Hackage. I've been working on this). ... > Thanks. > Steve -- gwern Information II captain SAS BRLO unclassified of Audiotel Taiwan RSOC -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080119/114df211/attachment.bin From gwern0 at gmail.com Sat Jan 19 12:42:22 2008 From: gwern0 at gmail.com (gwern0@gmail.com) Date: Sat Jan 19 12:42:53 2008 Subject: [Haskell-cafe] Throwback of inferred types In-Reply-To: <200801191730.50916.jon@ffconsultancy.com> References: <200801191730.50916.jon@ffconsultancy.com> Message-ID: <20080119174222.GA20380@localhost> On 2008.01.19 17:30:50 +0000, Jon Harrop scribbled 0.2K characters: > > Is it possible to get throwback of inferred types into Emacs or an IDE for > Haskell? > > -- > Dr Jon D Harrop, Flying Frog Consultancy Ltd. Sure. I once hacked together quite a while ago a little function for haskell-mode which looked like: ,---- | (defun getHaskellFunctionTypeSignature () | (interactive) | (progn | (setq file-name buffer-file-name) | (setq functionName (thing-at-point 'word)) | (shell-command (concat "echo :t " functionName " | ghci -v0 -cpp -fglasgow-exts -w " file-name "|grep " functionName) t))) | (global-set-key "\C-c\l" 'getHaskellFunctionTypeSignature) `---- And I think haskell-mode has a better way of doing things somewhere in its inf-haskell.el. -- gwern Information II captain SAS BRLO unclassified of Audiotel Taiwan RSOC -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080119/717223cb/attachment-0001.bin From bf3 at telenet.be Sat Jan 19 13:08:35 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Sat Jan 19 13:08:29 2008 Subject: [Haskell-cafe] Throwback of inferred types In-Reply-To: <200801191730.50916.jon@ffconsultancy.com> References: <200801191730.50916.jon@ffconsultancy.com> Message-ID: <001601c85ac6$4ed27920$ec776b60$@be> Visual Haskell does that, but IMHO not as good as the F# plugin for Visual Studio. Currently I just use Emacs and Haskell Mode and the ":t" command, but this only works for top level functions (is this correct? Maybe some syntax exists to refer to an inner function?), so yeah, it would be really handy to have a good IDE that shows you the inferred types on the fly. > -----Original Message----- > From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe- > bounces@haskell.org] On Behalf Of Jon Harrop > Sent: Saturday, January 19, 2008 6:31 PM > To: haskell-cafe@haskell.org > Subject: [Haskell-cafe] Throwback of inferred types > > > Is it possible to get throwback of inferred types into Emacs or an IDE > for > Haskell? > > -- > Dr Jon D Harrop, Flying Frog Consultancy Ltd. > http://www.ffconsultancy.com/products/?e > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From ben.franksen at online.de Sat Jan 19 13:07:31 2008 From: ben.franksen at online.de (Ben Franksen) Date: Sat Jan 19 13:10:00 2008 Subject: [Haskell-cafe] Re: Re: Re: 0/0 > 1 == False References: <20080111145420.1c82c377@solaris.tower> <20080111170335.GH27808@darcs.net> <20080111191247.55ab360d@solaris.tower> <51AF6510-6CC0-4D8A-94AA-D704CE47510A@fastmail.fm> <20080112082519.4e7d81f2@solaris.tower> <200801120920.m0C9KXdT009948@mi1.bluebottle.com> <20080112104517.411627aa@solaris.tower> <20080112112432.674dcaff@solaris.tower> <200801121127.m0CBRX3E023254@mi0.bluebottle.com> <200801191050.m0JAo95h016973@mi0.bluebottle.com> Message-ID: Kalman Noel wrote: > Ben Franksen wrote: >> Kalman Noel wrote: >> > (2) lim a_n = ? > [...] >> > (2) means that the sequence does not converge, because you can >> > always find a value that is /larger/ than what you hoped might >> > be the limit. >> >> (2) usually rather mean that for each positive limit A there is a number >> N such that a_N > A for /all/ n > N. > > You're right here. I tried to come up with a more wordy, informal > description, but failed on that. > >> Your definition of (2) is usually termed as '(a_n) contains a subsequence >> that tends toward +infinity'. > > May you elaborate? I don't see where a subsequence comes into play here. I'll show (2) <=> (2'), where (2'): (a_n) contains a subsequence that tends toward +infinity "=>" : Assume (2) holds. Construct a subsequence (b_m) of (a_n) by chosing, for each natural number m, an index n_m such that b_m = n_(n_m) is larger than m (which is possible by (2)). Then (b_m) is a subsequence of (a_n) that tends toward infinity (as I defined it). "<=" : Assume (2') holds. Let A > 0 be any positive number (that you "hope might be the limit"). We want to show that we can find N such that a_N > A. To do so, chose a M, such that b_M > A (which is possible by assumption). Then there exists an N such that a_N = b_M, because (b_n) is a subsequence of (a_n). q.e.d Cheers Ben From bf3 at telenet.be Sat Jan 19 13:11:13 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Sat Jan 19 13:11:15 2008 Subject: [Haskell-cafe] Throwback of inferred types In-Reply-To: <20080119174222.GA20380@localhost> References: <200801191730.50916.jon@ffconsultancy.com> <20080119174222.GA20380@localhost> Message-ID: <001701c85ac6$ad420a70$07c61f50$@be> The problem is that this only works when the complete source file compiles correctly no? I would find it most useful to get type inference information on the fly, even when not all of the code compiles correctly yet. > -----Original Message----- > From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe- > bounces@haskell.org] On Behalf Of gwern0@gmail.com > Sent: Saturday, January 19, 2008 6:42 PM > To: Jon Harrop; haskell-cafe@haskell.org > Subject: Re: [Haskell-cafe] Throwback of inferred types > > On 2008.01.19 17:30:50 +0000, Jon Harrop > scribbled 0.2K characters: > > > > Is it possible to get throwback of inferred types into Emacs or an > IDE > > for Haskell? > > > > -- > > Dr Jon D Harrop, Flying Frog Consultancy Ltd. > > Sure. I once hacked together quite a while ago a little function for > haskell-mode which looked like: > > ,---- > | (defun getHaskellFunctionTypeSignature () > | (interactive) > | (progn > | (setq file-name buffer-file-name) > | (setq functionName (thing-at-point 'word)) > | (shell-command (concat "echo :t " functionName " | ghci -v0 -cpp > | -fglasgow-exts -w " file-name "|grep " functionName) t))) > | (global-set-key "\C-c\l" 'getHaskellFunctionTypeSignature) > `---- > > And I think haskell-mode has a better way of doing things somewhere in > its inf-haskell.el. > > -- > gwern > Information II captain SAS BRLO unclassified of Audiotel Taiwan RSOC From benja.fallenstein at gmail.com Sat Jan 19 13:13:50 2008 From: benja.fallenstein at gmail.com (Benja Fallenstein) Date: Sat Jan 19 13:13:44 2008 Subject: [Haskell-cafe] functional graphs In-Reply-To: <4790A1B2.7030901@dfki.de> References: <4790A1B2.7030901@dfki.de> Message-ID: Hi Christian, On Jan 18, 2008 1:55 PM, Christian Maeder wrote: > data CGraph a b = CGraph [a] (a -> a -> b) > > Can I define an instance for the fgl Graph class? > > I had no idea how to define empty (except using undefined). Well, presumably the function does not need to be defined on values not in the list, so returning an error is fair enough-- empty = CGraph [] (const $ error "Node not in graph") I suppose you want to use the index in the list as the Node (= Int), which should be fine, but you'll run into problems with mkGraph, because you don't have an Eq constraint on a, so you can't implement the function to pass to CGraph. Since mkGraph is required to have the type mkGraph :: [LNode a] -> [LEdge b] -> CGraph a b for *all* a and b, you don't have a way to add an Eq constraint anywhere, either. So, no dice... However, if you'd be able to live with data CGraph a b = CGraph [LNode a] (Node -> Node -> b) then you should be able to write the instance like this-- instance Graph CGraph where empty = CGraph [] (const $ error "Node not in graph") isEmpty (CGraph xs _) = null xs labNodes (CGraph xs _) = xs mkGraph nodes edges = CGraph nodes f where f x y = fromMaybe (error "Edge not found") (lookup (x,y) edges') edges' = map (\(x,y,l) -> ((x,y),l)) edges match x (CGraph nodes f) = case lookup x nodes of Nothing -> (Nothing, CGraph nodes f) Just l -> let nodes' = filter ((/= x) . fst) nodes left = map (\(y,_) -> (f y x, y)) nodes' right = map (\(y,_) -> (f x y, y)) nodes' in (Just (left, x, l, right), CGraph nodes' f) - Benja From benja.fallenstein at gmail.com Sat Jan 19 13:15:52 2008 From: benja.fallenstein at gmail.com (Benja Fallenstein) Date: Sat Jan 19 13:15:47 2008 Subject: [Haskell-cafe] functional graphs In-Reply-To: <910ddf450801190905i2d8c7c9doaf897a0e96d366e1@mail.gmail.com> References: <4790A1B2.7030901@dfki.de> <910ddf450801190856r330be968u4c689a415c6225fd@mail.gmail.com> <910ddf450801190905i2d8c7c9doaf897a0e96d366e1@mail.gmail.com> Message-ID: Hi, On Jan 19, 2008 6:05 PM, Thomas Hartman wrote: > Do you just assume that every two nodes have an edge between them [...]? Since that's what "complete graph" means, I assume so =-) - Benja From alfonso.acosta at gmail.com Sat Jan 19 14:36:55 2008 From: alfonso.acosta at gmail.com (Alfonso Acosta) Date: Sat Jan 19 14:36:49 2008 Subject: [Haskell-cafe] threads + IORefs = Segmentation fault? In-Reply-To: <20080119133643.GH6197@darcs.net> References: <20080118232255.GF6197@darcs.net> <1200745667.4032.3.camel@localhost.localdomain> <20080119133643.GH6197@darcs.net> Message-ID: <6a7c66fc0801191136t51afe0c8wad6552a6f2ce981b@mail.gmail.com> On Jan 19, 2008 2:36 PM, David Roundy wrote: > Using ghc 6.6, but I've since isolated the bug as being unrelated to the > IORefs and threading, it was in an FFI binding that somehow never died > until I was testing this new code. In case the you are creating a binding of haskell code. Did you make sure that the runtime constructor and destructor (hs_* functions) are properly called? The could be the source of the segfault. From kalman.noel at bluebottle.com Sat Jan 19 14:57:46 2008 From: kalman.noel at bluebottle.com (Kalman Noel) Date: Sat Jan 19 14:57:45 2008 Subject: [Haskell-cafe] Re: Re: Re: 0/0 > 1 == False In-Reply-To: References: <20080111191247.55ab360d@solaris.tower> <51AF6510-6CC0-4D8A-94AA-D704CE47510A@fastmail.fm> <20080112082519.4e7d81f2@solaris.tower> <200801120920.m0C9KXdT009948@mi1.bluebottle.com> <20080112104517.411627aa@solaris.tower> <20080112112432.674dcaff@solaris.tower> <200801121127.m0CBRX3E023254@mi0.bluebottle.com> <200801191050.m0JAo95h016973@mi0.bluebottle.com> Message-ID: <200801192001.m0JK1gHt029816@mi0.bluebottle.com> Ben Franksen wrote: > Kalman Noel wrote: > > Ben Franksen wrote: > >> Kalman Noel wrote: > >> > (2) means that the sequence does not converge, because you can > >> > always find a value that is /larger/ than what you hoped might > >> > be the limit. > >> Your definition of (2) is usually termed as '(a_n) contains a subsequence > >> that tends toward +infinity'. > I'll show (2) <=> (2'), where > > (2'): (a_n) contains a subsequence that tends toward +infinity Only now did I understand that your point was to explain why and how my definition (2) is incorrect. It's clear to me now. Kalman ---------------------------------------------------------------------- Finally - A spam blocker that actually works. http://www.bluebottle.com/tag/4 From jon at ffconsultancy.com Sat Jan 19 15:04:04 2008 From: jon at ffconsultancy.com (Jon Harrop) Date: Sat Jan 19 16:58:03 2008 Subject: [Haskell-cafe] Throwback of inferred types In-Reply-To: <001701c85ac6$ad420a70$07c61f50$@be> References: <200801191730.50916.jon@ffconsultancy.com> <20080119174222.GA20380@localhost> <001701c85ac6$ad420a70$07c61f50$@be> Message-ID: <200801192004.04836.jon@ffconsultancy.com> On Saturday 19 January 2008 18:11:13 Peter Verswyvelen wrote: > I would find it most useful to get type inference information on the fly, > even when not all of the code compiles correctly yet. Yes. Is this not provided by any development environments then? -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?e From ronguida at mindspring.com Sat Jan 19 17:31:01 2008 From: ronguida at mindspring.com (Ronald Guida) Date: Sat Jan 19 17:30:56 2008 Subject: [Haskell-cafe] Hangman game Message-ID: <1200781861.23242.0.camel@RonPcUbuntu> Hi, I'm interested in learning how to program games. Since I have to start somewhere, I decided to write a simple Hangman game. I'm wondering if anyone can look at my code and give me some feedback. Thank you. -- Hangman game module Main where import Data.Char import Data.List import System.IO import System.Random import Control.Monad.State data GameState = GameState { gsAnswer :: String, -- the answer gsKnown :: [Maybe Char], -- partial answer known to the user gsGuesses :: [Char], -- incorrect letters guessed so far gsWrong :: Int, -- number of incorrect guesses gsWonLost :: Maybe Bool -- Just true = won, Just false = lost } deriving (Show) newGameState :: String -> GameState newGameState answer = GameState{ gsAnswer = map toUpper answer, gsKnown = (map (filt $ not . isAlpha) answer), gsGuesses = [], gsWrong = 0, gsWonLost = Nothing} data UserInput = UIGuess Char | UIQuit | UINewGame | UIRefresh deriving (Show) main :: IO () main = do hSetBuffering stdout NoBuffering putStr "Welcome to Hangman!\n\n" putStr instructions runStateT startNewGame undefined return () startNewGame :: StateT GameState IO () startNewGame = do nWord <- liftIO $ getStdRandom (randomR (0,length wordList - 1)) let word = wordList !! nWord let gs = newGameState word put gs liftIO $ putStrLn $ renderGameState gs gameLoop gameLoop :: StateT GameState IO () gameLoop = do ui <- liftIO getUserInput case ui of UIGuess c -> do modify $ handleGuess c gs <- get liftIO $ putStrLn $ renderGameState gs case (gsWonLost gs) of Nothing -> gameLoop Just True -> do liftIO $ putStrLn "Congratulations, you won!" startNewGame Just False -> do liftIO $ putStrLn "You've been hanged!" liftIO $ putStrLn $ "The word was \'" ++ (gsAnswer gs) ++ "\'." startNewGame UIQuit -> do gs <- get liftIO $ putStrLn $ "The word was \'" ++ (gsAnswer gs) ++ "\'." liftIO $ putStrLn "Thank you for playing!" UINewGame -> do gs <- get liftIO $ putStrLn $ "The word was \'" ++ (gsAnswer gs) ++ "\'." startNewGame UIRefresh -> do gs <- get liftIO $ putStrLn $ renderGameState gs gameLoop getUserInput :: IO UserInput getUserInput = do putStr "Hangman> " response <- getLine if null response then getUserInput else do let c:cs = response if isAlpha c then return $ UIGuess $ toUpper c else if c == ':' && not (null cs) then case toLower (head cs) of 'q' -> return UIQuit 'n' -> return UINewGame 'r' -> return UIRefresh '?' -> do putStr instructions getUserInput otherwise -> do putStrLn $ "Unknown command \'" ++ cs ++ "\'" putStrLn $ "Use \':?\' for help." getUserInput else do putStrLn $ "Invalid input \'" ++ response ++ "\'" putStrLn $ "Use \':?\' for help." getUserInput instructions :: String instructions = "Instructions:\n" ++ "To guess a letter, type the letter and press enter.\n" ++ "To quit or restart the game, use the following commands:\n" ++ " :q = quit\n" ++ " :n = new game\n" ++ " :r = re-display the game state\n" ++ " :? = show instructions\n" ++ "\n" filt :: (a -> Bool) -> a -> Maybe a filt pred x = if pred x then Just x else Nothing handleGuess :: Char -> GameState -> GameState handleGuess ch state = if (elem ch $ gsGuesses state) then state else if (elem ch $ gsAnswer state) then let revealed = map (filt (== ch)) (gsAnswer state) known = zipWith mplus (gsKnown state) revealed won = all (maybe False (const True)) known in state{gsKnown = known, gsWonLost = filt id won} else let wrong = 1 + (gsWrong state) in state{gsGuesses = ch:(gsGuesses state), gsWrong = wrong, gsWonLost = filt not (wrong < 7)} wordList :: [String] wordList = ["alligator", "angelfish", "ant", "bear", "buffalo", "butterfly", "canary", "chameleon", "crab", "dinosaur", "dog", "dolphin", "eel", "elephant", "flamingo", "frog", "giraffe", "goldfish", "grasshopper", "hedgehog", "hippopotamus", "horse", "iguana", "jaguar", "jellyfish", "kangaroo", "kinkajou", "lemur", "lizard", "llama", "meerkat", "moose", "mouse", "narwhal", "nautilus", "nuthatch", "ostrich", "owl", "panda", "pelican", "quail", "quokka", "raccoon", "rhinoceros", "salamander", "sea horse", "sea urchin", "snail", "tiger", "toucan", "uakari", "unicorn", "vampire bat", "vulture", "walrus", "wildebeest", "worm", "xenops", "yak", "yellow jacket", "zebra"] renderGameState :: GameState -> String renderGameState gs = let noose = renderNoose $ gsWrong gs report = ["","The Word:","",word,"","Your Guesses:","",guessed] word = intersperse ' ' $ map (maybe '_' id) (gsKnown gs) guessed = gsGuesses gs in (concat $ zipWith (++) noose $ map (++ "\n") report) renderNoose :: Int -> [String] renderNoose n | n <= 0 = [ " ___ ", " / | ", " | ", " | ", " | ", " | ", " | ", " -+- "] renderNoose 1 = [ " ___ ", " / | ", " | O ", " | ", " | ", " | ", " | ", " -+- "] renderNoose 2 = [ " ___ ", " / | ", " | O ", " | | ", " | ", " | ", " | ", " -+- "] renderNoose 3 = [ " ___ ", " / | ", " | O ", " | --| ", " | ", " | ", " | ", " -+- "] renderNoose 4 = [ " ___ ", " / | ", " | O ", " | --|-- ", " | ", " | ", " | ", " -+- "] renderNoose 5 = [ " ___ ", " / | ", " | O ", " | --|-- ", " | | ", " | ", " | ", " -+- "] renderNoose 6 = [ " ___ ", " / | ", " | O ", " | --|-- ", " | | ", " | / ", " | ", " -+- "] renderNoose n | n >= 7 = [ " ___ ", " / | ", " | O ", " | --|-- ", " | | ", " | / \\ ", " | ", " -+- "] From barsoap at web.de Sat Jan 19 17:54:43 2008 From: barsoap at web.de (Achim Schneider) Date: Sat Jan 19 17:54:49 2008 Subject: [Haskell-cafe] Re: Throwback of inferred types References: <200801191730.50916.jon@ffconsultancy.com> <20080119174222.GA20380@localhost> <001701c85ac6$ad420a70$07c61f50$@be> Message-ID: <20080119235443.4e877d50@solaris.tower> "Peter Verswyvelen" wrote: > The problem is that this only works when the complete source file > compiles correctly no? > ghc could just insert appropriate calls to error everywhere it can't compile, so you can choose whether to fix the bugs by lexical or operational ordering, ecj (the eclipse compiler) does exactly that. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From gale at sefer.org Sat Jan 19 18:21:26 2008 From: gale at sefer.org (Yitzchak Gale) Date: Sat Jan 19 18:21:22 2008 Subject: [Haskell-cafe] Hangman game In-Reply-To: <1200781861.23242.0.camel@RonPcUbuntu> References: <1200781861.23242.0.camel@RonPcUbuntu> Message-ID: <2608b8a80801191521o64094c4aq6b9bda240af1dbd8@mail.gmail.com> Hi Ronald, Ronald Guida wrote: > I'm interested in learning how to program games. Since I have to start > somewhere, I decided to write a simple Hangman game. I'm wondering if > anyone can look at my code and give me some feedback. Lots of fun, thanks! And nicely written. One point is that while it's OK to do your random calculation directly in IO for this simple case, in general you will have many random calculations and you will want to avoid forcing them all into IO. You can add one more field to GameState that holds a random generator. Let's say you call it gsRandGen. Make sure that gsRandGen gets initialized somewhere. Define this utility function: rand :: MonadState GameState m => (StdGen -> (a, StdGen)) -> m a rand f = do gs <- get let (x, g) = f $ gsRandGen gs put $ gs {gsRandGen = g} return x Now, instead of: > nWord <- liftIO $ getStdRandom (randomR (0,length wordList - 1)) you can write: > nWord <- rand $ randomR (0,length wordList - 1) If you want, you can even remove the dependence on StdGen by making some of your function types polymorphic, qualified where necessary by RandomGen g => ... Regards, Yitz From jonathanccast at fastmail.fm Sat Jan 19 19:05:57 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Sat Jan 19 19:05:55 2008 Subject: [Haskell-cafe] Re: 0/0 > 1 == False In-Reply-To: <20080119105215.GB5530@localdomain> References: <20080111145420.1c82c377@solaris.tower> <20080111170335.GH27808@darcs.net> <20080111191247.55ab360d@solaris.tower> <51AF6510-6CC0-4D8A-94AA-D704CE47510A@fastmail.fm> <20080112082519.4e7d81f2@solaris.tower> <200801120920.m0C9KXdT009948@mi1.bluebottle.com> <20080112104517.411627aa@solaris.tower> <20080112112432.674dcaff@solaris.tower> <200801121127.m0CBRX3E023254@mi0.bluebottle.com> <720E886C-9817-4006-B034-23F4911149E1@fastmail.fm> <20080119105215.GB5530@localdomain> Message-ID: <3878B8B3-1D3E-4703-A864-A29FB8EAAD0F@fastmail.fm> On 19 Jan 2008, at 2:52 AM, Kalman Noel wrote: > Jonathan Cast wrote: >> On 12 Jan 2008, at 3:23 AM, Kalman Noel wrote: >>> (2) lim a_n = ? > [...] >>> (2) means that the sequence does not converge, >> >> To a value in R. Again, inf is a perfectly well defined extended >> real number, and behaves like any other element of R u {-inf, inf}. >> (Although that structure isn't quite a field --- 0 * inf isn't >> defined, nor is inf - inf). > > Out of curiosity, is there some typical application domain for > extended real > numbers? In calculus and elementary analysis, the notion of limits at/to infinity, improper Riemann integrals, etc., are introduced by a succession of `special notations'. Taking the extended real numbers as the underlying space permits these notations to be defined more compositionally, because ? is now an ordinary mathematical object. For example, if f is a nonnegative measurable function, ?f on a measurable set is /always/ defined (as an extended real number) and the special case of an `integrable' function is simply one where the integral (which is an actual mathematical value) is an element of R. So, when we say ?f ? R, that notation is compositional --- that's real set membership there. Similarly, ?_{-?}^? f is defined (as a Lebesgue integral) the same way any other integral is, because the interval [-?, ?] is a perfectly good mathematical object. jcc From tphyahoo at gmail.com Sun Jan 20 00:56:17 2008 From: tphyahoo at gmail.com (Thomas Hartman) Date: Sun Jan 20 00:56:11 2008 Subject: [Haskell-cafe] overlapping instance error -- need help using instance Monoid (Sum a) where a is a map of "money" values Message-ID: <910ddf450801192156r747066c5kce4e59a83a57692b@mail.gmail.com> The code below compiles as given, however if I uncomment the tSM function I get the overlapping instance error mentioned in the subject line. Can someone give me advice on how to do what I want to do? basically I want to add, for example, (USD,1) and (USD,2) and (Euro,3) and get result fromList [(USD,3), (Euro,3)] the datatypes below are more verbose but the above is the basic idea thanks! thomas. ***** module TransactionRows {- ( mkTransactionRows,TransactionRows ) -} where import Data.Monoid import Data.List import qualified Data.Map as M data Currency a = Currency a deriving ( Show, Eq, Ord ) data Money c a = Money ( M.Map c a ) deriving Show instance (Num a, Ord c)=> Monoid ( Sum (Money c a) ) where mempty = Sum ( Money M.empty ) Sum ( Money m1 ) `mappend` Sum ( Money m2 ) = Sum (Money m1 `plusmoney` Money m2) plusmoney (Money m1s) (Money m2s) = Money msum where msum = foldl' f m1s (M.toList m2s) f m (k,v) = M.insertWith (+) k v m mkMoney1 :: Currency String -> Float -> Money (Currency String) Float mkMoney1 c a = Money $ M.singleton c a --sumMoney :: [Money (Currency String) Float] -> Money (Currency String) Float sumMoney ms = getSum $ mconcat $ map Sum ms -- if I uncomment this, get Overlapping instances for Monoid error --tSM = sumMoney [mkMoney1 (Currency "usd") 1 :: Money (Currency String) Float] From dave at zednenem.com Sun Jan 20 02:10:22 2008 From: dave at zednenem.com (David Menendez) Date: Sun Jan 20 02:10:17 2008 Subject: [Haskell-cafe] overlapping instance error -- need help using instance Monoid (Sum a) where a is a map of "money" values In-Reply-To: <910ddf450801192156r747066c5kce4e59a83a57692b@mail.gmail.com> References: <910ddf450801192156r747066c5kce4e59a83a57692b@mail.gmail.com> Message-ID: <49a77b7a0801192310y5aa66c3fw211483e48678993e@mail.gmail.com> On Jan 20, 2008 12:56 AM, Thomas Hartman wrote: > The code below compiles as given, however if I uncomment the tSM > function I get the overlapping instance error mentioned in the subject > line. > > Can someone give me advice on how to do what I want to do? > > basically I want to add, for example, (USD,1) and (USD,2) and (Euro,3) > and get result > > fromList [(USD,3), (Euro,3)] > > the datatypes below are more verbose but the above is the basic idea > > thanks! > > thomas. > > ***** > > module TransactionRows {- ( mkTransactionRows,TransactionRows ) -} where > import Data.Monoid > import Data.List > import qualified Data.Map as M > > data Currency a = Currency a > deriving ( Show, Eq, Ord ) > data Money c a = Money ( M.Map c a ) > deriving Show > instance (Num a, Ord c)=> Monoid ( Sum (Money c a) ) where > mempty = Sum ( Money M.empty ) > Sum ( Money m1 ) `mappend` Sum ( Money m2 ) = Sum (Money m1 > `plusmoney` Money m2) This is the overlap. Data.Monoid already defines an instance for Monoid (Sum a), so it's going to overlap with your Monoid (Sum (Money c a)). Unless you're planning to define more than one Monoid for Money, I suggest skipping Sum entirely. -- Dave Menendez -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080120/a31c60e3/attachment.htm From jamie.love at aviarc.com.au Sun Jan 20 02:26:39 2008 From: jamie.love at aviarc.com.au (Jamie Love) Date: Sun Jan 20 02:26:36 2008 Subject: [Haskell-cafe] Basic binary IO Message-ID: <4792F7AF.8040509@aviarc.com.au> Hello all, I'm wondering if anyone has a reference to any binary IO and data conversion tutorials. I'm playing around with generating a BMP file in haskell, and am a little stuck on the "best" way to go about the simple task of creating the BMP header. The header is "BM" + 4 bytes for file size + 4 bytes reserved + 4 bytes for offset where data begins. I have the basis starting off at: bmpHeader = B.pack $ [ 0x42, 0x4D ] ++ [0 , 0, 0, 0] ++ [0 , 0, 0, 0] ++ [14 :: Int32] (where B is Data.ByteString) I'm wondering how I can: 1/ convert a 32 bit number (Int32, Char32) to 4 Char8 elements 2/ rotate bits/bytes in a 32 bit Char32 (or Int32) so they are explicitly little-endian (I work on a mac powerbook, and it is big-endian) 3/ convert an Integer or Int type to an Int32 type Any pointers or suggestions would be helpful. Thanks -- Jamie Love Senior Consultant Aviarc Australia Mobile: +61 400 548 048 ------------------------------------------------------------ This message has been scanned for viruses and dangerous content by MailScanner and is believed to be clean. From allbery at ece.cmu.edu Sun Jan 20 02:28:51 2008 From: allbery at ece.cmu.edu (Brandon S. Allbery KF8NH) Date: Sun Jan 20 02:28:47 2008 Subject: [Haskell-cafe] Basic binary IO In-Reply-To: <4792F7AF.8040509@aviarc.com.au> References: <4792F7AF.8040509@aviarc.com.au> Message-ID: On Jan 20, 2008, at 2:26 , Jamie Love wrote: > I'm wondering if anyone has a reference to any binary IO and data > conversion tutorials. You want the binary package: http://hackage.haskell.org/cgi-bin/ hackage-scripts/package/binary-0.4.1 -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH From dons at galois.com Sun Jan 20 02:34:34 2008 From: dons at galois.com (Don Stewart) Date: Sun Jan 20 02:34:42 2008 Subject: [Haskell-cafe] Basic binary IO In-Reply-To: <4792F7AF.8040509@aviarc.com.au> References: <4792F7AF.8040509@aviarc.com.au> Message-ID: <20080120073434.GB12217@scytale.galois.com> jamie.love: > Hello all, > > I'm wondering if anyone has a reference to any binary IO and data > conversion tutorials. A good place to start looking is Data.Binary, http://hackage.haskell.org/cgi-bin/hackage-scripts/package/binary > I'm playing around with generating a BMP file in haskell, and am a > little stuck on the "best" way to go about the simple task of creating > the BMP header. The header is > > "BM" + 4 bytes for file size + 4 bytes reserved + 4 bytes for offset > where data begins. > > I have the basis starting off at: > > bmpHeader = runPut $ > [ 0x42, 0x4D ] ++ > [0 , 0, 0, 0] ++ > [0 , 0, 0, 0] ++ > [14 :: Int32] bmpHeader = runPut $ do put 'B' put 'M' put (0 :: Int32) put (0 :: Int32) put (14 :: Int32) Yields the lazy bytestring, "BM\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\SO" > (where B is Data.ByteString) > > I'm wondering how I can: > > 1/ convert a 32 bit number (Int32, Char32) to 4 Char8 elements Data.Binary.put (x :: Int32) etc. > 2/ rotate bits/bytes in a 32 bit Char32 (or Int32) so they are > explicitly little-endian (I work on a mac powerbook, and it is big-endian) Use the little endian 'put' primitives, putWord32le (fromIntegral (7 :: Int32)) > 3/ convert an Integer or Int type to an Int32 type > > Any pointers or suggestions would be helpful. fromIntegral Data.Binary should support all this nicely, I hope. -- Don From tretriluxana.s at gmail.com Sun Jan 20 02:41:58 2008 From: tretriluxana.s at gmail.com (Sukit Tretriluxana) Date: Sun Jan 20 02:41:53 2008 Subject: [Haskell-cafe] One-line haskell program with GHC In-Reply-To: <2EC85BB6-A9D8-4948-AAB8-FD2AB033E64B@fastmail.fm> References: <8252533f0801181357s50a1bf89y3dbb1253005521a4@mail.gmail.com> <6841b9520801181400w11dc1a95t66d671ccd796169a@mail.gmail.com> <2EC85BB6-A9D8-4948-AAB8-FD2AB033E64B@fastmail.fm> Message-ID: <8252533f0801192341p25664bcw5c130cc4c5d7cffe@mail.gmail.com> Thanks all. This really helps me a lot! On Jan 18, 2008 6:24 PM, Jonathan Cast wrote: > On 18 Jan 2008, at 2:00 PM, Clifford Beshers wrote: > > 2008/1/18 Sukit Tretriluxana : > > > Hi, > > > > I don't know if it's been asked before. I just wonder if GHC supports > > some sort of one-liner program that can be specify right as the argument to > > either ghci or runghc program. In perl, they have something like > > > > perl *-e* 'print "Hello"' > > > > Do we have similar thing with GHC? > > > > ghc -e 'putStrLn "Yes, we do."' > > > Although, unlike perl, you don't have to say print explicitly if you don't > need it: > > ghc -e '"This works great!"' > > jcc > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080119/2c100f5e/attachment.htm From jamie.love at aviarc.com.au Sun Jan 20 03:35:50 2008 From: jamie.love at aviarc.com.au (Jamie Love) Date: Sun Jan 20 03:35:45 2008 Subject: [Haskell-cafe] Basic binary IO In-Reply-To: <20080120073434.GB12217@scytale.galois.com> References: <4792F7AF.8040509@aviarc.com.au> <20080120073434.GB12217@scytale.galois.com> Message-ID: <479307E6.20805@aviarc.com.au> Ah, thanks Don, Brandon, I looked at this but neglected to read through and understand the example enough. Thanks for the tips, they're a great help. Don Stewart wrote: > jamie.love: > > bmpHeader = runPut $ do > put 'B' > put 'M' > put (0 :: Int32) > put (0 :: Int32) > put (14 :: Int32) > > Yields the lazy bytestring, > > "BM\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\SO" > -- Jamie Love Senior Consultant Aviarc Australia Mobile: +61 400 548 048 ------------------------------------------------------------ This message has been scanned for viruses and dangerous content by MailScanner and is believed to be clean. From dbryan.green at gmail.com Sun Jan 20 07:29:21 2008 From: dbryan.green at gmail.com (Bryan Green) Date: Sun Jan 20 07:29:14 2008 Subject: [Haskell-cafe] bytea decoding Message-ID: Does anyone know of a library that will handle bytea encodings from postgres? The bytea field that I need to access contains a jpg file. I want to retrieve it from the database and write it out for an image display program. bytea: Bytea octets are also escaped in the output. In general, each "non-printable" octet is converted into its equivalent three-digit octal value and preceded by one backslash. Most "printable" octets are represented by their standard representation in the client character set. The octet with decimal value 92 (backslash) has a special alternative output representation. Details are in Table 8-8. *Table 8-8. bytea Output Escaped Octets* Decimal Octet ValueDescriptionEscaped Output Representation ExampleOutput Result92backslash\\SELECT '\\134'::bytea;\\ 0 to 31 and 127 to 255 "non-printable" octets\*xxx* (octal value) SELECT '\\001'::bytea;\00132 to 126"printable" octetsclient character set representation SELECT '\\176'::bytea;~ Depending on the front end to PostgreSQL you use, you may have additional work to do in terms of escaping and unescaping bytea strings. For example, you may also have to escape line feeds and carriage returns if your interface automatically translates these. So, here is part of the file from the database: \377\330\377\340\000\020JFIF\000\001\001\000\000\001\000\001\000\000\377\333\000C\000\012\007\007\010\007\006\012\010\010\010\013\012\012\013\016\030\020\016\015\015\016\035\025\026\021\030#\037%$"\037"!&+7/&)4)!"0A149;>>>%.DIC;\377 I may have to write a converter myself but I don't like re-inventing the wheel if I don't need to do so. Any pointers would be greatly appreciated. Bryan Green -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080120/dd8135a8/attachment.htm From phercek at gmail.com Sun Jan 20 07:39:04 2008 From: phercek at gmail.com (Peter Hercek) Date: Sun Jan 20 07:39:07 2008 Subject: [Haskell-cafe] bug in all about monads tutorial Message-ID: Hi, About 3 weeks ago I reported this bug to Jeff Newbern. But I got no response - maybe I got filtered out as spam :) Since it was not fixed I'm trying once more here. Maybe there is somebody here who has access to the web site http://www.haskell.org/all_about_monads and cares enough to fix it. On page http://www.haskell.org/all_about_monads/html/writermonad.html there is "listens" defined like this: listens f m = do (a,w) <- m; return (a,f w) ... but it should be like this: listens f m = do (a,w) <- listen m; return (a,f w) ... or maybe a less strict option (as ghc libs have it): listens f m = do ~(a,w) <- listen m; return (a,f w) Peter. From paul at cogito.org.uk Sun Jan 20 12:08:49 2008 From: paul at cogito.org.uk (Paul Johnson) Date: Sun Jan 20 12:08:44 2008 Subject: [Haskell-cafe] Hangman game In-Reply-To: <1200781861.23242.0.camel@RonPcUbuntu> References: <1200781861.23242.0.camel@RonPcUbuntu> Message-ID: <47938021.3020002@cogito.org.uk> Ronald Guida wrote: > Hi, > > I'm interested in learning how to program games. Since I have to start > somewhere, I decided to write a simple Hangman game. I'm wondering if > anyone can look at my code and give me some feedback. Nicely written. The design reads very much like a straight translation from the imperative style, which is why so much of it is in the IO monad. There is nothing wrong with this for a simple game like Hangman, but for larger games it doesn't scale. So here are a few pointers to ways of rewriting it to keep the IO to the top level and the actual work in a functional style: 1: Your GameState type can itself be made into a monad. Take a look at the "All About Monads" tutorial, especially the State monad. Think about the invariants in GameState; can you produce a new monad that guarantees these invariants through a limited set of actions. How do these actions correspond to user perceptions? 2: You can layer monads by using monad transformers. Extend the solution to part 1 by using StateT IO instead of just State. 3: Your current design uses a random number generator in the IO monad. Someone already suggested moving that into the GameState. But you can also generate an infinite list of random numbers. Can you make your game a function of a list of random numbers? 4: User input can also be considered as a list. Haskell has "lazy input", meaning that you can treat user input as a list that actually only gets read as it is required. Can you make your game a function of the list of user inputs? How does this interact with the need to present output to the user? What about the random numbers? Good luck, Paul. From nionita at lycos.de Sun Jan 20 12:12:01 2008 From: nionita at lycos.de (Nicu Ionita) Date: Sun Jan 20 12:12:22 2008 Subject: [Haskell-cafe] Need help with Parsec Message-ID: <001a01c85b87$95b30870$14b2a8c0@A64X2> Hi, I'm playing since a few hours with Parsec and trying to write a small html (fragment) parser, but I'm stuck in a point which I really can't understand. The problem seem to be either in "parseProperCont" or in "closing" (see code below). It looks like closing does not work (but it is a very simple function!) or (also hard to believe) function "try" from Parsec has some problems. Anyway I get this answer: Prelude ParseSHtml> pf parseHtmlFrg "ptest.txt" Left "ptest.txt" (line 5, column 2): unexpected "/" expecting element name when I'm parsing this file: with this code (sorry for the longer mail): import Text.ParserCombinators.Parsec hiding (label) import Text.XHtml.Strict -- Helper function: parse a string up to one of the given chars upTo :: [Char] -> Parser [Char] upTo ds = many1 (noneOf ds) parseHtmlFrg :: Parser Html parseHtmlFrg = do many space choice [parseElem, parseText] "html fragment" parseElem :: Parser Html parseElem = do en <- parseElTag many1 space (ats, cnt) <- restElem en return $ compElem en cnt ! ats "html element" -- Compose a html element from tag name and content compElem en cnt = if isNoHtml cnt then itag en else tag en cnt parseElTag :: Parser String parseElTag = do char '<' en <- elemName return en "element tag" elemName :: Parser String elemName = many1 lower "element name" restElem :: String -> Parser ([HtmlAttr], Html) restElem nm = do ats <- parseAttList ht <- (restElNoCont <|> restElCont nm) return (ats, ht) ("> or /> to close the tag " ++ nm) -- Rest element with no content restElNoCont = do char '/' char '>' return noHtml "/>" -- Rest element with content restElCont nm = do char '>' many space els <- parseProperCont nm return $ concatHtml els "element with content" -- Parse closing tag or proper content(s) parseProperCont :: String -> Parser [Html] parseProperCont nm = try (do closing nm return [] ) <|> (do h <- parseHtmlFrg hs <- parseProperCont nm return (h:hs) ) -- <|> return [] "proper element content" closing nm = do char '<' char '/' nm1 <- elemName char '>' if nm1 == nm then return () else fail $ nm ++ ", encountered " ++ nm1 ("closing of " ++ nm) -- Parse a html attribute parseAttr :: Parser HtmlAttr parseAttr = do at <- many1 lower char '=' va <- parseQuote many space return $ strAttr at va "Attribut" parseAttList = many1 parseAttr <|> return [] "attribute list" -- Parse a quoted string parseQuote :: Parser String parseQuote = do char '"' cs <- upTo ['"'] char '"' return cs -- Parse a text element parseText :: Parser Html parseText = do s <- upTo "<" return (stringToHtml s) "some text" -- For tests: pf p file = parseFromFile p file Nicu From brad.larsen at gmail.com Sun Jan 20 12:20:32 2008 From: brad.larsen at gmail.com (Brad Larsen) Date: Sun Jan 20 12:20:22 2008 Subject: [Haskell-cafe] Type issues for a foldable trie in Haskell Message-ID: Hello there, I have written a trie in Haskell generalized to Eq a => [a] rather than simply String. I want to make this type an instance of Foldable, but I've run into a type dilemma. My datatypes look like this: data TrieElem a = Elem a | Start | End deriving (Read, Show, Eq, Ord) data Trie a = Trie {label :: TrieElem a ,children :: [Trie a]} deriving (Read, Show, Eq, Ord) The signature of Data.Foldable.foldr is (Data.Foldable.Foldable t) => (a -> b -> b) -> b -> t a -> b. However, I want the functions in Foldable to operate on the _list type_ that Trie stores rather than the _elements_ of that list type---Trie a stores lists of type a. For example, a Trie storing strings would have type Trie Char, and I want Trie Char to be Foldable, but where the functions operate on String rather than Char. So, with the datatype definitions of Trie and TrieElem as they are above, to define a fold function that operates the way I want would have signature ([a] -> b -> b) -> b -> Trie a -> b, which is no good for making Trie a an instance of Foldable. Hopefully this doesn't just seem like rambling :-). How might I rewrite my datatypes to do what I want, preferably without using ghc extensions? Thanks! Brad Larsen From s.clover at gmail.com Sun Jan 20 12:24:57 2008 From: s.clover at gmail.com (Sterling Clover) Date: Sun Jan 20 12:24:58 2008 Subject: [Haskell-cafe] Need help with Parsec In-Reply-To: <001a01c85b87$95b30870$14b2a8c0@A64X2> References: <001a01c85b87$95b30870$14b2a8c0@A64X2> Message-ID: Here's a handy simple function I've found very useful. You'll obviously also need to import Debug.Trace: pTrace s = pt <|> return () where pt = try $ do x <- try $ many1 anyChar trace (s++": " ++x) $ try $ char 'z' fail x It could perhaps be cleaner, but it does the job for me fine. Just insert a line like pTrace "label" anywhere in your parsing functions and whenever parsec hits that line you get a nice line of output: "label: " This tends to help track down just where your code goes wrong. Try works like it should in my experience, but that doesn't necessarily mean it works how you expect. Regards, s On Jan 20, 2008, at 12:12 PM, Nicu Ionita wrote: > Hi, > > I'm playing since a few hours with Parsec and trying to write a > small html > (fragment) parser, but I'm stuck in a point which I really can't > understand. > > The problem seem to be either in "parseProperCont" or in > "closing" (see code > below). It looks like closing does not work (but it is a very simple > function!) or (also hard to believe) function "try" from Parsec has > some > problems. > > Anyway I get this answer: > > Prelude ParseSHtml> pf parseHtmlFrg "ptest.txt" > Left "ptest.txt" (line 5, column 2): > unexpected "/" > expecting element name > > when I'm parsing this file: > >
> one line with break
> another line

> Mail: user@dom.at >
> > with this code (sorry for the longer mail): > > import Text.ParserCombinators.Parsec hiding (label) > import Text.XHtml.Strict > > -- Helper function: parse a string up to one of the given chars > upTo :: [Char] -> Parser [Char] > upTo ds = many1 (noneOf ds) > > parseHtmlFrg :: Parser Html > parseHtmlFrg = do many space > choice [parseElem, parseText] > "html fragment" > > parseElem :: Parser Html > parseElem = do en <- parseElTag > many1 space > (ats, cnt) <- restElem en > return $ compElem en cnt ! ats > "html element" > > -- Compose a html element from tag name and content > compElem en cnt = if isNoHtml cnt then itag en else tag en cnt > > parseElTag :: Parser String > parseElTag = do char '<' > en <- elemName > return en > "element tag" > > elemName :: Parser String > elemName = many1 lower "element name" > > restElem :: String -> Parser ([HtmlAttr], Html) > restElem nm = do ats <- parseAttList > ht <- (restElNoCont <|> restElCont nm) > return (ats, ht) > ("> or /> to close the tag " ++ nm) > > -- Rest element with no content > restElNoCont = do char '/' > char '>' > return noHtml > "/>" > > -- Rest element with content > restElCont nm = do char '>' > many space > els <- parseProperCont nm > return $ concatHtml els > "element with content" > > -- Parse closing tag or proper content(s) > parseProperCont :: String -> Parser [Html] > parseProperCont nm = try (do closing nm > return [] > ) > <|> (do h <- parseHtmlFrg > hs <- parseProperCont nm > return (h:hs) > ) > -- <|> return [] > "proper element content" > > closing nm = do char '<' > char '/' > nm1 <- elemName > char '>' > if nm1 == nm > then return () > else fail $ nm ++ ", encountered " ++ nm1 > ("closing of " ++ nm) > > -- Parse a html attribute > parseAttr :: Parser HtmlAttr > parseAttr = do at <- many1 lower > char '=' > va <- parseQuote > many space > return $ strAttr at va > "Attribut" > parseAttList = many1 parseAttr <|> return [] "attribute list" > > -- Parse a quoted string > parseQuote :: Parser String > parseQuote = do char '"' > cs <- upTo ['"'] > char '"' > return cs > > -- Parse a text element > parseText :: Parser Html > parseText = do s <- upTo "<" > return (stringToHtml s) > "some text" > > -- For tests: > pf p file = parseFromFile p file > > Nicu > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From agl at imperialviolet.org Sun Jan 20 12:37:59 2008 From: agl at imperialviolet.org (Adam Langley) Date: Sun Jan 20 12:37:54 2008 Subject: [Haskell-cafe] bytea decoding In-Reply-To: References: Message-ID: <396556a20801200937y525f6563sa1a62d856721116d@mail.gmail.com> 2008/1/20 Bryan Green : > Does anyone know of a library that will handle bytea encodings from > postgres? The bytea field that I need to access contains a jpg file. I > want to retrieve it from the database and write it out for an image display > program. I'd love to see Don give the correct ByteString solution, but here's a slow version I knocked up (probably buggy): import qualified Data.ByteString as B import Data.ByteString.Internal (c2w) import Data.Maybe (catMaybes) import Data.List (mapAccumL) byteaDecode :: B.ByteString -> B.ByteString byteaDecode = B.pack . catMaybes . snd . mapAccumL f initState . B.unpack where initState = (0, 0) f (0, _) 92 = ((1, 0), Nothing) f (0, _) x = ((0, 0), Just x) f (1, _) 92 = ((0, 0), Just 92) f (3, n) x = ((0, 0), Just (n * 8 + (x - 48))) f (c, n) x = ((c + 1, n * 8 + (x - 48)), Nothing) AGL -- Adam Langley agl@imperialviolet.org http://www.imperialviolet.org 650-283-9641 From lauri.pesonen at iki.fi Sun Jan 20 13:18:08 2008 From: lauri.pesonen at iki.fi (Lauri Pesonen) Date: Sun Jan 20 13:18:00 2008 Subject: [Haskell-cafe] Data.Binary questions Message-ID: Hi, I'm relatively new to Haskell so please bear with me. I'm trying to parse Java class files with Data.Binary and I'm having a few problems: (The class file format is described here: http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html and the bytecode instructions are described here: http://java.sun.com/docs/books/jvms/second_edition/html/Instructions.doc.html ) 1. The class file format contains a number of tables. The table definitions start with the length of the list and carry on with that many table entries. Lists would be a good representation for them in Haskell, because there is not need to index them directly (except with the constants table). I've created my own list type so that I can redefine the serialisation functions for it so that the serialisation matches the format defined in the class file format: newtype MyList e = MkList ([e]) deriving Show instance (Binary e) => Binary (MyList e) where put (MkList es) = do put (fromIntegral (length es) :: Word16) mapM_ put es get = do n <- get :: Get Word16 xs <- replicateM (fromIntegral n) get return (MkList xs) The problem is that one of the tables, namely the attribute_info structures, use a u32 length field whereas all the other tables use a u16 length field. My implementation uses u16, but it would be nice to be able to use the same data type for both types of tables. I think I can do it by adding a lenght field to MyList and specifying the type when I use MyList in some other data structure, but that would also mean that I have to keep track of the length of the list manually? I'm basically copy-pasting the same code just to use a u32 length field in the serialised form: data Info = MkInfo [Word8] deriving Show instance Binary Info where put (MkInfo xs) = do put (fromIntegral (length xs) :: Word32) mapM_ put xs get = do n <- get :: Get Word32 xs <- replicateM (fromIntegral n) get return (MkInfo xs) 2. This is the bigger problem. The Java class file contains a constants table in the beginning of the file. The other fields later on in the class file contain indexes that reference entries in that constants table. So in order to be able to replace an index in a data structure with the actual string, I need to be able to look up the string from the constants table while I'm deserialising the field. My guess is that I should be able to put the constants table into a state monad. On the other hand Data.Binary already uses the state monad for holding onto the binary data being deserialised. So it's not clear to me if I can use StateT with Data.Binary.Get? And if not, can I implement my own state monad and do it that way? I'm not very comfortable with Monads yet, so I might be missing something very obvious. This is what the get function looks like in my top-level Data.Binary instance: get = do magic <- get :: Get Word32 case magic == magicNumber of -- class files start with 0xCAFEBABE True -> do min <- get -- minor version number u16 maj <- get -- major version number u16 c <- get -- constants table a <- get -- access flags (public, abstract, ...) u16 t <- get -- a u16 index pointing to the name of this class in the constants table s <- get -- a u16 index pointing to the name of the super class in the constants table i <- get -- a table of interfaces f <- get -- a table of fields m <- get -- a table of methods attrs <- get -- a table of class level attributes return (ClassFile (min, maj) c a t s i f m attrs) False -> error "Invalid magic number" Thanks for all the help! -- ! Lauri From derek.a.elkins at gmail.com Sun Jan 20 12:57:35 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Sun Jan 20 13:58:14 2008 Subject: [Haskell-cafe] Data.Binary questions In-Reply-To: References: Message-ID: <1200851855.5570.32.camel@derek-laptop> On Sun, 2008-01-20 at 18:18 +0000, Lauri Pesonen wrote: > Hi, > > I'm relatively new to Haskell so please bear with me. I'm trying to > parse Java class files with Data.Binary and I'm having a few problems: > > (The class file format is described here: > http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html > and the bytecode instructions are described here: > http://java.sun.com/docs/books/jvms/second_edition/html/Instructions.doc.html > ) > > 1. The class file format contains a number of tables. The table > definitions start with the length of the list and carry on with that > many table entries. Lists would be a good representation for them in > Haskell, because there is not need to index them directly (except > with the constants table). I've created my own list type so that I can > redefine the serialisation functions for it so that the serialisation > matches the format defined in the class file format: > > newtype MyList e = MkList ([e]) > deriving Show > > instance (Binary e) => Binary (MyList e) where > put (MkList es) = do > put (fromIntegral (length es) :: Word16) > mapM_ put es > > get = do > n <- get :: Get Word16 > xs <- replicateM (fromIntegral n) get > return (MkList xs) > > The problem is that one of the tables, namely the attribute_info > structures, use a u32 length field whereas all the other tables use a > u16 length field. My implementation uses u16, but it would be nice to > be able to use the same data type for both types of tables. I think I > can do it by adding a lenght field to MyList and specifying the type > when I use MyList in some other data structure, but that would also > mean that I have to keep track of the length of the list manually? You may want to consider using the other side of Data.Binary rather than the Binary class. The -class- Binary is intended for de/serialization when you don't care about the format. From the documentation: "For parsing and generating simple external binary formats (e.g. C structures), Binary may be used, but in general is not suitable for complex protocols. Instead use the Put and Get primitives directly." Nevertheless, one way to solve your problem is with a phantom type. Change MyList to, newtype MyList t e = MkList [e] deriving Show getLengthType :: MyList t e -> t getLengthType = undefined instance (Binary e) => Binary (MyList t e) where put l@(MkList es) = do put (fromIntegral (length es) `asTypeOf` getLengthType l) mapM_ put es get = do n <- get xs <- replicateM (fromIntegral (n `asTypeOf` getLengthType t)) get return (MkList xs `asTypeOf` t) where t = undefined The asTypeOfs are just to propagate the type information around. GHC's extension for scoped type variables would make this code simpler and more direct. At any rate, now the code will use the Binary instance for whatever type t is to serialize the length. > 2. This is the bigger problem. The Java class file contains a > constants table in the beginning of the file. The other fields later > on in the class file contain indexes that reference entries in that > constants table. So in order to be able to replace an index in a data > structure with the actual string, I need to be able to look up the > string from the constants table while I'm deserialising the field. > > My guess is that I should be able to put the constants table into a > state monad. On the other hand Data.Binary already uses the state > monad for holding onto the binary data being deserialised. So it's not > clear to me if I can use StateT with Data.Binary.Get? And if not, can > I implement my own state monad and do it that way? I'm not very > comfortable with Monads yet, so I might be missing something very > obvious. If you mean that you there references to the constant table in e.g. the fields table then the problem here is that you need to the class methods to use that monad transformer (in this case, ReaderT is all you should need and not even that), but you can't change their type. These are the kind of issues that make the Binary class unsuitable for this type of work. If that is the case, the only way to use this is to explicitly write out the deserialization code rather than relying on get, i.e. you'll have to write a function 'getTable constantTable' that will deserialize the table. From gale at sefer.org Sun Jan 20 14:03:31 2008 From: gale at sefer.org (Yitzchak Gale) Date: Sun Jan 20 14:03:24 2008 Subject: [Haskell-cafe] Hangman game In-Reply-To: <47938021.3020002@cogito.org.uk> References: <1200781861.23242.0.camel@RonPcUbuntu> <47938021.3020002@cogito.org.uk> Message-ID: <2608b8a80801201103j10bcacedw6d02853fb002ff14@mail.gmail.com> Hi Paul, You gave some suggestions of other styles of Haskell programming that Ronald could try for his program. These styles are definitely worth knowing, so if Ronald is not familiar with them, he may want to try them out. However, in most cases, I think what Ronald already did is nicer than what you are suggesting. Paul Johnson wrote: > The design reads very much like a straight translation > from the imperative style, which is why so much of it is in the IO > monad. There is nothing wrong with this for a simple game like Hangman, > but for larger games it doesn't scale. It's a state monad, and most of his code is in that style. It doesn't read to me like imperative style at all. And it scales beautifully. There is a lot of liftIO, because that is the bulk of the work in this program. But Ronald cleanly separated out the game logic, and even the pure parts of the UI logic, into pure functions like "handleGuess" and "renderGameState". I personally might have kept a more consistently monadic style by writing those as pure monads, like: handleGuess :: MonadState GameState m => Char -> m () renderGameState :: MonadState GameState m -> m String In certain situations, that approach gives more flexiblity. Like for refactoring, or adding new features. But Ronald's approach is also very nice, and I might also do that. > 1: Your GameState type can itself be made into a monad. Yes, it can. But StateT GameState IO is the perfect monad for this game - writing a new monad would just be reinventing the wheel. It would certainly be a good learning experience for understanding the inner workings of the state monad transformer, though. > 2: You can layer monads by using monad transformers. Extend the > solution to part 1 by using StateT IO instead of just State. I think he is already using that type. > 3: Your current design uses a random number generator in the IO monad. > Someone already suggested moving that into the GameState. But you can > also generate an infinite list of random numbers. Can you make your > game a function of a list of random numbers? He could, but I would advise against that technique. In more complex games, you may need to do many different kinds of random calculations in complex orders. Keeping a random generator inside a state monad is perfect for that. And since Ronald already set up the plumbing for the state monad, he is already home. Generating an infinite list from a random generator "burns up" the generator, making it unusable for any further calculations. Sometimes that doesn't matter, but I think it's a bad habit. I admit you'll catch me doing it sometimes though, in "quick and dirty" situations like at the GHCi prompt. > 4: User input can also be considered as a list. Haskell has "lazy > input", meaning that you can treat user input as a list that actually > only gets read as it is required. Can you make your game a function of > the list of user inputs? How does this interact with the need to > present output to the user? What about the random numbers? That type of "lazy IO" is considered by many to be one of Haskell's few warts. It is a hole in the type system that lets a small amount of side-effects leak through, and even that small amount leads to bugs. In many situations it's hard to avoid without making a wreck out of your whole program structure (though more and more tools are becoming available to help, such as the ByteString stuff). Ronald did great without it - why resort to that? All that said - this is clearly a matter of taste, of course. Thanks for bringing up a variety of approaches. Regards, Yitz From agl at imperialviolet.org Sun Jan 20 14:17:29 2008 From: agl at imperialviolet.org (Adam Langley) Date: Sun Jan 20 14:17:21 2008 Subject: [Haskell-cafe] CPP and INLINE pragmas Message-ID: <396556a20801201117y663d2f34gaa74e88af70bea91@mail.gmail.com> Since CPP mode removes newlines in the out macro expansion. It appears to be impossible to have a macro expand to a function with an INLINE pragma since it appears to need to be in its own line. For example: #define GETHOSTWORD(name, m, type) \ {-# INLINE name #-} \ name :: m type ; \ name = getPtr (sizeOf (undefined :: type)) \ Does work (since you can't follow the INLINE pragma with anything else on the same line. Likewise: #define GETHOSTWORD(name, m, type) \ name :: m type ; \ name = getPtr (sizeOf (undefined :: type)) \ {-# INLINE name #-} Also doesn't work since the INLINE needs to start at the beginning of a line. Has anyone a workaround for this, or a way to get the preprocessor to output a newline? Cheers AGL -- Adam Langley agl@imperialviolet.org http://www.imperialviolet.org 650-283-9641 From jon at ffconsultancy.com Sun Jan 20 15:54:08 2008 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun Jan 20 16:00:28 2008 Subject: [Haskell-cafe] Parsec benchmarks Message-ID: <200801202054.08530.jon@ffconsultancy.com> I'd like to compare the performance of Parsec to other parsers but the only reference to a benchmark I have found is a dead link from one of the papers about Parsec: http://research.microsoft.com/users/daan/download/parsec/parsec.pdf Are there any surviving Parsec benchmarks? -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?e From gwern0 at gmail.com Sun Jan 20 16:02:04 2008 From: gwern0 at gmail.com (gwern0@gmail.com) Date: Sun Jan 20 16:02:15 2008 Subject: [Haskell-cafe] Throwback of inferred types In-Reply-To: <001701c85ac6$ad420a70$07c61f50$@be> References: <200801191730.50916.jon@ffconsultancy.com> <20080119174222.GA20380@localhost> <001701c85ac6$ad420a70$07c61f50$@be> Message-ID: <20080120210204.GC11197@localhost> On 2008.01.19 19:11:13 +0100, Peter Verswyvelen scribbled 1.4K characters: > The problem is that this only works when the complete source file compiles > correctly no? Yes. As I said, it's a very hackish solution - think of it as proof-of-concept. > I would find it most useful to get type inference information on the fly, > even when not all of the code compiles correctly yet. Does that make sense? If the code doesn't compile, then how could any type-inference be trustable? It might be reliable if the error is in definitions which don't get called or otherwise used by the function you are asking after, but there are going to be edge-cases, I should think, where it would bite you. -- gwern Freeh ASU 32 CIO GGL Force 97 b in Macintosh -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080120/7aeccc13/attachment.bin From jon at ffconsultancy.com Sun Jan 20 16:02:43 2008 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun Jan 20 16:09:04 2008 Subject: [Haskell-cafe] Throwback of inferred types In-Reply-To: <20080120210204.GC11197@localhost> References: <200801191730.50916.jon@ffconsultancy.com> <001701c85ac6$ad420a70$07c61f50$@be> <20080120210204.GC11197@localhost> Message-ID: <200801202102.43497.jon@ffconsultancy.com> On Sunday 20 January 2008 21:02:04 gwern0@gmail.com wrote: > On 2008.01.19 19:11:13 +0100, Peter Verswyvelen scribbled 1.4K characters: > > I would find it most useful to get type inference information on the fly, > > even when not all of the code compiles correctly yet. > > Does that make sense? If the code doesn't compile, then how could any > type-inference be trustable? Note that this functionality continues to be widely used in other functional languages, e.g. SML, OCaml, F#. I can't think why Haskell would be any different. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?e From agl at imperialviolet.org Sun Jan 20 16:26:30 2008 From: agl at imperialviolet.org (Adam Langley) Date: Sun Jan 20 16:26:23 2008 Subject: [Haskell-cafe] Re: ANN: A triple of new packages for talking tothe outside world In-Reply-To: <396556a20801151933h6a1b16f0m385dd3b70b30080c@mail.gmail.com> References: <396556a20801081226l5ebf5062p685a80c6aac6ba41@mail.gmail.com> <20080109234352.3ee84d4a@solaris.tower> <20080110010123.GF18915@darcs.net> <396556a20801091725p4a2dbf8aw3117a568b807c195@mail.gmail.com> <20080110184521.GA17906@scytale.galois.com> <396556a20801151523t314797atb40fa26688c6ec6@mail.gmail.com> <20080115232647.GD30040@scytale.galois.com> <396556a20801151605y602e9781kdda7a771416b0b8@mail.gmail.com> <404396ef0801151701r64b97023y981e8bd3f95f3e24@mail.gmail.com> <396556a20801151933h6a1b16f0m385dd3b70b30080c@mail.gmail.com> Message-ID: <396556a20801201326y7a68905te9f02540ae5a47b@mail.gmail.com> On Jan 15, 2008 7:33 PM, Adam Langley wrote: > Ok, no TH ;) I've just uploaded binary-strict 0.2.2 to Hackage which factors most of the common code out via CPP. Hopefully I didn't break anything. AGL -- Adam Langley agl@imperialviolet.org http://www.imperialviolet.org 650-283-9641 From johan.tibell at gmail.com Sun Jan 20 16:33:10 2008 From: johan.tibell at gmail.com (Johan Tibell) Date: Sun Jan 20 16:33:02 2008 Subject: [Haskell-cafe] Parsec benchmarks In-Reply-To: <200801202054.08530.jon@ffconsultancy.com> References: <200801202054.08530.jon@ffconsultancy.com> Message-ID: <90889fe70801201333q94053cdm5487bf4519d99c63@mail.gmail.com> On Jan 20, 2008 9:54 PM, Jon Harrop wrote: > > I'd like to compare the performance of Parsec to other parsers but the only > reference to a benchmark I have found is a dead link from one of the papers > about Parsec: > > http://research.microsoft.com/users/daan/download/parsec/parsec.pdf > > Are there any surviving Parsec benchmarks? I'm very interested in a common benchmark which I could try my ByteString implementation of Parsec against. -- Johan From barsoap at web.de Sun Jan 20 16:34:15 2008 From: barsoap at web.de (Achim Schneider) Date: Sun Jan 20 16:34:23 2008 Subject: [Haskell-cafe] Re: Throwback of inferred types References: <200801191730.50916.jon@ffconsultancy.com> <20080119174222.GA20380@localhost> <001701c85ac6$ad420a70$07c61f50$@be> <20080120210204.GC11197@localhost> Message-ID: <20080120223415.51954fdc@solaris.tower> gwern0@gmail.com wrote: > Does that make sense? If the code doesn't compile, then how could any > type-inference be trustable? > Why, of course it is trustable, because it's going to fail, and that means that the code has type a -> _|_. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From duncan.coutts at worc.ox.ac.uk Sun Jan 20 17:06:04 2008 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Sun Jan 20 17:06:19 2008 Subject: [Haskell-cafe] Throwback of inferred types In-Reply-To: <200801202102.43497.jon@ffconsultancy.com> References: <200801191730.50916.jon@ffconsultancy.com> <001701c85ac6$ad420a70$07c61f50$@be> <20080120210204.GC11197@localhost> <200801202102.43497.jon@ffconsultancy.com> Message-ID: <1200866764.5639.366.camel@localhost> On Sun, 2008-01-20 at 21:02 +0000, Jon Harrop wrote: > On Sunday 20 January 2008 21:02:04 gwern0@gmail.com wrote: > > On 2008.01.19 19:11:13 +0100, Peter Verswyvelen scribbled > 1.4K characters: > > > I would find it most useful to get type inference information on the fly, > > > even when not all of the code compiles correctly yet. > > > > Does that make sense? If the code doesn't compile, then how could any > > type-inference be trustable? > > Note that this functionality continues to be widely used in other functional > languages, e.g. SML, OCaml, F#. I can't think why Haskell would be any > different. Really? That's pretty cool. How does it work? Does it use Achim's suggestion of replacing expressions which fail to type with new type vars and at runtime an error message with the type error? Or do they use something more hacky that we could also implement quickly? like: foo = 3 bar = 'c' baz = foo + bar So we infer: foo :: Int foo = 3 bar :: Char bar = 'c' baz :: a baz = error "No instance for (Num Char) arising from a use of `+' at foo.hs:5:6-14" That would be cool. Then I can run the bits of my program that still work. It'd make the editor/interpreter session rather more "live". How close do the IDEs/emacs-modes for SML, OCaml, F# come to that? What are we missing out on? :-) Duncan From isaacdupree at charter.net Sun Jan 20 17:19:03 2008 From: isaacdupree at charter.net (Isaac Dupree) Date: Sun Jan 20 17:18:58 2008 Subject: [Haskell-cafe] CPP and INLINE pragmas In-Reply-To: <396556a20801201117y663d2f34gaa74e88af70bea91@mail.gmail.com> References: <396556a20801201117y663d2f34gaa74e88af70bea91@mail.gmail.com> Message-ID: <4793C8D7.1010209@charter.net> Adam Langley wrote: > Since CPP mode removes newlines in the out macro expansion. It appears > to be impossible to have a macro expand to a function with an INLINE > pragma since it appears to need to be in its own line. that's because INLINE uses layout like everything else, so you can use semicolons for it too. > For example: > > #define GETHOSTWORD(name, m, type) \ > {-# INLINE name #-} \ > name :: m type ; \ > name = getPtr (sizeOf (undefined :: type)) \ > something like #define GETHOSTWORD(name, m, type) \ {-# INLINE name #-} ; \ name :: m type ; \ name = getPtr (sizeOf (undefined :: type)) \ ~Isaac From jon at ffconsultancy.com Sun Jan 20 17:18:52 2008 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun Jan 20 17:25:12 2008 Subject: [Haskell-cafe] Throwback of inferred types In-Reply-To: <1200866764.5639.366.camel@localhost> References: <200801191730.50916.jon@ffconsultancy.com> <200801202102.43497.jon@ffconsultancy.com> <1200866764.5639.366.camel@localhost> Message-ID: <200801202218.53157.jon@ffconsultancy.com> On Sunday 20 January 2008 22:06:04 Duncan Coutts wrote: > On Sun, 2008-01-20 at 21:02 +0000, Jon Harrop wrote: > > On Sunday 20 January 2008 21:02:04 gwern0@gmail.com wrote: > > > On 2008.01.19 19:11:13 +0100, Peter Verswyvelen > > > scribbled > > > > 1.4K characters: > > > > I would find it most useful to get type inference information on the > > > > fly, even when not all of the code compiles correctly yet. > > > > > > Does that make sense? If the code doesn't compile, then how could any > > > type-inference be trustable? > > > > Note that this functionality continues to be widely used in other > > functional languages, e.g. SML, OCaml, F#. I can't think why Haskell > > would be any different. > > Really? That's pretty cool. How does it work? With OCaml you compile with the -dtypes option and inferred types are available in the IDE. For example, in Emacs you hit C+C C+T to get the type of the subexpression under the cursor. In OCaIDE, this is provided as graphical throwback of the subexpression under the mouse in Eclipse and repeat type checking passes are automated. In F#, the Visual Studio mode provides the same functionality. I believe MLton provides the same functionality for SML. > Does it use Achim's suggestion of replacing expressions which fail to > type with new type vars and at runtime an error message with the type > error? I believe it just dumps the types of all subexpressions to file with source code locations as they are inferred. In the case of broken code, the given type is either non-existant (nothing is given because nothing has been inferred), more general that it should be (because later unifications have not yet been made) or wrong (which is most valuable when debugging type errors). > Or do they use something more hacky that we could also implement > quickly? OCaml generates .annot files that look like this: "nth.ml" 6 68 78 "nth.ml" 6 68 91 type( string -> int Gram.Entry.t ) "nth.ml" 6 68 92 "nth.ml" 6 68 97 type( int Gram.Entry.t ) "nth.ml" 6 68 92 "nth.ml" 6 68 97 type( string ) "nth.ml" 6 68 72 "nth.ml" 6 68 97 type( int Gram.Entry.t ) > That would be cool. Then I can run the bits of my program that still > work. It'd make the editor/interpreter session rather more "live". Exactly. > How close do the IDEs/emacs-modes for SML, OCaml, F# come to that? What > are we missing out on? :-) You're missing out on a lot if this isn't available for Haskell yet. I didn't realise just how invaluable this is until a system upgrade broke it and I really struggled to write OCaml code without it: I don't know how I managed before! Some people argue that functional programming languages don't need decent development environments but, having used F#, I know better... -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?e From jonathanccast at fastmail.fm Sun Jan 20 17:26:13 2008 From: jonathanccast at fastmail.fm (Jonathan Cast) Date: Sun Jan 20 17:26:08 2008 Subject: [Haskell-cafe] Throwback of inferred types In-Reply-To: <20080120210204.GC11197@localhost> References: <200801191730.50916.jon@ffconsultancy.com> <20080119174222.GA20380@localhost> <001701c85ac6$ad420a70$07c61f50$@be> <20080120210204.GC11197@localhost> Message-ID: On 20 Jan 2008, at 1:02 PM, gwern0@gmail.com wrote: > On 2008.01.19 19:11:13 +0100, Peter Verswyvelen > scribbled 1.4K characters: >> The problem is that this only works when the complete source file >> compiles >> correctly no? > > Yes. As I said, it's a very hackish solution - think of it as proof- > of-concept. > >> I would find it most useful to get type inference information on >> the fly, >> even when not all of the code compiles correctly yet. > > Does that make sense? If the code doesn't compile, then how could > any type-inference be trustable? It might be reliable if the error > is in definitions which don't get called or otherwise used by the > function you are asking after, but there are going to be edge- > cases, I should think, where it would bite you. Even if it's not reliable, the compiler gives its error messages based on some form of partial type inference. It would be quite interesting, some times, to see what the compiler thinks the types are, when it gives a type error (this bit me recently trying polymorphic recursion: I had a long list of polymorphic functions defined without type signatures (since the names were clear enough), factored out some duplicated code, and wound up with a set of mutually recursive functions, one of which was polymorphically recursive. I'll dig the example up if you want (it's kind of compilcated). Knowing that the compiler had various types inferred correctly would have helped me zero in on the place I needed a type signature (or at least I remember wanting to find such things out at the time)). jcc From miguelimo38 at yandex.ru Sun Jan 20 17:34:23 2008 From: miguelimo38 at yandex.ru (Miguel Mitrofanov) Date: Sun Jan 20 17:34:33 2008 Subject: [Haskell-cafe] Throwback of inferred types In-Reply-To: <20080120210204.GC11197@localhost> References: <200801191730.50916.jon@ffconsultancy.com> <20080119174222.GA20380@localhost> <001701c85ac6$ad420a70$07c61f50$@be> <20080120210204.GC11197@localhost> Message-ID: <1D8BF3DD-9619-4382-B5F0-AECBDE5FB3F8@yandex.ru> >> I would find it most useful to get type inference information on >> the fly, >> even when not all of the code compiles correctly yet. > > Does that make sense? Not much if you're writing from scratch, but if you're making minor changes in the already written code, it appears to be very useful. I use C-c C-t all the time, and it gives me the types as they were before my changes - if I didn't change them, this hints are helpful, and if i did - I'm aware of that. From Malcolm.Wallace at cs.york.ac.uk Sun Jan 20 18:33:31 2008 From: Malcolm.Wallace at cs.york.ac.uk (Malcolm Wallace) Date: Sun Jan 20 18:33:23 2008 Subject: [Haskell-cafe] CPP and INLINE pragmas In-Reply-To: <396556a20801201117y663d2f34gaa74e88af70bea91@mail.gmail.com> References: <396556a20801201117y663d2f34gaa74e88af70bea91@mail.gmail.com> Message-ID: <20080120233331.6f6cf66c.Malcolm.Wallace@cs.york.ac.uk> "Adam Langley" writes: > Has anyone a workaround for this, or a way to get the preprocessor to > output a newline? You can use cpphs with the --layout flag, to preserve newlines in macro expansion. http://haskell.org/cpphs For instance, with ghc you need to add the following flags: ghc -cpp -pgmPcpphs -optP--cpp -optP--layout Regards, Malcolm From agl at imperialviolet.org Sun Jan 20 19:20:29 2008 From: agl at imperialviolet.org (Adam Langley) Date: Sun Jan 20 19:20:21 2008 Subject: [Haskell-cafe] CPP and INLINE pragmas In-Reply-To: <20080120233331.6f6cf66c.Malcolm.Wallace@cs.york.ac.uk> References: <396556a20801201117y663d2f34gaa74e88af70bea91@mail.gmail.com> <20080120233331.6f6cf66c.Malcolm.Wallace@cs.york.ac.uk> Message-ID: <396556a20801201620u4676b32fyaf5a275783bdf03b@mail.gmail.com> Thanks Isaac and Malcolm. That neatly solves all my problems! AGL -- Adam Langley agl@imperialviolet.org http://www.imperialviolet.org 650-283-9641 From stevelihn at gmail.com Sun Jan 20 21:38:48 2008 From: stevelihn at gmail.com (Steve Lihn) Date: Sun Jan 20 21:38:40 2008 Subject: [Haskell-cafe] First go at reactive programming In-Reply-To: <479272C2.1010309@optusnet.com.au> References: <478C98FF.2060903@optusnet.com.au> <478F25C6.6020306@optusnet.com.au> <479272C2.1010309@optusnet.com.au> Message-ID: This fixed the second example. Thanks. > > I think handleConnection should be > > handleConnection :: RequestHandler -> Handle -> IO () > > handleConnection r h = > handleToRequest h >>= responseSend h . runRequestHandler r > > > Levi > > > From dekudekuplex at yahoo.com Sun Jan 20 21:49:39 2008 From: dekudekuplex at yahoo.com (Benjamin L. Russell) Date: Sun Jan 20 21:49:31 2008 Subject: [Haskell-cafe] bug in all about monads tutorial In-Reply-To: Message-ID: <628530.779.qm@web30208.mail.mud.yahoo.com> Since nobody with write access to that page seems to be responding here, you may wish to try reporting this bug to the main Haskell mailing list (haskell@haskell.org). Posting to that list may get the attention of some Haskell users who may not regularly read this mailing list. Benjamin L. Russell --- Peter Hercek wrote: > Hi, > > About 3 weeks ago I reported this bug to Jeff > Newbern. > But I got no response - maybe I got filtered out > as spam :) > Since it was not fixed I'm trying once more here. > Maybe > there is somebody here who has access to the web > site > http://www.haskell.org/all_about_monads and cares > enough > to fix it. > > On page > > http://www.haskell.org/all_about_monads/html/writermonad.html > there is "listens" defined like this: > listens f m = do (a,w) <- m; return (a,f w) > ... but it should be like this: > listens f m = do (a,w) <- listen m; return (a,f w) > ... or maybe a less strict option (as ghc libs have > it): > listens f m = do ~(a,w) <- listen m; return (a,f > w) > > Peter. > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From anshuman at students.iiit.ac.in Mon Jan 21 01:00:19 2008 From: anshuman at students.iiit.ac.in (anshuman@students.iiit.ac.in) Date: Mon Jan 21 01:00:17 2008 Subject: [Haskell-cafe] Invitation for MathematiKa '08 : projectEuler format Message-ID: <52732.192.168.36.204.1200895219.squirrel@students.iiit.ac.in> Hello Math Enthusiast, IIIT-Hyderabad, India cordially invites you to be a part of Mathematika '08, an online competition that emphasizes on fusion of mathematics and computing. Where: http://felicity.iiit.ac.in/~math When: 4th February, 2008 This Online Math Contest will consist of 10-12 problems made randomly from different domains of existing Math. All problem statements will be visible to the contestant from the start of contest spanning over a 10 hour period. The solution to each problem would be an integer or a floating point number which is to be submitted in real-time. One Minute Rule: The problems are designed in a way that support 1 minute rule which means that an efficient implementation will allow a solution to be obtained on a modestly powered computer in less than one minute. Also, make sure to bring your appetite for math, programming and fun. There will be plenty of all three to go around. Regards Mathematika Team http://felicity.iiit.ac.in/~math From Christian.Maeder at dfki.de Mon Jan 21 04:49:14 2008 From: Christian.Maeder at dfki.de (Christian Maeder) Date: Mon Jan 21 04:49:05 2008 Subject: [Haskell-cafe] functional graphs In-Reply-To: <910ddf450801190904w663db5c6j7c7df9b8bf640444@mail.gmail.com> References: <4790A1B2.7030901@dfki.de> <910ddf450801190904w663db5c6j7c7df9b8bf640444@mail.gmail.com> Message-ID: <47946A9A.7050202@dfki.de> Thomas Hartman wrote: > I don't think this will work. > > From > > http://www.haskell.org/ghc/docs/latest/html/libraries/fgl/src/Data-Graph-Inductive-Graph.html > > the minimal implementatin for Graph is > > -- | Minimum implementation: 'empty', 'isEmpty', 'match', 'mkGraph', 'labNodes' > .... > -- | Decompose a 'Graph' into the 'MContext' found for the given node and the > -- remaining 'Graph'. > match :: Node -> gr a b -> Decomp gr a b > > Basically, match given a node returns the graph minus the node, and a > "context for the node which has ingoing edges/labels, outgoing > edges/labels, the node itself and the node label. With the & operator > you can compose these two things and get back your original graph. > > With the implementation you have described I can't see any way to > implement this match function, unless per my above comment you're > doing something weird like having no graph edges, or all possible > graph edges. And then why use a graph? It's a _complete_ graph, i.e. there is an edge between every two nodes. I want to compute the minimum spanning tree using http://www.haskell.org/ghc/docs/latest/html/libraries/fgl/Data-Graph-Inductive-Query-MST.html without rewriting the FGL code and without generating the many edges explicitly. Eventually I want to have a "proper" tree (Data.Tree.Tree) for pre-order traversal. Preorder traversal of a MST gives a sub-optimal solution (not worse than twice as long as the optimum) for the travelling salesman problem (TSP). I may be on the wrong track, though. Thanks Christian > Unless I'm missing something... > > Thomas. > > > 2008/1/18, Christian Maeder : >> Hi, >> >> Given a complete graph as a list of nodes whose edge labels are given by >> a function over two nodes: >> >> data CGraph a b = CGraph [a] (a -> a -> b) >> >> Can I define an instance for the fgl Graph class? >> >> import Data.Graph.Inductive.Graph >> >> instance Graph CGraph where >> empty = CGraph [] -- and now? >> >> I had no idea how to define empty (except using undefined). >> >> I thought of requiring a context for the node labels of type a, but this >> type is not mentioned in the class header. So it looked to me like the >> impossibility to define sets (requiring an Ord) as monads. (i.e. >> instance Monad Data.Set.Set) >> >> Any working proposals for my graph problem? >> >> Cheers Christian From Christian.Maeder at dfki.de Mon Jan 21 04:57:41 2008 From: Christian.Maeder at dfki.de (Christian Maeder) Date: Mon Jan 21 04:57:31 2008 Subject: [Haskell-cafe] functional graphs In-Reply-To: References: <4790A1B2.7030901@dfki.de> Message-ID: <47946C95.8020506@dfki.de> Benja Fallenstein wrote: > However, if you'd be able to live with > > data CGraph a b = CGraph [LNode a] (Node -> Node -> b) > > then you should be able to write the instance like this-- > > instance Graph CGraph where > empty = CGraph [] (const $ error "Node not in graph") > isEmpty (CGraph xs _) = null xs > labNodes (CGraph xs _) = xs > mkGraph nodes edges = CGraph nodes f where > f x y = fromMaybe (error "Edge not found") (lookup (x,y) edges') > edges' = map (\(x,y,l) -> ((x,y),l)) edges > match x (CGraph nodes f) = case lookup x nodes of > Nothing -> (Nothing, CGraph nodes f) > Just l -> > let nodes' = filter ((/= x) . fst) nodes > left = map (\(y,_) -> (f y x, y)) nodes' > right = map (\(y,_) -> (f x y, y)) nodes' > in (Just (left, x, l, right), CGraph nodes' f) Thanks for pointing out this proposal. The actual problem is mkGraph that needs all the many edges created beforehand (that's what I wanted to avoid). Cheers Christian From bulat.ziganshin at gmail.com Mon Jan 21 03:03:48 2008 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Mon Jan 21 06:03:13 2008 Subject: [Haskell-cafe] Throwback of inferred types In-Reply-To: <200801202218.53157.jon@ffconsultancy.com> References: <200801191730.50916.jon@ffconsultancy.com> <200801202102.43497.jon@ffconsultancy.com> <1200866764.5639.366.camel@localhost> <200801202218.53157.jon@ffconsultancy.com> Message-ID: <1374768251.20080121110348@gmail.com> Hello Jon, Monday, January 21, 2008, 1:18:52 AM, you wrote: > You're missing out on a lot if this isn't available for Haskell yet. I didn't > realise just how invaluable this is until a system upgrade broke it and I > really struggled to write OCaml code without it: I don't know how I managed > before! oh, yes, i have a really hard times debugging large chunks of new code. nothing works, ghc error messages are next to useless and the best thing i can do - is just to add type annotations everywhere in order to find where ghc and me thinks different -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From benja.fallenstein at gmail.com Mon Jan 21 06:13:49 2008 From: benja.fallenstein at gmail.com (Benja Fallenstein) Date: Mon Jan 21 06:13:39 2008 Subject: [Haskell-cafe] functional graphs In-Reply-To: <47946C95.8020506@dfki.de> References: <4790A1B2.7030901@dfki.de> <47946C95.8020506@dfki.de> Message-ID: Hi Christian, On Jan 21, 2008 10:57 AM, Christian Maeder wrote: > Thanks for pointing out this proposal. The actual problem is mkGraph > that needs all the many edges created beforehand (that's what I wanted > to avoid). Well, uh, at the risk of being obvious, if you can avoid using fgl functions that call mkGraph, then there is nothing to say that mkGraph has ever to be called, and conversely, if you must use fgl functions that call mkGraph, then there is no way to avoid the fact that it gets the edge labels in a list... :-) A quick grep of the library shows that use of mkGraph is very rare. I haven't chased down the uses of functions that call mkGraph, though, so I don't really know whether many or few functions use mkGraph internally. Of course, you can use (mkGraph = error "mkGraph") and see whether you trip over it at all. Best, - Benja From hjgtuyl at chello.nl Mon Jan 21 06:21:50 2008 From: hjgtuyl at chello.nl (hjgtuyl@chello.nl) Date: Mon Jan 21 06:21:38 2008 Subject: [Haskell-cafe] Parsec benchmarks In-Reply-To: <200801202054.08530.jon@ffconsultancy.com> References: <200801202054.08530.jon@ffconsultancy.com> Message-ID: I think you should try again, the link is not dead. On Sun, 20 Jan 2008 21:54:08 +0100, Jon Harrop wrote: > > I'd like to compare the performance of Parsec to other parsers but the > only > reference to a benchmark I have found is a dead link from one of the > papers > about Parsec: > > http://research.microsoft.com/users/daan/download/parsec/parsec.pdf > > Are there any surviving Parsec benchmarks? > -- Met vriendelijke groet, Henk-Jan van Tuyl -- http://functor.bamikanarie.com http://Van.Tuyl.eu/ -- From lemming at henning-thielemann.de Mon Jan 21 06:29:09 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Mon Jan 21 06:28:59 2008 Subject: [Haskell-cafe] Re: Properties of optimizer rule application? In-Reply-To: <638ABD0A29C8884A91BC5FB5C349B1C315A53A546C@EA-EXMSG-C334.europe.corp.microsoft.com> References: <20080103192002.GF4775@scytale.galois.com> <47830A3B.7040401@cse.unsw.edu.au> <478DF9E7.30204@cse.unsw.edu.au> <638ABD0A29C8884A91BC5FB5C349B1C315A53A546C@EA-EXMSG-C334.europe.corp.microsoft.com> Message-ID: On Thu, 17 Jan 2008, Simon Peyton-Jones wrote: > | To give a precise example: If I have a sequence of 'map's > | map f0 . map f1 . ... . map fn > | then there is some length where this is no longer collapsed to a single > | 'map'? > > (a) GHC tries to do as much as possible in a single iteration of the > simplifer; I think it uses an outermost-first strategy for this. > > (b) For each phase it runs the simplifier until nothing changes, or a > maximum of N times, where N is settable by a command-line-flag > -fmax-simplifier-iterations. After N it stops running that phase, even > if the simplification has not terminated. This means that the simplifier follows a specific direction (outermost to inner or vice versa). I shall not rely on the order, but I must expect that there is an order, which restricts the application of rules. If it would really do "as much as possible in a single iteration" then there would be nothing left to do after one iteration, since the set of applicable rules remains the same within one phase. > | However then I wonder, how it is possible to make the compiler to > | go into an infinite loop by the rule > | > | "loop" forall x,y. f x y = f y x > > Yes, it's possible. Remember (a) does "as much as possible", which in your rule means rather a lot. "as much as possible" in a particular order (which I shall not rely on), right? > In this thread Roman and I have described stuff that isn't in the > manual. Henning, would you feel like elaborating the Wiki page > http://haskell.org/haskellwiki/GHC/Using_rules > (which already has a lot of info) to reflect what you've learned? That way it's preserved for others. I have added many points and I hope I haven't made things more confusing as they are and I have set more links and added more articles to http://www.haskell.org/haskellwiki/Category:Program_transformation I think I also found a typo: http://www.haskell.org/ghc/docs/latest/html/users_guide/pragmas.html#phase-control The last line in the list, should certainly be "NOINLINE[~k] f" means: be willing to inline f until phase k, but from phase k onwards do not inline it. ^^ Recently I found that specialisation interacts in an unexpected way with explicit RULES (and with inlining). I used a function multiple times and this seemed to make GHC specialising this function (although I did not used a SPECIALISE pragma) to the particular type. But then this function was no longer available for fusion. It reminds me on the sharing problem - it is not always an optimization to share common sub-expressions. In this case the common sub-expression was a function which was used with the same type (thus same class dictionary) for each call. Also in one case declaring a function 'foo' as INLINE [0] avoided fusion of 'foo', where NOINLINE [0] did the fusion in phase 2. I assumed that these two pragmas are identical in phases before 0. Summarized I think it is not only required to have better control over the phases of the optimizer but to have a clear unifying concept of several kinds of program transformations, namely SPECIALISE, INLINE, RULES. From jlareyes at cybercia.com Mon Jan 21 07:42:08 2008 From: jlareyes at cybercia.com (=?US-ASCII?Q?Jose_Luis_Reyes_F.?=) Date: Mon Jan 21 07:42:02 2008 Subject: [Haskell-cafe] Hamming's Problem In-Reply-To: <20080118123544.GA4270@zombie.inf.tu-dresden.de> References: <003f01c85908$edbf5950$c93e0bf0$@com> <20080118123544.GA4270@zombie.inf.tu-dresden.de> Message-ID: <000301c85c2b$0a465630$1ed30290$@com> Bertram Thanks for your help, I tried to solve the problem this weekend but I have some dudes. My reasoning is: The sequence is [1,a1,a2,a3,..] where a1 = h 1 1, a2 = h 1 a1, and so on So, I want to construct the list of lists [[1,a1,a2,a3], [h 1 1, h 1 a1, h 1 a2,..], [h a1 1, h a1 a1, h a1 a2,...] ... [h an 1, h an a2,h an a3,...] ... ] The function is hammingx = 1 : foldl1 merge [ map (h x) hammingx | x <- hammingx] However this is not a solution because the list is a infinite list of infinite lists. Please some advices to resolve this problem. Thanks Jose Luis -----Mensaje original----- De: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] En nombre de Bertram Felgenhauer Enviado el: viernes, 18 de enero de 2008 8:36 Para: haskell-cafe@haskell.org Asunto: Re: [Haskell-cafe] Hamming's Problem Jose Luis Reyes F. wrote: > Hi, > > In exercise 2 of http://www.walenz.org/Dijkstra/page0145.html we need to > write a function that holds > > (1) The value 1 is in the sequence > (2) If x and y are in the sequence, so is f(x,y), where f has the > properties > a. f(x,y) > x > b. (y1 > y2) => (f(x,y1)>f(x,y2)) > > This is a solution for this problem, but an inefficient one > > hammingff :: [Integer] > hammingff = 1 : merge [ h x y | x <- hammingff, y <- hammingff ] > [ h x y | y <- hammingff, x <- hammingff ] That's not sufficient. In fact, because hammingff is an infinite sequence, this is equivalent to hammingff = 1 : merge [ h (head hammingff) y | y <- hammingff ] [ h x (head hammingff) | x <- hammingff ] > h x y = 2*x+3*y [snip merge function] Indeed, the first few terms of hammingff are [1,5,13,17,29], and the value h 5 5 = 25 is missing. > anybody has a better solution?. I have some ideas, but maybe you want to work on a correct solution first? Btw, with your choice of h, the result list will contain all natural numbers that are not divisible by 3 and are = 1 (mod 4). Evaluating the first n elements of that list will require O(n^2) evaluations of h. Bertram _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe __________ Informacisn de NOD32, revisisn 2805 (20080118) __________ Este mensaje ha sido analizado con NOD32 antivirus system http://www.nod32.com From stevelihn at gmail.com Mon Jan 21 10:15:52 2008 From: stevelihn at gmail.com (Steve Lihn) Date: Mon Jan 21 10:15:45 2008 Subject: [Haskell-cafe] Re: need help for cabal-install In-Reply-To: <1200758537.5639.291.camel@localhost> References: <86ve5qzaov.fsf@pullcord.laptop.org> <1200752299.5639.278.camel@localhost> <1200758537.5639.291.camel@localhost> Message-ID: Duncan, I got the latest cabal. The stack overflow is fixed. But the install command still does not work (on a very simple package). Attached is the verbose output. It does not like to proceed somewhere between configure and build. But the verbose is not telling why! I also attached my cabal dance with exactly the same configure options. ---- /home2/ecoin/garden> cabal install -v HTTP-Simple /home2/ecoin/ghc/bin/ghc --numeric-version looking for package tool: ghc-pkg near compiler in /home2/ecoin/ghc/bin found package tool in /home2/ecoin/ghc/bin/ghc-pkg /home2/ecoin/ghc/bin/ghc-pkg --version /home2/ecoin/ghc/bin/ghc -c /tmp/tmp26702.c -o /tmp/tmp26702.o /usr/bin/ld -x -r /tmp/tmp26702.o -o /tmp/tmp26703.o Reading installed packages... /home2/ecoin/ghc/bin/ghc-pkg list --global --user 'HTTP-Simple-0.1' is cached. Extracting /home2/ecoin/.cabal/packages/hackage.haskell.org/HTTP-Simple/0.1/HTTP -Simple-0.1.tar.gz to /tmp/TMPHTTP-Simple-0.1... Creating dist/setup (and its parents) /home2/ecoin/ghc/bin/ghc --make Setup.lhs -o dist/setup/setup -odir dist/setup - hidir dist/setup [1 of 1] Compiling Main ( Setup.lhs, dist/setup/Main.o ) Linking dist/setup/setup ... dist/setup/setup configure --verbose=2 --ghc --prefix=/home2/ecoin/htools --user cabal: Error: some packages failed to install: HTTP-Simple-0.1 ---- Configuring HTTP-Simple-0.1... Warning: No build-type specified. If possible use build-type: Simple Preprocessing library HTTP-Simple-0.1... Building HTTP-Simple-0.1... [1 of 1] Compiling Network.HTTP.Simple ( Network/HTTP/Simple.hs, dist/build/Netw ork/HTTP/Simple.o ) /usr/bin/ar: creating dist/build/libHSHTTP-Simple-0.1.a Installing: /home2/ecoin/htools/lib/HTTP-Simple-0.1/ghc-6.6.1 Registering HTTP-Simple-0.1... Reading package info from "dist/installed-pkg-config" ... done. Saving old package config file... done. Writing new package config file... done. From bertram.felgenhauer at googlemail.com Mon Jan 21 10:17:52 2008 From: bertram.felgenhauer at googlemail.com (Bertram Felgenhauer) Date: Mon Jan 21 10:17:46 2008 Subject: [Haskell-cafe] Hamming's Problem In-Reply-To: <000301c85c2b$0a465630$1ed30290$@com> References: <003f01c85908$edbf5950$c93e0bf0$@com> <20080118123544.GA4270@zombie.inf.tu-dresden.de> <000301c85c2b$0a465630$1ed30290$@com> Message-ID: <20080121151752.GB5845@zombie.inf.tu-dresden.de> Jose Luis Reyes F. wrote: > Thanks for your help, I tried to solve the problem this weekend but I have > some dudes. > > My reasoning is: > > The sequence is [1,a1,a2,a3,..] where a1 = h 1 1, a2 = h 1 a1, and so on > > So, I want to construct the list of lists > [[1,a1,a2,a3], > [h 1 1, h 1 a1, h 1 a2,..], > [h a1 1, h a1 a1, h a1 a2,...] > ... > [h an 1, h an a2,h an a3,...] > ... > ] > > The function is > > hammingx = 1 : foldl1 merge [ map (h x) hammingx | x <- hammingx] > > However this is not a solution because the list is a infinite list of > infinite lists. Oh, but it's pretty close working, actually. We only need two small modifications: 1) use the right fold. foldl on an infinite list *never* produces a result. 'merge' is associative, so we can just use foldr instead: hammingx = 1 : foldr1 merge [map (h x) hammingx | x <- hammingx ] 2) we still haven't exploited the property that h x 1 > x. This property ensures that of the two arguments that 'merge' is applied to by 'foldr', the first one starts with the smaller element. So we can write merge' (x:xs) ys = x : merge xs ys hammingx = 1 : foldr1 merge' [map (h x) hammingx | x <- hammingx] which actually works. I'd actually define 'hamming' as a higher order function: hamming :: Ord a => (a -> a -> a) -> a -> [a] hamming f a = result where result = a : foldr1 merge' [map (f x) result | x <- result] hammingx = hamming h 1 HTH, Bertram From droundy at darcs.net Mon Jan 21 10:28:35 2008 From: droundy at darcs.net (David Roundy) Date: Mon Jan 21 10:28:25 2008 Subject: [Haskell-cafe] threads + IORefs = Segmentation fault? In-Reply-To: <6a7c66fc0801191136t51afe0c8wad6552a6f2ce981b@mail.gmail.com> References: <20080118232255.GF6197@darcs.net> <1200745667.4032.3.camel@localhost.localdomain> <20080119133643.GH6197@darcs.net> <6a7c66fc0801191136t51afe0c8wad6552a6f2ce981b@mail.gmail.com> Message-ID: <20080121152833.GK6197@darcs.net> On Sat, Jan 19, 2008 at 08:36:55PM +0100, Alfonso Acosta wrote: > On Jan 19, 2008 2:36 PM, David Roundy wrote: > > Using ghc 6.6, but I've since isolated the bug as being unrelated to the > > IORefs and threading, it was in an FFI binding that somehow never died > > until I was testing this new code. > > In case the you are creating a binding of haskell code. Did you make > sure that the runtime constructor and destructor (hs_* functions) are > properly called? The could be the source of the segfault. No, there are no bindings to haskell code involved. Perhaps it's even a segfault in libwww itself. -- David Roundy Department of Physics Oregon State University From seliverstov.a at gmail.com Mon Jan 21 10:37:38 2008 From: seliverstov.a at gmail.com (Alexander Seliverstov) Date: Mon Jan 21 10:37:26 2008 Subject: [Haskell-cafe] Newbie question Message-ID: <6ffb76200801210737u853b60fyf6e7014ff3d98bad@mail.gmail.com> Hi, I try to undestand why this code dosen't work f :: (Num a)=>Integer->a f i = i Integer is an instance of Num, so why does this code produce error: "Couldn't match expected type 'a' againsta inferred type 'Integer' ..." -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080121/e78567b1/attachment.htm From byorgey at gmail.com Mon Jan 21 10:43:47 2008 From: byorgey at gmail.com (Brent Yorgey) Date: Mon Jan 21 10:43:37 2008 Subject: [Haskell-cafe] Newbie question In-Reply-To: <6ffb76200801210737u853b60fyf6e7014ff3d98bad@mail.gmail.com> References: <6ffb76200801210737u853b60fyf6e7014ff3d98bad@mail.gmail.com> Message-ID: <22fcbd520801210743w16a0c7a4n25ff2cb28b0c65b3@mail.gmail.com> 2008/1/21 Alexander Seliverstov : > Hi, I try to undestand why this code dosen't work > > f :: (Num a)=>Integer->a > > f i = i > > Integer is an instance of Num, so why does this code produce error: > "Couldn't match expected type 'a' againsta inferred type 'Integer' ..." > But the type of this function says that it can return *any* instance of Num -- that is, the caller gets to choose which particular instance of Num they want. This function can only ever return an Integer. There is actually a function of this type, however; it's called fromIntegral. It works because it is a member of the Num type class. -Brent -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080121/4c049275/attachment.htm From icfp.publicity at googlemail.com Mon Jan 21 10:53:22 2008 From: icfp.publicity at googlemail.com (Matthew Fluet (ICFP Publicity Chair)) Date: Mon Jan 21 10:53:14 2008 Subject: [Haskell-cafe] ICFP2008 Call for Papers Message-ID: <53ff55480801210753i7753e6a9tc33bed3112b228a1@mail.gmail.com> Call for Papers ICFP 2008: International Conference on Functional Programming Victoria, BC, Canada, 22-24 September 2008 http://www.icfpconference.org/icfp2008 Submission deadline: 2 April 2008 ICFP 2008 seeks original papers on the art and science of functional programming. Submissions are invited on all topics from principles to practice, from foundations to features, from abstraction to application. The scope includes all languages that encourage functional programming, including both purely applicative and imperative languages, as well as languages with objects and concurrency. Particular topics of interest include * Applications and Domain-Specific Languages: systems programming; scientific and numerical computing; symbolic computing; artificial intelligence; databases; graphical user interfaces; multimedia programming; scripting; system administration; distributed-systems and web programming; XML processing; security * Foundations: formal semantics; lambda calculus; type theory; monads; continuations; control; state; effects * Design: algorithms and data structures; modules; type systems; concurrency and distribution; components and composition; relations to object-oriented or logic programming * Implementation: abstract machines; compile-time and run-time optimization; just-in-time compilers; memory management; parallel hardware; interfaces to foreign functions, services, components or low-level machine resources * Transformation and Analysis: abstract interpretation; partial evaluation; program transformation * Software-development Techniques: design patterns; specification; verification; validation; debugging; test generation; tracing; profiling * Functional Pearls: elegant, instructive, and fun essays on functional programming * Practice and Experience: novel results drawn from experience in education or industry. Experience Reports are also solicited, which are short papers (2-4 pages) that provide evidence that functional programming really works or describe obstacles that have kept it from working in a particular application. Functional Pearls and Experience Reports are separate categories of papers that need not report original research results and must be marked as such at the time of submission. Detailed guidelines on both categories are below. What's different this year? ~~~~~~~~~~~~~~~~~~~~~~~~~~~ * No double blind reviewing. Instructions for authors ~~~~~~~~~~~~~~~~~~~~~~~~ By Wednesday, 2 April 2008, 09:00 AM Apia time, submit an abstract of at most 300 words and a full paper of at most 12 pages (4 pages for an Experience Report), including bibliography and figures. The deadline will be strictly enforced and papers not meeting the page limits are summarily rejected. Authors have the option to attach supplementary material to a submission, on the understanding that reviewers are not expected to read it. A submission will be evaluated according to its relevance, correctness, significance, originality, and clarity. It should explain its contributions in both general and technical terms, clearly identifying what has been accomplished, explaining why it is significant, and comparing it with previous work. The technical content should be accessible to a broad audience. Each submission must adhere to SIGPLAN's republication policy, as explained on the web. Violation risks summary rejection of the offending submission. Proceedings will be published by ACM Press. Authors of accepted submissions are expected to transfer the copyright to ACM. They may have the option to have their presentation videotaped and published along with the conference proceedings in the ACM Digital Library. Video recordings will only be released at the consent of the presenter, which is expressed by signing an additional copyright release/permission form. Formatting ~~~~~~~~~~ Submissions must be in PDF format printable in black and white on US Letter sized paper and interpretable by Ghostscript. If this requirement is a hardship, make contact with the program chair at least one week before the deadline. ICFP proceedings are printed in black and white. It is permissible to include color in a submission, but you risk annoying reviewers who will have to decide if your final paper will be understandable without it. Papers must adhere to the standard ACM conference format: two columns, nine-point font on a ten-point baseline, with columns 20pc (3.33in) wide and 54pc (9in) tall, with a column gutter of 2pc (0.33in). A suitable document template for LaTeX is available from SIGPLAN. Submission ~~~~~~~~~~ Submissions will be accepted electronically; the submission page is not yet ready. The deadline is set at Samoan time, so if your submission is in by 09:00 AM Wednesday according to your local time, wherever you are, the submission will be on time. The world clock (http://www.timeanddate.com/worldclock/fixedtime.html?month=4&day=2&year=2008&hour=9&min=0&sec=0&p1=282) can give you the equivalent in your local time, e.g.,1:00 PM Wednesday in Seattle, 4:00 PM Wednesday in New York, and 9:00 PM Wednesday in London. Citation ~~~~~~~~ We recommend (but do not require) that you put your citations into author-date form. This procedure makes your paper easier to review. For example, if you cite a result on testing as ``(Claessen and Hughes 2000)'', many reviewers will recognize the result instantly. On the other hand, if you cite it as ``[4]'', even the best-informed reviewer has to page through your paper to find the reference. By using author-date form, you enable a knowledgeable reviewer to focus on content, not arbitrary numbering of references. LaTeX users can simply use the natbib package along with the plainnat bibliography style. Author response ~~~~~~~~~~~~~~~ You will have a 48-hour period, starting at 09:00 on 21 May 2008 Apia time, to read and respond to reviews. Special categories of papers ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In addition to research papers, ICFP solicits two kinds of papers that do not require original research contributions: Functional Pearls, which are full papers, and Experience Reports, which are limited to four pages. Authors submitting such papers may wish to consider the following advice. Functional Pearls ~~~~~~~~~~~~~~~~~ A Functional Pearl is an elegant essay about something related to functional programming. It might offer: * a new and thought-provoking way of looking at an old idea * an instructive example of program calculation or proof * a nifty presentation of an old or new data structure * an interesting application of functional programming techniques * a novel use or exposition of functional programming in the classroom Functional Pearls are not restricted to the above varieties, however. While pearls often demonstrate an idea through the development of a short program, there is no requirement or expectation that they do so. Thus, they encompass the notions of theoretical and educational pearls. A pearl should be concise, instructive, and entertaining. Your pearl is likely to be rejected if your readers get bored, if the material gets too complicated, if too much specialized knowledge is needed, or if the writing is inelegant. The key to writing a good pearl is polishing. Some advice from Richard Bird: * Throw away the rule book for writing research papers. * Get in quick; get out quick. * Be self-contained; don't go deep into related work, with lengthy references. * You are telling a story, so some element of surprise is welcome. * Above all, be engaging. * Give a talk on the pearl to non-specialists, your students, or your department. If you changed the order of presentation for the talk, consider using the new order in the next draft. * Put the pearl away for a while, then take it out and polish it again. Experience Reports ~~~~~~~~~~~~~~~~~~ ICFP has long solicited submissions on the practice and experience of functional programming. But reports of experience are inherently different from research papers, and when judged by the criteria of scientific merit, novelty, or research contribution, they have not competed well against traditional ICFP submissions. Yet we believe that the functional-programming community would benefit from being able to draw on and cite the experience of others. For this reason, we have introduced the ICFP Experience Report. Unlike a normal ICFP paper, the purpose of an Experience Report is not to add to the body of knowledge of the functional-programming community. Rather, the purpose of an Experience Report is to help create a body of published, refereed, citable evidence that functional programming really works---or to describe what obstacles prevent it from working. An Experience Report is distinguished from a normal ICFP paper by its title, by its length, and by the criteria used to evaluate it. * Both in the proceedings and in any citations, the title of each accepted Experience Report must begin with the words ``Experience Report'' followed by a colon. * An Experience Report is at most 4 pages long. Each accepted Experience Report will be presented at the conference, but depending on the number of Experience Reports and regular papers accepted, authors of Experience reports may be asked to give shorter talks. * Because the purpose of Experience Reports is to enable our community to accumulate a body of evidence about the efficacy of functional programming, an acceptable Experience Report need not present novel results or conclusions. It is sufficient if the Report states a clear thesis and provides supporting evidence. The thesis must be relevant to ICFP, but it need not be novel. The program committee will accept or reject Experience Reports based on whether they judge the evidence to be convincing. Anecdotal evidence will be acceptable provided it is well argued and the author explains what efforts were made to gather as much evidence as possible. Typically, more convincing evidence is obtained from papers which show how functional programming was used than from papers which only say that functional programming was used. The most convincing evidence often includes comparisons of situations before and after the introduction or discontinuation of functional programming. Evidence drawn from a single person's experience may be sufficient, but more weight will be given to evidence drawn from the experience of groups of people. Possible topics for an Experience Report include, but are not limited to * Insights gained from real-world projects using functional programming * Comparison of functional programming with conventional programming in the context of an industrial project or a university curriculum * Project-management, business, or legal issues encountered when using functional programming in a real-world project * Curricular issues encountered when using functional programming in education * Real-world constraints that created special challenges for an implementation of a functional language or for functional programming in general An Experience Report should be short and to the point: make a claim about how well functional programming worked on your project and why, and produce evidence to substantiate your claim. If functional programming worked for you in the same ways it has worked for others, you need only to summarize the results---the main part of your paper should discuss how well it worked and in what context. Most readers will not want to know all the details of your project and its implementation, but please characterize your project and its context well enough so that readers can judge to what degree your experience is relevant to their own projects. Be especially careful to highlight any unusual aspects of your project. Also keep in mind that specifics about your project are more valuable than generalities about functional programming; for example, it is more valuable to say that your team delivered its software a month ahead of schedule than it is to say that functional programming made your team more productive. If your paper not only describes experience but also presents new technical results, or if your experience refutes cherished beliefs of the functional-programming community, you may be better off submitting it as a full paper, which will be judged by the usual criteria of novelty, originality, and relevance. If you are unsure in which category to submit, the program chair will be happy to help you decide. Other information ~~~~~~~~~~~~~~~~~ Conference Chair ~~~~~~~~~~~~~~~~ James Hook (Portland State University) Program Chair ~~~~~~~~~~~~~ Peter Thiemann Albert-Ludwigs-Universit?t Georges-K?hler-Allee 079 79110 Freiburg, Germany Email: icfp08@informatik.uni-freiburg.de Phone: +49 761 203 8051 Fax: +49 761 203 8052 Mail sent to the address above is filtered for spam. If you send mail and do not receive a prompt response, particularly if the deadline is looming, feel free to telephone and reverse the charges. Program Committee ~~~~~~~~~~~~~~~~~ Derek Dreyer (Max Planck Institute for Software Systems) Robert Ennals (Intel Research) Kathleen Fisher (AT&T Research) Zhenjiang Hu (University of Tokyo) Frank Huch (University of Kiel) Andrew Kennedy (Microsoft Research) Kevin Millikin (Google) Henrik Nilsson (University of Nottingham) Chris Okasaki (United States Military Academy) Brigitte Pientka (McGill University) Rinus Plasmeijer (University of Nijmegen) Alan Schmitt (INRIA) Chung-chieh Shan (Rutgers) Mitchell Wand (Northeastern University) Stephen Weeks (Jane Street Capital) Important Dates (at 09:00 Apia time, UTC-11) ~~~~~~~~~~~~~~~ Submission: 2 April 2008 Author response: 21 May 2008 Notification: 16 June 2008 Final papers due: 7 July 2008 ICFP 2008 Web Site ~~~~~~~~~~~~~~~~~~ http://www.icfpconference.org/icfp2008/ Special Journal Issue ~~~~~~~~~~~~~~~~~~~~~ There will be a special journal issue with papers from ICFP 2008. The program committee will invite the authors of select accepted papers to submit a journal version to this issue. From lauri.pesonen at iki.fi Mon Jan 21 11:18:55 2008 From: lauri.pesonen at iki.fi (Lauri Pesonen) Date: Mon Jan 21 11:18:45 2008 Subject: [Haskell-cafe] Data.Binary questions In-Reply-To: <1200851855.5570.32.camel@derek-laptop> References: <1200851855.5570.32.camel@derek-laptop> Message-ID: Hi Derek, Thanks for the reply. On 20/01/2008, Derek Elkins wrote: > You may want to consider using the other side of Data.Binary rather than > the Binary class. The -class- Binary is intended for de/serialization > when you don't care about the format. From the documentation: > > "For parsing and generating simple external binary formats (e.g. C > structures), Binary may be used, but in general is not suitable for > complex protocols. Instead use the Put and Get primitives directly." Yes, you are right. I read that bit of the documentation, but didn't understand how to use the Get and Put primitives. So I started by using the Binary class and after getting quick results carried on with it. I'll rewrite what I have with Get and Put once I figure out how they actually work. > Nevertheless, one way to solve your problem is with a phantom type. > Change MyList to, > newtype MyList t e = MkList [e] deriving Show > > getLengthType :: MyList t e -> t > getLengthType = undefined > ... > > The asTypeOfs are just to propagate the type information around. GHC's > extension for scoped type variables would make this code simpler and > more direct. At any rate, now the code will use the Binary instance for > whatever type t is to serialize the length. Ah, very clever. Is this a common idiom in Haskell? > If you mean that you there references to the constant table in e.g. the > fields table then the problem here is that you need to the class methods > to use that monad transformer (in this case, ReaderT is all you should > need and not even that), but you can't change their type. These are the > kind of issues that make the Binary class unsuitable for this type of > work. If that is the case, the only way to use this is to explicitly > write out the deserialization code rather than relying on get, i.e. > you'll have to write a function 'getTable constantTable' that will > deserialize the table. As an example, a method is serialised in the class file as the following structure: method_info { u2 access_flags; u2 name_index; u2 descriptor_index; u2 attributes_count; attribute_info attributes[attributes_count]; } Both the name_index and the descriptor_index are indices that point into the constants pool. In Haskell I would represent this as the type data Method = Method Access String String [Attribute] So I want to replace the indices with the actual strings that they point to. I guess in the final deserialised version of the class file the constant pool would not exist at all and it would be recreated when the class file is serialised again. So, AFAICT, I should be able to first deserialise the constants table as part of deserialising the whole class file and then pass the constant pool into the functions that deserialise fields, methods etc. so that they are able to look up the constants from the pool. I have to stare at the Get and Put primitives as well as ReaderT to figure out how all this will work together. Let's call it a learning experience. -- ! Lauri From rahn at ira.uka.de Mon Jan 21 11:21:07 2008 From: rahn at ira.uka.de (Mirko Rahn) Date: Mon Jan 21 11:21:12 2008 Subject: [Haskell-cafe] Re: functional graphs In-Reply-To: <47946A9A.7050202@dfki.de> References: <4790A1B2.7030901@dfki.de> <910ddf450801190904w663db5c6j7c7df9b8bf640444@mail.gmail.com> <47946A9A.7050202@dfki.de> Message-ID: Hello, > It's a _complete_ graph, i.e. there is an edge between every two nodes. > I want to compute the minimum spanning tree. Eventually I want to have a sub-optimal solution for the travelling salesman problem (TSP). A direct solution for this problem would be: -- | place a f-minimal element to the left, remember the minimal value min_left :: Ord b => (a -> b) -> [a] -> ([a],b) min_left _ [] = error "min_left: empty list" min_left f (x:xs) = ms (x,f x) [] xs $ map f xs where ms (y,v) nonmin (z:zs) (w:ws) | w < v = ms (z,w) (y:nonmin) zs ws | otherwise = ms (y,v) (z:nonmin) zs ws ms (y,v) nonmin _ _ = (y:nonmin,v) -- | the same for cross xs ys and a f with arity two mins :: Ord c => (a -> b -> c) -> [a] -> [b] -> [(a, ([b],c))] mins f xs ys = fst $ min_left (snd . snd) [(x,min_left (f x) ys) | x <- xs] -- | *complete* graph data CGraph a b = CGraph [a] (a -> a -> b) -- | give a list of edges with weight that form a minimal spanning tree prim :: Ord b => CGraph a b -> [(a,a,b)] prim (CGraph [] _) = [] prim (CGraph (x:xs) w) = build [x] xs where build _ [] = [] build seen open = let (f,(t:rest,v)):_ = mins w seen open in (f,t,v) : build (t:seen) rest -- | calculate the complete round trip and its (accumulated) weight round_trip :: (Eq a, Ord b, Num b) => CGraph a b -> [(a,a,b,b)] round_trip = rt 0 [] . prim where rt _ [] [] = [] rt s ((c,r,v):bs) [] = (c,r,v,s+v) : rt (s+v) bs [] rt s [] ((r,c,v):ys) = (r,c,v,s+v) : rt (s+v) [(c,r,v)] ys rt s (b@(z,t,w):bs) ((r,c,v):ys) | r == z = (r,c,v,s+v) : rt (s+v) ((c,r,v):b:bs) ys | otherwise = (z,t,w,s+w) : rt (s+w) bs ((r,c,v):ys) {- *Main> round_trip $ CGraph [0..5] (\ x y -> mod (x+y) 4) [(0,4,0,0),(4,5,1,1),(5,3,0,1),(3,1,0,1),(1,3,0,1),(3,2,1,2),(2,3,1,3),(3,5,0,3),(5,4,1,4),(4,0,0,4)] -} Have fun! /BR, Mirko Rahn From seliverstov.a at gmail.com Mon Jan 21 11:36:18 2008 From: seliverstov.a at gmail.com (Alexander Seliverstov) Date: Mon Jan 21 11:36:07 2008 Subject: [Haskell-cafe] Newbie question In-Reply-To: <22fcbd520801210743w16a0c7a4n25ff2cb28b0c65b3@mail.gmail.com> References: <6ffb76200801210737u853b60fyf6e7014ff3d98bad@mail.gmail.com> <22fcbd520801210743w16a0c7a4n25ff2cb28b0c65b3@mail.gmail.com> Message-ID: <6ffb76200801210836w776d9469q5228ad506480a1e1@mail.gmail.com> How does caller choose which particular instance of Num they want? In object-oriented language If function return type is an interface it means that it can return any implementation of this interface, but caller can't choose which particular inplementation they want. What the difference between haskell class and interface in object-oriented languge such Java or C#? 2008/1/21, Brent Yorgey : > > > 2008/1/21 Alexander Seliverstov : > > > Hi, I try to undestand why this code dosen't work > > > > f :: (Num a)=>Integer->a > > > > f i = i > > > > Integer is an instance of Num, so why does this code produce error: > > "Couldn't match expected type 'a' againsta inferred type 'Integer' ..." > > > But the type of this function says that it can return *any* instance of > Num -- that is, the caller gets to choose which particular instance of Num > they want. This function can only ever return an Integer. > > There is actually a function of this type, however; it's called > fromIntegral. It works because it is a member of the Num type class. > > -Brent > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080121/34585218/attachment.htm From jon.fairbairn at cl.cam.ac.uk Mon Jan 21 11:56:08 2008 From: jon.fairbairn at cl.cam.ac.uk (Jon Fairbairn) Date: Mon Jan 21 11:56:10 2008 Subject: [Haskell-cafe] Re: Newbie question References: <6ffb76200801210737u853b60fyf6e7014ff3d98bad@mail.gmail.com> <22fcbd520801210743w16a0c7a4n25ff2cb28b0c65b3@mail.gmail.com> <6ffb76200801210836w776d9469q5228ad506480a1e1@mail.gmail.com> Message-ID: "Alexander Seliverstov" writes: > How does caller choose which particular instance of Num they want? They specify the type... or just pass the result to something that specifies the type. Try it in ghci: Prelude> let f:: Integral i => Integer -> i; f = fromIntegral Prelude> let g :: Int -> Int; g = id Prelude> :t g (f 5) g (f 5) :: Int Prelude> let h :: Integer -> Integer; h = id Prelude> :t h (f 5) h (f 5) :: Integer Prelude> > What the difference between haskell class and interface in object-oriented > languge such Java or C#? Really they are completely different animals that look a lot alike because they serve similar purposes -- convergent evolution! -- J?n Fairbairn Jon.Fairbairn@cl.cam.ac.uk From simonpj at microsoft.com Mon Jan 21 12:00:01 2008 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Mon Jan 21 11:59:51 2008 Subject: [Haskell-cafe] Re: Properties of optimizer rule application? In-Reply-To: References: <20080103192002.GF4775@scytale.galois.com> <47830A3B.7040401@cse.unsw.edu.au> <478DF9E7.30204@cse.unsw.edu.au> <638ABD0A29C8884A91BC5FB5C349B1C315A53A546C@EA-EXMSG-C334.europe.corp.microsoft.com> Message-ID: <638ABD0A29C8884A91BC5FB5C349B1C315A5528B45@EA-EXMSG-C334.europe.corp.microsoft.com> | I think I also found a typo: Quite right, thanks -- now fixed. | Recently I found that specialisation interacts in an unexpected way with | explicit RULES (and with inlining). I used a function multiple times and | this seemed to make GHC specialising this function (although I did not | used a SPECIALISE pragma) to the particular type. But then this function | was no longer available for fusion. Yes, specialisation generates new RULES. These new rules apply all the time, so they may rewrite your call to f before your fusion rules run. This is a bad thing. Really, specialisation should generate rules for a particular phase 'spec', and you should be able to add your fusion rules to precede or follow 'spec'. | Also in one case declaring a function 'foo' as INLINE [0] avoided fusion | of 'foo', where NOINLINE [0] did the fusion in phase 2. I assumed that | these two pragmas are identical in phases before 0. I'm not sure what is going on here | Summarized I think it is not only required to have better control over the | phases of the optimizer but to have a clear unifying concept of several | kinds of program transformations, namely SPECIALISE, INLINE, RULES. I can hardly argue with a "clear unifying concept". But I'm not quite sure what you mean. Here's a stab. You could put this on the wiki and refine it with help from this end. * SPECIALISE generates a rule * RULES specifies a rule * INLINE is just like a rule (lhs = rhs) The latter two can be controlled to some extend by the "phase" mechanism. The first should be. Did you mean more than that? Simon From jake.mcarthur at gmail.com Mon Jan 21 12:03:08 2008 From: jake.mcarthur at gmail.com (Jake McArthur) Date: Mon Jan 21 12:03:01 2008 Subject: [Haskell-cafe] Hangman game In-Reply-To: <2608b8a80801201103j10bcacedw6d02853fb002ff14@mail.gmail.com> References: <1200781861.23242.0.camel@RonPcUbuntu> <47938021.3020002@cogito.org.uk> <2608b8a80801201103j10bcacedw6d02853fb002ff14@mail.gmail.com> Message-ID: <01F8A978-6B9C-4224-86B9-F852271973FC@gmail.com> On Jan 20, 2008, at 1:03 PM, Yitzchak Gale wrote: > Generating an infinite list from a random generator "burns up" > the generator, making it unusable for any further calculations. That's what the split function is for. ^_^ - Jake From seliverstov.a at gmail.com Mon Jan 21 12:28:33 2008 From: seliverstov.a at gmail.com (Alexander Seliverstov) Date: Mon Jan 21 12:28:22 2008 Subject: [Haskell-cafe] Re: Newbie question In-Reply-To: References: <6ffb76200801210737u853b60fyf6e7014ff3d98bad@mail.gmail.com> <22fcbd520801210743w16a0c7a4n25ff2cb28b0c65b3@mail.gmail.com> <6ffb76200801210836w776d9469q5228ad506480a1e1@mail.gmail.com> Message-ID: <6ffb76200801210928v5464a589g5513bb5cba8a20d2@mail.gmail.com> So, the function type "(Num a)=>Integer->a" means that return value of this function can be cast to any particular instance of class Num. Ok. I have a my own class "class A a" and want to write function like this "f:: (A a)=>Integer->a". Can I do it? 2008/1/21, Jon Fairbairn : > > "Alexander Seliverstov" writes: > > > How does caller choose which particular instance of Num they want? > > They specify the type... or just pass the result to > something that specifies the type. Try it in ghci: > > Prelude> let f:: Integral i => Integer -> i; f = fromIntegral > Prelude> let g :: Int -> Int; g = id > Prelude> :t g (f 5) > g (f 5) :: Int > Prelude> let h :: Integer -> Integer; h = id > Prelude> :t h (f 5) > h (f 5) :: Integer > Prelude> > > > What the difference between haskell class and interface in > object-oriented > > languge such Java or C#? > > Really they are completely different animals that look a lot > alike because they serve similar purposes -- convergent > evolution! > > -- > J¨®n Fairbairn Jon.Fairbairn@cl.cam.ac.uk > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- §³ §å§Ó§Ñ§Ø§Ö§ß§Ú§Ö§Þ, §³§Ö§Ý§Ú§Ó§Ö§â§ã§ä§à§Ó §¡§Ý§Ö§Ü§ã§Ñ§ß§Õ§â -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080121/cf98bc1f/attachment.htm From byorgey at gmail.com Mon Jan 21 12:33:54 2008 From: byorgey at gmail.com (Brent Yorgey) Date: Mon Jan 21 12:33:45 2008 Subject: [Haskell-cafe] Re: Newbie question In-Reply-To: <6ffb76200801210928v5464a589g5513bb5cba8a20d2@mail.gmail.com> References: <6ffb76200801210737u853b60fyf6e7014ff3d98bad@mail.gmail.com> <22fcbd520801210743w16a0c7a4n25ff2cb28b0c65b3@mail.gmail.com> <6ffb76200801210836w776d9469q5228ad506480a1e1@mail.gmail.com> <6ffb76200801210928v5464a589g5513bb5cba8a20d2@mail.gmail.com> Message-ID: <22fcbd520801210933y327d3602ka32be95cd3878c4b@mail.gmail.com> 2008/1/21 Alexander Seliverstov : > So, the function type "(Num a)=>Integer->a" means that return value of > this function can be cast to any particular instance of class Num. > > Ok. I have a my own class "class A a" and want to write function like > this "f:: (A a)=>Integer->a". Can I do it? > > Only if you make the function f a member of class A. Then it is the responsibility of each particular type which is an instance of A to define a way of converting an Integer into a value of that type. For example: class A a where f :: Integer -> a ... other functions... instance A Integer where f = id instance A String where f = show and so on. -Brent -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080121/818936ea/attachment.htm From cetin.sert at gmail.com Mon Jan 21 13:12:26 2008 From: cetin.sert at gmail.com (Cetin Sert) Date: Mon Jan 21 13:12:16 2008 Subject: [Haskell-cafe] Yi and Data.ByteString Message-ID: <1ff5dedc0801211012x6fdedd40ha0b44a5ac776c27b@mail.gmail.com> 1) Can anyone tell me how I can build Yi or point me to a binary release of that editor? I tried to follow the instructions on http://www.nobugs.org/developer/yi/building.html but got a missing component error each time. 2) When if ever is Data.ByteString going to be the default string representation in GHC? I study computational linguistics and plan to switch to Haskell in the near future, that is once I get to grips with the language and the whole new thought model one has to develop as an imperative programmer. Best Regards, Cetin Sert www.corsis.de -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080121/695a2f95/attachment.htm From jon.fairbairn at cl.cam.ac.uk Mon Jan 21 13:28:09 2008 From: jon.fairbairn at cl.cam.ac.uk (Jon Fairbairn) Date: Mon Jan 21 13:28:15 2008 Subject: [Haskell-cafe] Re: Newbie question References: <6ffb76200801210737u853b60fyf6e7014ff3d98bad@mail.gmail.com> <22fcbd520801210743w16a0c7a4n25ff2cb28b0c65b3@mail.gmail.com> <6ffb76200801210836w776d9469q5228ad506480a1e1@mail.gmail.com> <6ffb76200801210928v5464a589g5513bb5cba8a20d2@mail.gmail.com> Message-ID: "Alexander Seliverstov" writes: > So, the function type "(Num a)=>Integer->a" means that return value of > this function can be cast to any particular instance of class Num. For some meanings of the word "cast" yes. I'd rather say "f:: Num a=> Integer -> a" means that for any type a that is an instance of Num, given an integer f will return a member of that type. > Ok. I have a my own class "class A a" and want to write function like > this "f:: (A a)=>Integer->a". Can I do it? You need to be a bit more specific about what f is supposed to do without that, I can answer unequivocally yes, and give you f:: (A a) => Integer -> a f n = undefined :-P But in general you are going to want something a bit more useful, which means that you have to have a path from Integer to a -- what the path can be is depends on what "methods" you give class A. For example: class A a where first_a :: a second_a :: a f :: A t => Integer -> t f n | odd n = first_a | otherwise = second_a -- J?n Fairbairn Jon.Fairbairn@cl.cam.ac.uk From nominolo at googlemail.com Mon Jan 21 13:50:02 2008 From: nominolo at googlemail.com (Thomas Schilling) Date: Mon Jan 21 13:51:27 2008 Subject: [Haskell-cafe] Yi and Data.ByteString In-Reply-To: <1ff5dedc0801211012x6fdedd40ha0b44a5ac776c27b@mail.gmail.com> References: <1ff5dedc0801211012x6fdedd40ha0b44a5ac776c27b@mail.gmail.com> Message-ID: <1200941403.5883.7.camel@intothevoid> On Mon, 2008-01-21 at 19:12 +0100, Cetin Sert wrote: > 1) Can anyone tell me how I can build Yi or point me to a binary > release of that editor? > > I tried to follow the instructions on > http://www.nobugs.org/developer/yi/building.html but got a missing > component error each time. You need ghc-6.8.2, the latest yi from darcs darcs get http://code.haskell.org/yi as well as the latest version of fingertree and vty or gtk. If you have further question please use the yi-devel mailing list (http://groups.google.com/group/yi-devel). Note though, that yi is not ready for regular use, yet. But, of course, contributions are accepted anytime. > 2) When if ever is Data.ByteString going to be the default string > representation in GHC? > Not anytime soon (if ever). It's not guaranteed to be faster in any case, but its generally faster for bigger inputs. If you're worried about literals, that's not a problem anymore. You can just use: myErrorMsg = "Oops!" :: ByteString > I study computational linguistics and plan to switch to Haskell in the > near future, that is once I get to grips with the language and the > whole new thought model one has to develop as an imperative > programmer. Good luck! From dons at galois.com Mon Jan 21 13:56:25 2008 From: dons at galois.com (Don Stewart) Date: Mon Jan 21 13:56:19 2008 Subject: [Haskell-cafe] Haskell web dev: Using Haskell and HAppS for Openomy API v2.0 Message-ID: <20080121185625.GB25564@scytale.galois.com> A deployment of HAppS, AlexJ et al's web framework for Haskell, at "openomy", > The latest release of our API is written in Haskell using the new HAppS > framework. The good news, > Since being in production, we've so far found very few issues and > everything runs quickly and smoothly. Haskell and HAppS have turned > out to be a very nice addition to our stable of tools and services. See the review here, http://blog.openomy.com/2008/01/case-study-using-haskell-and-happs-for.html Congratulations to Alex, Musasabi, Shapr, Igloo, Lemmih et al who've worked on getting HAppS into the real world! :) -- Don From seliverstov.a at gmail.com Mon Jan 21 14:09:33 2008 From: seliverstov.a at gmail.com (Alexander Seliverstov) Date: Mon Jan 21 14:09:24 2008 Subject: [Haskell-cafe] Re: Newbie question In-Reply-To: References: <6ffb76200801210737u853b60fyf6e7014ff3d98bad@mail.gmail.com> <22fcbd520801210743w16a0c7a4n25ff2cb28b0c65b3@mail.gmail.com> <6ffb76200801210836w776d9469q5228ad506480a1e1@mail.gmail.com> <6ffb76200801210928v5464a589g5513bb5cba8a20d2@mail.gmail.com> Message-ID: <6ffb76200801211109i260dc8bfn45f4ace17320501f@mail.gmail.com> Thanks. I get it. 2008/1/21, Jon Fairbairn : > > "Alexander Seliverstov" writes: > > > So, the function type "(Num a)=>Integer->a" means that return value of > > this function can be cast to any particular instance of class Num. > > For some meanings of the word "cast" yes. I'd rather say > "f:: Num a=> Integer -> a" means that for any type a that is > an instance of Num, given an integer f will return a member > of that type. > > > Ok. I have a my own class "class A a" and want to write function like > > this "f:: (A a)=>Integer->a". Can I do it? > > You need to be a bit more specific about what f is supposed > to do without that, I can answer unequivocally yes, and give > you > > f:: (A a) => Integer -> a > f n = undefined > > :-P > > But in general you are going to want something a bit more > useful, which means that you have to have a path from > Integer to a -- what the path can be is depends on what > "methods" you give class A. For example: > > class A a where > first_a :: a > second_a :: a > > f :: A t => Integer -> t > f n | odd n = first_a > | otherwise = second_a > > -- > J¨®n Fairbairn Jon.Fairbairn@cl.cam.ac.uk > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- §³ §å§Ó§Ñ§Ø§Ö§ß§Ú§Ö§Þ, §³§Ö§Ý§Ú§Ó§Ö§â§ã§ä§à§Ó §¡§Ý§Ö§Ü§ã§Ñ§ß§Õ§â -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080121/ef68d3d3/attachment.htm From gwern0 at gmail.com Mon Jan 21 14:18:15 2008 From: gwern0 at gmail.com (gwern0@gmail.com) Date: Mon Jan 21 14:18:12 2008 Subject: [Haskell-cafe] Yi and Data.ByteString In-Reply-To: <1ff5dedc0801211012x6fdedd40ha0b44a5ac776c27b@mail.gmail.com> References: <1ff5dedc0801211012x6fdedd40ha0b44a5ac776c27b@mail.gmail.com> Message-ID: <20080121191815.GB30857@localhost> On 2008.01.21 19:12:26 +0100, Cetin Sert scribbled 1.9K characters: > 1) Can anyone tell me how I can build Yi or point me to a binary release of that editor? > > I tried to follow the instructions on http://www.nobugs.org/developer/yi/building.html but got > a missing component error each time. The specific error would help a lot. Also, yi-devel might be a good list to subscribe to. > 2) When if ever is Data.ByteString going to be the default string representation in GHC? Not sure. I once asked about this, and it seems that ByteStrings don't support all the operations and definitions [Char] does; and there was mention of Unicode problems. Plus, ByteStrings aren't really built-in - they're a separate library. You could perhaps suggest that [Char] could be often optimized into ByteString operations but then ByteStrings need to either lose their library status and be incorporated into GHC or you need to expand the list of depended libraries... I wouldn't look for't anytime soon. > I study computational linguistics and plan to switch to Haskell in the near future, that is > once I get to grips with the language and the whole new thought model one has to develop as an > imperative programmer. Well, you're not the first computational linguist. There are some pretty impressive projects in Haskell. > Best Regards, > Cetin Sert -- gwern argus ARPA garbage Internet Halliburton Corporation SASP disruptio Egret SLBM -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080121/de2e4f92/attachment-0001.bin From k.pierre.k at gmail.com Mon Jan 21 14:28:40 2008 From: k.pierre.k at gmail.com (pierre) Date: Mon Jan 21 14:28:38 2008 Subject: [Haskell-cafe] Yi and Data.ByteString In-Reply-To: <1ff5dedc0801211012x6fdedd40ha0b44a5ac776c27b@mail.gmail.com> References: <1ff5dedc0801211012x6fdedd40ha0b44a5ac776c27b@mail.gmail.com> Message-ID: <20080121192840.GG9346@localdomain> Hello, On Mon, Jan 21, 2008 at 07:12:26PM +0100, Cetin Sert wrote: > 2) When if ever is Data.ByteString going to be the default string > representation in GHC? Why would you need such a thing? ByteStrings don't have any unicode support, and they can be quite slow for small strings. They are just a different tool for different task. But if you wish, you could use string literals as bytestrings with -XOverloadedStrings ghc (>=6.8) flag > Best Regards, > Cetin Sert > www.corsis.de -- pierre From bos at serpentine.com Mon Jan 21 14:53:56 2008 From: bos at serpentine.com (Bryan O'Sullivan) Date: Mon Jan 21 14:53:46 2008 Subject: [Haskell-cafe] Draft chapters of "Real World Haskell" now publicly available Message-ID: <4794F854.1050008@serpentine.com> John, Don and I are pleased to announce the beginning of the public beta programme for our upcoming book, "Real World Haskell". For further details, please see the following blog entry: http://www.realworldhaskell.org/blog/2008/01/21/finally-the-public-beta-programme-begins/ Thanks to all of the Haskell community members who have so far performed sterling service in commenting on our closed drafts. We look forward to your feedback! References: <1200851855.5570.32.camel@derek-laptop> Message-ID: <1200943383.5570.41.camel@derek-laptop> On Mon, 2008-01-21 at 16:18 +0000, Lauri Pesonen wrote: > Hi Derek, > > Thanks for the reply. > > On 20/01/2008, Derek Elkins wrote: > > > You may want to consider using the other side of Data.Binary rather than > > the Binary class. The -class- Binary is intended for de/serialization > > when you don't care about the format. From the documentation: > > > > "For parsing and generating simple external binary formats (e.g. C > > structures), Binary may be used, but in general is not suitable for > > complex protocols. Instead use the Put and Get primitives directly." > > Yes, you are right. I read that bit of the documentation, but didn't > understand how to use the Get and Put primitives. So I started by > using the Binary class and after getting quick results carried on with > it. I'll rewrite what I have with Get and Put once I figure out how > they actually work. > > > Nevertheless, one way to solve your problem is with a phantom type. > > Change MyList to, > > newtype MyList t e = MkList [e] deriving Show > > > > getLengthType :: MyList t e -> t > > getLengthType = undefined > > > ... > > > > The asTypeOfs are just to propagate the type information around. GHC's > > extension for scoped type variables would make this code simpler and > > more direct. At any rate, now the code will use the Binary instance for > > whatever type t is to serialize the length. > > Ah, very clever. Is this a common idiom in Haskell? Phantom types are a very common technique. They allow you to use the static type system to enforce guarantees (and, in this case, generate code). Essentially they let you add types to an untyped representation giving you the benefits of both. Usually you can avoid doing the asTypeOf chicanery I did. > > If you mean that you there references to the constant table in e.g. the > > fields table then the problem here is that you need to the class methods > > to use that monad transformer (in this case, ReaderT is all you should > > need and not even that), but you can't change their type. These are the > > kind of issues that make the Binary class unsuitable for this type of > > work. If that is the case, the only way to use this is to explicitly > > write out the deserialization code rather than relying on get, i.e. > > you'll have to write a function 'getTable constantTable' that will > > deserialize the table. > > As an example, a method is serialised in the class file as the > following structure: > > method_info { > u2 access_flags; > u2 name_index; > u2 descriptor_index; > u2 attributes_count; > attribute_info attributes[attributes_count]; > } > > Both the name_index and the descriptor_index are indices that point > into the constants pool. In Haskell I would represent this as the type > > data Method = Method Access String String [Attribute] > > So I want to replace the indices with the actual strings that they > point to. I guess in the final deserialised version of the class file > the constant pool would not exist at all and it would be recreated > when the class file is serialised again. > > So, AFAICT, I should be able to first deserialise the constants table > as part of deserialising the whole class file and then pass the > constant pool into the functions that deserialise fields, methods etc. > so that they are able to look up the constants from the pool. > > I have to stare at the Get and Put primitives as well as ReaderT to > figure out how all this will work together. Let's call it a learning > experience. As I hinted, ReaderT isn't really necessary either in this case. All it amounts to is passing an extra parameter. In this case it is probably clearer and simpler to explicitly pass the extra parameter, though you can decide that for yourself. Anyway, this documentation page may be more useful: http://hackage.haskell.org/packages/archive/binary/0.4.1/doc/html/index.html Basically your code will look similar to what it does now except instead of using get you'll use getWord32le or whatever and your own functions that will deserialize more involved structures, e.g. a getTable function. From monnier at iro.umontreal.ca Mon Jan 21 16:10:44 2008 From: monnier at iro.umontreal.ca (Stefan Monnier) Date: Mon Jan 21 16:10:44 2008 Subject: [Haskell-cafe] Re: Newbie question References: <6ffb76200801210737u853b60fyf6e7014ff3d98bad@mail.gmail.com> <22fcbd520801210743w16a0c7a4n25ff2cb28b0c65b3@mail.gmail.com> <6ffb76200801210836w776d9469q5228ad506480a1e1@mail.gmail.com> Message-ID: > How does caller choose which particular instance of Num they want? By passing the type they want. That's what the "Num a =>" thingy does. > In object-oriented language If function return type is an interface it means > that it can return any implementation of this interface, but caller can't > choose which particular inplementation they want. The full type of "f" you've given is: forall a . (Num a) => Integer -> a where the "forall a ." is normally not written. What you describe (a function that returns something where the type can be chosen by the function itself) would have type: Integer -> (exists a . (Num a) => a) I.e. the "a" is not passed as a (type) argument, but instead it's returned by the function. > What the difference between haskell class and interface in object-oriented > languge such Java or C#? >From a low-level point of view, the difference is that the vtable is manipulated separately from the objects. The "Num a" basically stands for the type of the vtable (which is called "dictionary" in Haskell). To bundle an object with its vtable as is traditionally done in OO languages, you need to create an existential package, e.g. something of type (exists a . (Num a) => a). Stefan From bf3 at telenet.be Mon Jan 21 16:36:49 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Mon Jan 21 16:36:39 2008 Subject: [Haskell-cafe] Re: Newbie question In-Reply-To: References: <6ffb76200801210737u853b60fyf6e7014ff3d98bad@mail.gmail.com> <22fcbd520801210743w16a0c7a4n25ff2cb28b0c65b3@mail.gmail.com> <6ffb76200801210836w776d9469q5228ad506480a1e1@mail.gmail.com> Message-ID: <1200951409.4231.11.camel@localhost.localdomain> Hey, I knew about the forall (I use that to represent OO style collections, very handy), but not about the exists. Thanks. But GHC 6.8.2 (with -fglasgow-exts) does not seem to accept this "exists" keyword? Does a book or document already exist (except the website) that tells more about not standarized yet very cool Haskell thingies that make writing real world applications possible? I would LOVE such a book. Cheers, Peter On Mon, 2008-01-21 at 16:10 -0500, Stefan Monnier wrote: > > How does caller choose which particular instance of Num they want? > > By passing the type they want. That's what the "Num a =>" thingy does. > > > In object-oriented language If function return type is an interface it means > > that it can return any implementation of this interface, but caller can't > > choose which particular inplementation they want. > > The full type of "f" you've given is: > > forall a . (Num a) => Integer -> a > > where the "forall a ." is normally not written. What you describe (a > function that returns something where the type can be chosen by the > function itself) would have type: > > Integer -> (exists a . (Num a) => a) > > I.e. the "a" is not passed as a (type) argument, but instead it's > returned by the function. > > > What the difference between haskell class and interface in object-oriented > > languge such Java or C#? > > >From a low-level point of view, the difference is that the vtable is > manipulated separately from the objects. The "Num a" basically stands > for the type of the vtable (which is called "dictionary" in Haskell). > > To bundle an object with its vtable as is traditionally done in OO > languages, you need to create an existential package, e.g. something of > type (exists a . (Num a) => a). > > > Stefan > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From bf3 at telenet.be Mon Jan 21 16:47:33 2008 From: bf3 at telenet.be (Peter Verswyvelen) Date: Mon Jan 21 16:47:24 2008 Subject: [Haskell-cafe] Draft chapters of "Real World Haskell" now publicly available In-Reply-To: <4794F854.1050008@serpentine.com> References: <4794F854.1050008@serpentine.com> Message-ID: <1200952053.4231.16.camel@localhost.localdomain> Oops, I just replied to another message asking for such a book! Amazing that my prayers are answered even before I asked them ;-) Peter On Mon, 2008-01-21 at 11:53 -0800, B ryan O'Sullivan wrote: > John, Don and I are pleased to announce the beginning of the public beta > programme for our upcoming book, "Real World Haskell". For further > details, please see the following blog entry: > > http://www.realworldhaskell.org/blog/2008/01/21/finally-the-public-beta-programme-begins/ > > Thanks to all of the Haskell community members who have so far performed > sterling service in commenting on our closed drafts. > > We look forward to your feedback! > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From derek.a.elkins at gmail.com Mon Jan 21 15:55:51 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Mon Jan 21 16:56:26 2008 Subject: [Haskell-cafe] Re: Newbie question In-Reply-To: <1200951409.4231.11.camel@localhost.localdomain> References: <6ffb76200801210737u853b60fyf6e7014ff3d98bad@mail.gmail.com> <22fcbd520801210743w16a0c7a4n25ff2cb28b0c65b3@mail.gmail.com> <6ffb76200801210836w776d9469q5228ad506480a1e1@mail.gmail.com> <1200951409.4231.11.camel@localhost.localdomain> Message-ID: <1200948952.5570.50.camel@derek-laptop> On Mon, 2008-01-21 at 22:36 +0100, Peter Verswyvelen wrote: > Hey, I knew about the forall (I use that to represent OO style > collections, very handy), but not about the exists. Thanks. But GHC > 6.8.2 (with -fglasgow-exts) does not seem to accept this "exists" > keyword? That's because it isn't GHC syntax, Stefan was just using for demonstration purposes. (However, I think HBC does accept free existentials.) GHC does support local existentials (with two different syntaxes) and that's what you are probably using to make your "OO style collections". When you write: data Foo = forall a.Foo (Num a => a) this is an -existential-. The type of (the data constructor) Foo is: Foo :: forall a.(Num a => a) -> Foo The rules of logic give: Foo :: (exists a.Num a => a) -> Foo note the change in scoping and compare this to local universal quantification: data Foo = Foo (forall a.Num a => a) Foo :: (forall a.Num a => a) -> Foo From barsoap at web.de Mon Jan 21 17:24:50 2008 From: barsoap at web.de (Achim Schneider) Date: Mon Jan 21 17:24:52 2008 Subject: [Haskell-cafe] Re: Draft chapters of "Real World Haskell" now publicly available References: <4794F854.1050008@serpentine.com> Message-ID: <20080121232450.5775e598@solaris.tower> Bryan O'Sullivan wrote: > We look forward to your feedback! > My browser shows me this: Dat geev en Fehler, as http://book.realworldhaskell.org/beta/funcstypes.html laadt w??r: Tiet op Server aflopen Verbinnen bestunn na book.realworldhaskell.org an Port 80 I think you have just been cafed. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From daniel.is.fischer at web.de Mon Jan 21 17:51:31 2008 From: daniel.is.fischer at web.de (Daniel Fischer) Date: Mon Jan 21 17:50:28 2008 Subject: [Haskell-cafe] Draft chapters of "Real World Haskell" now publicly available In-Reply-To: <4794F854.1050008@serpentine.com> References: <4794F854.1050008@serpentine.com> Message-ID: <200801212351.31205.daniel.is.fischer@web.de> Am Montag, 21. Januar 2008 20:53 schrieb Bryan O'Sullivan: > John, Don and I are pleased to announce the beginning of the public beta > programme for our upcoming book, "Real World Haskell". For further > details, please see the following blog entry: > > http://www.realworldhaskell.org/blog/2008/01/21/finally-the-public-beta-pro >gramme-begins/ > > Thanks to all of the Haskell community members who have so far performed > sterling service in commenting on our closed drafts. > > We look forward to your feedback! > > Enum (Ratio a) (with the same implementation as for Floating point numbers). The joy of "it": "When we couple 'it' with liberal use of the arrow keys to recall and edit the last expression we typed, and this gives us a fairly decent environment for interactive experiments, where the cost of mistakes is very low." That sentence is broken. One possible fix could be "We can couple 'it' with liberal use of the arrow keys to recall and edit the last expression we typed. This gives us a fairly decent environment for interactive experiments where the cost of mistakes is very low." You can probably do better. I look forward to buying and reading that book:) Cheers, Daniel From g9ks157k at acme.softbase.org Mon Jan 21 18:35:11 2008 From: g9ks157k at acme.softbase.org (Wolfgang Jeltsch) Date: Mon Jan 21 18:35:08 2008 Subject: [Haskell-cafe] Re: Newbie question In-Reply-To: <1200948952.5570.50.camel@derek-laptop> References: <6ffb76200801210737u853b60fyf6e7014ff3d98bad@mail.gmail.com> <1200951409.4231.11.camel@localhost.localdomain> <1200948952.5570.50.camel@derek-laptop> Message-ID: <200801220035.11470.g9ks157k@acme.softbase.org> Am Montag, 21. Januar 2008 21:55 schrieb Derek Elkins: > On Mon, 2008-01-21 at 22:36 +0100, Peter Verswyvelen wrote: > > Hey, I knew about the forall (I use that to represent OO style > > collections, very handy), but not about the exists. Thanks. But GHC > > 6.8.2 (with -fglasgow-exts) does not seem to accept this "exists" > > keyword? > > That's because it isn't GHC syntax, Stefan was just using for > demonstration purposes. (However, I think HBC does accept free > existentials.) GHC does support local existentials (with two different > syntaxes) and that's what you are probably using to make your "OO style > collections". When you write: > data Foo = forall a.Foo (Num a => a) > this is an -existential-. > The type of (the data constructor) Foo is: > Foo :: forall a.(Num a => a) -> Foo I think you have a typo here. The type of the data constructor should be this: forall a. Num a => (a -> Foo) > The rules of logic give: > Foo :: (exists a.Num a => a) -> Foo > note the change in scoping and compare this to local universal > quantification: > data Foo = Foo (forall a.Num a => a) > Foo :: (forall a.Num a => a) -> Foo Best wishes, Wolfgang From duncan.coutts at worc.ox.ac.uk Mon Jan 21 18:35:32 2008 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Mon Jan 21 18:35:23 2008 Subject: [Haskell-cafe] Re: need help for cabal-install In-Reply-To: References: <86ve5qzaov.fsf@pullcord.laptop.org> <1200752299.5639.278.camel@localhost> <1200758537.5639.291.camel@localhost> Message-ID: <1200958532.5639.431.camel@localhost> On Mon, 2008-01-21 at 10:15 -0500, Steve Lihn wrote: > Duncan, > I got the latest cabal. The stack overflow is fixed. But the install > command still does not work (on a very simple package). Attached is > the verbose output. It does not like to proceed somewhere between > configure and build. But the verbose is not telling why! > > I also attached my cabal dance with exactly the same configure options. > ---- > /home2/ecoin/garden> cabal install -v HTTP-Simple > /home2/ecoin/ghc/bin/ghc --numeric-version > looking for package tool: ghc-pkg near compiler in /home2/ecoin/ghc/bin > found package tool in /home2/ecoin/ghc/bin/ghc-pkg > /home2/ecoin/ghc/bin/ghc-pkg --version > /home2/ecoin/ghc/bin/ghc -c /tmp/tmp26702.c -o /tmp/tmp26702.o > /usr/bin/ld -x -r /tmp/tmp26702.o -o /tmp/tmp26703.o > Reading installed packages... > /home2/ecoin/ghc/bin/ghc-pkg list --global --user > 'HTTP-Simple-0.1' is cached. > Extracting /home2/ecoin/.cabal/packages/hackage.haskell.org/HTTP-Simple/0.1/HTTP > -Simple-0.1.tar.gz to /tmp/TMPHTTP-Simple-0.1... > Creating dist/setup (and its parents) > /home2/ecoin/ghc/bin/ghc --make Setup.lhs -o dist/setup/setup -odir > dist/setup - hidir dist/setup > [1 of 1] Compiling Main ( Setup.lhs, dist/setup/Main.o ) > Linking dist/setup/setup ... > dist/setup/setup configure --verbose=2 --ghc --prefix=/home2/ecoin/htools --user So at this point configuring the HTTP-Simple package is failing without any error message. That's not so good. :-) > cabal: Error: some packages failed to install: > HTTP-Simple-0.1 So, for debugging, try configuring that package manually and see if the behaviour is the same and if so what the exit code is. Duncan From gale at sefer.org Mon Jan 21 18:41:45 2008 From: gale at sefer.org (Yitzchak Gale) Date: Mon Jan 21 18:41:34 2008 Subject: [Haskell-cafe] Hangman game In-Reply-To: <01F8A978-6B9C-4224-86B9-F852271973FC@gmail.com> References: <1200781861.23242.0.camel@RonPcUbuntu> <47938021.3020002@cogito.org.uk> <2608b8a80801201103j10bcacedw6d02853fb002ff14@mail.gmail.com> <01F8A978-6B9C-4224-86B9-F852271973FC@gmail.com> Message-ID: <2608b8a80801211541y11ffd956l4664e4515cfb4300@mail.gmail.com> I wrote: >> Generating an infinite list from a random generator "burns up" >> the generator, making it unusable for any further calculations. Jake McArthur wrote: > That's what the split function is for. ^_^ Yes, that is a nice approach. I have been avoiding it due to the following comment in the docs for System.Random: "This is very useful in functional programs... but very little work has been done on statistically robust implementations of split ([System.Random#Burton, System.Random#Hellekalek] are the only examples we know of)." And my own experience has been that cases where I need split tend to be in a state monad anyway, where there isn't any real advantage to split. That said, looking around briefly, I came up with this paper by L'Ecuyer et al that does seem to describe a decent random generator with properties of split worked out: http://citeseer.ist.psu.edu/493863.html L'Ecuyer's implementations in C, C++ and Java are here: http://www.iro.umontreal.ca/~lecuyer/myftp/streams00/ If we had something like that in Haskell, I might use split more often. Regards, Yitz From derek.a.elkins at gmail.com Mon Jan 21 17:54:51 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Mon Jan 21 18:55:19 2008 Subject: [Haskell-cafe] Hangman game In-Reply-To: <2608b8a80801211541y11ffd956l4664e4515cfb4300@mail.gmail.com> References: <1200781861.23242.0.camel@RonPcUbuntu> <47938021.3020002@cogito.org.uk> <2608b8a80801201103j10bcacedw6d02853fb002ff14@mail.gmail.com> <01F8A978-6B9C-4224-86B9-F852271973FC@gmail.com> <2608b8a80801211541y11ffd956l4664e4515cfb4300@mail.gmail.com> Message-ID: <1200956091.5570.51.camel@derek-laptop> On Tue, 2008-01-22 at 01:41 +0200, Yitzchak Gale wrote: > I wrote: > >> Generating an infinite list from a random generator "burns up" > >> the generator, making it unusable for any further calculations. > > Jake McArthur wrote: > > That's what the split function is for. ^_^ > > Yes, that is a nice approach. I have been avoiding it due to > the following comment in the docs for System.Random: > > "This is very useful in functional programs... but very little > work has been done on statistically robust implementations > of split ([System.Random#Burton, System.Random#Hellekalek] > are the only examples we know of)." > > And my own experience has been that cases where I need split > tend to be in a state monad anyway, where there isn't any > real advantage to split. > > That said, looking around briefly, I came up with this paper > by L'Ecuyer et al that does seem to describe a decent > random generator with properties of split worked out: > > http://citeseer.ist.psu.edu/493863.html > > L'Ecuyer's implementations in C, C++ and Java are here: > > http://www.iro.umontreal.ca/~lecuyer/myftp/streams00/ > > If we had something like that in Haskell, I might use > split more often. According to the documentation http://www.haskell.org/ghc/docs/latest/html/libraries/random/System-Random.html That -is- what we have. From barsoap at web.de Mon Jan 21 19:05:06 2008 From: barsoap at web.de (Achim Schneider) Date: Mon Jan 21 19:05:05 2008 Subject: [Haskell-cafe] Re: Hangman game References: <1200781861.23242.0.camel@RonPcUbuntu> <47938021.3020002@cogito.org.uk> <2608b8a80801201103j10bcacedw6d02853fb002ff14@mail.gmail.com> <01F8A978-6B9C-4224-86B9-F852271973FC@gmail.com> <2608b8a80801211541y11ffd956l4664e4515cfb4300@mail.gmail.com> Message-ID: <20080122010506.3e33ee7e@solaris.tower> "Yitzchak Gale" wrote: > L'Ecuyer's implementations in C, C++ and Java are here: > > http://www.iro.umontreal.ca/~lecuyer/myftp/streams00/ > > If we had something like that in Haskell, I might use > split more often. > Speaking of that, the generators that come in the box are awfully slow, I ended up calling into http://www.math.sci.hiroshima-u.ac.jp/ ~m-mat/MT/SFMT/index.html via the ffi. I wouldn't know how to fit it into the Random type, though, it only supports floats and doubles, and converting the C source to use a struct for its data to make it instantiable is another obstacle. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From gale at sefer.org Mon Jan 21 19:24:00 2008 From: gale at sefer.org (Yitzchak Gale) Date: Mon Jan 21 19:23:49 2008 Subject: [Haskell-cafe] Hangman game In-Reply-To: <1200956091.5570.51.camel@derek-laptop> References: <1200781861.23242.0.camel@RonPcUbuntu> <47938021.3020002@cogito.org.uk> <2608b8a80801201103j10bcacedw6d02853fb002ff14@mail.gmail.com> <01F8A978-6B9C-4224-86B9-F852271973FC@gmail.com> <2608b8a80801211541y11ffd956l4664e4515cfb4300@mail.gmail.com> <1200956091.5570.51.camel@derek-laptop> Message-ID: <2608b8a80801211624y30ca4b70s825a5380c1f31b8b@mail.gmail.com> I wrote: >> That said, looking around briefly, I came up with this paper >> by L'Ecuyer et al that does seem to describe a decent >> random generator with properties of split worked out: Derek Elkins wrote: > According to the documentation > That -is- what we have. No, we have a much older algorithm of L'Ecuyer. It has a much smaller period - 2e18 vs. 3e51. Much less was known about testing generator randomness at that time. More importantly, very little was said in that paper about splitting. The newer algorithm includes all the computational details about splitting. Sadly, even the newer paper does not propose any tests for the independence properties of streams after splitting. The assumption seems to be that the voluminous testing of the underlying generator is sufficient for that also. Regards, Yitz From derek.a.elkins at gmail.com Mon Jan 21 18:32:41 2008 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Mon Jan 21 19:33:12 2008 Subject: [Haskell-cafe] Hangman game In-Reply-To: <2608b8a80801211624y30ca4b70s825a5380c1f31b8b@mail.gmail.com> References: <1200781861.23242.0.camel@RonPcUbuntu> <47938021.3020002@cogito.org.uk> <2608b8a80801201103j10bcacedw6d02853fb002ff14@mail.gmail.com> <01F8A978-6B9C-4224-86B9-F852271973FC@gmail.com> <2608b8a80801211541y11ffd956l4664e4515cfb4300@mail.gmail.com> <1200956091.5570.51.camel@derek-laptop> <2608b8a80801211624y30ca4b70s825a5380c1f31b8b@mail.gmail.com> Message-ID: <1200958361.5484.0.camel@derek-laptop> On Tue, 2008-01-22 at 02:24 +0200, Yitzchak Gale wrote: > I wrote: > >> That said, looking around briefly, I came up with this paper > >> by L'Ecuyer et al that does seem to describe a decent > >> random generator with properties of split worked out: > > Derek Elkins wrote: > > According to the documentation > > That -is- what we have. > > No, we have a much older algorithm of L'Ecuyer. It has > a much smaller period - 2e18 vs. 3e51. Much less was > known about testing generator randomness at that time. Yeah, my fault. From cetin.sert at gmail.com Mon Jan 21 19:39:33 2008 From: cetin.sert at gmail.com (Cetin Sert) Date: Mon Jan 21 19:39:23 2008 Subject: [Haskell-cafe] Yi and Data.ByteString In-Reply-To: <20080121192840.GG9346@localdomain> References: <1ff5dedc0801211012x6fdedd40ha0b44a5ac776c27b@mail.gmail.com> <20080121192840.GG9346@localdomain> Message-ID: <1ff5dedc0801211639o4b8dc589kdbac70d267eefc5d@mail.gmail.com> -- Yi that's the error message I got following the instructions on http://www.nobugs.org/developer/yi/building.html setup: At least the following dependencies are missing: fingertree -any make: *** [dist/setup-config] Error 1 Where can I get fingertree from? Do I need a specific version of this package? -- Data.ByteString Where can I read more about GHC options like -XOverloadedStrings or this ":: ByteString" type declaration? I did not know ByteString was less performant than a linked list of characters. It is used even in the language shootout benchmark programs. Cetin On 21/01/2008, pierre wrote: > > Hello, > > On Mon, Jan 21, 2008 at 07:12:26PM +0100, Cetin Sert wrote: > > 2) When if ever is Data.ByteString going to be the default string > > representation in GHC? > > Why would you need such a thing? ByteStrings don't have any unicode > support, and they can be quite slow for small strings. They are just a > different tool for different task. > > But if you wish, you could use string literals as bytestrings with > -XOverloadedStrings ghc (>=6.8) flag > > > Best Regards, > > Cetin Sert > > www.corsis.de > > -- > pierre > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080122/841c1184/attachment.htm From gale at sefer.org Mon Jan 21 19:41:30 2008 From: gale at sefer.org (Yitzchak Gale) Date: Mon Jan 21 19:41:19 2008 Subject: [Haskell-cafe] Re: Hangman game In-Reply-To: <20080122010506.3e33ee7e@solaris.tower> References: <1200781861.23242.0.camel@RonPcUbuntu> <47938021.3020002@cogito.org.uk> <2608b8a80801201103j10bcacedw6d02853fb002ff14@mail.gmail.com> <01F8A978-6B9C-4224-86B9-F852271973FC@gmail.com> <2608b8a80801211541y11ffd956l4664e4515cfb4300@mail.gmail.com> <20080122010506.3e33ee7e@solaris.tower> Message-ID: <2608b8a80801211641y45ad75c5q9a6091dcdcb83d92@mail.gmail.com> Achim Schneider wrote: > Speaking of that, the generators that come in the box are awfully slow, > I ended up calling into > http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/index.html > via the ffi. Yes, it would be nice to have the Mersenne Twister available. Not only for speed - it is widely used, so it could sometimes be very useful for us to be able to generate random sequences that are bit-compatible with the sequences generated in other languages. > I wouldn't know how to fit it into the Random type, though, it only > supports floats and doubles, and converting the C source to use a > struct for its data to make it instantiable is another obstacle. A few people worked all of that out. It's not a big deal. But it never was quite finished and put into the libraries. Yes, it is all the rage these days to do the calculations in floating point, due to the properties of current processors. It's not a problem to fit it into the RandomGen class - just convert to an Int when you're done. But that slows things down. Too bad the current Random class always forces you to go through Int. It was a good idea back then. We could fix this without breaking any current code. Regards, Yitz From dons at galois.com Mon Jan 21 19:41:26 2008 From: dons at galois.com (Don Stewart) Date: Mon Jan 21 19:41:34 2008 Subject: [Haskell-cafe] Yi and Data.ByteString In-Reply-To: <1ff5dedc0801211639o4b8dc589kdbac70d267eefc5d@mail.gmail.com> References: <1ff5dedc0801211012x6fdedd40ha0b44a5ac776c27b@mail.gmail.com> <20080121192840.GG9346@localdomain> <1ff5dedc0801211639o4b8dc589kdbac70d267eefc5d@mail.gmail.com> Message-ID: <20080122004126.GA27617@scytale.galois.com> cetin.sert: > -- Yi > > that's the error message I got following the instructions on > [1]http://www.nobugs.org/developer/yi/building.html > > setup: At least the following dependencies are missing: > fingertree -any > make: *** [dist/setup-config] Error 1 > > Where can I get fingertree from? Do I need a specific version of this > package? > > -- Data.ByteString > > Where can I read more about GHC options like -XOverloadedStrings or this > ":: ByteString" type declaration? > > I did not know ByteString was less performant than a linked list of > characters. It is used even in the language shootout benchmark programs. > It's not "always slower" or "always faster". There's some particular operations where short [Char] is going to be faster than a pinned array. -- Don From gwern0 at gmail.com Mon Jan 21 20:02:47 2008 From: gwern0 at gmail.com (gwern0@gmail.com) Date: Mon Jan 21 20:04:10 2008 Subject: [Haskell-cafe] Yi and Data.ByteString In-Reply-To: <1ff5dedc0801211639o4b8dc589kdbac70d267eefc5d@mail.gmail.com> References: <1ff5dedc0801211012x6fdedd40ha0b44a5ac776c27b@mail.gmail.com> <20080121192840.GG9346@localdomain> <1ff5dedc0801211639o4b8dc589kdbac70d267eefc5d@mail.gmail.com> Message-ID: <20080122010247.GA2999@localhost> On 2008.01.22 01:39:33 +0100, Cetin Sert scribbled 3.4K characters: > -- Yi > > that's the error message I got following the instructions on > http://www.nobugs.org/developer/yi/building.html > > setup: At least the following dependencies are missing: > fingertree -any > make: *** [dist/setup-config] Error 1 > > Where can I get fingertree from? Do I need a specific version of this package? http://hackage.haskell.org/cgi-bin/hackage-scripts/package/fingertree-0.0 Always a good idea to check Hackage when dependencies are missing. > -- Data.ByteString > > Where can I read more about GHC options like -XOverloadedStrings or this ":: ByteString" type > declaration? The ByteString API documentation, presumably. > I did not know ByteString was less performant than a linked list of characters. It is used > even in the language shootout benchmark programs. > > Cetin As Don said, it's a matter of domain. For small amounts of data, the overhead erases the performance gains - although no one is denying that for medium (like you see on the Shootout) to large amounts of data (up to tera-, I think someone benchmarked) ByteString is excellent. -- gwern O/S bet pipe-bomb SARA Adriatic BSS M5 LBSD NOCS CBNRC -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080121/392733b7/attachment.bin From tharris at microsoft.com Mon Jan 21 21:07:07 2008 From: tharris at microsoft.com (Tim Harris (RESEARCH)) Date: Mon Jan 21 21:06:59 2008 Subject: [Haskell-cafe] Control.Concurrent.STM.old? In-Reply-To: <1200698062.3374.5.camel@localhost> References: <1200698062.3374.5.camel@localhost> Message-ID: Hi, I don't think we included this in the version we checked in. It should be fairly easy to add to the current implementation: it will mirror ReadTVar except that the old value is always selected. I'm afraid I can't remember exactly why we didn't include it. One reason might have been that it would constrain alternative implementations -- for example one built over hardware transactional memory which might not necessarily provide access to the old state. Tim -----Original Message----- From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Thomas DuBuisson Sent: 19 January 2008 00:14 To: haskell-cafe@haskell.org Subject: [Haskell-cafe] Control.Concurrent.STM.old? Does the 'old' function referenced in the SPJ and Tim Harris data invariants paper stil exist? It is of type STM a -> STM a and allowed invariants to compare old TVar values with new ones. I can't find it in any of the Haddocks or the code (and the 'check' funciton is not commented in the Haddock). Tom _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe From dons at galois.com Mon Jan 21 22:53:13 2008 From: dons at galois.com (Don Stewart) Date: Mon Jan 21 22:53:10 2008 Subject: [Haskell-cafe] Announce: mersenne-random 0.1, very fast pseudo-random number generation for Haskell Message-ID: <20080122035313.GB27617@scytale.galois.com> Hey all, I'm pleased to announce the creation of the mersenne-random package, The Mersenne twister is a pseudorandom number generator developed by Makoto Matsumoto and Takuji Nishimura, that provides for fast generation of very high quality pseudorandom numbers, suitable for simulators and monte carlo modelling. This library binds to 'SFMT', the SIMD-oriented Fast Mersenne Twister. SFMT is a variant of Mersenne Twister that is much faster than the original. It is designed to be fast when it runs on 128-bit SIMD. To compile in the vector instructions use Cabal, and pass '-f use_sse2' or '-f use_altivec' to configure, depend on which set your cpu supports (or none if it doesn't). The use of sse2 instructions will typically halve the generation time. The library is very fast (generation of Ints and Doubles will be some 50x faster than System.Random), but the implementation we bind to is heavily impure, so only a single generator is possible per-process (splitting generators is also not supported). Some light abstractions are implemented over the raw C interface, including a type class for SFMT-generated Haskell values, and lists of those values. Full 64 bit Ints and Doubles, and 53-bit precision Doubles, are supported on 64 bit machines. As usual, the stable branch is on hackage, so you can install it with cabal: $ cabal install mersenne-random Note that the cpu isn't detected automatically, so to turn on SIMD flags for your cpu, you'll need to build it by hand from: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/mersenne-random And the darcs repo is at code.haskell.org, darcs get http://code.haskell.org/~dons/code/mersenne-random A test suite and example programs are provided. Enjoy, Don From ronguida at mindspring.com Mon Jan 21 22:56:26 2008 From: ronguida at mindspring.com (Ronald Guida) Date: Mon Jan 21 22:56:16 2008 Subject: [Haskell-cafe] Hangman game In-Reply-To: <2608b8a80801201103j10bcacedw6d02853fb002ff14@mail.gmail.com> References: <1200781861.23242.0.camel@RonPcUbuntu> <47938021.3020002@cogito.org.uk> <2608b8a80801201103j10bcacedw6d02853fb002ff14@mail.gmail.com> Message-ID: <1200974186.2879.2.camel@RonPcUbuntu> Thank you for the positive responses. The best kind of feedback is the kind that makes me have to think, and I've done alot of thinking. _Regarding monads and interfaces_ Paul Johnson wrote: > 1: Your GameState type can itself be made into a monad. Take a look > at the "All About Monads" tutorial, especially the State > monad. Think about the invariants in GameState; can you produce a > new monad that guarantees these invariants through a limited set of > actions. How do these actions correspond to user perceptions? > > 2: You can layer monads by using monad transformers. Extend the > solution to part 1 by using StateT IO instead of just State. OK, Here's the new monad and the corresponding transformer. > type Hangman = State GameState > type HangmanT = StateT GameState And here's an interface for the Hangman monad. > newHangmanGame :: (MonadState GameState m) => String -> m () > newHangmanGame = put . newGameState > > renderHangmanGame :: (MonadIO m, MonadState GameState m) => m () > renderHangmanGame = get >>= return . renderGameState > >>= liftIO . putStrLn > > guessLetter :: (MonadState GameState m) => Char -> m () > guessLetter = modify . handleGuess > > getWonLost :: (MonadState GameState m) => m (Maybe Bool) > getWonLost = get >>= return . gsWonLost > > getAnswer :: (MonadState GameState m) => m String > getAnswer = get >>= return . gsAnswer This all seems a little pointless :) for a simple game, nevertheless I proceeded to modify startNewGame and gameLoop to use the Hangman interface. The modifications were trivial. The type signatures for startNewGame and gameLoop become: > startNewGame :: HangmanT IO () > gameLoop :: HangmanT IO () _Regarding random numbers_ Yitzchak Gale wrote: > You can add one more field to GameState that holds a random > generator. I tried it; it was very easy. Paul Johnson wrote: > Can you make your game a function of a list of random numbers? Yitzchak Gale wrote: > I would advise against that technique. In more complex games, you > may need to do many different kinds of random calculations in > complex orders. Keeping a random generator inside a state monad is > perfect for that. And since Ronald already set up the plumbing for > the state monad, he is already home. I simply modified startNewGame and gameLoop to accept a list of integers. In startNewGame, I use the first integer in the list to choose a word, and then I pass the rest of the list to gameLoop. In gameLoop, I simply pass the list along to every recursive call to startNewGame or gameLoop. > main :: IO () > main = do > ... > g <- getStdGen > let rs = randomRs (0,length wordList - 1) g > runStateT (startNewGame rs) undefined > return () > > startNewGame :: [Int] -> HangmanT IO () > startNewGame (r:rs) = do > let word = wordList !! r > newHangmanGame word > renderHangmanGame > gameLoop rs > > gameLoop :: [Int] -> HangmanT IO () > gameLoop rs = ... I suppose I could easily push the list of random numbers into GameState to avoid manually threading it around my program. If I did that, then the only difference between the two techniques would be (1) adding a field to hold a random number generator, vs (2) adding a field to hold an infinite list of random numbers. If I store a list of numbers, then I have to choose a probability distribution at initialization time. If I store the generator, then I am free to change the probability distribution on the fly. For a Hangman game, the only time I need to change the probability distribution is if I load a new word list. If I wanted to be able to load a new word list, then perhaps I need to carry the word list inside the GameState as well? _Random numbers continued_ So let me create a HangmanRand monad to encapsulate the process of selecting random words. > type HangmanRand = State RandState > type HangmanRandT = StateT RandState > > data RandState = RandState { > rsRandGen :: StdGen, -- the random number generator > rsWordList :: [String] -- the word list > } > > initHangmanRand :: (MonadState RandState m) => [String] -> StdGen -> m () > initHangmanRand words g = put $ RandState{ > rsRandGen = g, > rsWordList = words} > > getRandomWord :: (MonadState RandState m) => m String > getRandomWord = do > rs <- get > let words = rsWordList rs > let (n, g) = randomR (0,length words - 1) $ rsRandGen rs > put $ rs{rsRandGen = g} > return $ words !! n I can easily modify the game to use HangmanRand. My gameLoop doesn't have to change at all (apart from the type signature). > main :: IO () > main = do > hSetBuffering stdout NoBuffering > putStr "Welcome to Hangman!\n\n" > putStr instructions > let seed = 5 > let g = mkStdGen seed > runStateT (runStateT (initGame wordList g) undefined) undefined > return () > > initGame :: [String] -> StdGen -> HangmanT (HangmanRandT IO) () > initGame words g = do > lift $ initHangmanRand words g > startNewGame > > startNewGame :: HangmanT (HangmanRandT IO) () > startNewGame = do > word <- lift getRandomWord > newHangmanGame word > renderHangmanGame > gameLoop > > gameLoop :: HangmanT (HangmanRandT IO) () > gameLoop = ... If I wanted to make my program a function of a list of random numbers, then I would need to change main, initGame, and the implementation of HangmanRand. Again, the gameLoop wouldn't have to change at all. _Regarding user input_ Paul Johnson wrote: > 4: User input can also be considered as a list. Haskell has "lazy > input", meaning that you can treat user input as a list that > actually only gets read as it is required. Can you make your game a > function of the list of user inputs? How does this interact with the > need to present output to the user? What about the random numbers? Yitzchak Gale wrote: > That type of "lazy IO" is considered by many to be one of Haskell's > few warts. It is a hole in the type system that lets a small amount > of side-effects leak through, and even that small amount leads to > bugs. It turns out there is only one place in my entire code where I request input from the user. This place is the call to getLine inside the function getUserInput: > getUserInput :: IO UserInput > getUserInput = do > putStr "Hangman> " > response <- getLine > ... I tried changing this to: > getUserInput :: [String] -> IO (UserInput, [String]) > getUserInput (response:rs)= do > putStr "Hangman> " > ... In order to make this work, I need to thread the list of inputs around my program. Thus: > startNewGame :: [String] -> HangmanT IO [String] > gameLoop :: [String] -> HangmanT IO [String] To get the whole thing started: > main :: IO () > main = do > ... > rs <- hGetContents stdin >>= return . lines > ... This approach fails because the "Hangman>" prompt is not printed until immediately /after/ the user enters a response. I tried using hFlush but that didn't work. In order to keep input and output synchronized, I had to do this: > getUserInput :: [String] -> IO (UserInput, [String]) > getUserInput rs'= do > putStr "Hangman> " > let (response:rs) = rs' > ... Apparently, if I am accepting my input as a list, then I have to be careful to avoid forcing the elements of that list until I actually need them. Meanwhile, just like with the random numbers, I can avoid manually threading the list of inputs through the program. All I would have to do is push the list of inputs into the GameState and add a utility function that pulls off one input at a time. Or better yet, I could create a HangmanIO monad to store the list of inputs. > type HangmanIO = State HangmanIOState > type HangmanIOT = StateT HangmanIOState > > initHangmanIO :: (MonadState HangmanIOState m) => [String] -> m () > initHangmanIO userInputs = put $ HangmanIOState{ > hioInputList = userInputs} > > getResponse :: (MonadState HangmanIOState m) => m String > getResponse = do > s <- get > let (x:xs) = hioInputList s > put $ s{hioInputList = xs} > return x > > data HangmanIOState = HangmanIOState { > hioInputList :: [String] -- the list of user inputs > } I have to modify the program like this: > main :: IO () > main = do > hSetBuffering stdout NoBuffering > putStr "Welcome to Hangman!\n\n" > putStr instructions > let seed = 5 > let g = mkStdGen seed > responses <- hGetContents stdin >>= return . lines > runStateT (runStateT (runStateT > (initGame wordList g responses) > undefined) undefined) undefined > return () > > initGame :: [String] -> StdGen -> [String] -> > HangmanT (HangmanRandT (HangmanIOT IO)) () > initGame words g responses = do > lift $ initHangmanRand words g > lift $ lift $ initHangmanIO responses > startNewGame > > startNewGame :: HangmanT (HangmanRandT (HangmanIOT IO)) () > startNewGame = ... > > gameLoop :: HangmanT (HangmanRandT (HangmanIOT IO)) () > gameLoop = do > ui <- lift $ lift getUserInput > ... > > getUserInput :: (MonadIO m, MonadState HangmanIOState m) => m UserInput > getUserInput = do > liftIO $ putStr "Hangman> " > response <- getResponse > ... -- and I have to use liftIO for my output commands I successfully moved my game input from the IO monad to my HangmanIO monad. I actually attempted to go all the way and move /output/ from the IO monad to HangmanIO as well. The resulting program uses "interact" at the top level in main. Unfortunately, the program doesn't work. None of the output actually appears until I quit the game, and then all the output is produced at one time. And this time I have no idea how to fix it. Moving random number generation and IO around has been a nice learning exercise for me. In particular, moving the random number generator into its own monad (or into GameState) seems like a very useful thing to do. On the other hand, moving the game's IO into its own monad (HangmanIO) seems like reinventing the wheel. My understanding is that back in ancient times "main" had the signature "String -> String". Programs were very hard to write because they needed to have just the right mix of laziness and strictness to ensure proper interleaving of inputs and outputs. Then one day someone realized that there's this esoteric concept in category theory that could solve the IO problem, and the rest is history. I'm simply better off using the IO monad. _Regarding scalability_ Paul Johnson wrote: > The design reads very much like a straight translation from the > imperative style, which is why so much of it is in the IO monad. > There is nothing wrong with this for a simple game like Hangman, > but for larger games it doesn't scale. Yitzchak Gale wrote: > It's a state monad, and most of his code is in that style. It > doesn't read to me like imperative style at all. And it scales > beautifully. To see if my code can scale, I would have to think about extensions to my Hangman game, or think about more complicated games. I think this one will have to wait until much later. -- Ron From iseff at iseff.com Tue Jan 22 00:29:40 2008 From: iseff at iseff.com (Ian Sefferman) Date: Tue Jan 22 00:29:33 2008 Subject: [Haskell-cafe] Haskell web dev: Using Haskell and HAppS for Openomy API v2.0 In-Reply-To: <20080121185625.GB25564@scytale.galois.com> References: <20080121185625.GB25564@scytale.galois.com> Message-ID: Indeed, from us at Openomy, we thank all those involved in HAppS for their work, and more importantly, their help with all our questions along the way. :) We're happy to answer any questions anyone may have on our experience, implementation, etc. Ian On 1/21/08, Don Stewart wrote: > A deployment of HAppS, AlexJ et al's web framework for Haskell, at "openomy", > > > The latest release of our API is written in Haskell using the new HAppS > > framework. > > The good news, > > > Since being in production, we've so far found very few issues and > > everything runs quickly and smoothly. Haskell and HAppS have turned > > out to be a very nice addition to our stable of tools and services. > > See the review here, > > http://blog.openomy.com/2008/01/case-study-using-haskell-and-happs-for.html > > Congratulations to Alex, Musasabi, Shapr, Igloo, Lemmih et al who've worked on > getting HAppS into the real world! :) > > -- Don > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- Ian Sefferman http://www.openomy.com | http://www.iseff.com From cetin.sert at gmail.com Tue Jan 22 01:03:37 2008 From: cetin.sert at gmail.com (Cetin Sert) Date: Tue Jan 22 01:03:26 2008 Subject: [Haskell-cafe] non-alphabetical mathematical symbols as non-infix function names Message-ID: <1ff5dedc0801212203k49d4aeeei1c6c9a758495a12a@mail.gmail.com> (?) :: Bool ? Bool (?) q = not q q = True ? q : parser error on input q ? : parser error (possibly incorrect indentation) (? q) : Couldn't match expected type `Bool -> t' against inferred type `Bool' In the expression: (? True) In the definition of `it': it = (? True) * (q ?) : False (Why) is it not possible to define a (non-infix) function whose name consists of a single non-alphabetical mathematical symbol? ? :: Bool ? Bool -- parser error on input ** ? q = not q -- parser error on input ** Cetin Sert -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080122/53b57437/attachment-0001.htm From miguelimo38 at yandex.ru Tue Jan 22 01:23:50 2008 From: miguelimo38 at yandex.ru (Miguel Mitrofanov) Date: Tue Jan 22 01:23:50 2008 Subject: [Haskell-cafe] non-alphabetical mathematical symbols as non-infix function names In-Reply-To: <1ff5dedc0801212203k49d4aeeei1c6c9a758495a12a@mail.gmail.com> References: <1ff5dedc0801212203k49d4aeeei1c6c9a758495a12a@mail.gmail.com> Message-ID: MigMit:~ MigMit$ ghci GHCi, version 6.8.2: http://www.haskell.org/ghc/ :? for help Loading package base ... linking ... done. Prelude> let {(?) :: Bool -> Bool; (?) = not} Prelude> (?) True False On 22 Jan 2008, at 09:03, Cetin Sert wrote: > (?) :: Bool ? Bool > (?) q = not q > > q = True > ? q : parser error on input > q ? : parser error (possibly incorrect indentation) > (? q) : Couldn't match expected type `Bool -> t' against inferred > type `Bool' In the expression: (? True) In the definition of `it': > it = (? True) * > (q ?) : False > > (Why) is it not possible to define a (non-infix) function whose name > consists of a single non-alphabetical mathematical symbol? > > ? :: Bool ? Bool -- parser error on input ** > ? q = not q -- parser error on input ** > > Cetin Sert > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From bulat.ziganshin at gmail.com Mon Jan 21 14:32:50 2008 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Tue Jan 22 02:11:59 2008 Subject: [Haskell-cafe] Newbie question In-Reply-To: <6ffb76200801210737u853b60fyf6e7014ff3d98bad@mail.gmail.com> References: <6ffb76200801210737u853b60fyf6e7014ff3d98bad@mail.gmail.com> Message-ID: <8510380570.20080121223250@gmail.com> Hello Alexander, Monday, January 21, 2008, 6:37:38 PM, you wrote: > Hi, I try to undestand why this code dosen't work > f :: (Num a)=>Integer->a > f i = i as for every beginner which tries to grok type classes, i recommend you to read http://haskell.org/haskellwiki/OOP_vs_type_classes and especially papers mentioned there in References section also, i recommend you to subscribe to ru_declarative and ru_lambda LiveJournal communities and read them back - several month ago i've placed there simple explanation of differences between C++ templates, OOP classes and Haskell type classes -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bulat.ziganshin at gmail.com Mon Jan 21 14:39:25 2008 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Tue Jan 22 02:12:14 2008 Subject: [Haskell-cafe] Newbie question In-Reply-To: <6ffb76200801210836w776d9469q5228ad506480a1e1@mail.gmail.com> References: <6ffb76200801210737u853b60fyf6e7014ff3d98bad@mail.gmail.com> <22fcbd520801210743w16a0c7a4n25ff2cb28b0c65b3@mail.gmail.com> <6ffb76200801210836w776d9469q5228ad506480a1e1@mail.gmail.com> Message-ID: <1297610100.20080121223925@gmail.com> Hello Alexander, Monday, January 21, 2008, 7:36:18 PM, you wrote: > How does caller choose which particular instance of Num they want? > In object-oriented language If function return type is an interface > it means that it can return any implementation of this interface, > but caller can't choose which particular inplementation they want. but type class isn't an interface! it's just like interface in one concrete area - it includes method specifications, but not includes data fields the type that should ?? returned by function is passed by means of so-called dictionary and which type should be returned is defined by type inference process. for example main = print (length [] + f 1) here f should return Int because length return Int and you can't add values of different types (without explicit type conversion). you should also read something about two-way type inference but i don't know any good source please note that in modern OOP languages (latest C# versions, C++ 0x) support for *one-way* type inference was only added, i.e. they only can deduce type of expression from types of operands, while Haskell deduces types in both directions -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bulat.ziganshin at gmail.com Mon Jan 21 14:41:21 2008 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Tue Jan 22 02:12:34 2008 Subject: [Haskell-cafe] Re: Newbie question In-Reply-To: <6ffb76200801210928v5464a589g5513bb5cba8a20d2@mail.gmail.com> References: <6ffb76200801210737u853b60fyf6e7014ff3d98bad@mail.gmail.com> <22fcbd520801210743w16a0c7a4n25ff2cb28b0c65b3@mail.gmail.com> <6ffb76200801210836w776d9469q5228ad506480a1e1@mail.gmail.com> <6ffb76200801210928v5464a589g5513bb5cba8a20d2@mail.gmail.com> Message-ID: <636691941.20080121224121@gmail.com> Hello Alexander, Monday, January 21, 2008, 8:28:33 PM, you wrote: > So, the function type "(Num a)=>Integer->a" means that return value > of this function can be cast to any particular instance of class Num. no! this means that the function really can return value of any type - the calller (implicitly, via dictionary) says which type should be returned -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bulat.ziganshin at gmail.com Mon Jan 21 14:43:00 2008 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Tue Jan 22 02:12:47 2008 Subject: [Haskell-cafe] Yi and Data.ByteString In-Reply-To: <1ff5dedc0801211012x6fdedd40ha0b44a5ac776c27b@mail.gmail.com> References: <1ff5dedc0801211012x6fdedd40ha0b44a5ac776c27b@mail.gmail.com> Message-ID: <1653031251.20080121224300@gmail.com> Hello Cetin, Monday, January 21, 2008, 9:12:26 PM, you wrote: > 2) When if ever is Data.ByteString going to be the default string representation in GHC? there is no need, you can just use it as any other type. having rich library is enough condition -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bulat.ziganshin at gmail.com Mon Jan 21 14:46:29 2008 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Tue Jan 22 02:13:01 2008 Subject: [Haskell-cafe] Re: Newbie question In-Reply-To: References: <6ffb76200801210737u853b60fyf6e7014ff3d98bad@mail.gmail.com> <22fcbd520801210743w16a0c7a4n25ff2cb28b0c65b3@mail.gmail.com> <6ffb76200801210836w776d9469q5228ad506480a1e1@mail.gmail.com> <6ffb76200801210928v5464a589g5513bb5cba8a20d2@mail.gmail.com> Message-ID: <1622216372.20080121224629@gmail.com> Hello Jon, Monday, January 21, 2008, 9:28:09 PM, you wrote: >> Ok. I have a my own class "class A a" and want to write function like >> this "f:: (A a)=>Integer->a". Can I do it? > But in general you are going to want something a bit more > useful, which means that you have to have a path from > Integer to a i.e. you should have other functions that produce A from Integer and at the last end this means that class A should provide some way to do it -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From magnus at therning.org Tue Jan 22 04:29:08 2008 From: magnus at therning.org (Magnus Therning) Date: Tue Jan 22 04:29:07 2008 Subject: [Haskell-cafe] Has character changed in GHC 6.8? Message-ID: <4795B764.8010305@therning.org> I vaguely remember that in GHC 6.6 code like this length $ map ord "a string" being able able to generate a different answer than length "a string" At the time I thought that the encoding (in my case UTF-8) was ?leaking through?. After switching to GHC 6.8 the behaviour seems to have changed, and mapping 'ord' on a string results in a list of ints representing the Unicode code point rather than the encoding: > map ord "???" [229,228,246] Is this the case, or is there something strange going on with character encodings? I was hoping that this would mean that 'chr . ord' would basically be a no-op, but no such luck: > chr . ord $ '?' '\229' What would I have to do to get an '?' from '229'? /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus?therning?org Jabber: magnus?therning?gmail?com http://therning.org/magnus What if I don't want to obey the laws? Do they throw me in jail with the other bad monads? -- Daveman -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 189 bytes Desc: OpenPGP digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080122/a16dd2a3/signature.bin From felipe.lessa at gmail.com Tue Jan 22 04:45:14 2008 From: felipe.lessa at gmail.com (Felipe Lessa) Date: Tue Jan 22 04:45:02 2008 Subject: [Haskell-cafe] Has character changed in GHC 6.8? In-Reply-To: <4795B764.8010305@therning.org> References: <4795B764.8010305@therning.org> Message-ID: 2008/1/22 Magnus Therning : > I vaguely remember that in GHC 6.6 code like this > > length $ map ord "a string" > > being able able to generate a different answer than > > length "a string" I guess it's not very difficult to prove that ? f xs. length xs == length (map f xs) even in the presence of seq. -- Felipe. From miguelimo38 at yandex.ru Tue Jan 22 04:56:42 2008 From: miguelimo38 at yandex.ru (Miguel Mitrofanov) Date: Tue Jan 22 04:56:42 2008 Subject: [Haskell-cafe] Has character changed in GHC 6.8? In-Reply-To: 1630000000233858523 References: 1630000000233858523 Message-ID: <1442921200995802@webmail40.yandex.ru> > > chr . ord $ '?' > '\229' > What would I have to do to get an '?' from '229'? It seems you already have it; '?' is the same as '\229'. But IO output is still 8-bit, so when you ask ghci to print '?', you get '\229'. You can use utf-string library (from hackage). From jon.fairbairn at cl.cam.ac.uk Tue Jan 22 05:04:48 2008 From: jon.fairbairn at cl.cam.ac.uk (Jon Fairbairn) Date: Tue Jan 22 05:04:44 2008 Subject: [Haskell-cafe] Re: Newbie question References: <6ffb76200801210737u853b60fyf6e7014ff3d98bad@mail.gmail.com> <22fcbd520801210743w16a0c7a4n25ff2cb28b0c65b3@mail.gmail.com> <6ffb76200801210836w776d9469q5228ad506480a1e1@mail.gmail.com> <6ffb76200801210928v5464a589g5513bb5cba8a20d2@mail.gmail.com> <1622216372.20080121224629@gmail.com> Message-ID: Bulat Ziganshin writes: > Hello Jon, > > Monday, January 21, 2008, 9:28:09 PM, you wrote: > >>> Ok. I have a my own class "class A a" and want to write function like >>> this "f:: (A a)=>Integer->a". Can I do it? > >> But in general you are going to want something a bit more >> useful, which means that you have to have a path from >> Integer to a > > i.e. you should have other functions that produce A from Integer and > at the last end this means that class A should provide some way to > do it I'm not sure we're using the same terminology. In the example I gave, the class A doesn't provide anything from Integer to a, unless defining an overloaded function outside the class definition counts as the class providing something. -- J?n Fairbairn Jon.Fairbairn@cl.cam.ac.uk From bertram.felgenhauer at googlemail.com Tue Jan 22 05:08:20 2008 From: bertram.felgenhauer at googlemail.com (Bertram Felgenhauer) Date: Tue Jan 22 05:08:07 2008 Subject: [Haskell-cafe] Hamming's Problem In-Reply-To: <20080121151752.GB5845@zombie.inf.tu-dresden.de> References: <003f01c85908$edbf5950$c93e0bf0$@com> <20080118123544.GA4270@zombie.inf.tu-dresden.de> <000301c85c2b$0a465630$1ed30290$@com> <20080121151752.GB5845@zombie.inf.tu-dresden.de> Message-ID: <30e962d20801220208i993b8a6he410f771d6558ca9@mail.gmail.com> I wrote: > merge' (x:xs) ys = x : merge xs ys > > hammingx = 1 : foldr1 merge' [map (h x) hammingx | x <- hammingx] Sorry. 'foldr1' is still slightly too strict. (Why doesn't the Haskell report define foldr1 in terms of foldr?) The code that works is marge' [] ys = ys merge' (x:xs) ys = x : merge xs ys hammingx = 1 : foldr merge' [] [map (h x) hammingx | x <- hammingx] I had tested that version, but I assumed the foldr1 version would be equivalent. > which actually works. And I wrote that without testing. Shame on me. Bertram From duncan.coutts at worc.ox.ac.uk Tue Jan 22 05:36:44 2008 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Tue Jan 22 05:37:09 2008 Subject: [Haskell-cafe] Has character changed in GHC 6.8? In-Reply-To: <4795B764.8010305@therning.org> References: <4795B764.8010305@therning.org> Message-ID: <1200998205.5639.495.camel@localhost> On Tue, 2008-01-22 at 09:29 +0000, Magnus Therning wrote: > I vaguely remember that in GHC 6.6 code like this > > length $ map ord "a string" > > being able able to generate a different answer than > > length "a string" That seems unlikely. > At the time I thought that the encoding (in my case UTF-8) was ?leaking > through?. After switching to GHC 6.8 the behaviour seems to have > changed, and mapping 'ord' on a string results in a list of ints > representing the Unicode code point rather than the encoding: Yes. GHC 6.8 treats .hs files as UTF-8 where it previously treated them as Latin-1. > > map ord "???" > [229,228,246] > > Is this the case, or is there something strange going on with character > encodings? That's what we'd expect. Note that GHCi still uses Latin-1. This will change in GHC-6.10. > I was hoping that this would mean that 'chr . ord' would basically be a > no-op, but no such luck: > > > chr . ord $ '?' > '\229' > > What would I have to do to get an '?' from '229'? Easy! Prelude> '?' == '\229' True Prelude> '?' == Char.chr 229 True Remember, when you type: Prelude> '?' what you really get is: Prelude> putStrLn (show '?') So perhaps what is confusing you is the Show instance for Char which converts Char -> String into a portable ascii representation. Duncan From duncan.coutts at worc.ox.ac.uk Tue Jan 22 05:40:21 2008 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Tue Jan 22 05:40:40 2008 Subject: [Haskell-cafe] non-alphabetical mathematical symbols as non-infix function names In-Reply-To: <1ff5dedc0801212203k49d4aeeei1c6c9a758495a12a@mail.gmail.com> References: <1ff5dedc0801212203k49d4aeeei1c6c9a758495a12a@mail.gmail.com> Message-ID: <1200998421.5639.499.camel@localhost> On Tue, 2008-01-22 at 07:03 +0100, Cetin Sert wrote: > (?) :: Bool ? Bool > (?) q = not q > > q = True > ? q : parser error on input > q ? : parser error (possibly incorrect indentation) > (? q) : Couldn't match expected type `Bool -> t' against inferred type > `Bool' In the expression: (? True) In the definition of `it': it = (? > True) * > (q ?) : False > > (Why) is it not possible to define a (non-infix) function whose name > consists of a single non-alphabetical mathematical symbol? Haskell does not support user-defined unary prefix operators, only infix. The only one is prefix negation -n. Duncan From duncan.coutts at worc.ox.ac.uk Tue Jan 22 05:46:52 2008 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Tue Jan 22 05:47:12 2008 Subject: [Haskell-cafe] Has character changed in GHC 6.8? In-Reply-To: <1442921200995802@webmail40.yandex.ru> References: 1630000000233858523 <1442921200995802@webmail40.yandex.ru> Message-ID: <1200998812.5639.507.camel@localhost> On Tue, 2008-01-22 at 12:56 +0300, Miguel Mitrofanov wrote: > > > chr . ord $ '?' > > '\229' > > What would I have to do to get an '?' from '229'? > > It seems you already have it; '?' is the same as '\229'. Yes. > But IO output is still 8-bit, so when you ask ghci to print '?', you get '\229'. No. :-) if you 'print' it you get: print '?' = putStrLn (show '?') = putStrLn "\229" this has nothing to do with 8-bit IO. It's just what 'show' does for Char. If you.. putStrLn "?" then you do get the low 8 bits being printed. But that's not what is going on above. > You can use utf-string library (from hackage). import qualified Codec.Binary.UTF8.String as UTF8 putStrLn (UTF8.encodeString "?") or just: import qualified System.IO.UTF8 UTF8.putStrLn "?" Duncan From gale at sefer.org Tue Jan 22 06:18:04 2008 From: gale at sefer.org (Yitzchak Gale) Date: Tue Jan 22 06:17:51 2008 Subject: [Haskell-cafe] Announce: mersenne-random 0.1, very fast pseudo-random number generation for Haskell In-Reply-To: <20080122035313.GB27617@scytale.galois.com> References: <20080122035313.GB27617@scytale.galois.com> Message-ID: <2608b8a80801220318h15086dd9g4888eccff0167bb9@mail.gmail.com> Don Stewart wrote: > I'm pleased to announce the creation of the mersenne-random package, Excellent! We were just discussing that. > ...the implementation we bind to is heavily > impure, so only a single generator is possible per-process (splitting > generators is also not supported)... > Note that the cpu isn't detected automatically, so to turn on SIMD flags > for your cpu, you'll need to build it by hand These are critical pieces of information. The only place I see them is in this email. Perhaps you should add them to the description on the Hackage page? Or at least to the README? > Some light abstractions are implemented over the raw C interface, including > a type class for SFMT-generated Haskell values, and lists of those values. Haddocks for this? Thanks, Yitz From lemming at henning-thielemann.de Tue Jan 22 07:48:11 2008 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Tue Jan 22 07:47:59 2008 Subject: [Haskell-cafe] Has character changed in GHC 6.8? In-Reply-To: <1200998205.5639.495.camel@localhost> References: <4795B764.8010305@therning.org> <1200998205.5639.495.camel@localhost> Message-ID: On Tue, 22 Jan 2008, Duncan Coutts wrote: > > At the time I thought that the encoding (in my case UTF-8) was ?leaking > > through?. After switching to GHC 6.8 the behaviour seems to have > > changed, and mapping 'ord' on a string results in a list of ints > > representing the Unicode code point rather than the encoding: > > Yes. GHC 6.8 treats .hs files as UTF-8 where it previously treated them > as Latin-1. Can this be controlled by an option? From duncan.coutts at worc.ox.ac.uk Tue Jan 22 08:18:00 2008 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Tue Jan 22 08:17:54 2008 Subject: [Haskell-cafe] Has character changed in GHC 6.8? In-Reply-To: References: <4795B764.8010305@therning.org> <1200998205.5639.495.camel@localhost> Message-ID: <1201007880.5639.511.camel@localhost> On Tue, 2008-01-22 at 13:48 +0100, Henning Thielemann wrote: > On Tue, 22 Jan 2008, Duncan Coutts wrote: > > > > At the time I thought that the encoding (in my case UTF-8) was ?leaking > > > through?. After switching to GHC 6.8 the behaviour seems to have > > > changed, and mapping 'ord' on a string results in a list of ints > > > representing the Unicode code point rather than the encoding: > > > > Yes. GHC 6.8 treats .hs files as UTF-8 where it previously treated them > > as Latin-1. > > Can this be controlled by an option? >From the GHC manual: GHC assumes that source files are ASCII or UTF-8 only, other encodings are not recognised. However, invalid UTF-8 sequences will be ignored in comments, so it is possible to use other encodings such as Latin-1, as long as the non-comment source code is ASCII only. There is no option to have GHC assume a different encoding. You can use something like iconv to convert .hs files from another encoding into UTF-8. Duncan From bulat.ziganshin at gmail.com Tue Jan 22 03:06:03 2008 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Tue Jan 22 08:53:29 2008 Subject: [Haskell-cafe] Yi and Data.ByteString In-Reply-To: <20080121191815.GB30857@localhost> References: <1ff5dedc0801211012x6fdedd40ha0b44a5ac776c27b@mail.gmail.com> <20080121191815.GB30857@localhost> Message-ID: <1094142233.20080122110603@gmail.com> Hello gwern0, Monday, January 21, 2008, 10:18:15 PM, you wrote: > really built-in - they're a separate library. You could perhaps > suggest that [Char] could be often optimized into ByteString > operations but then ByteStrings need to either lose their library > status and be incorporated into GHC it is no problem, although it should be done in a bit different way. some concrete version of ByteString library should be built-in into GHC (base library, probably) and used *only* for this purpose while ByteString library by itself should remain separate and continue to improve -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bulat.ziganshin at gmail.com Tue Jan 22 03:08:52 2008 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Tue Jan 22 08:53:44 2008 Subject: [Haskell-cafe] Re: Newbie question In-Reply-To: <1200951409.4231.11.camel@localhost.localdomain> References: <6ffb76200801210737u853b60fyf6e7014ff3d98bad@mail.gmail.com> <22fcbd520801210743w16a0c7a4n25ff2cb28b0c65b3@mail.gmail.com> <6ffb76200801210836w776d9469q5228ad506480a1e1@mail.gmail.com> <1200951409.4231.11.camel@localhost.localdomain> Message-ID: <6280202.20080122110852@gmail.com> Hello Peter, Tuesday, January 22, 2008, 12:36:49 AM, you wrote: > Hey, I knew about the forall (I use that to represent OO style > collections, very handy), but not about the exists. Thanks. But GHC > 6.8.2 (with -fglasgow-exts) does not seem to accept this "exists" > keyword? > Does a book or document already exist (except the website) that tells > more about not standarized yet very cool Haskell thingies that make > writing real world applications possible? I would LOVE such a book. are you read GHC docs? its chapter 7 is all about language extensions and also contains further references -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From barsoap at web.de Tue Jan 22 09:02:38 2008 From: barsoap at web.de (Achim Schneider) Date: Tue Jan 22 09:02:35 2008 Subject: [Haskell-cafe] Re: Hangman game References: <1200781861.23242.0.camel@RonPcUbuntu> <47938021.3020002@cogito.org.uk> <2608b8a80801201103j10bcacedw6d02853fb002ff14@mail.gmail.com> <1200974186.2879.2.camel@RonPcUbuntu> Message-ID: <20080122150238.28189ff4@solaris.tower> Ronald Guida wrote: > For a Hangman game, the only time I need to change the probability > distribution is if I load a new word list. If I wanted to be able to > load a new word list, then perhaps I need to carry the word list > inside the GameState as well? > What about carrying a list of Strings inside the State? Write a RandomGen and Random instance that return some dictionary file in random order. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. From p.f.moore at gmail.com Tue Jan 22 09:19:37 2008 From: p.f.moore at gmail.com (Paul Moore) Date: Tue Jan 22 09:19:23 2008 Subject: [Haskell-cafe] Draft chapters of "Real World Haskell" now publicly available In-Reply-To: <4794F854.1050008@serpentine.com> References: <4794F854.1050008@serpentine.com> Message-ID: <79990c6b0801220619r7b024e31v67f855583b7c3a19@mail.gmail.com> On 21/01/2008, Bryan O'Sullivan wrote: > John, Don and I are pleased to announce the beginning of the public beta > programme for our upcoming book, "Real World Haskell". For further > details, please see the following blog entry: > > http://www.realworldhaskell.org/blog/2008/01/21/finally-the-public-beta-programme-begins/ > > Thanks to all of the Haskell community members who have so far performed > sterling service in commenting on our closed drafts. > > We look forward to your feedback! I'm posting here because there doesn't seem to be an "overall" comment section, but the TOC seems to cover less ground than I expected. Is the TOC meant to be complete? In one of the earlier blog postings, you said you were