Re: [Haskell-cafe] HList darcs repo missing?
Most things that could be moved to community.haskell.org weren't moved across to the new machine: http://www.haskell.org/pipermail/haskell/2010-January/021861.html Thanks, I found what seems to be the latest version here (last update 14th Jan 2010): http://old-darcs.well-typed.com/HList/ Yes, and please take careful note that this URL is temporary and will disappear in less than a month's time. Regards, Malcolm ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANN: operational-0.1.0.0
Brent Yorgey wrote: I am very pleased to announce that Issue 15 of The Monad.Reader is now available for your reading pleasure [1]. Issue 15 consists of the following four articles: * The hp2any project by Gergely Patai * Adventures in Three Monads by Edward Z. Yang * The Operational Monad Tutorial by Heinrich Apfelmus * Implementing STM in pure Haskell by Andrew Coppin I'm pleased to release a small package named operational in conjunction with The Operational Monad Tutorial. The tutorial presents a method to implement monads by specifying the primitive instructions and their operational semantics. The main abstraction is a type Programm which corresponds to a list of instructions. The operational package contains an efficient version of the Program abstraction, ready for implementing your monads in production code. Furthermore, the operational package introduces a type ProgramT to implement monad transformers; the lifting laws are satisfied automatically. The library comes with example code and excessive documentation, including a proof that the monad laws do indeed hold. Get it from hackage: http://hackage.haskell.org/package/operational Regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] OT: How a Common Lisp user views other programming languages
On Thu, Jan 21, 2010 at 03:58:08PM -0800, Scott Michel wrote: Off topic, but funny: http://kvardek-du.kerno.org/2010/01/how-common-lisp-programmer-views-users.html ... This one is similar and IMHO even better: http://axgle.github.com/images/haskell.jpg -Petr ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Codensity improvement of free monads
On Mon, Jan 25, 2010 at 7:37 PM, Luke Palmer lrpal...@gmail.com wrote: Hello haskell-cafe, I have just read Asymptotic Improvement of Computations over Free Monads by Janis Voigtlander, since I have been working with free monads a lot recently and don't want to get hit by their quadratic performance when I start to care about that. But after reading the paper, I still don't really understand how improve actually improves anything. Can anyone provide a good explanation for where the work is saved? Edward gives the perfect explanation below. Thanks, Janis. With a free monad, the structure keeps growing via substitution. This requires you on each bind to re-traverse the common root of the free monad, which isn't changing in each successive version. Lets say the size of this accumulated detritus increases by one each time. Then you will be traversing over 1, 2, 3, 4, ... items to get to the values that you are substituting as you keep binding your free monadic computation. The area near the root of your structure keeps getting walked over and over, but there isn't any work do to there, the only thing bind can do is substitution, and all the substitution is down by the leaves. On the other hand, when you have CPS transformed it, at each layer you only have to climb over the 1 item you just added to get to where you apply the next computation. This only gets better when you are dealing with free monads that provide multiple points for extension: i.e. that grow in a treelike fashion like: data Bin a = Bin a a data Free f a = Return a | Free (f (Free f a)) data Codensity f a = Codensity (forall r. (a - f r) - f r) If you build the free monad Free Bin, then you will wind up having to walk all the way down to the leaves on each bind, well, modulo demand, that is. But since it is a free monad, the 'body' of the tree will never change. Just the data you are substituting at the leaves. Codensity (Free Bin) lets you only generate the body of the tree once, while your substitutions just get pushed down to the leaves in one pass. An interesting exercise is to work out why Codensity can change the asymptotics of certain operations over Free Bin, but Density doesn't change the asymptotics of anything non-trivial over Cofree Bin for the better. -Edward Kmett -- Jun.-Prof. Dr. Janis Voigtländer http://www.iai.uni-bonn.de/~jv/ mailto:j...@iai.uni-bonn.de ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Why no merge and listDiff?
Derek Elkins derek.a.elkins at gmail.com writes: On Wed, Jan 20, 2010 at 9:42 AM, Will Ness will_n48 at yahoo.com wrote: Derek Elkins derek.a.elkins at gmail.com writes: On Sun, Jan 17, 2010 at 2:22 PM, Will Ness will_n48 at yahoo.com wrote: Hello cafe, I wonder, if we have List.insert and List.union, why no List.merge (:: Ord a = [a] - [a] - [a]) and no List.minus ? These seem to be pretty general operations. You probably also want to look at the package data-ordlist on hackage (http://hackage.haskell.org/packages/archive/data- ordlist/0.0.1/doc/html/Data- OrdList.html) which represents sets and bags as ordered lists and has all of the operations you mention. I did, thanks again! Although, that package deals with non-decreasing lists, i.e. lists with multiples possibly. As such, its operations produce non- decreasing lists, i.e. possibly having multiples too. It is clear that some of the operations are guaranteed to produce sets given sets. The documentation could be better in this regard though. The 'union' and 'minus' functions of ordlist meet this requirement if you satisfy the preconditions. Yes, thanks, it's exactly what I was looking for. I've recognized from the code that `minus' was OK, but `merge' was different. As it turns out, OrdList.union is exactly what I have under `merge'. Better (or any at all really) documentation for Data.OrdList would be a big help. I don't know if it's at all easy to separate Sets and Bags, though it may seem desirable. I seem to have read something about Circle/Ellipse problem, i.e. the Sets/Bags problem which are not easily detachable from one another? Although I don't know the details of that. The background for this is my attempts to classify the various primes- generating code variants. Apparently, the essense of sieve is the composites removal, and both composites and natural numbers are naturally represented as strictly increasing lists. Same with merging the lists of multiples of each prime to construct the composites. I had to provide the `minus' and `merge' definitions along with the actual code and searched for something standard. You can check it out on the Haskellwiki Prime Numbers page (work still in progress, the comparison tables are missing). We had also a recent thread here in cafe under FASTER primes. The original idea of Heinrich Apfelmus of treefold merging the composites really panned out. I found a little bit better structure for the folding tree, and Daniel Fischer was a great help in fixing the space leaks there (two of them) so that now the resulting code, with wheel optimization, runs very close to the PQ-based O'Neill's sieve (actually faster than it if interpreted in GHCi). More importantly (?) there's a natural progression of code now, straight from the classic Turner's sieve, so it's not an ad-hoc thing anymore. It also became apparent that the essence of prime wheels is Euler's sieve. And vice versa. :) Thanks a lot for all the help from all the posters! Cheers, ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] foldl in terms of foldr
Hi, I am reading Real World Haskell and have some questions about the piece of code implementing foldl in terms of foldr: -- file: ch04/Fold.hs myFoldl :: (a - b - a) - a - [b] - a myFoldl f z xs = foldr step id xs z where step x g a = g (f a x) The first argument to foldr is of type (a - b - a), which takes 2 arguments. But 'step' here is defined as a function taking 3 arguments. What am I missing here? (Partial application? The order of execution?) Btw, is there a way I can observe the type signature of 'step' in this code? Thanks in advance! -- Pan, Xingzhi http://www.panxingzhi.net ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Spelling checker exercise
Matthew Phillips-5 wrote: I also found it to to be very slow. My variant: http://a-ejeli-tak.livejournal.com/1326.html Spellchecker in Haskell String version runs in 2.5 sec, ByteString in 1.2 sec (just for one word e.g. just to build the tree). 8 sec to check input of 400 words (copied from Norvig's example). I think laziness helps here to avoid unnecessary checks (once the first match is found). Haven't tried it on a larger data sets neither tried to optimize it. Cheated on dictionary parsing though... -- View this message in context: http://old.nabble.com/Spelling-checker-exercise-tp27269320p27322382.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Why no merge and listDiff?
Will Ness wrote: You can check it out on the Haskellwiki Prime Numbers page (work still in progress, the comparison tables are missing). We had also a recent thread here in cafe under FASTER primes. The original idea of Heinrich Apfelmus of treefold merging the composites really panned out. (Just for historical reference, credit for the data structure that works with infinite merges goes to Dave Bayer, I merely contributed the mnemonic aid of interpreting it in terms of VIPs.) Regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Spelling checker exercise
Am Dienstag 26 Januar 2010 14:11:06 schrieb Eduard Sergeev: Matthew Phillips-5 wrote: I also found it to to be very slow. My variant: http://a-ejeli-tak.livejournal.com/1326.html Spellchecker in Haskell String version runs in 2.5 sec, ByteString in 1.2 sec (just for one word e.g. just to build the tree). 8 sec to check input of 400 words (copied from Norvig's example). Slower here, time for building the set is approximately equal to that of of the frequency map [either String or ByteString], lookup a little slower if one edit is needed, much faster if two are needed (of course). But the lazy Levenshtein distance is much faster again, for the 'tests2' data from Norvig's http://norvig.com/spell.py (400 words), $ xargs -a tdata.txt time ./nLDBSWSpelling /dev/null 4.50user 0.03system 0:04.53elapsed 100%CPU $ time ./esergSpellBS big.txt tdata.txt /dev/null 28.23user 0.09system 0:28.32elapsed 100%CPU surprisingly (?), your plain String version is faster for that than your ByteString version: $ time ./esergSpellS big.txt tdata.txt /dev/null 25.07user 0.10system 0:25.18elapsed 99%CPU I think laziness helps here to avoid unnecessary checks (once the first match is found). But that's the point, these checks aren't unnecessary (unless the word under inspection is known). You want to propose the most likely correct word. If your input is arthetic, should you return aesthetic, just because it's the first of the (at least four) correct words with edit distance 2[*] which is produced by your arbitrary ordering of edit steps or it's the lexicographically smallest? I think you shouldn't. Haven't tried it on a larger data sets neither tried to optimize it. Cheated on dictionary parsing though... [*] The others I know are bathetic, pathetic and arthritic - without context, I'd go for arthritic because I think spelling errors are more common i the middle of a word than at the beginning or at the end, but plain frequency analysis of the corpus suggests pathetic. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] foldl in terms of foldr
Xingzhi Pan wrote: The first argument to foldr is of type (a - b - a), which takes 2 arguments. But 'step' here is defined as a function taking 3 arguments. What am I missing here? You can think of step as a function of two arguments which returns a function with one argument (although in reality, as any curried function, 'step' is _one_ argument function anyway): step :: b - (a - c) - (b - c) e.g. 'step' could have been defined as such: step x g = \a - g (f a x) to save on lambda 'a' was moved to argument list. -- View this message in context: http://old.nabble.com/foldl-in-terms-of-foldr-tp27322307p27324376.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Supporting GHC 6.10 and 6.12 in HDBC-postgresql Setup.hs
Hi folks, I've gotten some reports (see below) of issues with building HDBC-postgresql on GHC 6.12. Its Setup.hs file [1] is the culprit. The problem is that AnyVersion needs to be removed to work with Cabal in GHC 6.12. But I still want to support older Cabal. Following the directions in the Cabal manual, I tried: #if MIN_VERSION_Cabal(1,8,0) pgconfigProgram (withPrograms lbi) #else pgconfigProgram AnyVersion (withPrograms lbi) #endif While of course adding the needed bits to invoke CPP. This didn't resolve it; apparently Cabal doesn't define macros for use in Setup.hs, only for use in the application. There also seems to be no conditional for use in the .cabal file to resolve this. I could check the GHC version, but that doesn't necessarily correspond to Cabal version. Any ideas? -- John [1] http://git.complete.org/hdbc-postgresql?a=blob;f=Setup.hs;h=0656cb41adc814de8542b6f28040e131ae86be3c;hb=HEAD ---BeginMessage--- Hello John, I don't know if you're aware but HDBC-postgresql is failing to build on hackage. I think this is because the requireProgram function used in Setup.hs has changed between cabal 1.6 and cabal 1.7 (the version parameter has been removed). It seems to build fine if you simply remove the AnyVersion argument in Setup.hs line 39, apparently this is the only thing stopping it from building on cabal 1.8/ghc 6.12, I haven't checked cabal 1.7/ghc 6.10. I don't know what changes to the versions in the cabal file should go with this, if just adding cabal = 1.7 is correct or not. Will you be able to upload a fixed version to hackage in the near future? It would be handy for me so that my project's haddock docs appear there on hackage (my project is hssqlppp). It's not particularly urgent, so please don't rush on my account. Thanks for all your great contributions on hackage, Real World Haskell and elsewhere, Jake Wheat ---End Message--- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] foldl in terms of foldr
On Tue, Jan 26, 2010 at 11:24 PM, Eduard Sergeev eduard.serg...@gmail.com wrote: Xingzhi Pan wrote: The first argument to foldr is of type (a - b - a), which takes 2 arguments. But 'step' here is defined as a function taking 3 arguments. What am I missing here? You can think of step as a function of two arguments which returns a function with one argument (although in reality, as any curried function, 'step' is _one_ argument function anyway): step :: b - (a - c) - (b - c) e.g. 'step' could have been defined as such: step x g = \a - g (f a x) to save on lambda 'a' was moved to argument list. Right. But then step is of the type b - (a - c) - (b - c). But as the first argument to foldr, does it agree with (a - b - a), which was what I saw when I type :t foldr in ghci? -- View this message in context: http://old.nabble.com/foldl-in-terms-of-foldr-tp27322307p27324376.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Pan, Xingzhi http://www.panxingzhi.net ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Spelling checker exercise
Daniel Fischer-4 wrote: But that's the point, these checks aren't unnecessary (unless the word under inspection is known). You want to propose the most likely correct word. I just wanted to rewrite original Nornig's Python code in Haskell :) (maybe I misunderstood the algorithm?). Of course it is far from being able to produce 'most likely correct' result. Btw, where can I find the source for this super-fast 'nLDBSWSpelling' variant? -- View this message in context: http://old.nabble.com/Spelling-checker-exercise-tp27269320p27324740.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] foldl in terms of foldr
Xingzhi Pan wrote: On Tue, Jan 26, 2010 at 11:24 PM, Eduard Sergeev eduard.serg...@gmail.com wrote: Xingzhi Pan wrote: The first argument to foldr is of type (a - b - a), which takes 2 arguments. But 'step' here is defined as a function taking 3 arguments. What am I missing here? You can think of step as a function of two arguments which returns a function with one argument (although in reality, as any curried function, 'step' is _one_ argument function anyway): step :: b - (a - c) - (b - c) e.g. 'step' could have been defined as such: step x g = \a - g (f a x) to save on lambda 'a' was moved to argument list. Right. But then step is of the type b - (a - c) - (b - c). But as the first argument to foldr, does it agree with (a - b - a), which was what I saw when I type :t foldr in ghci? step is of type b - (a - a) - (a - a), which does agree with (a - b - b), the first argument to foldr (what you posted, both times, a - b - a, is the type of the first argument of *foldl* not foldr). The code is building up a function (type: a - a) from the list items, which it then applies to the initial value given to foldl. Thanks, Neil. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Job opportunities at Citrix Systems (Cambridge, UK)
Hi folks, I have recently started working for Citrix in Cambridge. We are working on the open source software in Ocaml. Admittedly Ocaml is only a second best compared to Haskell ;o) and I hope my post does not count as too off-topic here. But Ocaml is still a decent language. My experience was primarily with Haskell and I only started working with Ocaml in earnest at Citrix. (So I hope that showing a way to transplant Haskell skills to the real world --- via the roundabout route of Ocaml --- justifies my posting.) So --- if you are looking for a job in Cambridge that involves functional programming, free software [1] and free beer [2], please feel free to drop me a line. I have included our original advert to the Ocaml mailing list for those who want more information first. Cheers, Matthias. [1] As in free speech. LGPL [2] As in free beer. We also get other perks, like snacks and a pool table. -- Forwarded message -- From: Dave Scott dave.sc...@eu.citrix.com Date: 2010/1/18 Subject: [Caml-list] [jobs] Citrix Systems (Cambridge, UK) To: caml-l...@yquem.inria.fr caml-l...@yquem.inria.fr, ocaml-j...@inria.fr ocaml-j...@inria.fr Dear fellow OCaml users, Summary: We (Citrix Systems) are looking for OCaml programmers to join our team in Cambridge, UK. We use OCaml extensively in the xapi tool-stack: the control-plane used in the Xen Cloud Platform[1] on which the widely used XenServer server virtualisation product[2] is based. XCP aims to provide a complete open-source cloud infrastructure platform with a powerful management stack based on standards-based APIs, support for multi-tenancy, SLA guarantees and detailed metrics for consumption based charging. We are looking to recruit top-class engineers to work on the tool-stack; applicants must have a good knowledge of data structures and algorithms, experience of programming in the context of large systems and general aesthetic good taste when it comes to code and architecture. Our code base is significant and varied: over 130,000 lines of OCaml, solving problems ranging from the low-level (Xen hypercalls) to the high-level (resource pool management), to the compiler-driven (generating language bindings for our Xen datamodel). Our ideal candidate will have: * significant experience of applications programming in high-level languages (such as OCaml :-) * an aptitude for implementing (and reasoning about) complex concurrent, distributed systems * the skills required to contribute to both the architectural design and day-to-day development of a large code-base * strong communication skills and problem solving ability * a determination to deliver great products that perform brilliantly and meet our customers' needs So if you want to tackle interesting and challenging programming problems and contribute to an innovative, fast-growing product that is already used by tens of thousands of customers across the world, please don't hesitate to send me your CV. [1] http://www.xen.org/products/cloudxen.html [2] http://www.citrix.com/English/ps2/products/feature.asp?contentID=1686939 Thanks, -- Dave Scott dave.sc...@eu.citrix.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] foldl in terms of foldr
Am Dienstag 26 Januar 2010 16:44:11 schrieb Xingzhi Pan: On Tue, Jan 26, 2010 at 11:24 PM, Eduard Sergeev eduard.serg...@gmail.com wrote: Xingzhi Pan wrote: The first argument to foldr is of type (a - b - a), which takes 2 arguments. But 'step' here is defined as a function taking 3 arguments. What am I missing here? You can think of step as a function of two arguments which returns a function with one argument (although in reality, as any curried function, 'step' is _one_ argument function anyway): step :: b - (a - c) - (b - c) e.g. 'step' could have been defined as such: step x g = \a - g (f a x) to save on lambda 'a' was moved to argument list. Right. But then step is of the type b - (a - c) - (b - c). But as the first argument to foldr, does it agree with (a - b - a), which was what I saw when I type :t foldr in ghci? No, typo by Eduard, step :: b - (a - c) - (a - c). foldr :: (t - u - u) - u - [t] - u , so t === b, u === a - c Now, in foldr step id xs, id has type u === a - c, hence c === a. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] foldl in terms of foldr
Neil Brown-7 wrote: step is of type b - (a - a) - (a - a), which does agree with (a - b - b) Not quite right.. Let's rewite the function: myFoldl f z xs = foldr (step f) id xs z step f x g = \a - g (f a x) now (from ghci): step (+) :: (Num t1) = t1 - (t1 - t3) - t1 - t3 or even: step (flip (:)) :: t - ([t] - t3) - [t] - t3 But yes, the type from my first post was wrong -- View this message in context: http://old.nabble.com/foldl-in-terms-of-foldr-tp27322307p27325072.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] foldl in terms of foldr
On Tue, Jan 26, 2010 at 11:51 PM, Neil Brown nc...@kent.ac.uk wrote: Xingzhi Pan wrote: On Tue, Jan 26, 2010 at 11:24 PM, Eduard Sergeev eduard.serg...@gmail.com wrote: Xingzhi Pan wrote: The first argument to foldr is of type (a - b - a), which takes 2 arguments. But 'step' here is defined as a function taking 3 arguments. What am I missing here? You can think of step as a function of two arguments which returns a function with one argument (although in reality, as any curried function, 'step' is _one_ argument function anyway): step :: b - (a - c) - (b - c) e.g. 'step' could have been defined as such: step x g = \a - g (f a x) to save on lambda 'a' was moved to argument list. Right. But then step is of the type b - (a - c) - (b - c). But as the first argument to foldr, does it agree with (a - b - a), which was what I saw when I type :t foldr in ghci? step is of type b - (a - a) - (a - a), which does agree with (a - b - b), the first argument to foldr (what you posted, both times, a - b - a, is the type of the first argument of *foldl* not foldr). The code is building up a function (type: a - a) from the list items, which it then applies to the initial value given to foldl. Thanks, Neil. My mistake with the foldr signature. I'm a little confused with the type of step here. Can it be considered as taking 2 or 3 arguments and then the compiler has to infer to decide? Say if I, as a code reader, meet such a function defined with three formal parameters, how can I draw the conclusion of its type (and it takes 2 arguments actually)? Thanks. -- Pan, Xingzhi http://www.panxingzhi.net ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] foldl in terms of foldr
On Wed, Jan 27, 2010 at 12:05 AM, Eduard Sergeev eduard.serg...@gmail.com wrote: Neil Brown-7 wrote: step is of type b - (a - a) - (a - a), which does agree with (a - b - b) Not quite right.. Let's rewite the function: myFoldl f z xs = foldr (step f) id xs z step f x g = \a - g (f a x) I am not very sure about this. This rewriting was my first reaction against the original code but it failed compilation with GHC. More over, does foldr step f id xs z equal to foldr (step f) id xs z?? Thanks! now (from ghci): step (+) :: (Num t1) = t1 - (t1 - t3) - t1 - t3 or even: step (flip (:)) :: t - ([t] - t3) - [t] - t3 But yes, the type from my first post was wrong -- View this message in context: http://old.nabble.com/foldl-in-terms-of-foldr-tp27322307p27325072.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Pan, Xingzhi http://www.panxingzhi.net ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] foldl in terms of foldr
Xingzhi Pan wrote: More over, does foldr step f id xs z equal to foldr (step f) id xs z?? No, it does not. The former passes three-argument function 'step' to foldr and the later passes two-argument function which is the result of the partial application (step f). -- View this message in context: http://old.nabble.com/foldl-in-terms-of-foldr-tp27322307p27325448.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] foldl in terms of foldr
Eduard Sergeev wrote: The former passes three-argument function 'step' to foldr and the later passes two-argument function which is the result of the partial application (step f). Correction :) 4-arg and 3-arg respectively. -- View this message in context: http://old.nabble.com/foldl-in-terms-of-foldr-tp27322307p27325593.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] foldl in terms of foldr
On Tue, 26 Jan 2010, Xingzhi Pan wrote: Hi, I am reading Real World Haskell and have some questions about the piece of code implementing foldl in terms of foldr: -- file: ch04/Fold.hs myFoldl :: (a - b - a) - a - [b] - a myFoldl f z xs = foldr step id xs z where step x g a = g (f a x) The first argument to foldr is of type (a - b - a), which takes 2 arguments. But 'step' here is defined as a function taking 3 arguments. What am I missing here? (Partial application? The order of execution?) http://www.haskell.org/haskellwiki/Foldl_as_foldr Btw, is there a way I can observe the type signature of 'step' in this code? http://www.haskell.org/haskellwiki/Determining_the_type_of_an_expression ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] darcs 2.4 beta 3 release
Hi all, The darcs team would like to announce the immediate availability of darcs 2.4 beta 3. darcs 2.4 will contain many improvements and bugfixes compared to darcs 2.3.1. Highlights are the faster operation of record, revert and related commands, and the experimental interactive hunk editing. This beta is your chance to test-drive these improvements and make darcs even better. Compared to darcs 2.4 beta 2, the interface of interactive hunk editing has become more user-friendly. The easiest way to install darcs is using the Haskell Platform [1]. If you have installed the Haskell Platform or cabal-install, you can install this beta release by doing: $ cabal update $ cabal install --reinstall darcs-beta Alternatively, you can download the tarball from http://darcs.net/releases/darcs-beta-2.3.98.3.tar.gz , and build it by hand as explained in the README file. Interactive hunk editing To try out interactive hunk editing, press 'e' when you are prompted with a hunk patch by 'darcs record'. You will then be shown an editor screen in which you can edit the state you want to record between the last two ruler lines. You can find more information about the hunk editing feature on http://wiki.darcs.net/HunkEditor . Reporting bugs -- If you have an issue with darcs 2.4 beta 3, you can report it via the web on http://bugs.darcs.net/ . You can also report bugs by email to b...@darcs.net. What's New -- A list of important changes since 2.3.1 is as follows (please let me know if there's something you miss!): * Use fast index-based diffing everywhere (Petr) * Interactive patch splitting (Ganesh) * An 'optimize --upgrade' option to convert to hashed format in-place (Eric) * Hunk matching (Kamil Dworakowski, tat.wright) * Progress reporting is no longer deceptive (Roman) * A 'remove --recursive' option to remove a directory tree from revision control (Roman) * 'show files' accepts arguments to show a subset of tracked files (Luca) * A '--remote-darcs' flag for pushing to a host where darcs isn't called darcs * Many miscellaneous Windows improvements (Salvatore, Petr and others) * 'darcs send' now mentions the repository name in the email body (Joachim) * Handle files with boring names in the repository correctly (Petr) * Fix parsing of .authorspellings file (Tomáš) * Various sane new command-line option names (Florent) * Remove the '--checkpoint' option (Petr) * Use external libraries for all UTF-8 handling (Eric, Reinier) * Use the Haskell zlib package exclusively for compression (Petr) A list of issues resolved since 2.3.1: * 183: do not sort changes --summary output * 223: add --remote-darcs flag to specify name of remote darcs executable * 291: provide (basic) interactive patch splitting * 540: darcs remove --recursive * 835: 'show files' with arguments * 1122: get --complete should not offer to create a lazy repository * 1216: list Match section in ToC * 1224: refuse to convert a repo that's already in darcs-2 format * 1300: logfile deleted on unsucessful record * 1308: push should warn about unpulled patches before patch-selection * 1336: sane error message on --last (empty string to numbers parser) * 1362: mention repo name in mail send body * 1377: getProgname for local darcs instances * 1392: use parsec to parse .authorspelling * 1424: darcs get wrongly reports using lazy repository if you ctrl-c old-fashioned get * 1447: different online help for send/apply --cc * 1488: fix crash in whatsnew when invoked in non-tracked directory * 1548: show contents requires at least one argument * 1554: allow opt-out of -threaded (fix ARM builds) * 1563: official thank-you page * 1578: don't put newlines in the Haskeline prompts * 1583: on darcs get, suggest upgrading source repo to hashed * 1584: provide optimize --upgrade command * 1588: add --skip-conflicts option * 1594: define PREPROCHTML in makefile * 1620: make amend leave a log file when it should * 1636: hunk matching * 1643: optimize --upgrade should do optimize * 1652: suggest cabal update before cabal install * 1659: make restrictBoring take recorded state into account * 1677: create correct hashes for empty directories in index * 1681: preserve log on amend failure * 1709: fix short version of progress reporting * 1712: correctly report number of patches to pull * 1720: fix cabal haddock problem * 1731: fix performance regression in check and repair Kind Regards, the darcs release manager, Reinier Lamers [1]: You can download the Haskell platform from http://hackage.haskell.org/platform/ signature.asc Description: This is a digitally signed message part. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org
Re: [Haskell-cafe] Re: could we get a Data instance for Data.Text.Text?
2010/1/26 José Pedro Magalhães j...@cs.uu.nl Hi Jeremy, As Neil Mitchell said before, if you really don't want to expose the internals of Text (by just using a derived instance) then you have no other alternative than to use String conversion. If you've been using it already and performance is not a big problem, then I guess it's ok. Regarding the Serialize issue, maybe I am not understanding the problem correctly: isn't that just another generic function? There are generic implementations of binary get and put for at least two generic programming libraries in Hackage [1, 2], and writing one for SYB shouldn't be hard either, I think. Then you could have a trivial way of generating instances of Serialize, namely something like instance Serialize MyType where getCopy = gget putCopy = gput But in what package does, instance Serialize Text, live? text? happstack-data? a new package, serialize-text? That is the question at hand. Each of those choices has rather annoying complications. As for using generics, Serialization can not be 100% generic, because we also support migration when the type changes. For example, right now ClockTime is defined: data ClockTime = TOD Integer Integer Let's say that it is later changed to: data ClockTime = TOD Bool Integer Integer Attempting to read the old data you saved would now fail, because the saved data does not have the 'Bool' value. However, perhaps the old data can be migrated by simply setting the Bool to True or False by default. In happstack we would have: $(deriveSerialize ''Old.ClockTime) instance Version Old.ClockTime $(deriveSerialize ''ClockTime) instance Version ClockTime where mode = extension 1 (Proxy :: Proxy Old.ClockTime) instance Migrate Old.ClockTime ClockTime where migrate (Old.TOD i j) = TOD False i j The Version class is a super class of the Serialize class, which is required so that when the deserializer is trying to deserialize ClockTime, and runs across an older version of the data type, it knows how to find the older deserialization function that works with that version of the type, and where to find the migrate function to bring it up to the latest version. - jeremy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: could we get a Data instance for Data.Text.Text?
Hello, Attached is my new and improved patch to add a Data instance to Data.Text. The patch just adds: +-- This instance preserves data abstraction at the cost of inefficiency. +-- We omit reflection services for the sake of data abstraction. + +instance Data Text where + gfoldl f z txt = z pack `f` (unpack txt) + toConstr _ = error toConstr + gunfold _ _= error gunfold + dataTypeOf _ = mkNoRepType Data.Text.Text Which is based on what the Data instances for Set and Map do: http://www.haskell.org/ghc/docs/latest/html/libraries/containers-0.3.0.0/src/Data-Set.html http://www.haskell.org/ghc/docs/latest/html/libraries/containers-0.3.0.0/src/Data-Map.html Yay for cargo culting! It seems like this is better than nothing, possibly the correct answer, and if someone does decide to add better instances for toConstr and gunfold in the future, nothing should break? For happstack-data, I think we only need dataTypeOf. The instance I posted before definitely did not have valid toConstr / gunfold instances, so I think we would have noticed if we were actually trying to use them.. - jeremy On Fri, Jan 22, 2010 at 4:24 PM, Jeremy Shaw jer...@n-heptane.com wrote: Hello, Would it be possible to get a Data instance for Data.Text.Text? This would allow us to create a Serialize instance of Text for use with happstack -- which would be extremely useful. We (at seereason) are currently using this patch: http://src.seereason.com/haskell-text-debian/debian/patches/add_Data_instance.patch which basically adds: +textType = mkStringType Data.Text + +instance Data Text where + toConstr x = mkStringConstr textType (unpack x) + gunfold _k z c = case constrRep c of + (CharConstr x) - z (pack [x]) + _ - error gunfold for Data.Text + dataTypeOf _ = textType + This particular implementation avoids exposing the internals of the Data.Text type by casting it to a String in toConstr and gunfold. That is similar to how Data is implemented for some numeric types. However, the space usage of casting in Float to a Double is far less than casting a Text to a String, so maybe that is not a good idea? Alternatively, Data.ByteString just does 'deriving Data'. However, bytestring also exports Data.ByteString.Internal, wheres Data.Text.Internal is not exported. Any thoughts? I would like to get this handled upstream so that all happstack users can benefit from it. - jeremy --- haskell-text-0.7.0.1/Data/Text.hs 2009-12-23 11:48:15.0 -0600 +++ haskell-text-0.7.0.1.new/Data/Text.hs 2010-01-26 11:50:11.0 -0600 @@ -166,12 +166,13 @@ Eq(..), Ord(..), (++), Read(..), Show(..), (), (||), (+), (-), (.), ($), (), (*), -div, not, return, otherwise) +div, error, not, return, otherwise) #if defined(HAVE_DEEPSEQ) import Control.DeepSeq (NFData) #endif import Control.Exception (assert) import Data.Char (isSpace) +import Data.Data (Data(gfoldl, toConstr, gunfold, dataTypeOf), mkNoRepType) import Control.Monad (foldM) import Control.Monad.ST (ST) import qualified Data.Text.Array as A @@ -221,6 +222,15 @@ instance NFData Text #endif +-- This instance preserves data abstraction at the cost of inefficiency. +-- We omit reflection services for the sake of data abstraction. + +instance Data Text where + gfoldl f z txt = z pack `f` (unpack txt) + toConstr _ = error toConstr + gunfold _ _= error gunfold + dataTypeOf _ = mkNoRepType Data.Text.Text + -- - -- * Conversion to/from 'Text' ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: could we get a Data instance for Data.Text.Text?
On Tue, Jan 26, 2010 at 11:52:34AM -0600, Jeremy Shaw wrote: + toConstr _ = error toConstr + gunfold _ _= error gunfold Isn't it better to write error Data.Text.Text: toConstr Usually I try to do this as we don't get stack traces for _|_. -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: could we get a Data instance for Data.Text.Text?
On Tue, Jan 26, 2010 at 11:55 AM, Felipe Lessa felipe.le...@gmail.comwrote: On Tue, Jan 26, 2010 at 11:52:34AM -0600, Jeremy Shaw wrote: + toConstr _ = error toConstr + gunfold _ _= error gunfold Isn't it better to write error Data.Text.Text: toConstr Usually I try to do this as we don't get stack traces for _|_. I think so... none of the other instances do.. but I guess that is not a very good excuse :) - jeremy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Supporting GHC 6.10 and 6.12 in HDBC-postgresql Setup.hs
jgoerzen: Hi folks, I've gotten some reports (see below) of issues with building HDBC-postgresql on GHC 6.12. Its Setup.hs file [1] is the culprit. The problem is that AnyVersion needs to be removed to work with Cabal in GHC 6.12. The other HDBC problem I have is various dependencies relying on QC1. The next HP will ship with QC 2.1 (in coming weeks), so it might be a good time for people to start migrating, since that will be the only version of QC on many distros. -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] scheduling an alarm
Brian Denheyer bri...@aracnet.com wrote: On Mon, 25 Jan 2010 23:19:53 -0800 Thomas DuBuisson thomas.dubuis...@gmail.com wrote: 1) Don't use System.Posix.Signals It isn't necessary and makes your code less portable 2) The POSIX SIGALRM is used/caught by the RTS and that is why you are seeing strange behavior. 3) Consider using Haskell exceptions from Control.Concurrent (throwTo). Not sure what you want to do but you can always myThreadId = \tid - forkIO $ threadDelay someDelayTime (throwTo tid someExceptionVal) I just want a routine to run every 15 min. You can still use Control.Concurrent: import Control.Concurrent doEvent f usDelay = forkIO $ threadDelay usDelay doEvent f usDelay f Or a wrapper around Control.Concurrent - Ex: The Control-Event package. I'm not clear on why the throwTo is in you example. It will give you an exception just like you were expecting from SIGALRM. Thomas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Spelling checker exercise
Am Dienstag 26 Januar 2010 16:46:42 schrieb Eduard Sergeev: Daniel Fischer-4 wrote: But that's the point, these checks aren't unnecessary (unless the word under inspection is known). You want to propose the most likely correct word. I just wanted to rewrite original Norvig's Python code in Haskell :) (maybe I misunderstood the algorithm?). Seems so. NWORDS is the frequency map built from the corpus. return max(candidates, key=NWORDS.get) returns the candidate with the highest value in NWORDS, i.e. the candidate that occurred most often in the corpus (if there are several with the same highest count, I think the one found first is taken, the order in which an iterator traverses a Python set is not specified, IIRC, so it might be any of those). Of course it is far from being able to produce 'most likely correct' result. Even taking word frequency into account doesn't get really close. You'd have to take into account that some errors are more common than others (e.g. award a penalty for words starting with a different letter, substitution cost should be lower for letters adjacent on common keyboards than for letters far apart, but it should also be lower for letter pairs of similar sound [e - i, d - t and so on], insertion/deletion cost should be lower for double letters [diging is more likely to be a misspelling of digging than of diving, although g and v are neighbours on qwerty and qwertz keyboards], -able - -ible confusion is extremely common). It's really hairy. But a combination of edit distance and word frequency is a good start. Btw, where can I find the source for this super-fast 'nLDBSWSpelling' variant? Nowhere, unless you come over with a sixpack or two ;) It originated from a contest-related (codechef, www.codechef.com , a fork or similar of SPOJ) question end of November. To not spoil the contest, I didn't post the code then. When I first mentioned the idea in this thread, I hadn't ported the code to the current setting yet, so I couldn't post it, even if I wanted, besides I didn't want to distract from the topic of proting Norvig's algorithm. But since you ask and it's been long enough ago (and not directly applicable to the contest), here comes the modified source, I've added comments and a few further improvements, time for the 400 words is now 4.02user 0.04system 0:04.07elapsed 100%CPU 2.8s for building the map, so on average 3 milliseconds per correction :D -- {-# LANGUAGE BangPatterns #-} module Main (main) where import Data.ByteString.Unsafe (unsafeIndex) import qualified Data.ByteString.Char8 as B import qualified Data.ByteString as BS import Data.Char (toLower) import Data.Map (Map, findWithDefault, insertWith', member, assocs, empty) import Data.List (inits, tails, foldl') import System.Environment (getArgs) import Data.Word (Word8) import Data.Bits ((.|.)) dataFile = big.txt alphabet = abcdefghijklmnopqrstuvwxyz infixl 9 ! {-# INLINE (!) #-} (!) :: B.ByteString - Int - Word8 (!) = unsafeIndex {- Lazily calculate Levenshtein distance, cut off at 3, modified to have transpositions count as one edit. -} distance :: B.ByteString - B.ByteString - Int distance start target = go 0 m n where m = B.length start n = B.length target go l i j {- if number of edits so far + difference of lengths left is larger than 2, the total number of edits will be at least 3 -} | l+i j+2 || l+j i+2 = 3 {- if start is completely consumed, we need j additional inserts -} | i == 0= l+j {- if target is completely consumed, we need i additional deletions -} | j == 0= l+i {- no edit nor branch if we look at identical letters -} | a == b= go l (i-1) (j-1) | otherwise = let -- replace x = go (l+1) (i-1) (j-1) -- insert y = go (l+1) i (j-1) -- delete z = go (l+1) (i-1) j -- transpose w = go (l+1) (i-2) (j-2) -- but only if the letters match t | i 1 j 1 b == start!(i-2) a == target! (j-2) = w | otherwise = 3 in case compare i j of -- if there's more of target left than of start, a deletion -- can't give a path of length 3, since after that we'd -- need at least two inserts LT - t `seq` x `seq` y `seq` min x (min y t) -- if both remaining segments have the same length, -- we must try all edit steps EQ - t `seq` x `seq` y `seq` z `seq` min x (min y (min t z)) -- if there's more of start left than of
Re: [Haskell-cafe] foldl in terms of foldr
On Tue, Jan 26, 2010 at 5:04 AM, Xingzhi Pan vengeance.st...@gmail.com wrote: myFoldl :: (a - b - a) - a - [b] - a myFoldl f z xs = foldr step id xs z where step x g a = g (f a x) Btw, is there a way I can observe the type signature of 'step' in this code? Here is how I do it: Prelude :t \[f] - \x g a - g (f a x) \[f] - \x g a - g (f a x) :: [t1 - t - t2] - t - (t2 - t3) - t1 - t3 The [] are unnecessary but help me differentiate the givens from the actual arguments to the function. Here's a way that gives better type variables and properly constrains the type of f: Prelude let test [f] x g a = g (f a x) where typeF = f `asTypeOf` const Prelude :t test test :: [a - b - a] - b - (a - t) - a - t -- ryan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] foldl in terms of foldr
On Tue, Jan 26, 2010 at 1:56 PM, Ryan Ingram ryani.s...@gmail.com wrote: On Tue, Jan 26, 2010 at 5:04 AM, Xingzhi Pan vengeance.st...@gmail.com wrote: myFoldl :: (a - b - a) - a - [b] - a myFoldl f z xs = foldr step id xs z where step x g a = g (f a x) Btw, is there a way I can observe the type signature of 'step' in this code? Here is how I do it: Prelude :t \[f] - \x g a - g (f a x) \[f] - \x g a - g (f a x) :: [t1 - t - t2] - t - (t2 - t3) - t1 - t3 The [] are unnecessary but help me differentiate the givens from the actual arguments to the function. This is the only thing I use -XImplicitParams for: {--} :t \x g a - g (?f a x) \x g a - g (?f a x) :: (?f::t - t1 - t2) = t1 - (t2 - t3) - t - t3 Which differentiates the givens and gives them names :-) Luke ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Darcs fundraising 2010 - send us to ZuriHac! (only $957 more by 15 Feb)
Hi everybody, Here's the update for our second week of fundraising. We've managed to raise $1043. We're now halfway there! That's only $957 to go by the 15th of February. Many thanks to everybody who has made a donation so far. If you're still thinking of helping out, now is a good time! :-) Otherwise, stay tuned at http://darcs.net/donations.html for our progress. Eric PS. If you could send me an email when you make a donation, I can provide a daily update on our fundraising status. Donating by Google Checkout -- Donating via Google Checkout puts more of your donation to work, since Google charges no Checkout fees to 501(c)(3) organizations. Please visit http://darcs.net/donations.html for more details. Donating by check (USA) -- The next best option is to donate by check if you have a US bank account. Checks should be made payable to Software Freedom Conservancy, Inc., with Directed donation: Darcs in the memo. They can be mailed to Software Freedom Conservancy 1995 BROADWAY FL 17 NEW YORK NY 10023-5882 USA Donating by Paypal -- Please visit http://darcs.net/donations.html for more details. -- Eric Kow http://www.nltg.brighton.ac.uk/home/Eric.Kow PGP Key ID: 08AC04F9 pgp4IDbDbenUN.pgp Description: PGP signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Why no merge and listDiff?
Heinrich Apfelmus apfelmus at quantentunnel.de writes: Will Ness wrote: You can check it out on the Haskellwiki Prime Numbers page (work still in progress, the comparison tables are missing). We had also a recent thread here in cafe under FASTER primes. The original idea of Heinrich Apfelmus of treefold merging the composites really panned out. (Just for historical reference, credit for the data structure that works with infinite merges goes to Dave Bayer, I merely contributed the mnemonic aid of interpreting it in terms of VIPs.) Regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com yes, yes, my bad. GMANE is very unreliable at presenting the discussion threads in full. :| I saw it first on the Haskellwiki page though, and it was your code there, that's the reason for my mistake. :) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] foldl in terms of foldr
On Jan 26, 2010, at 8:11 AM, Xingzhi Pan wrote: I'm a little confused with the type of step here. Can it be considered as taking 2 or 3 arguments and then the compiler has to infer to decide? The compiler is going to build up a sequence of functions. Consider the following (mathematical) function: f(x, y, z) = x^2 + y^2 + z^2. This is a function in three arguments. But if you bind any of them (say, x) to a value x', you end up with a function g(y,z) = f(x',y,z). This is a function in two arguments. Bind another variable, and you get another function, with one less argument. You need to bind all the variables in order to compute f for a point. Say if I, as a code reader, meet such a function defined with three formal parameters, how can I draw the conclusion of its type (and it takes 2 arguments actually)? You can derive this from the syntactic properties of types. Count the number of arrows that are not in parentheses. That's how many arguments the function takes. f :: a - b - c is a function that takes an a, a b, and returns a c. g :: (a - b) - c takes one argument, which is expected to be a function from a to b. g returns a c. That stuff I mentioned before about variable binding and function application still applies. We can show that f and g have isomorphic types. But they are conceptually different types. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] foldl in terms of foldr
f :: a - b - c is a function that takes an a, a b, and returns a c. g :: (a - b) - c takes one argument, which is expected to be a function from a to b. g returns a c. That stuff I mentioned before about variable binding and function application still applies. We can show that f and g have isomorphic types. But they are conceptually different types. Except that f and g are not isomorphic. In fact, there exists no defined fuction g :: (a - b) - c (what type would (g id) be?) Perhaps you meant g :: a - (b - c)? Alexander Solla wrote: On Jan 26, 2010, at 8:11 AM, Xingzhi Pan wrote: I'm a little confused with the type of step here. Can it be considered as taking 2 or 3 arguments and then the compiler has to infer to decide? The compiler is going to build up a sequence of functions. Consider the following (mathematical) function: f(x, y, z) = x^2 + y^2 + z^2. This is a function in three arguments. But if you bind any of them (say, x) to a value x', you end up with a function g(y,z) = f(x',y,z). This is a function in two arguments. Bind another variable, and you get another function, with one less argument. You need to bind all the variables in order to compute f for a point. Say if I, as a code reader, meet such a function defined with three formal parameters, how can I draw the conclusion of its type (and it takes 2 arguments actually)? You can derive this from the syntactic properties of types. Count the number of arrows that are not in parentheses. That's how many arguments the function takes. f :: a - b - c is a function that takes an a, a b, and returns a c. g :: (a - b) - c takes one argument, which is expected to be a function from a to b. g returns a c. That stuff I mentioned before about variable binding and function application still applies. We can show that f and g have isomorphic types. But they are conceptually different types. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] foldl in terms of foldr
f :: a - b - c is a function that takes an a, a b, and returns a c. Except that f and g are not isomorphic. In fact, there exists no defined fuction g :: (a - b) - c (what type would (g id) be? The types are isomorphic. They both have the same extension. Both types are empty. How do you make a function that returns an ununtyped value? You can't. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: could we get a Data instance for Data.Text.Text?
Hi The problem with Data for Text isn't that we have to write a new instance, but that you could argue that proper handling of Text with Data would not be using a type class, but have special knowledge baked in to Data. That's far worse than the Serialise problem mentioned above, and no one other than the Data authors could solve it. Of course, I don't believe that, but it is a possible interpretation. Right.. that is the problem with Text. Do you think the correct thing to do for gunfold and toConstr is to convert the Text to a String and then call the gufold and toConstr for String? Or something else? No idea sadly - the SYB stuff was never designed to work with abstract structures, or structures containing strict/unboxed components. Converting the Text to a String should work, so in the absence of any better suggestions, that seems reasonable. The Serialise problem is a serious one. I can't think of any good solutions, but I recommend you give knowledge of your serialise class to Derive (http://community.haskell.org/~ndm/derive/) and then at least the instances can be auto-generated. Writing lots of boilerplate and regularly ripping it up is annoying, setting up something to generate it for you reduces the pain. We currently use template haskell to generate the Serialize instances in most cases (though some data types have more optimized encodings that were written by hand). However, you must supply the Version and Migration instances by hand (they are super classes of Serialize). I am all for splitting the Serialize stuff out of happstack .. it is not really happstack specific. Though I suspect pulling it out is not entirely trivial either. I think the existing code depends on syb-with-class. If you switch to Derive then you can generate the classes with Template Haskell, or run the Derive tool as a preprocessor. Derive abstracts over these details, and also tends to be much easier than working within Template Haskell (which I always find surprisingly difficult). Thanks, Neil ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Maybe, maybe not.
Just noticed this difference in the definition of fromMaybe in two different places: http://haskell.org/ghc/docs/latest/html/libraries/base-4.2.0.0/src/Data-Maybe.html#fromMaybe -- | The 'fromMaybe' function takes a default value and and 'Maybe' -- value. If the 'Maybe' is 'Nothing', it returns the default values; -- otherwise, it returns the value contained in the 'Maybe'. fromMaybe :: a - Maybe a - a fromMaybe d x = case x of {Nothing - d;Just v - v} and http://en.wikibooks.org/wiki/Haskell/Hierarchical_libraries/Maybe fromMaybe :: a - Maybe a - a fromMaybe z = maybe z id Michael ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: ghc: unrecognised flags: -I
I found the problem. I had an empty entry for extra library includes in my cabal configuration. Once I commented this out things started working again. I think that cabal should probably not include a lone -I in this case though. Is there somewhere I can file a bug? Thanks guys. On Mon, Jan 25, 2010 at 4:58 PM, Christian Maeder christian.mae...@dfki.de wrote: Lyndon Maydwell schrieb: For example, when I cabal install -v storable-complex I get the following: /usr/bin/ghc -package-name storable-complex-0.2.1 --make -hide-all-packages -i -idist/build -i. -idist/build/autogen -Idist/build/autogen -Idist/build -I -optP-include -optPdist/build/autogen/cabal_macros.h -odir dist/build -hidir dist/build -stubdir dist/build -package base-3.0.3.1 -O Foreign.Storable.Complex ghc: unrecognised flags: -I For me this works (and does not have that single -I): /home/mac-bkb/bin/ghc -package-name storable-complex-0.2.1 --make -hide-all-packages -i -idist/build -i. -idist/build/autogen -Idist/build/autogen -Idist/build -optP-include -optPdist/build/autogen/cabal_macros.h -odir dist/build -hidir dist/build -stubdir dist/build -package base-3.0.3.1 -O Foreign.Storable.Complex Has anyone encountered this before, or more realistically, can anyone give me some advice on how to narrow this problem down further? Sorry, no idea. I'm running cabal version 1.6.0.1, ghc 6.10.4 on OS X 10.5. I've got Cabal-1.6.0.3, ghc 6.10.4 on OS X 10.5 (Intel) cabal-install version 0.6.2 using version 1.6.0.3 of the Cabal library Christian ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Maybe, maybe not.
Excerpts from michael rice's message of Tue Jan 26 21:34:42 -0500 2010: fromMaybe d x = case x of {Nothing - d;Just v - v} fromMaybe z = maybe z id They're equivalent. Here the definition of maybe: maybe :: b - (a - b) - Maybe a - b maybe n _ Nothing = n maybe _ f (Just x) = f x Cheers, Edward ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Maybe, maybe not.
Didn't recognize the sameness. Aside from there being many ways to do the same thing, partial application makes the mixup even merrier. Thanks, Michael --- On Tue, 1/26/10, Edward Z. Yang ezy...@mit.edu wrote: From: Edward Z. Yang ezy...@mit.edu Subject: Re: [Haskell-cafe] Maybe, maybe not. To: michael rice nowg...@yahoo.com Cc: haskell-cafe haskell-cafe@haskell.org Date: Tuesday, January 26, 2010, 10:52 PM Excerpts from michael rice's message of Tue Jan 26 21:34:42 -0500 2010: fromMaybe d x = case x of {Nothing - d;Just v - v} fromMaybe z = maybe z id They're equivalent. Here the definition of maybe: maybe :: b - (a - b) - Maybe a - b maybe n _ Nothing = n maybe _ f (Just x) = f x Cheers, Edward ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Maybe, maybe not.
There are actually only two (extensionally) possible total functions with that type, as far as I can see :) On Tue, Jan 26, 2010 at 11:12 PM, michael rice nowg...@yahoo.com wrote: Didn't recognize the sameness. Aside from there being many ways to do the same thing, partial application makes the mixup even merrier. Thanks, Michael --- On *Tue, 1/26/10, Edward Z. Yang ezy...@mit.edu* wrote: From: Edward Z. Yang ezy...@mit.edu Subject: Re: [Haskell-cafe] Maybe, maybe not. To: michael rice nowg...@yahoo.com Cc: haskell-cafe haskell-cafe@haskell.org Date: Tuesday, January 26, 2010, 10:52 PM Excerpts from michael rice's message of Tue Jan 26 21:34:42 -0500 2010: fromMaybe d x = case x of {Nothing - d;Just v - v} fromMaybe z = maybe z id They're equivalent. Here the definition of maybe: maybe :: b - (a - b) - Maybe a - b maybe n _ Nothing = n maybe _ f (Just x) = f x Cheers, Edward ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Maybe, maybe not.
Excerpts from Daniel Peebles's message of Tue Jan 26 23:25:28 -0500 2010: There are actually only two (extensionally) possible total functions with that type, as far as I can see :) Is the other one... const? Cheers, Edward ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Maybe, maybe not.
2010/1/27 Edward Z. Yang ezy...@mit.edu: Excerpts from Daniel Peebles's message of Tue Jan 26 23:25:28 -0500 2010: There are actually only two (extensionally) possible total functions with that type, as far as I can see :) Is the other one... const? As far as I can tell, yes. -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com Jonathan Swift - May you live every day of your life. - http://www.brainyquote.com/quotes/authors/j/jonathan_swift.html ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Maybe, maybe not.
It might be more obvious by giving: fromMaybe :: a - (a - x, x) - x Ivan Miljenovic wrote: 2010/1/27 Edward Z. Yang ezy...@mit.edu: Excerpts from Daniel Peebles's message of Tue Jan 26 23:25:28 -0500 2010: There are actually only two (extensionally) possible total functions with that type, as far as I can see :) Is the other one... const? As far as I can tell, yes. -- Tony Morris http://tmorris.net/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Maybe, maybe not.
2010/1/27 Tony Morris tonymor...@gmail.com: It might be more obvious by giving: fromMaybe :: a - (a - x, x) - x I actually found this more confusing, and am not sure of its validity: should that be Maybe a there at the beginning? -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com Pablo Picasso - Computers are useless. They can only give you answers. - http://www.brainyquote.com/quotes/authors/p/pablo_picasso.html ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Maybe, maybe not.
Ivan Miljenovic wrote: 2010/1/27 Tony Morris tonymor...@gmail.com: It might be more obvious by giving: fromMaybe :: a - (a - x, x) - x I actually found this more confusing, and am not sure of its validity: should that be Maybe a there at the beginning? Sorry a mistake. Correction: fromMaybe :: a - ((a - x, x) - x) - x {-# LANGUAGE RankNTypes #-} data Maybe' a = M (forall x. (a - x, x) - x) to :: Maybe' t - Maybe t to (M f) = f (Just, Nothing) from :: Maybe a - Maybe' a from (Just a) = M (flip fst a) from Nothing = M snd -- Tony Morris http://tmorris.net/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] scheduling an alarm
On Tue, 26 Jan 2010 10:54:03 -0800 Thomas DuBuisson thomas.dubuis...@gmail.com wrote: doEvent f usDelay = forkIO $ threadDelay usDelay doEvent f usDelay f Are you sure that's right ? It seems to be a memory-gobbling infinite loop... How about this: f = putStrLn foo doEvent f usDelay = do forkIO f threadDelay usDelay doEvent f 100 main = doEvent f 100 which seems to work. That makes me suspicious :-| Brian ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] scheduling an alarm
Brian Denheyer bri...@aracnet.com wrote: On Tue, 26 Jan 2010 10:54:03 -0800 Thomas DuBuisson thomas.dubuis...@gmail.com wrote: doEvent f usDelay = forkIO $ threadDelay usDelay doEvent f usDelay f Are you sure that's right ? It seems to be a memory-gobbling infinite loop... Infinite loop? yes, that is what you wanted. Memory gobbling? Why would you think that? Are you assuming no TCO and a full stack push on every function call? Haskell compilers don't work that way. How about this: f = putStrLn foo doEvent f usDelay = do forkIO f threadDelay usDelay doEvent f 100 main = doEvent f 100 which seems to work. That makes me suspicious :-| 1) There are a million ways to do this - why does one working make you suspicious of another? You can always test the other - it does work so long as you fix the missing 'do'. 2) It strikes me as funny you suspect the first way when there is zero fundamental difference between that and the way you posted except that: a) My version maintains the correct delay. b) My version forks the doEvent call and runs the action in the older thread while yours forks the action thread and keeps the doEvent in the older thread. I suppose keeping the doEvent as the old thread is good so you can kill it with the original ThreadID that would be returned to the caller. Some people miss the fact that threadDelay is a us value and an Int type - this limits the maximum delay to something like 35 minutes (assume a 32 bit Int) or even just 134 seconds if you go by Haskell 98 minimum of 27 bit Ints. Just making sure you realize this seeing as we are talking about delays in that order of magnitude. I advise the overly-complex but functional Control-Event package if you want longer delays. Cheers, Thomas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe