Re: [Haskell-cafe] Problem with monadic formlets
Jeremy == Jeremy Shaw jer...@n-heptane.com writes: Jeremy Hello, I hacked your code into a runnable example, and it Jeremy seems to work for me. Jeremy Which looks correct to me. Your code looks fine to me as Jeremy well... Perhaps the error is not in the code you pasted, Jeremy but somewhere else. I am running on an older, and somewhat Jeremy forked version of Formlets, so there could also be a bug Jeremy in the new code I guess. Though, that seems unlikely. But Jeremy it is worth noting that we are not using the same version Jeremy of the formlets library. I did some debugging in ghci, but was unable to step through the ensure and check routines, which is where the apparent data corruprion is occurring. I am suspecting a bug in the formlets library (I have version 0.6). So I have created a slightly cut-down (no database involved) complete working program. Can you see if this works ok with your version of formlets: module Main where import Control.Applicative import Control.Applicative.Error import Control.Applicative.State import Data.List as List import Text.Formlets import qualified Text.XHtml.Strict.Formlets as F import qualified Text.XHtml.Strict as X import Text.XHtml.Strict ((+++), ()) import Happstack.Server type XForm a = F.XHtmlForm IO a data Registration = Registration { regUser :: String , regPass :: String } deriving Show handleRegistration :: ServerPartT IO Response handleRegistration = withForm register register showErrorsInline (\u - okHtml $ regUser u ++ is successfully registered) withForm :: String - XForm a - (X.Html - [String] - ServerPartT IO Response) - (a - ServerPartT IO Response) - ServerPartT IO Response withForm name frm handleErrors handleOk = dir name $ msum [ methodSP GET $ createForm [] frm = okHtml , withDataFn lookPairs $ \d - methodSP POST $ handleOk' $ simple d ] where handleOk' d = do let (extractor, html, _) = runFormState d frm v - liftIO extractor case v of Failure faults - do f - createForm d frm handleErrors f faults Success s - handleOk s simple d = List.map (\(k,v) - (k, Left v)) d showErrorsInline :: X.Html - [String] - ServerPartT IO Response showErrorsInline renderedForm errors = okHtml $ X.toHtml (show errors) +++ renderedForm createForm :: Env - XForm a - ServerPartT IO X.Html createForm env frm = do let (extractor, xml, endState) = runFormState env frm xml' - liftIO xml return $ X.form X.! [X.method POST] (xml' +++ X.submit submit Submit) okHtml :: (X.HTML a) = a - ServerPartT IO Response okHtml content = ok $ toResponse $ htmlPage $ content htmlPage :: (X.HTML a) = a - X.Html htmlPage content = (X.header (X.thetitle Testing forms)) +++ (X.body content) register :: XForm Registration register = Registration $ user * passConfirmed user :: XForm String user = pure_user `F.checkM` F.ensureM valid error where valid name = return True error = Username already exists in the database! pure_user :: XForm String pure_user = input `F.check` F.ensure valid error where input = Username `label` F.input Nothing valid = (= 3) . length error = Username must be three characters or longer. passConfirmed :: XForm String passConfirmed = fst $ passwords `F.check` F.ensure equal error where passwords = (,) $ pass Password * pass Password (confirm) equal (a, b) = a == b error = The entered passwords do not match! pass :: String - XForm String pass caption = input `F.check` F.ensure valid error where input = caption `label` F.password Nothing valid = (=6) . length error = Password must be six characters or longer. label :: String - XForm String - XForm String label l = F.plug (\xhtml - X.p (X.label (l ++ : ) +++ xhtml)) main = simpleHTTP (nullConf {port = 9959}) handleRegistration -- Colin Adams Preston Lancashire ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: moe html combinator
2009/08/27 Bulat Ziganshin bulat.zigans...@gmail.com: ...stop reusing Prelude operators, in particular, replace - with $? I have to say, the `$ do` construct is an eyesore and `- do` is a lot easier on the eyes. Would it introduce ambiguity in the Haskell grammar if foo do... foo case... foo if... were always parsed as: foo (do...) foo (case...) foo (if...) This is what is usually meant. -- Jason Dusek ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Is logBase right?
Lennart Augustsson lenn...@augustsson.net writes: Prelude toRational 697.04157958259998 3065621287177675 % 4398046511104 Prelude toRational 697.0415795826 3065621287177675 % 4398046511104 As you can see, both numbers are represented by the same Double. Haskell prints a Double with the simplest number that converts back to the same bit pattern. So there's no keep more decimals, just a matter of string conversion. What puzzled me (and the parent article indicated), was that Python appeared to be able to work with more precision, and thus be more numerically correct than GHC. Since it's all machine precision floating point, this is even more strange, and I couldn't reproduce the behavior for any other numbers than the one used in the example. One test that I *didn't* make is this one: Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type help, copyright, credits or license for more information. 697.0415795826 697.04157958259998 So yes - it's just a matter of Python printing the number as 697.04157958259998, while GHC prints it as 697.0415795826. Thanks for clarifying, and apologies for the confusion. Its been fixed in the latest versions of Python: round(697.04157958254996, 10) 697.0415795825 I get (Python 2.6.2): round(697.04157958254996,10) 697.04157958259998 ghci roundN 697.04157958254996 10 697.0415795826 I suppose it is likely that 697.04157958254996 is closer to the real decimal value of this particular number than GHC's representation, which is 697.04157958255. Whether this is a problem is a different matter, and I'm curious what programs usefully depend on one behavior or the other in decimal rounding near the limit of precision. -k -- If I haven't seen further, it is by standing in the footprints of giants ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Mapping over multiple values of a list at once?
Raynor Vliegendhart shinnon...@gmail.com writes: Just wondering, what should be the expected output be of something like mavg 4 [1..3]? [3%2] or []? [0%1, 1%4, 3%4, 3%2, 3%2, 5%4, 3%4, 0%1], of course ;-P -- Jón Fairbairn jon.fairba...@cl.cam.ac.uk ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] tomorrow: Edinburgh Meetup (Sat 29 Aug) and Hack Day (Sun 30 Aug)
Dear Haskellers, Last minute reminder: We will be having a Hack Day in Edinburgh on Sunday 30 August (ICFP venue). That's this weekend! For the interested, we will also be meeting up the day before 09:30 Saturday 29 August just outside the RCPE (ie. the ICFP venue again). We'll have a quick wander and hopefully find some nice places to sit, chat and hack. On Sunday the real Hack Day begins at the ICFP venue, rooms 4/5. http://www.haskell.org/haskellwiki/Hac7 And for the interested, Brent says: I'll be there Saturday morning---looking forward to meeting people! Also, I have purchased a ticket to hear a concert of some 16th-century a capella 16th-century music at the Canongate Kirk at 5pm on Saturday: http://www.edfringe.com/ticketing/detail.php?id=13649 Just thought I'd mention it, so if there's anyone else coming to the meetup day and 16th-century a capella sounds like your cup of tea, you can get a ticket too and we can go together. Looking forward to seeing you, Eric PS. Bring a name tag if you've got one. There are about 15 people registered so far. It's not too late to register! (yes, you could also just drop by...) -- Eric Kow http://www.nltg.brighton.ac.uk/home/Eric.Kow PGP Key ID: 08AC04F9 pgpCNrkyR9Njj.pgp Description: PGP signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Uninstall a cabal package?
What is the procedure to uninstall a cabal package? -- Colin Adams Preston Lancashire ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Re[Haskell-cafe] duction Sequence of simple Fibonacci sequence implementation
Thanks for the memo trick! Now I understand that the haskell compiler cannot memoize functions of integers, because it could change the space behaviour. However I think it could memoize everything else. Because all types that are data objects sitting in memory (so the arg is essentially a reference) can be memoized, without changing the space properties (except for overall constants). Does haskell do this? And if it doesn't can you turn it on? Cheers, Gerben -- View this message in context: http://www.nabble.com/Reduction-Sequence-of-simple-Fibonacci-sequence-implementation-tp25178377p25187256.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[2]: Re[Haskell-cafe] duction Sequence of simple Fibonacci sequence implementation
Hello staafmeister, Friday, August 28, 2009, 1:54:38 PM, you wrote: it just works other way. imagine a whole haskell program as a graph. i.e. expression 1+2, for example, forms a node with (=) in its root and 1 and 2 as its subtrees. computation of program is a series of graph reductions, replacing nodes with results, f.e. 1+2 = 3 this graph can share computations in only one way - when you give sharec node a name and use this name twice. for example, the following sum[1..1000] + prod[1..1000] don't share anything, but this let list = [1..1000] in sum list + prod list share the list. performing sharing via explicit naming common subexpressions is the only way to memoize results you imagine something highly inefficient like storing results of every computation ever done. are you think it really makes a sense? sometimes haskell compilers may deduce that some computation is used twice. if result of this computation definitely require less memory than computation itself, compiler may perform optimization by storing its result. it's called Common Subexpression Elimination. but its' not guaranteed, and afaik is pretty limited in ghc Thanks for the memo trick! Now I understand that the haskell compiler cannot memoize functions of integers, because it could change the space behaviour. However I think it could memoize everything else. Because all types that are data objects sitting in memory (so the arg is essentially a reference) can be memoized, without changing the space properties (except for overall constants). Does haskell do this? And if it doesn't can you turn it on? Cheers, Gerben -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Re[Haskell-cafe] duction Sequence of simple Fibonacci sequence implementation
On Fri, Aug 28, 2009 at 3:54 AM, staafmeisterg.c.stave...@uu.nl wrote: Thanks for the memo trick! Now I understand that the haskell compiler cannot memoize functions of integers, because it could change the space behaviour. However I think it could memoize everything else. Because all types that are data objects sitting in memory (so the arg is essentially a reference) can be memoized, without changing the space properties (except for overall constants). Does haskell do this? And if it doesn't can you turn it on? Integers are nothing special. Consider functions on: data Nat = Zero | Succ Nat Now, perhaps you mean memoize specific Nat *references* (a meaningless question for Haskell, only for specific implementations) rather than the *values*. Eg., for some f: would not. let x = Succ Zero in f x + f x would memoize the result of f, but: f (Succ Zero) + f (Succ Zero) would not. GHC does not do this. However, I am working in my free time on an experimental graph reducer which does. It implements a semantics called complete laziness[1]. I'm experimenting to see how that changes the engineering trade-offs (I have a blog post about what I expect those to be: http://lukepalmer.wordpress.com/2009/07/07/emphasizing-specialization/) For programs that do not benefit from the extra sharing, I should be lucky to run them only 50 times slower. This is an indication why GHC doesn't do this. Complete laziness is a fairly young research field. Maybe someday we'll get a smokin' fast completely lazy reducer. [1] http://www.lsv.ens-cachan.fr/Publis/PAPERS/PDF/sinot-wrs07.pdf ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Re[Haskell-cafe] [2]: Reduction Sequence of simple Fibonacci sequence implementation
Bulat Ziganshin-2 wrote: this graph can share computations in only one way - when you give sharec node a name and use this name twice. for example, the following sum[1..1000] + prod[1..1000] don't share anything, but this let list = [1..1000] in sum list + prod list share the list. performing sharing via explicit naming common subexpressions is the only way to memoize results you imagine something highly inefficient like storing results of every computation ever done. are you think it really makes a sense? Well in case I call (prod list) again it could lookup the reference and see that this computation has already been performed and just lookup the answer. In case `list' becomes GCed the GC should also destroy the lookup in the cache. The overhead is a O(1) overhead for the function because it needs to check if a computation has already performed. And the space overhead is not so big because every data object in memory there are a couple of references to be stored in lookup tables. So although there is space overhead it is not excessive. -- View this message in context: http://www.nabble.com/Reduction-Sequence-of-simple-Fibonacci-sequence-implementation-tp25178377p25187710.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] Uninstall a cabal package?
As far as I know the current stable release of Cabal doesn't keep track of installed packages, so you can only # ghc-pkg unregister pkg-id and then manually delete the files. Peter 2009/8/28 Colin Paul Adams co...@colina.demon.co.uk: What is the procedure to uninstall a cabal package? -- Colin Adams Preston Lancashire ___ 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[2]: Re[Haskell-cafe] [2]: Reduction Sequence of simple Fibonacci sequence implementation
Hello staafmeister, Friday, August 28, 2009, 2:34:07 PM, you wrote: Well in case I call (prod list) again it could lookup the reference and see so it should keep a list of all values ever computed in program, together with their expressions? :) are you like idea of prod[1..10^6] computation taking 10 mbytes of memory? -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Re[Haskell-cafe] [2]: Re[2]: Reduction Sequence of simple Fibonacci sequence implementation
Bulat Ziganshin-2 wrote: Hello staafmeister, Friday, August 28, 2009, 2:34:07 PM, you wrote: Well in case I call (prod list) again it could lookup the reference and see so it should keep a list of all values ever computed in program, together with their expressions? :) are you like idea of prod[1..10^6] computation taking 10 mbytes of memory? The list you give prod is also 10 MB so it not a terribly inefficient program. It's a factor of 2. Well haskell also has often a factor of 2 overhead with respect to C and people are not terribl concerned about that -- View this message in context: http://www.nabble.com/Reduction-Sequence-of-simple-Fibonacci-sequence-implementation-tp25178377p25188000.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: Re[Haskell-cafe] [2]: Re[2]: Reduction Sequence of simple Fibonacci sequence implementation
On Fri, Aug 28, 2009 at 1:03 PM, staafmeisterg.c.stave...@uu.nl wrote: The list you give prod is also 10 MB so it not a terribly inefficient program. That list takes memory only if it is forced. If it is passed to a lazy function, all the list may not be in memory at once. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: Re[Haskell-cafe] [2]: Re[2]: Reduction Sequence of simple Fibonacci sequence implementation
Hello staafmeister, Friday, August 28, 2009, 3:03:13 PM, you wrote: so it should keep a list of all values ever computed in program, together with their expressions? :) are you like idea of prod[1..10^6] computation taking 10 mbytes of memory? The list you give prod is also 10 MB so it not a terribly inefficient program. no, it's produced on need so it needs O(1) memory It's a factor of 2. Well haskell also has often a factor of 2 overhead with respect to C and people are not terribl concerned about that factor of 2 compared to ALL VALUES ever produced when evaluating program. since computer performs about 10^9 computations per second, you are going to store 10^9 values each second, some of those may be multi-megabyte by itself -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Re[Haskell-cafe] [2]: Re[2]: Reduction Sequence of simple Fibonacci sequence implementation
david48 wrote: On Fri, Aug 28, 2009 at 1:03 PM, staafmeisterg.c.stave...@uu.nl wrote: The list you give prod is also 10 MB so it not a terribly inefficient program. That list takes memory only if it is forced. If it is passed to a lazy function, all the list may not be in memory at once. In that case the GC cleaned up the whole list and while cleaning up it should also clean up the references in the cache lookup table. So then there is no space overhead either. -- View this message in context: http://www.nabble.com/Reduction-Sequence-of-simple-Fibonacci-sequence-implementation-tp25178377p25188238.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: Re[Haskell-cafe] [2]: Re[2]: Re[2]: Reduction Sequence of simple Fibonacci sequence implementation
Bulat Ziganshin-2 wrote: Hello staafmeister, Friday, August 28, 2009, 3:03:13 PM, you wrote: so it should keep a list of all values ever computed in program, together with their expressions? :) are you like idea of prod[1..10^6] computation taking 10 mbytes of memory? The list you give prod is also 10 MB so it not a terribly inefficient program. no, it's produced on need so it needs O(1) memory It's a factor of 2. Well haskell also has often a factor of 2 overhead with respect to C and people are not terribl concerned about that factor of 2 compared to ALL VALUES ever produced when evaluating program. since computer performs about 10^9 computations per second, you are going to store 10^9 values each second, some of those may be multi-megabyte by itself Hi Bulat, All the values that are computed but are also GCed (and they will be, 10^9 bytes is the mem limit). If the GC removes a value then all references in cache to those values can also be removed. Gerben -- View this message in context: http://www.nabble.com/Reduction-Sequence-of-simple-Fibonacci-sequence-implementation-tp25178377p25188333.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] Uninstall a cabal package?
Peter == Peter Robinson thaldy...@gmail.com writes: Peter As far as I know the current stable release of Cabal Peter doesn't keep track of installed packages, so you can only # Peter ghc-pkg unregister pkg-id and then manually delete the Peter files. Thanks. That works. -- Colin Adams Preston Lancashire ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Problem with monadic formlets
Colin == Colin Paul Adams co...@colina.demon.co.uk writes: Jeremy == Jeremy Shaw jer...@n-heptane.com writes: Colin apparent data corruprion is occurring. I am suspecting a Colin bug in the formlets library (I have version 0.6). Colin So I have created a slightly cut-down (no database Colin involved) complete working program. Can you see if this Colin works ok with your version of formlets: I managed to uninstall formlets-0.6 myself, and then installed 0.5 instead. After adding the necessary extra argument to runFormletState (an empty string), the test program works fine. So this seems to be a bug in formlets-0.6. -- Colin Adams Preston Lancashire ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Re[Haskell-cafe] [2]: Re[2]: Reduction Sequence of simple Fibonacci sequence implementation
staafmeister g.c.stave...@uu.nl writes: The list you give prod is also 10 MB so it not a terribly inefficient program. It's a factor of 2. No, it is not. The expression: prod [1..1000] + sum [1..1000] will first evaluate prod [1..1000], generating values from 1 to 1000 lazily and accumulating the product incrementally, allowing the used values to be GC'ed. Then the sum will be evaluated similarly, and the two results will be added. It will run in constant - and very small space. If you do common sub-expression elimination (CSE), and write let ls = [1..1000] in prod ls + sum ls the product will force ls to be evaluated, but since there is another reference to this value (for the sum), it cannot be garbage collected. Thus, the difference is more like a factor of 1000, which is a big deal. -k -- If I haven't seen further, it is by standing in the footprints of giants ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: Re[Haskell-cafe] [2]: Re[2]: Re[2]: Reduction Sequence of simple Fibonacci sequence implementation
Hello staafmeister, Friday, August 28, 2009, 3:31:13 PM, you wrote: All the values that are computed but are also GCed (and they will be, 10^9 bytes is the mem limit). If the GC removes a value then all references in cache to those values can also be removed. it looks like cache of values computed since the last GC, because on GC all those intermediate results will be collected. i think it's not very useful outside of fib example that does exact that - reusing recently computed values -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Arrows extentions and ArrowApplicable
Arrows syntax supports Arrow, ArrowChoice(if, case etc.) and ArrowLoop(rec) - but not ArrowApplicable. Therefore it is not possible to write: proc x - do a - someArrow - x a - x but proc x - do a - someArrow - x app - (a, x) and proc x - do a - someArrow - x app - (otherArrow a, x) instead of proc x - do a - someArrow - x otherArrow a - x Such approach adds some syntax sugar but without adding any additional keyword and IMHO it can simplify writing ArrowApply (especially Kleisli IO). Regards signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Mapping over multiple values of a list at once?
hask...@kudling.de wrote: You are asked to iterate over the list and calculate the average value of each 3 neighbouring values. Lambda Fu, form 72 - three way dragon zip averages3 xs = zipWith3 avg xs (drop 1 xs) (drop 2 xs) where avg a b c = (a+b+c) / 3 Regards, apfelmus -- http://apfelmus.nfshost.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Arrows extentions and ArrowApplicable
On Fri, Aug 28, 2009 at 02:33:08PM +0200, Maciej Piechotka wrote: Arrows syntax supports Arrow, ArrowChoice(if, case etc.) and ArrowLoop(rec) - but not ArrowApplicable. Therefore it is not possible to write: proc x - do a - someArrow - x a - x You can write proc x - do a - someArrow - x a - x (See the Arrow notation section of the GHC User's Guide.) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Time constrained computation
Hi! I am not really sure if this is correct term for it but I am open to better (search) terms. pure ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Time constrained computation
Hi! Ups, missed save button and pressed send. ;-) So I am not really sure if this is correct term for it but I am open to better (search) terms. I am wondering if it is possible to make a time constrained computation. For example if I have a computation of an approximation of a value which can take more or less time (and you get more or less precise value) or if I have an algorithm which is searching some search-space it can find better or worse solution depending how much time you allow. So I would like to say to Haskell to (lazily, if it really needs it) get me some value but not to spend more than so much time calculating it. One abstraction of this would be to have an infinity list of values and I would like to get the last element I can get in t milliseconds of computational time. One step further would be to be able to stop computation not at predefined time but with some other part of the program deciding it is enough. So I would have a system which would monitor computation and a pure computation I would be able to stop. Is this possible? Is it possible to have a pure computation interrupted and get whatever it has computed until then? How could I make this? Is there anything already done for it? Some library I have not found? Of course all this should be as performance wise as it is possible. So the best interface for me would be to be able to start a pure computation and put an upper bound on computation time but also be able to stop it before that upper bound. And all this should be as abstracted as it is possible. Mitar ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] strictness analysis on algebraic data types
I'm reading the book Modern Compiler Designhttp://www.cs.vu.nl/~dick/MCD.html, and in the chapter about functional programming it is stated that strictness analysis in the presence of ADTs (aka records) is a very hard problem to tackle. I'm not sure what the current state of art is here (e.g GHC or JHC), and don't understand what the problem is. Does it mean that it's a good idea to carefully consider when to make data constructor arguments (aka fields) strict, since the compiler can't do good strictness analysis when it encounters say a record with many lazy fields? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Another thanks for inspiration to RWH - Bloom Filters
Hi all, My app has to use rather large amounts of static data in order to run. I have been using an SQLite database to hold this data so far. The largest chunk of data was a table with roughly 80k records. I only make use of this table to see if a particular key is present. Reading RWH over from time to time I came accross the Bloom Filter and finally realized that this would be a much better solution. So I could insert all the keys in the table into a suitable bloom filter instead and the just query the bloom filter instead of the database. I haven't figured out yet how to write a literal representation of the filled bloom filter yet though and could do with some tipps. I'm using the bloomfilter package from hackage. Günther ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Time constrained computation
On Fri, Aug 28, 2009 at 6:01 AM, Mitarmmi...@gmail.com wrote: Hi! Ups, missed save button and pressed send. ;-) So I am not really sure if this is correct term for it but I am open to better (search) terms. I am wondering if it is possible to make a time constrained computation. For example if I have a computation of an approximation of a value which can take more or less time (and you get more or less precise value) or if I have an algorithm which is searching some search-space it can find better or worse solution depending how much time you allow. So I would like to say to Haskell to (lazily, if it really needs it) get me some value but not to spend more than so much time calculating it. One abstraction of this would be to have an infinity list of values and I would like to get the last element I can get in t milliseconds of computational time. One step further would be to be able to stop computation not at predefined time but with some other part of the program deciding it is enough. So I would have a system which would monitor computation and a pure computation I would be able to stop. Is this possible? Is it possible to have a pure computation interrupted and get whatever it has computed until then? How could I make this? Is there anything already done for it? Some library I have not found? Of course all this should be as performance wise as it is possible. So the best interface for me would be to be able to start a pure computation and put an upper bound on computation time but also be able to stop it before that upper bound. And all this should be as abstracted as it is possible. Mitar ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe In general, you need to do this either within the IO monad, to avoid breaking referential transparency, or using unsafePerformIO, if you know that your use of it is safe, which seems somewhat unlikely. You may want to look at System.Timeout. Another possibility would be the unamb package from Hackage. Hope that helps, Alex ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Time constrained computation
I tried this using timeout, but was never able to get it to work. The timeout doesn't behave like I expect. I can take several seconds for it to timeout, even with very low timeouts. Any ideas? - Job module Main where import Data.IORef import System.Timeout import System.IO.Unsafe tailScan f (x:xs) = resultList where resultList = x : zipWith f resultList xs facts = 1 : tailScan (*) [1..] fac n = facts !! n eterm x n = x^n / (fac n) eseries x = fmap (eterm x) [0..] ePrecisionList x = tailScan (+) $ eseries x computeUntil t xs = do a - newIORef undefined timeout t $ sequence $ fmap (writeIORef a) xs readIORef a -- compute e for only 10 microseconds e x = computeUntil 10 (ePrecisionList x) main = do -- compute e print = e 1 On Fri, Aug 28, 2009 at 9:01 AM, Mitar mmi...@gmail.com wrote: Hi! Ups, missed save button and pressed send. ;-) So I am not really sure if this is correct term for it but I am open to better (search) terms. I am wondering if it is possible to make a time constrained computation. For example if I have a computation of an approximation of a value which can take more or less time (and you get more or less precise value) or if I have an algorithm which is searching some search-space it can find better or worse solution depending how much time you allow. So I would like to say to Haskell to (lazily, if it really needs it) get me some value but not to spend more than so much time calculating it. One abstraction of this would be to have an infinity list of values and I would like to get the last element I can get in t milliseconds of computational time. One step further would be to be able to stop computation not at predefined time but with some other part of the program deciding it is enough. So I would have a system which would monitor computation and a pure computation I would be able to stop. Is this possible? Is it possible to have a pure computation interrupted and get whatever it has computed until then? How could I make this? Is there anything already done for it? Some library I have not found? Of course all this should be as performance wise as it is possible. So the best interface for me would be to be able to start a pure computation and put an upper bound on computation time but also be able to stop it before that upper bound. And all this should be as abstracted as it is possible. Mitar ___ 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] Re: Time constrained computation
This is my go at the problem: module Main where import Control.Concurrent import Data.IORef -- From the Haskell wiki primes :: [Integer] primes = sieve [2..] where sieve (p:xs) = p : sieve [x | x - xs, x `mod` p /= 0] producePrimes :: IORef [Integer] - IO () producePrimes ref = go primes where go (x:xs) = modifyIORef ref (\ys - x:ys) go xs go [] = error Euclid was wrong! -- Calculate as much primes as possible in 't' picoseconds getPrimes :: Int - IO [Integer] getPrimes t = do ref - newIORef [] producer - forkIO (producePrimes ref) threadDelay t killThread producer readIORef ref main = do ps - getPrimes 100 print $ length ps Or view my hpaste: http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8782#a8782 If you run this a few times in GHCI you will find that it calculates an increasingly large number of primes within the same time span. This is because the previous results are retained. Compile and run or restart GHCI for every run for accurate results. On Fri, Aug 28, 2009 at 3:01 PM, Mitarmmi...@gmail.com wrote: Hi! Ups, missed save button and pressed send. ;-) So I am not really sure if this is correct term for it but I am open to better (search) terms. I am wondering if it is possible to make a time constrained computation. For example if I have a computation of an approximation of a value which can take more or less time (and you get more or less precise value) or if I have an algorithm which is searching some search-space it can find better or worse solution depending how much time you allow. So I would like to say to Haskell to (lazily, if it really needs it) get me some value but not to spend more than so much time calculating it. One abstraction of this would be to have an infinity list of values and I would like to get the last element I can get in t milliseconds of computational time. One step further would be to be able to stop computation not at predefined time but with some other part of the program deciding it is enough. So I would have a system which would monitor computation and a pure computation I would be able to stop. Is this possible? Is it possible to have a pure computation interrupted and get whatever it has computed until then? How could I make this? Is there anything already done for it? Some library I have not found? Of course all this should be as performance wise as it is possible. So the best interface for me would be to be able to start a pure computation and put an upper bound on computation time but also be able to stop it before that upper bound. And all this should be as abstracted as it is possible. Mitar ___ 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] Re: Is logBase right?
On Aug 28, 2009, at 03:24 , Ketil Malde wrote: What puzzled me (and the parent article indicated), was that Python appeared to be able to work with more precision, and thus be more numerically correct than GHC. Since it's all machine precision floating point, this is even more strange, and I couldn't reproduce the behavior for any other numbers than the one used in the example. -fexcess-precision or other gcc compile options? -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon universityKF8NH PGP.sig Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Re[2]: Re[Haskell-cafe] [2]: Re[2]: Re[2]: Reduction Sequence of simple Fibonacci sequence implementation
On Fri, Aug 28, 2009 at 6:04 AM, Bulat Ziganshinbulat.zigans...@gmail.com wrote: Hello staafmeister, Friday, August 28, 2009, 3:31:13 PM, you wrote: All the values that are computed but are also GCed (and they will be, 10^9 bytes is the mem limit). If the GC removes a value then all references in cache to those values can also be removed. it looks like cache of values computed since the last GC, because on GC all those intermediate results will be collected. i think it's not very useful outside of fib example that does exact that - reusing recently computed values I wouldn't be so quick to call it useless. This caching idea, when combined with HNF instead of WHNF reduction, leads to a strategy which is capable of automatically specializing away layers of interpretation. That is to say, it turns all interpreters into compilers. Now, there are some disadvantages too, some of which have to do with memory performance. But it's not clear that the disadvantages always outweigh the advantages; rather I suspect you get a strategy which implies a whole different set of trade-offs for engineering efficient programs. Luke ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] rotate image
Hello, Nobody any idea? I want to paint in some widget, but this will be in front of some background, so the bg should be transparent. -- best regards h. -- View this message in context: http://www.nabble.com/rotate-image-tp25122912p25198054.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] SLD resolution code in Haskell
Hi, is there any haskell code for SLD-resolution; I wanna learn it. Thanks a lot. Steffen. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] rotate image
Not really. Best thing I can think to do is use the X11 library to pull the pixels under your window then draw them as a surface on the drawingarea, then draw your rotated image on top of that. You have to have a window, and Gtk windows do not have an alpha. You'll want it to be undecorated, too... On Fri, Aug 28, 2009 at 6:38 PM, h.h._h._...@hotmail.com wrote: Hello, Nobody any idea? I want to paint in some widget, but this will be in front of some background, so the bg should be transparent. -- best regards h. -- View this message in context: http://www.nabble.com/rotate-image-tp25122912p25198054.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 mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Snow Leopard Breaks GHC
Just thought I'd point out that my old GHC install is now broken by the update to Snow Leopard. Dave ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Snow Leopard Breaks GHC
My 6.10.1 install still works alright after upgrade to 10.6/Snow Leopard. What version did you have? -Ross On Aug 28, 2009, at 7:15 PM, David Leimbach wrote: Just thought I'd point out that my old GHC install is now broken by the update to Snow Leopard. Dave ___ 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] Snow Leopard Breaks GHC
6.10.4. Did you try to build any binaries? It doesn't produce correct assembly code (it looks like). Dave On Fri, Aug 28, 2009 at 4:55 PM, Ross Mellgren rmm-hask...@z.odi.ac wrote: My 6.10.1 install still works alright after upgrade to 10.6/Snow Leopard. What version did you have? -Ross On Aug 28, 2009, at 7:15 PM, David Leimbach wrote: Just thought I'd point out that my old GHC install is now broken by the update to Snow Leopard. Dave ___ 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] Snow Leopard Breaks GHC
I did a trivial compile and it worked yes (the binary it produced was alright, also). Did the binary it generate have problems, or was it the compilation that failed? -Ross On Aug 28, 2009, at 7:57 PM, David Leimbach wrote: 6.10.4. Did you try to build any binaries? It doesn't produce correct assembly code (it looks like). Dave On Fri, Aug 28, 2009 at 4:55 PM, Ross Mellgren rmm- hask...@z.odi.ac wrote: My 6.10.1 install still works alright after upgrade to 10.6/Snow Leopard. What version did you have? -Ross On Aug 28, 2009, at 7:15 PM, David Leimbach wrote: Just thought I'd point out that my old GHC install is now broken by the update to Snow Leopard. Dave ___ 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] Snow Leopard Breaks GHC
The compilation failed. On Fri, Aug 28, 2009 at 4:58 PM, Ross Mellgren rmm-hask...@z.odi.ac wrote: I did a trivial compile and it worked yes (the binary it produced was alright, also). Did the binary it generate have problems, or was it the compilation that failed? -Ross On Aug 28, 2009, at 7:57 PM, David Leimbach wrote: 6.10.4. Did you try to build any binaries? It doesn't produce correct assembly code (it looks like). Dave On Fri, Aug 28, 2009 at 4:55 PM, Ross Mellgren rmm-hask...@z.odi.acwrote: My 6.10.1 install still works alright after upgrade to 10.6/Snow Leopard. What version did you have? -Ross On Aug 28, 2009, at 7:15 PM, David Leimbach wrote: Just thought I'd point out that my old GHC install is now broken by the update to Snow Leopard. Dave ___ 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] Snow Leopard Breaks GHC
The same here: $ghc hw.hs /var/folders/1J/1JKije6yHpm78qqdjF5N2U+++TI/-Tmp-/ghc7743_0/ ghc7743_0.s:1357:0: suffix or operands invalid for `push' /var/folders/1J/1JKije6yHpm78qqdjF5N2U+++TI/-Tmp-/ghc7743_0/ ghc7743_0.s:1401:0: suffix or operands invalid for `push' ... I've tried to build ghc from svn, but build process failed, cause it requires working version of GHC. I've tried to cross build from Ubuntu, but it failed too. There is a ticket - http://hackage.haskell.org/trac/ghc/ticket/3400, but it's not helpful for me. D On 29/08/2009, at 10:06 AM, David Leimbach wrote: The compilation failed. On Fri, Aug 28, 2009 at 4:58 PM, Ross Mellgren rmm- hask...@z.odi.ac wrote: I did a trivial compile and it worked yes (the binary it produced was alright, also). Did the binary it generate have problems, or was it the compilation that failed? -Ross On Aug 28, 2009, at 7:57 PM, David Leimbach wrote: 6.10.4. Did you try to build any binaries? It doesn't produce correct assembly code (it looks like). Dave On Fri, Aug 28, 2009 at 4:55 PM, Ross Mellgren rmm- hask...@z.odi.ac wrote: My 6.10.1 install still works alright after upgrade to 10.6/Snow Leopard. What version did you have? -Ross On Aug 28, 2009, at 7:15 PM, David Leimbach wrote: Just thought I'd point out that my old GHC install is now broken by the update to Snow Leopard. Dave ___ 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 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Unifcation and matching in Abelian groups
I cleaned up the code, partitioned it into a library and an executable, and made the package available on hackage as agum-1.0. Enjoy. John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] SLD resolution code in Haskell
On Fri, Aug 28, 2009 at 6:03 PM, Steffen Bockbock.stef...@yahoo.de wrote: Hi, is there any haskell code for SLD-resolution; I wanna learn it. What's SLD-resolution? Antoine ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] SLD resolution code in Haskell
Hey Steffen, I actually made it one time, remember me to send it to you on monday... Hector Guilarte -Original Message- From: Steffen Bock bock.stef...@yahoo.de Date: Fri, 28 Aug 2009 23:03:24 To: Haskell-Cafe@haskell.org Subject: [Haskell-cafe] SLD resolution code in Haskell ___ 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] rotate image
Hello, Thanks for your answers and your time, but I fear that I didn't described the problem accurately enough. The background is in the window created with gtk2hs (windowNew). It's just a fixed layout (fixedNew): bg - imageNewFromFile bg.jpg fixedPut fBox bg (0,0) If I now create the new image (with imageNewFromFile my.png) with it's alpha values, I can put it somewhere via fixedPut, and the other image is just covered where it should be, but I can't rotate the image. So cairo and the surface come into play. This works as well, the surface has it's alpha values where it should, but a drawingArea created with drawingAreaNew has a rectangular shape and a color. This is the problem. -- best regards h. -- View this message in context: http://www.nabble.com/rotate-image-tp25122912p25199462.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] Snow Leopard Breaks GHC
On Fri, Aug 28, 2009 at 5:28 PM, Dmitri Sosnik dim...@gmail.com wrote: The same here:$ghc hw.hs /var/folders/1J/1JKije6yHpm78qqdjF5N2U+++TI/-Tmp-/ghc7743_0/ghc7743_0.s:1357:0: suffix or operands invalid for `push' /var/folders/1J/1JKije6yHpm78qqdjF5N2U+++TI/-Tmp-/ghc7743_0/ghc7743_0.s:1401:0: suffix or operands invalid for `push' ... I've tried to build ghc from svn, but build process failed, cause it requires working version of GHC. I've tried to cross build from Ubuntu, but it failed too. There is a ticket - http://hackage.haskell.org/trac/ghc/ticket/3400, but it's not helpful for me. There is a closed ticket for this bug, but it doesn't exactly tell us how or when we'll see a fix :-) Maybe the answer is run windows or linux :-) D On 29/08/2009, at 10:06 AM, David Leimbach wrote: The compilation failed. On Fri, Aug 28, 2009 at 4:58 PM, Ross Mellgren rmm-hask...@z.odi.acwrote: I did a trivial compile and it worked yes (the binary it produced was alright, also). Did the binary it generate have problems, or was it the compilation that failed? -Ross On Aug 28, 2009, at 7:57 PM, David Leimbach wrote: 6.10.4. Did you try to build any binaries? It doesn't produce correct assembly code (it looks like). Dave On Fri, Aug 28, 2009 at 4:55 PM, Ross Mellgren rmm-hask...@z.odi.acwrote: My 6.10.1 install still works alright after upgrade to 10.6/Snow Leopard. What version did you have? -Ross On Aug 28, 2009, at 7:15 PM, David Leimbach wrote: Just thought I'd point out that my old GHC install is now broken by the update to Snow Leopard. Dave ___ 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 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Snow Leopard Breaks GHC
leimy2k: On Fri, Aug 28, 2009 at 5:28 PM, Dmitri Sosnik dim...@gmail.com wrote: The same here: $ghc hw.hs /var/folders/1J/1JKije6yHpm78qqdjF5N2U+++TI/-Tmp-/ghc7743_0/ ghc7743_0.s:1357:0: suffix or operands invalid for `push' /var/folders/1J/1JKije6yHpm78qqdjF5N2U+++TI/-Tmp-/ghc7743_0/ ghc7743_0.s:1401:0: suffix or operands invalid for `push' ... I've tried to build ghc from svn, but build process failed, cause it requires working version of GHC. I've tried to cross build from Ubuntu, but it failed too. There is a ticket - http://hackage.haskell.org/trac/ghc/ticket/3400, but it's not helpful for me. There is a closed ticket for this bug, but it doesn't exactly tell us how or when we'll see a fix :-) Maybe the answer is run windows or linux :-) If it is closed, it is fixed in the HEAD. -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe