[Haskell-cafe] google-like do you mean? feature
I'm thinking of writing a parser to load files that my customers have created. I'm a software requirements engineer; the data consists of the customers' thoughts in response to the latest release of the requirements doc. In fact, the files will probably be copies of the requirements doc itself, into which customers have entered their notes and made changes. The original requirements doc will have a format that can be parsed; probably something simple like lines marked with codes like //customer={customer name goes here} //requirement= {requirement text goes here} When I parse the documents that come back from the customers, they are likely to contain some errors. Field names may be mangled or misspelled. Customer names may be entered in unrecognizable variants (e.g. someone named Michael is indicated as Mike) and so forth. I was thinking that it might be useful to have a Google-like do you mean this? feature. If the field name is //customer=, then the parser might recognize a huge list of variants like //ustomer=, //customor=, etc... that is, recognize them well enough to continue parsing and give a decent error message in context. Any ideas how to go about this? I don't think I would create a parser language that includes every variant, but instead the field names would be tokens that could be passed to another routine. The variants could be generated ahead of time. I would limit the number of variants to something manageable, like 10,000 for each field name. Thanks, Mike ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] google-like do you mean? feature
2009/4/16 Michael Mossey m...@alumni.caltech.edu: I was thinking that it might be useful to have a Google-like do you mean this? feature. If the field name is //customer=, then the parser might recognize a huge list of variants like //ustomer=, //customor=, etc... that is, recognize them well enough to continue parsing and give a decent error message in context. Any ideas how to go about this? To measure how similar two strings are, you can use a metric like Levenshtein distance, Damerau-Levenshtein distance, or Jaro-Winkler distance: http://en.wikipedia.org/wiki/Levenshtein_distance http://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance http://en.wikipedia.org/wiki/Jaro-Winkler_distance The first two basically count the number of mistakes that a user would have to make to get from the correct string to the one you read from the file. There's an 'edit-distance' package in Hackage that implements the first two: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/edit-distance When you find an unrecognised field name in the file, you could calculate the edit distance to each correct field name, and if there's one within a certain threshold, assume that's what the user meant (if there's more than one close match, maybe it's better to report an error than risk choosing the wrong one). I imagine this brute-force approach would be fast enough, but if not you could look at the techniques used by spell checkers to suggest corrections. Maybe even use a spell checking library, if such a thing exists (either pure Haskell or a binding to a library like aspell, although I couldn't see either from a quick search in Hackage). Andy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] google-like do you mean? feature
On Wed, 15 Apr 2009 23:31:50 -0700 Michael Mossey m...@alumni.caltech.edu wrote: I was thinking that it might be useful to have a Google-like do you mean this? feature. If the field name is //customer=, then the parser might recognize a huge list of variants like //ustomer=, //customor=, etc... You could reduce the probability of such errors by providing a standard template that could be copy-pasted in wherever necessary. -- Robin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: Elerea, another FRP library
On the other hand, I hadn't got round to cleaning up the interface, let alone firming the theoretical foundations, so perhaps this isn't an exception to your rule?-) But I thought I'd mention it on the topic of other FRP libraries, with variations of approach/concepts. Thanks for the pointers. I remember coming across this one earlier, but I forgot about it. Your description suggests that FunWorlds has a lot in common with Elerea. It's mostly the interface that looks different. Apparently I'll have to play with this one too. :) Gergely -- http://www.fastmail.fm - The professional email service ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] google-like do you mean? feature
Robin Green wrote: On Wed, 15 Apr 2009 23:31:50 -0700 Michael Mossey m...@alumni.caltech.edu wrote: I was thinking that it might be useful to have a Google-like do you mean this? feature. If the field name is //customer=, then the parser might recognize a huge list of variants like //ustomer=, //customor=, etc... You could reduce the probability of such errors by providing a standard template that could be copy-pasted in wherever necessary. Yes, that will be there. My example is not so good because it seems concerned with the keywords only. I'm more concerned about errors in the data they enter... for example, names of people and references to document names. Thanks, Mike ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] google-like do you mean? feature
2009/4/16 Michael Mossey m...@alumni.caltech.edu: I don't think I would create a parser language that includes every variant, but instead the field names would be tokens that could be passed to another routine. Right. The variants could be generated ahead of time. I would limit the number of variants to something manageable, like 10,000 for each field name. Generating variants ahead of time isn't necessary. Instead, you could just look at the edit distance between the token you get and each possible valid field name using something like http://hackage.haskell.org/cgi-bin/hackage-scripts/package/edit-distance. The token with the least edit distance is the one you should suggest. Cheers, Max ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Code Golf
Matt Morrow wrote: And i forgot to include the defs of (co)prod: coprod () i1 i2 = (\a b - i1 a i2 b) lambdabot pl \f i1 i2 - (\a b - i1 a `f` i2 b) (flip .) . (((.) .) .) . (.) Muhahaha. :-D Too bad the flip is still in there. :-) Martijn. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Code Golf
Hi, On 16.04.2009, at 05:08, Matt Morrow wrote: And i forgot to include the defs of (co)prod: prod () p1 p2 = (\a - p1 a p2 a) I think this one is liftM2 of the ((-) a) Monad instance. Cheers, Jan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Cabal and WinHugs
On Sun, 2009-04-12 at 20:02 -0700, Iavor Diatchki wrote: Hello, What is the preferred way to install a cabal package so that it works with winhugs? When I tried cabal install --user --hugs I got an error that it could not find hugsffi. I managed to get things working by manually downloading the package, and extracting the appropriate source directories to the packages folder of winhugs (i.e., basically skipping cabal) but this is kind of clunky. So to summarize, here are my two questions: 1. Am I doing something wrong, or does cabal not support WinHugs?, and 2. Does WinHugs have a user specific packages folder (so that each user can have their own set of packages)? I've never tried with winhugs and to be honest we don't test much with hugs either. Don't take that as a discouragement though, it'd be great to have better support for hugs and winhugs in the cabal tool. All it needs is someone to pay it a little attention. For the specific issue, does winhugs come with the hugsffi tool? I expect that it should do though perhaps it's hidden away in some directory. I believe that by default hugs uses $HOME/lib/packages/* for per-user packages. I'm not quite sure what winhugs does. It'd be good to adjust the defaults to make this just work. Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Code Golf
ghci let diag = foldr (curry (prod mappend fst snd . uncurry (coprod mappend (splitAt 2) (splitAt 1 [] nice :) thanks to the comments of Martijn and Jan we can replace prod and coprod by liftA2 and fancy dots: let diag = foldr (curry (liftA2 mappend fst snd.uncurry (((flip.). (((.).).).(.)) mappend (splitAt 2) (splitAt 1 [] It works for the finite tests but, unfortunately, not for the infinite one :( take 10 $ diag [[ (m,n) | n - [1..]] | m - [1..]] *** Exception: stack overflow ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] glut installation using cabal failed
On Wed, 2009-04-15 at 01:53 +0200, Henk-Jan van Tuyl wrote: On Tue, 14 Apr 2009 08:25:52 +0200, Raja Koduru kscr...@gmail.com wrote: hi, I am a beginner to haskell. I am trying to install glut using cabal install glut Pasting here a tail of the output checking for GLUT/glut.h... no configure: error: no GLUT header found, so this package cannot be built See `config.log' for more details. But I do have glut.h in my D:\ghc\ghc-6.10.2\include\mingw\GL. Define the environment variable: C_INCLUDE_PATH=D:\ghc\ghc-6.10.2\include\mingw (you can add more directories, separate them by ';') To let the linker find the libraries, define LIBRARY_PATH. Hmm, that is annoying. I've filed a tracker bug here: http://trac.haskell.org/haskell-platform/ticket/11 and also noted the issue here: http://hackage.haskell.org/trac/hackage/ticket/458#comment:2 Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Looking for the fastest Haskell primes algorithm
Niemeijer, R.A. wrote: Today I happened to need a large list of prime numbers. Obviously this is a well-known problem, so I figured there would be something on Hackage that I could use. Surprisingly, there isn't, or if there is it's not easy to find. Since it's such a common problem I'd say it would be a good idea to add a package to Hackage that exports primes :: [Integer] and hides the ugly implementation details. +1 except that exporting the potentially infinite list of primes is problematic in that it may become a memory leak. I'd suggest to export two versions primes :: [Integer] primes' :: () - [Integer] for casual (i.e. throwaway program to solve a Project Euler problem) and for memory aware use respectively. 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] ANN: Elerea, another FRP library
On the other hand, breaking referential transparency in the external interface is a very bad idea, in my opinion. Actually, this means that the library user would have to turn certain compiler optimizations off to get the intended behavior. However, in practice you can compile Elerea with -O2 without ill effects. In fact, that's what happens if you install it with cabal. Just have a look at the Haddock docs of unsafePerformIO. Yes, I did that too, and came up with the following checklist: - the order of side effects doesn't matter much, since the resulting networks are equivalent if we don't rely on the automatic delay feature (applicative optimisations can be different, but still with the same net effect) - unsafePerformIO is apparently never inlined, i.e. each instance is executed once, so sharing works as desired - let-floating is no problem, because all instances of unsafePerformIO rely on surrounding function arguments - CSE is no problem either, it even helps if it's performed (and it is with optimisations turned on), since it results in smaller equivalent networks I think we can expect it to be fairly well-behaving, because the 'side effect' of Elerea primitives is basically the same as that of pure values in general: upon evaluation a value is created in the memory and we get a reference to it. We only have an extra constraint for the compiler: never duplicate these values. Merging identical ones is okay, and in fact desirable. The following code demonstrates this if you compile it with and without optimisations: import Control.Applicative import Control.Monad import FRP.Elerea import System.IO.Unsafe cint a b = unsafePerformIO (putStrLn !) `seq` transfer 0 (\dt x x0 - x0+x*dt) b mysig = (latcher 0 (b @ 0.3) (const (cint a b) $ cint a b)) + (cint a b) + (cint a b) + a where a = pure 4 b = stateful 0 (+) main = replicateM 10 (superstep mysig 0.1) = print I'd like to see an example where optimisation does make a difference, because I'm still unsure about the consequences of 'unsafeness'. Gergely -- http://www.fastmail.fm - Or how I learned to stop worrying and love email again ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Issues with running Ghci from emacs
I end up doing :set -i../Documents/haskell/SOE/src To set the search directory so that ghci can find the source. I've not been how to tailor that 'cd' which is run at start up (but I've not looked to hard) Neil On 16 Apr 2009, at 04:12, Daryoush Mehrtash wrote: I am having problem running GHCI with Haskell files that include imports.I am running emacs22 on Ubuntu, with haskell-mode-2.4 extensions. I load my file (Fal.lhs in this case) in emacs. Then try to run the Ghci by doing C-c C-l. The result is shown below. Ghci fails to find the Draw.lhs which is also on the same directory as the Fal.lhs. Note: If I go to the directory where Fal.lhs is and run Ghci directly it all works fine. Any idea how I can get the interepreter to work form emacs? GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. Prelude :cd ~/.cabal/ Prelude :load ../Documents/haskell/SOE/src/Fal.lhs ../Documents/haskell/SOE/src/Fal.lhs:76:9: Could not find module `Draw': Use -v to see a list of the files searched for. Failed, modules loaded: none. Prelude Thanks, Daryoush ___ 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] ANN: Elerea, another FRP library
There's no guarantee about unsafePerformIO not being inlined, that's just how ghc treats it. 2009/4/16 Patai Gergely patai_gerg...@fastmail.fm: On the other hand, breaking referential transparency in the external interface is a very bad idea, in my opinion. Actually, this means that the library user would have to turn certain compiler optimizations off to get the intended behavior. However, in practice you can compile Elerea with -O2 without ill effects. In fact, that's what happens if you install it with cabal. Just have a look at the Haddock docs of unsafePerformIO. Yes, I did that too, and came up with the following checklist: - the order of side effects doesn't matter much, since the resulting networks are equivalent if we don't rely on the automatic delay feature (applicative optimisations can be different, but still with the same net effect) - unsafePerformIO is apparently never inlined, i.e. each instance is executed once, so sharing works as desired - let-floating is no problem, because all instances of unsafePerformIO rely on surrounding function arguments - CSE is no problem either, it even helps if it's performed (and it is with optimisations turned on), since it results in smaller equivalent networks I think we can expect it to be fairly well-behaving, because the 'side effect' of Elerea primitives is basically the same as that of pure values in general: upon evaluation a value is created in the memory and we get a reference to it. We only have an extra constraint for the compiler: never duplicate these values. Merging identical ones is okay, and in fact desirable. The following code demonstrates this if you compile it with and without optimisations: import Control.Applicative import Control.Monad import FRP.Elerea import System.IO.Unsafe cint a b = unsafePerformIO (putStrLn !) `seq` transfer 0 (\dt x x0 - x0+x*dt) b mysig = (latcher 0 (b @ 0.3) (const (cint a b) $ cint a b)) + (cint a b) + (cint a b) + a where a = pure 4 b = stateful 0 (+) main = replicateM 10 (superstep mysig 0.1) = print I'd like to see an example where optimisation does make a difference, because I'm still unsure about the consequences of 'unsafeness'. Gergely -- http://www.fastmail.fm - Or how I learned to stop worrying and love email again ___ 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] Issues with running Ghci from emacs
I end up doing :set -i../Documents/haskell/SOE/src To set the search directory so that ghci can find the source. I've not been how to tailor that 'cd' which is run at start up (but I've not looked to hard) It is looking for the closest ancestor directory with a file ending in .cabal, and that's where cd goes. Probably the simplest way to trick it without chaniging any setting is to create an empty dummy.cabal in the directory of your program. Gergely -- http://www.fastmail.fm - Send your email first class ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: Elerea, another FRP library
Well, the documentation says: Use {-# NOINLINE foo #-} as a pragma on any function foo that calls unsafePerformIOfile:///C:/app/ghc-6.10.1/doc/libraries/base/System-IO-Unsafe.html#v%3AunsafePerformIO. If the call is inlined, the I/O may be performed more than once. So you claim this does not prevent GHC to inline it anyway? That feels like a bug then, both in the documentation and NOINLINE On Thu, Apr 16, 2009 at 10:18 AM, Lennart Augustsson lenn...@augustsson.net wrote: There's no guarantee about unsafePerformIO not being inlined, that's just how ghc treats it. 2009/4/16 Patai Gergely patai_gerg...@fastmail.fm: On the other hand, breaking referential transparency in the external interface is a very bad idea, in my opinion. Actually, this means that the library user would have to turn certain compiler optimizations off to get the intended behavior. However, in practice you can compile Elerea with -O2 without ill effects. In fact, that's what happens if you install it with cabal. Just have a look at the Haddock docs of unsafePerformIO. Yes, I did that too, and came up with the following checklist: - the order of side effects doesn't matter much, since the resulting networks are equivalent if we don't rely on the automatic delay feature (applicative optimisations can be different, but still with the same net effect) - unsafePerformIO is apparently never inlined, i.e. each instance is executed once, so sharing works as desired - let-floating is no problem, because all instances of unsafePerformIO rely on surrounding function arguments - CSE is no problem either, it even helps if it's performed (and it is with optimisations turned on), since it results in smaller equivalent networks I think we can expect it to be fairly well-behaving, because the 'side effect' of Elerea primitives is basically the same as that of pure values in general: upon evaluation a value is created in the memory and we get a reference to it. We only have an extra constraint for the compiler: never duplicate these values. Merging identical ones is okay, and in fact desirable. The following code demonstrates this if you compile it with and without optimisations: import Control.Applicative import Control.Monad import FRP.Elerea import System.IO.Unsafe cint a b = unsafePerformIO (putStrLn !) `seq` transfer 0 (\dt x x0 - x0+x*dt) b mysig = (latcher 0 (b @ 0.3) (const (cint a b) $ cint a b)) + (cint a b) + (cint a b) + a where a = pure 4 b = stateful 0 (+) main = replicateM 10 (superstep mysig 0.1) = print I'd like to see an example where optimisation does make a difference, because I'm still unsure about the consequences of 'unsafeness'. Gergely -- http://www.fastmail.fm - Or how I learned to stop worrying and love email again ___ 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] Issues with running Ghci from emacs
Thanks, that does the trick. Daryoush 2009/4/16 Patai Gergely patai_gerg...@fastmail.fm I end up doing :set -i../Documents/haskell/SOE/src To set the search directory so that ghci can find the source. I've not been how to tailor that 'cd' which is run at start up (but I've not looked to hard) It is looking for the closest ancestor directory with a file ending in .cabal, and that's where cd goes. Probably the simplest way to trick it without chaniging any setting is to create an empty dummy.cabal in the directory of your program. Gergely -- http://www.fastmail.fm - Send your email first class ___ 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: Looking for the fastest Haskell primes
Heinrich Apfelmus wrote: +1 except that exporting the potentially infinite list of primes is problematic in that it may become a memory leak. I'd suggest to export two versions primes :: [Integer] primes' :: () - [Integer] for casual (i.e. throwaway program to solve a Project Euler problem) and for memory aware use respectively. I'm afraid I don't quite follow. Would you mind explaining what the first parameter is for and how it would solve the memory leak? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Looking for the fastest Haskell primes
The parameterless version is a top-level definition and won't get garbage-collected, IIRC. So, if you evaluate primes!!1000, you'll end up with a 1000-element list hanging in memory forever. If you evaluate (primes' ()) !! 1000, you won't. 2009/4/16 Niemeijer, R.A. r.a.niemei...@tue.nl: Heinrich Apfelmus wrote: +1 except that exporting the potentially infinite list of primes is problematic in that it may become a memory leak. I'd suggest to export two versions primes :: [Integer] primes' :: () - [Integer] for casual (i.e. throwaway program to solve a Project Euler problem) and for memory aware use respectively. I'm afraid I don't quite follow. Would you mind explaining what the first parameter is for and how it would solve the memory leak? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Eugene Kirpichov Web IR developer, market.yandex.ru ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Looking for the fastest Haskell primes
Eugene Kirpichov ekirpic...@gmail.com wrote: The parameterless version is a top-level definition and won't get garbage-collected, IIRC. So, if you evaluate primes!!1000, you'll end up with a 1000-element list hanging in memory forever. If you evaluate (primes' ()) !! 1000, you won't. {-# CAF foo #-} {-# NOCAF foo #-} -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or quoting of this signature prohibited. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Looking for the fastest Haskell primes
But things are a little more complicated than that. If the () argument to primes' is not used in calculating the primes then ghc might decide to lift the computed list of primes into a top level CAF, and so you will have a memory leak anyway. If ghc does so or not depends, e.g., on the optimization level. -- Lennart On Thu, Apr 16, 2009 at 11:21 AM, Heinrich Apfelmus apfel...@quantentunnel.de wrote: Niemeijer, R.A. wrote: Heinrich Apfelmus wrote: +1 except that exporting the potentially infinite list of primes is problematic in that it may become a memory leak. I'd suggest to export two versions primes :: [Integer] primes' :: () - [Integer] for casual (i.e. throwaway program to solve a Project Euler problem) and for memory aware use respectively. I'm afraid I don't quite follow. Would you mind explaining what the first parameter is for and how it would solve the memory leak? Sure. Lazy evaluation means that values, once evaluated, are stored in memory until garbage collections reclaims them because it is clear that they won't be used anymore. A memory leak happens when the programmer knows that values won't be used anymore while this knowledge is not available to the garbage collector. More specifically, consider the following example main = do print (primes !! 100) print (primes !! 20) This program will calculate the first 100 primes, and then print the 100th and the 1st prime. Now, after having printed the 100th prime, the 21th to 100th prime won't be used anymore and could thus be safely reclaimed by garbage collection. But since they are part of the primes list and this list is still in use for printing the 20th prime, this won't happen; we have a memory leak. The memory leak above can be avoided at the expense of recalculating the list. Using a function primes' with a dummy argument ensures^1 that the list of primes will be recalculated and garbage collected each time it is used: main = do print (primes' () !! 100) print (primes' () !! 20) Here, the first 100 primes are calculated, garbage collected and then the first 20 primes are (re-)calculated and garbage collected. We can fine control memory usage with the dummy argument version by using let statements or where clauses main = do let ps = primes' () in do print (ps !! 101) print (ps !! 100) -- no recalculation of ps print (primes' () !! 20) -- recalculates first 20 primes ^1: Compiler optimizations may interfere with that behavior. Generally, consensus is that the compiler should preserve sharing meticulously, but this is not guaranteed. See also: full laziness transform. The above is folklore and should be written down properly at someplace prominent. The wiki page http://www.haskell.org/haskellwiki/Memory_leak is a start, but I think the explanation there is currently a bit murky. Feel free to incorporate my writings above. Regards, apfelmus -- http://apfelmus.nfshost.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
Re: [Haskell-cafe] Re: Looking for the fastest Haskell primes
2009/04/16 Achim Schneider bars...@web.de: {-# CAF foo #-} {-# NOCAF foo #-} Where do I find docs for these pragmas? -- Jason Dusek ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Looking for the fastest Haskell primes
Jason Dusek jason.du...@gmail.com wrote: 2009/04/16 Achim Schneider bars...@web.de: {-# CAF foo #-} {-# NOCAF foo #-} Where do I find docs for these pragmas? ...in your friendly bug tracker, under the label missing feature -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or quoting of this signature prohibited. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] ANN: Elerea, another FRP library
Hello Peter, Thursday, April 16, 2009, 12:29:41 PM, you wrote: Lennart (and Patai) said about unsafePerformIO, you - about NOINLINE Well, the documentation says: Use {-# NOINLINE foo #-} as a pragma on any function foo that calls unsafePerformIO. If the call is inlined, the I/O may be performed more than once. So you claim this does not prevent GHC to inline it anyway? That feels like a bug then, both in the documentation and NOINLINE On Thu, Apr 16, 2009 at 10:18 AM, Lennart Augustsson lenn...@augustsson.net wrote: There's no guarantee about unsafePerformIO not being inlined, that's just how ghc treats it. 2009/4/16 Patai Gergely patai_gerg...@fastmail.fm: On the other hand, breaking referential transparency in the external interface is a very bad idea, in my opinion. Actually, this means that the library user would have to turn certain compiler optimizations off to get the intended behavior. However, in practice you can compile Elerea with -O2 without ill effects. In fact, that's what happens if you install it with cabal. Just have a look at the Haddock docs of unsafePerformIO. Yes, I did that too, and came up with the following checklist: - the order of side effects doesn't matter much, since the resulting networks are equivalent if we don't rely on the automatic delay feature (applicative optimisations can be different, but still with the same net effect) - unsafePerformIO is apparently never inlined, i.e. each instance is executed once, so sharing works as desired - let-floating is no problem, because all instances of unsafePerformIO rely on surrounding function arguments - CSE is no problem either, it even helps if it's performed (and it is with optimisations turned on), since it results in smaller equivalent networks I think we can expect it to be fairly well-behaving, because the 'side effect' of Elerea primitives is basically the same as that of pure values in general: upon evaluation a value is created in the memory and we get a reference to it. We only have an extra constraint for the compiler: never duplicate these values. Merging identical ones is okay, and in fact desirable. The following code demonstrates this if you compile it with and without optimisations: import Control.Applicative import Control.Monad import FRP.Elerea import System.IO.Unsafe cint a b = unsafePerformIO (putStrLn !) `seq` transfer 0 (\dt x x0 - x0+x*dt) b mysig = (latcher 0 (b @ 0.3) (const (cint a b) $ cint a b)) + (cint a b) + (cint a b) + a where a = pure 4 b = stateful 0 (+) main = replicateM 10 (superstep mysig 0.1) = print I'd like to see an example where optimisation does make a difference, because I'm still unsure about the consequences of 'unsafeness'. Gergely -- http://www.fastmail.fm - Or how I learned to stop worrying and love email again ___ 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 -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: Elerea, another FRP library
With NOINLINE you should be safe, but you never mentioned that originally. :) On Thu, Apr 16, 2009 at 10:29 AM, Peter Verswyvelen bugf...@gmail.com wrote: Well, the documentation says: Use {-# NOINLINE foo #-} as a pragma on any function foo that calls unsafePerformIO. If the call is inlined, the I/O may be performed more than once. So you claim this does not prevent GHC to inline it anyway? That feels like a bug then, both in the documentation and NOINLINE On Thu, Apr 16, 2009 at 10:18 AM, Lennart Augustsson lenn...@augustsson.net wrote: There's no guarantee about unsafePerformIO not being inlined, that's just how ghc treats it. 2009/4/16 Patai Gergely patai_gerg...@fastmail.fm: On the other hand, breaking referential transparency in the external interface is a very bad idea, in my opinion. Actually, this means that the library user would have to turn certain compiler optimizations off to get the intended behavior. However, in practice you can compile Elerea with -O2 without ill effects. In fact, that's what happens if you install it with cabal. Just have a look at the Haddock docs of unsafePerformIO. Yes, I did that too, and came up with the following checklist: - the order of side effects doesn't matter much, since the resulting networks are equivalent if we don't rely on the automatic delay feature (applicative optimisations can be different, but still with the same net effect) - unsafePerformIO is apparently never inlined, i.e. each instance is executed once, so sharing works as desired - let-floating is no problem, because all instances of unsafePerformIO rely on surrounding function arguments - CSE is no problem either, it even helps if it's performed (and it is with optimisations turned on), since it results in smaller equivalent networks I think we can expect it to be fairly well-behaving, because the 'side effect' of Elerea primitives is basically the same as that of pure values in general: upon evaluation a value is created in the memory and we get a reference to it. We only have an extra constraint for the compiler: never duplicate these values. Merging identical ones is okay, and in fact desirable. The following code demonstrates this if you compile it with and without optimisations: import Control.Applicative import Control.Monad import FRP.Elerea import System.IO.Unsafe cint a b = unsafePerformIO (putStrLn !) `seq` transfer 0 (\dt x x0 - x0+x*dt) b mysig = (latcher 0 (b @ 0.3) (const (cint a b) $ cint a b)) + (cint a b) + (cint a b) + a where a = pure 4 b = stateful 0 (+) main = replicateM 10 (superstep mysig 0.1) = print I'd like to see an example where optimisation does make a difference, because I'm still unsure about the consequences of 'unsafeness'. Gergely -- http://www.fastmail.fm - Or how I learned to stop worrying and love email again ___ 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] Re: Looking for the fastest Haskell primes
Am Donnerstag 16 April 2009 10:41:43 schrieb Niemeijer, R.A.: Heinrich Apfelmus wrote: +1 except that exporting the potentially infinite list of primes is problematic in that it may become a memory leak. I'd suggest to export two versions primes :: [Integer] primes' :: () - [Integer] for casual (i.e. throwaway program to solve a Project Euler problem) and for memory aware use respectively. I'm afraid I don't quite follow. Would you mind explaining what the first parameter is for and how it would solve the memory leak? If your programme uses primes some time early and again at the end, the list of primes (calculated so far) is kept in memory, because it's a top level constant (CAF). If you don't need the primes in between, calculate many of them at the start and use only a few at the end, that's a terrible memory-waste. If you don't use primes later, it *may* be that they're garbage-collected, but I wouldn't count on it. primes' is a function, so the list of primes is calculated anew every time you use primes' () in your programme and garbage collected when the programme leaves that use site. Which behaviour is desired depends of course on the programme. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Looking for the fastest Haskell primes
I vaguely remember someone (maybe Duncan Coutts?) saying that this was a commonly held misconception, and that GHC did indeed GC CAFs when optimization is enabled. If I am remembering incorrectly, does anyone have a reference to a ticket outlining this non-GC'ed CAF behavior? Thanks, Dan On Thu, Apr 16, 2009 at 4:57 AM, Eugene Kirpichov ekirpic...@gmail.com wrote: The parameterless version is a top-level definition and won't get garbage-collected, IIRC. So, if you evaluate primes!!1000, you'll end up with a 1000-element list hanging in memory forever. If you evaluate (primes' ()) !! 1000, you won't. 2009/4/16 Niemeijer, R.A. r.a.niemei...@tue.nl: Heinrich Apfelmus wrote: +1 except that exporting the potentially infinite list of primes is problematic in that it may become a memory leak. I'd suggest to export two versions primes :: [Integer] primes' :: () - [Integer] for casual (i.e. throwaway program to solve a Project Euler problem) and for memory aware use respectively. I'm afraid I don't quite follow. Would you mind explaining what the first parameter is for and how it would solve the memory leak? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Eugene Kirpichov Web IR developer, market.yandex.ru ___ 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: Looking for the fastest Haskell primes
Eugene Kirpichov wrote: The parameterless version is a top-level definition and won't get garbage-collected, IIRC. This has not-much to do with CAFs and is really just about scope + values + liveness. live values (those which a program still refers to, e.g. from a function which might get called in the future) don't get GCed. CAFs are just in the top-most scope and particularly likely to get held live in this fashion. As Lennart points out, optimisations occasionally increase sharing, although GHC tries fairly hard not to do this. Jules ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Data.ByteString woes
http://pastebin.com/m88c7dc It works fine if you delete the .Lazy. Enjoy, and thanks... David On Thu, Apr 16, 2009 at 12:35 AM, Jason Dusek jason.du...@gmail.com wrote: Could you pastebin something that demoes the error? -- Jason Dusek ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] how to upgrade?
On Fri, 2009-04-03 at 12:47 +0200, Johannes Waldmann wrote: Is there a nice way of upgrading ghc: I mean does cabal-upgrade know to install exactly the packages that I had with the previous ghc version? There will be soon! http://hackage.haskell.org/trac/hackage/ticket/199 There's a patch waiting for me (or anyone else) to review and integrate into cabal-install. Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Data.ByteString woes
On Thu, 2009-04-16 at 12:49 +0100, David Carter wrote: http://pastebin.com/m88c7dc It works fine if you delete the .Lazy. Enjoy, and thanks... This will be because the version of the regex lib you're using does not have an instance for lazy ByteStrings. Do you know what versions of the regex libs you were using in each case? They're not necessarily related to your ghc version if you installed the regex libs via cabal-install. Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Looking for the fastest Haskell primes
On Thu, 2009-04-16 at 07:11 -0400, Daniel Peebles wrote: I vaguely remember someone (maybe Duncan Coutts?) saying that this was a commonly held misconception, and that GHC did indeed GC CAFs when optimization is enabled. If I am remembering incorrectly, does anyone have a reference to a ticket outlining this non-GC'ed CAF behavior? It was Simon Marlow. I quote: FUD! CAFs are definitely garbage collected http://haskell.org/pipermail/haskell-cafe/2009-February/055525.html Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Strange type error with associated type synonyms
| But the core part of my suggestion (which this example was meant | to help explain) remains attractive, at least to me: somewhere during | type inference, GHC *does* unify the *apparently free* 'd' with an | internal type variable (lets call it 'd1, as in the type error message) You are speculating about the *algorithm*. There is no need to reason about the algorithm, only about its observable results ('d1' appeared in the error message, but not in the inferred type). But I've finally figured out what had me confused - sadly something that has come up before, I just had forgotten to apply it here. First, the code again: {-# LANGUAGE NoMonomorphismRestriction #-} {-# LANGUAGE TypeFamilies #-} class Fun d where type Memo d :: * - * abst :: (d - a) - Memo d a appl :: Memo d a - (d - a) -- f :: (Fun d) = Memo d a - Memo d a-- (1) f = abst . appl (1) is the type inferred by GHCi. If we uncomment it, we get this error: D:\home\Haskell\tmp\desktop\types.hs:11:11: Couldn't match expected type `Memo d1' against inferred type `Memo d' In the second argument of `(.)', namely `appl' In the expression: abst . appl In the definition of `f': f = abst . appl My _erroneous_ reasoning was that some unknown 'd1' was being unified with the 'd' from the signature. So I wanted that 'd1' to be represented in the signature inferred by GHCi. Of course, the error message really says something quite different, and if I had recalled that 'Memo' is a type synonym, I would have noticed that. If GHC ever provides an option to bracket fully applied type synonyms, I'd probably switch it on by default. (what one actually wants is a way to distinguish type-level general functions from type-level constructors that can be decomposed during unification, similar to what Haskell does with capitalization at the expression level, to distinguish general functions from constructors that can be decomposed during matching). With such an option, the inferred type would look like this (er, hi Conor): f :: (Fun d) = {Memo d} a - {Memo d} a The first parameter of 'Memo' is not directly available for unification, so this signature is ambiguous as it stands, as you tried to point out (with no way to pin down 'd', 'Memo d' can never unify with anything other than itself, identically). Apart from bracketing fully applied type synonyms, the error message could be improved by providing the missing bit of information about 'Memo': D:\home\Haskell\tmp\desktop\types.hs:11:11: Couldn't match expected type `Memo d1' against inferred type `Memo d' (type Memo d :: * - *) In the second argument of `(.)', namely `appl' In the expression: abst . appl In the definition of `f': f = abst . appl Sorry about letting myself get confused again by this known issue. Claus PS. I thought I'd try this alternative signature, to make the ambiguity explicit: f :: (Memo d~md,Fun d) = md a - md a -- (2) but the error message is even less helpful: D:\home\Haskell\tmp\desktop\types.hs:11:11: Couldn't match expected type `Memo d' against inferred type `md' `md' is a rigid type variable bound by the type signature for `f' at D:\home\Haskell\tmp\desktop\types.hs:10:14 In the second argument of `(.)', namely `appl' In the expression: abst . appl In the definition of `f': f = abst . appl Shouldn't the inferred type still be 'Memo d1'? Why is part of the _declared_ type expected ('Memo d'), the other inferred ('md')? Could GHC perhaps be more detailed about 'expected', 'inferred', and 'declared', and use these terms from a user perspective? Even in the original error message, shouldn't 'expected' and 'inferred' be the other way round? And if we add the missing contexts for the types mentioned in the message, the error message could really be: D:\home\Haskell\tmp\desktop\types.hs:11:11: Couldn't match inferred type `Memo d1' (f :: (Fun d1) = {Memo d1} a - {Memo d1} a) against declared type `Memo d' (f :: (Fun d) = {Memo d} a - {Memo d} a) (type {Memo d} :: * - *) In the second argument of `(.)', namely `appl' In the expression: abst . appl In the definition of `f': f = abst . appl Perhaps then I would have seen what was going on?-) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] understanding generics
Hello Anatoly, On Sat, Apr 11, 2009 at 20:44, Anatoly Yakovenko aeyakove...@gmail.comwrote: i am trying to understand how data.data works. How would i traverse the subterms of one type and build another type out of them. something like this: gmapQ (\a - Right a) (Just hello) I am not sure I understand what you're trying to do here. However, in general, 'gmapQ' is used in combination with 'mkQ' or 'extQ'. Those are not in Data.Data: you can import Data.Generics to get everything syb-related. Cheers, Pedro interactive:1:0: Inferred type is less polymorphic than expected Quantified type variable `d' escapes In the first argument of `gmapQ', namely `(\ a - Right a)' In the expression: gmapQ (\ a - Right a) (Just hello) In the definition of `it': it = gmapQ (\ a - Right a) (Just hello) Thanks, Anatoly ___ 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] Looking for the fastest Haskell primes algorithm
On Apr 15, 2009, at 5:27 PM, Adrian Neumann wrote: I've just uploaded a package with some functions I had lying around. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Numbers This package seems to be missing the source file Data/Numbers/ Primes.hs so I couldn't compare it to my own implementation (see separate announcement). Cheers, Sebastian ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] [Announce] primes
I am pleased to announce the package 'primes' that implements lazy wheel sieves for efficient, purely functional generation of prime numbers in Haskell. Following the current discussion about primes in Haskell, I packaged up an implementation inspired by the papers Lazy wheel sieves and spirals of primes by Colin Runciman and The Genuine Sieve of Eratosthenes by Melissa O'Neil. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/primes The package does not implement all that was wished for in the mentioned discussion. It only exports two operations: The global constant primes :: [Integer] is an infinite list of primes and wheelSieve :: Int - [Integer] is the function used to build this list. If you are worried about the memory requirements of using a global constant, you can use `wheelSieve 6` instead of `primes`. The implementation is reasonably efficient. The query primes !! 100 15485867 answers after a few seconds. Feel free to contribute more functionality to this package. The sources are on Github: http://github.com/sebfisch/primes If you fork my project, I'll be happy to merge your changes. Cheers, Sebastian ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Issues with running Ghci from emacs
It is looking for the closest ancestor directory with a file ending in .cabal, and that's where cd goes. Probably the simplest way to trick it without chaniging any setting is to create an empty dummy.cabal in the directory of your program. The haskell-mode code in the CVS repository has a fix for that problem. Stefan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] RE: [Announce] primes
Sebastian Fischer wrote: I am pleased to announce the package 'primes' that implements lazy wheel sieves for efficient, purely functional generation of prime numbers in Haskell. The implementation is reasonably efficient. The query primes !! 100 15485867 answers after a few seconds. Feel free to contribute more functionality to this package. The sources are on Github: http://github.com/sebfisch/primes If you fork my project, I'll be happy to merge your changes. I have just finished benchmarking all the implementations provided in http://www.cs.hmc.edu/~oneill/code/haskell-primes.zip (the zip file linked to from the Haskell wiki article on primes). NaurPrimes.hs is by far the fastest version, and at least 2 or 3 times faster than your current implementation. I'm pretty sure it also uses less memory. I want to find efficient algorithms for the other proposed functions before forking, but I figured I'd let you know in the meantime. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: [Announce] primes
I have just finished benchmarking all the implementations provided in http://www.cs.hmc.edu/~oneill/code/haskell-primes.zip (the zip file linked to from the Haskell wiki article on primes). NaurPrimes.hs is by far the fastest version, and at least 2 or 3 times faster than your current implementation. Thanks for the benchmarks! I'm pretty sure it also uses less memory. Do you understand the memory requirements of my implementation? I'm not sure if I do. Is it only that the queue of multiples gets larger and larger the more primes we query? I want to find efficient algorithms for the other proposed functions before forking, but I figured I'd let you know in the meantime. Thanks! Feel free to incorporate ideas from NaurPrimes.hs. I don't understand them yet. Cheers, Sebastian ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: google-like do you mean? feature
To measure how similar two strings are, you can use a metric like Levenshtein distance, Damerau-Levenshtein distance, or Jaro-Winkler I tried some of those just the other day, and in my app this worked much better: http://www.catalysoft.com/articles/StrikeAMatch.html ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] RE: [Announce] primes
Am Donnerstag 16 April 2009 16:45:59 schrieb Niemeijer, R.A.: Sebastian Fischer wrote: I am pleased to announce the package 'primes' that implements lazy wheel sieves for efficient, purely functional generation of prime numbers in Haskell. The implementation is reasonably efficient. The query primes !! 100 15485867 answers after a few seconds. Feel free to contribute more functionality to this package. The sources are on Github: http://github.com/sebfisch/primes If you fork my project, I'll be happy to merge your changes. I have just finished benchmarking all the implementations provided in http://www.cs.hmc.edu/~oneill/code/haskell-primes.zip (the zip file linked to from the Haskell wiki article on primes). NaurPrimes.hs is by far the fastest version, and at least 2 or 3 times faster than your current implementation. I'm pretty sure it also uses less memory. I want to find efficient algorithms for the other proposed functions before forking, but I figured I'd let you know in the meantime. Nevertheless, a bitsieve is much faster: Prelude NaurPrimes length $ primesToLimit (10^8) 5761455 (26.50 secs, 5734921092 bytes) Prelude NaurPrimes :l Ok, modules loaded: none. (0.00 secs, 0 bytes) Prelude :m +Euler.Primes Prelude Euler.Primes length $ primesUpTo (10^8) Loading package base-3.0.3.0 ... linking ... done. Loading package euler-0.1 ... linking ... done. 5761455 (2.14 secs, 573050276 bytes) The problems for a bitsieve are a) you don't easily get the small primes before sieving is complete b) how to proceed after the sieving bound ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] RE: [Announce] primes
On Thu, Apr 16, 2009 at 12:39 PM, Daniel Fischer daniel.is.fisc...@web.de wrote: Am Donnerstag 16 April 2009 16:45:59 schrieb Niemeijer, R.A.: Sebastian Fischer wrote: I am pleased to announce the package 'primes' that implements lazy wheel sieves for efficient, purely functional generation of prime numbers in Haskell. The implementation is reasonably efficient. The query primes !! 100 15485867 answers after a few seconds. Feel free to contribute more functionality to this package. The sources are on Github: http://github.com/sebfisch/primes If you fork my project, I'll be happy to merge your changes. I have just finished benchmarking all the implementations provided in http://www.cs.hmc.edu/~oneill/code/haskell-primes.zip (the zip file linked to from the Haskell wiki article on primes). NaurPrimes.hs is by far the fastest version, and at least 2 or 3 times faster than your current implementation. I'm pretty sure it also uses less memory. I want to find efficient algorithms for the other proposed functions before forking, but I figured I'd let you know in the meantime. Nevertheless, a bitsieve is much faster: Prelude NaurPrimes length $ primesToLimit (10^8) 5761455 (26.50 secs, 5734921092 bytes) Prelude NaurPrimes :l Ok, modules loaded: none. (0.00 secs, 0 bytes) Prelude :m +Euler.Primes Prelude Euler.Primes length $ primesUpTo (10^8) Loading package base-3.0.3.0 ... linking ... done. Loading package euler-0.1 ... linking ... done. 5761455 (2.14 secs, 573050276 bytes) The problems for a bitsieve are a) you don't easily get the small primes before sieving is complete b) how to proceed after the sieving bound You can solve both of these by always sieving up to powers of 2. If you've sieved up to 2^n you can extend it to 2^(n+1) by restarting the sieve and using the fact that you don't need to recheck the first half of the range. The result shouldn't be much slower than a full sieve, and can probably be written entirely with unboxed array monads (no unsafePerformIO) if desired. Geoffrey ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: How the following works
I find it easier to understand when looking at the declarative meaning of the definition. There is the trivial case of the empty list, but for the non-empty list: The possible inits of the list is the empty list and the inits of the rest of the list with the head element it their front. The execution would look like this: 1. The recurrsion would get to the tail of the list and calculate its inits, [[]]. 2. Then the recursion would go back, add the (n-th) element at the front of all the previously calculated inits [[x_n]], and add the empty list, we get [[],[x_n]]. 3. The same applies for the element n-1 and we get, [x, [x_(n-1)], [x_(n-1), n]] ... I hope this helped :p JP Tsunkiet Man wrote: Hello, I can hardly imagine how the following code works: cinits :: [a] - [[a]] cinits [] = [[]] cinits (x:xs) = [] : map (x:) (cinits xs) can someone give me a good explaination? (I understand it a bit, but it's really hard for me to figure out how a map in a map function works.) Thank you for your time, Tsunkiet ___ 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: How the following works
I don't know if the following explanation seems too basic or redundant to you, I'm sorry if that is the case, but it might help if you don't understand high order functions very well: In my description of the declarative meaning of the definition I understood this: map (x:) (cinits xs) as add the element 'x' in the front of every element (int this case, the elements are lists) of the list returned by (cinit xs) Thing of (:) as a function: (:) :: a - [a] - [a] That appends its first argument in the front of the list given as a second argument. Then (x:) is a function with type: (x:) :: [a] - [a] It is a function that appends to a fixed element x to a given list. As map f list returns a new list that is the result of applying f to every element of list, assuming list is a list of lists, map (x:) list returns a new list that has 'x' in the front of every element. An example: map (1:) [[2], [3], [4]] Prelude map (1:) [[2], [3], [4]] [[1,2],[1,3],[1,4]] Because: map f [[2], [3], [4]] = [f [2], f [3], f [4]] So let f = (x:) then: map f [[2], [3], [4]] = [(1:) [2], (1:) [3], (1:) [4]] = [[1, 2], [1, 3], [1, 4]] JP Juan Pedro Bolivar Puente wrote: I find it easier to understand when looking at the declarative meaning of the definition. There is the trivial case of the empty list, but for the non-empty list: The possible inits of the list is the empty list and the inits of the rest of the list with the head element it their front. The execution would look like this: 1. The recurrsion would get to the tail of the list and calculate its inits, [[]]. 2. Then the recursion would go back, add the (n-th) element at the front of all the previously calculated inits [[x_n]], and add the empty list, we get [[],[x_n]]. 3. The same applies for the element n-1 and we get, [x, [x_(n-1)], [x_(n-1), n]] ... I hope this helped :p JP Tsunkiet Man wrote: Hello, I can hardly imagine how the following code works: cinits :: [a] - [[a]] cinits [] = [[]] cinits (x:xs) = [] : map (x:) (cinits xs) can someone give me a good explaination? (I understand it a bit, but it's really hard for me to figure out how a map in a map function works.) Thank you for your time, Tsunkiet ___ 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: [Announce] primes
Just curious, what kind of super-cooled processor is this guy running on? I got the same answer but it took almost three minutes (2:43:15). Michael --- On Thu, 4/16/09, Geoffrey Irving irv...@naml.us wrote: From: Geoffrey Irving irv...@naml.us Subject: Re: [Haskell-cafe] RE: [Announce] primes To: Daniel Fischer daniel.is.fisc...@web.de Cc: haskell-cafe@haskell.org Date: Thursday, April 16, 2009, 12:57 PM The implementation is reasonably efficient. The query primes !! 100 15485867 answers after a few seconds. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Best text editor
Excerpts from Toby Hutton's message of Wed Apr 15 05:00:16 +0200 2009: On Wed, Apr 15, 2009 at 8:57 AM, Jeff Wheeler j...@nokrev.com wrote: As one of the Yi developers, I'd love to hear some more specific feedback on this. Do you remember any specific Vim features that were missing? My main gripe with the vi emulation in Yi was in vty mode[1] and how it was unable to tell that 'esc' wasn't always 'meta-'. e.g., If I leave insert mode with esc and hit j to go down a line too quickly it interpreted it as meta-j. Quite annoying. This was a little while ago though. I think this one is fixed, at least I cannot reproduce it. Also, I remember the cursor would go beyond the last character in a line in command mode, which is very un-vi-ish. At the time I remember thinking I should try and fix these things myself... but.. umm... This one have been fixed too. [1] vty Yi is the only one I would use--coding must always live inside a screen session :) I really dislike wrapping a GUI around vi(m). I don't want toolbars, tabs, scrollbars nor menus. I don't even want a titlebar. Absolute full screen terminal running screen is perfect. :) +1 -- Nicolas Pouillard ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] RE: [Announce] primes
michael rice wrote: Just curious, what kind of super-cooled processor is this guy running on? I got the same answer but it took almost three minutes (2:43:15). Only took a few seconds on my machine (Core 2 Duo 2.53GHz). - Jake ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] RE: [Announce] primes
Jake McArthur wrote: michael rice wrote: Just curious, what kind of super-cooled processor is this guy running on? I got the same answer but it took almost three minutes (2:43:15). Only took a few seconds on my machine (Core 2 Duo 2.53GHz). Maybe it's the version of GHC that matters? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Best text editor
On Thu, Apr 16, 2009 at 1:32 PM, Nicolas Pouillard nicolas.pouill...@gmail.com wrote: Excerpts from Toby Hutton's message of Wed Apr 15 05:00:16 +0200 2009: On Wed, Apr 15, 2009 at 8:57 AM, Jeff Wheeler j...@nokrev.com wrote: As one of the Yi developers, I'd love to hear some more specific feedback on this. Do you remember any specific Vim features that were missing? My main gripe with the vi emulation in Yi was in vty mode[1] and how it was unable to tell that 'esc' wasn't always 'meta-'. e.g., If I leave insert mode with esc and hit j to go down a line too quickly it interpreted it as meta-j. Quite annoying. This was a little while ago though. I think this one is fixed, at least I cannot reproduce it. Also, I remember the cursor would go beyond the last character in a line in command mode, which is very un-vi-ish. At the time I remember thinking I should try and fix these things myself... but.. umm... This one have been fixed too. [1] vty Yi is the only one I would use--coding must always live inside a screen session :) I really dislike wrapping a GUI around vi(m). I don't want toolbars, tabs, scrollbars nor menus. I don't even want a titlebar. Absolute full screen terminal running screen is perfect. :) +1 Can/Does yi integrate ghci somehow? That'd be most outstanding, but I've not seen it done. I use yi sometimes for SVN commits :-) Dave -- Nicolas Pouillard ___ 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] Converting IO [XmlTree] to [XmlTree]
On Tue, 14 Apr 2009, rodrigo.bonifacio wrote: I guess this is a very simple question. How can I convert IO [XmlTree] to just a list of XmlTree? The old Wiki had: http://www.haskell.org/wikisnapshot/ThatAnnoyingIoType.html Should be ported to the new Wiki since it is a FAQ ... ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] wxHaskell not in scope
Hello, I'm trying to create a GUI by using wxHaskell. However I get the weird error message of Not in scope dt, well so I sorted them so that my so called dt was in scope, however it failed. Can someone please tell me how I can solve this error? ... A lot of code that is not relevant in my opinion, if I'm wrong please correct me and I will post my full code --Debug text -- dt - staticText f [text := Hello world!] imagePanel - panel f [position := Point 2 2, clientSize := Size 100 100, tooltip := This is a drawPanel, bgcolor := rgb 255 255 255] set f [ clientSize := Size 700 500, menuBar := [mFile, mHelp], visible := True, on (menu exit) := close f, on (menu open) := onOpen f vFile ] return () where onOpen :: Frame a - Var b - IO () onOpen frame var = do file - fileOpenDialog frame False True Open File [(PGM bestanden (*.pgm),[*.pgm]),(Alle bestanden (*.*),[*.*])] case file of Nothing - return () Just file -set dt [text := HELLO] return () Thank you for your help, I really owe haskell-cafe. Greetings Tsunkiet Man ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] wxHaskell not in scope
Variables bound in the do block are not in scope in the where. Use a let inside the do for onOpen instead. On Thu, Apr 16, 2009 at 11:53 PM, Tsunkiet Man temp.t...@gmail.com wrote: Hello, I'm trying to create a GUI by using wxHaskell. However I get the weird error message of Not in scope dt, well so I sorted them so that my so called dt was in scope, however it failed. Can someone please tell me how I can solve this error? ... A lot of code that is not relevant in my opinion, if I'm wrong please correct me and I will post my full code --Debug text -- dt - staticText f [text := Hello world!] imagePanel - panel f [position := Point 2 2, clientSize := Size 100 100, tooltip := This is a drawPanel, bgcolor := rgb 255 255 255] set f [ clientSize := Size 700 500, menuBar := [mFile, mHelp], visible := True, on (menu exit) := close f, on (menu open) := onOpen f vFile ] return () where onOpen :: Frame a - Var b - IO () onOpen frame var = do file - fileOpenDialog frame False True Open File [(PGM bestanden (*.pgm),[*.pgm]),(Alle bestanden (*.*),[*.*])] case file of Nothing - return () Just file - set dt [text := HELLO] return () Thank you for your help, I really owe haskell-cafe. Greetings Tsunkiet Man ___ 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: [Announce] primes
Andrew Coppin wrote: Jake McArthur wrote: michael rice wrote: Just curious, what kind of super-cooled processor is this guy running on? I got the same answer but it took almost three minutes (2:43:15). Only took a few seconds on my machine (Core 2 Duo 2.53GHz). Maybe it's the version of GHC that matters? 6.10.1 here. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] wxHaskell not in scope
Thank you for your response, however if I can't do that, why can the example of wxHaskell do that? I refer to the following code inside http://darcs.haskell.org/wxhaskell/samples/wx/ (ImageViewer.hs) Line 99 untill 110 openImage sw vbitmap mclose status fname = do -- load the new bitmap bm - bitmapCreateFromFile fname -- can fail with exception closeImage vbitmap set vbitmap [value := Just bm] set mclose [enabled := True] set status [text := fname] -- reset the scrollbars bmsize - get bm size set sw [virtualSize := bmsize] repaint sw `catch` \err - repaint sw if I'm correct the openImage is also defined in the where clause. Therefor by what I think it should not be possible, but it is. Thanks for everything. 2009/4/17 Lennart Augustsson lenn...@augustsson.net Variables bound in the do block are not in scope in the where. Use a let inside the do for onOpen instead. On Thu, Apr 16, 2009 at 11:53 PM, Tsunkiet Man temp.t...@gmail.com wrote: Hello, I'm trying to create a GUI by using wxHaskell. However I get the weird error message of Not in scope dt, well so I sorted them so that my so called dt was in scope, however it failed. Can someone please tell me how I can solve this error? ... A lot of code that is not relevant in my opinion, if I'm wrong please correct me and I will post my full code --Debug text -- dt - staticText f [text := Hello world!] imagePanel - panel f [position := Point 2 2, clientSize := Size 100 100, tooltip := This is a drawPanel, bgcolor := rgb 255 255 255] set f [ clientSize := Size 700 500, menuBar := [mFile, mHelp], visible := True, on (menu exit) := close f, on (menu open) := onOpen f vFile ] return () where onOpen :: Frame a - Var b - IO () onOpen frame var = do file - fileOpenDialog frame False True Open File [(PGM bestanden (*.pgm),[*.pgm]),(Alle bestanden (*.*),[*.*])] case file of Nothing - return () Just file -set dt [text := HELLO] return () Thank you for your help, I really owe haskell-cafe. Greetings Tsunkiet Man ___ 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] wxHaskell not in scope
The names defined in the where clause are in scope in the do block, but not vice versa. On Fri, Apr 17, 2009 at 12:43 AM, Tsunkiet Man temp.t...@gmail.com wrote: Thank you for your response, however if I can't do that, why can the example of wxHaskell do that? I refer to the following code inside http://darcs.haskell.org/wxhaskell/samples/wx/ (ImageViewer.hs) Line 99 untill 110 openImage sw vbitmap mclose status fname = do -- load the new bitmap bm - bitmapCreateFromFile fname -- can fail with exception closeImage vbitmap set vbitmap [value := Just bm] set mclose [enabled := True] set status [text := fname] -- reset the scrollbars bmsize - get bm size set sw [virtualSize := bmsize] repaint sw `catch` \err - repaint sw if I'm correct the openImage is also defined in the where clause. Therefor by what I think it should not be possible, but it is. Thanks for everything. 2009/4/17 Lennart Augustsson lenn...@augustsson.net Variables bound in the do block are not in scope in the where. Use a let inside the do for onOpen instead. On Thu, Apr 16, 2009 at 11:53 PM, Tsunkiet Man temp.t...@gmail.com wrote: Hello, I'm trying to create a GUI by using wxHaskell. However I get the weird error message of Not in scope dt, well so I sorted them so that my so called dt was in scope, however it failed. Can someone please tell me how I can solve this error? ... A lot of code that is not relevant in my opinion, if I'm wrong please correct me and I will post my full code --Debug text -- dt - staticText f [text := Hello world!] imagePanel - panel f [position := Point 2 2, clientSize := Size 100 100, tooltip := This is a drawPanel, bgcolor := rgb 255 255 255] set f [ clientSize := Size 700 500, menuBar := [mFile, mHelp], visible := True, on (menu exit) := close f, on (menu open) := onOpen f vFile ] return () where onOpen :: Frame a - Var b - IO () onOpen frame var = do file - fileOpenDialog frame False True Open File [(PGM bestanden (*.pgm),[*.pgm]),(Alle bestanden (*.*),[*.*])] case file of Nothing - return () Just file - set dt [text := HELLO] return () Thank you for your help, I really owe haskell-cafe. Greetings Tsunkiet Man ___ 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: wxHaskell not in scope (Source available)
Note: the source can be found here: http://www.students.cs.uu.nl/~jtkman/Application.hs (It's my own work, please tell me what I did wrong) 2009/4/16 Tsunkiet Man temp.t...@gmail.com Hello, I'm trying to create a GUI by using wxHaskell. However I get the weird error message of Not in scope dt, well so I sorted them so that my so called dt was in scope, however it failed. Can someone please tell me how I can solve this error? ... A lot of code that is not relevant in my opinion, if I'm wrong please correct me and I will post my full code --Debug text -- dt - staticText f [text := Hello world!] imagePanel - panel f [position := Point 2 2, clientSize := Size 100 100, tooltip := This is a drawPanel, bgcolor := rgb 255 255 255] set f [ clientSize := Size 700 500, menuBar := [mFile, mHelp], visible := True, on (menu exit) := close f, on (menu open) := onOpen f vFile ] return () where onOpen :: Frame a - Var b - IO () onOpen frame var = do file - fileOpenDialog frame False True Open File [(PGM bestanden (*.pgm),[*.pgm]),(Alle bestanden (*.*),[*.*])] case file of Nothing - return () Just file -set dt [text := HELLO] return () Thank you for your help, I really owe haskell-cafe. Greetings Tsunkiet Man ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] wxHaskell not in scope
PS: a small note, sorry for multiple mails. After doing the let ... in function it did not work. =( It gave the error that 'do' has to end with some result. I did: do let the function in all the code that was behind the do and it still didn't work =(. I'm doing something wrong I think. Thanks for your help. 2009/4/17 Tsunkiet Man temp.t...@gmail.com Thank you for your response, however if I can't do that, why can the example of wxHaskell do that? I refer to the following code inside http://darcs.haskell.org/wxhaskell/samples/wx/ (ImageViewer.hs) Line 99 untill 110 openImage sw vbitmap mclose status fname = do -- load the new bitmap bm - bitmapCreateFromFile fname -- can fail with exception closeImage vbitmap set vbitmap [value := Just bm] set mclose [enabled := True] set status [text := fname] -- reset the scrollbars bmsize - get bm size set sw [virtualSize := bmsize] repaint sw `catch` \err - repaint sw if I'm correct the openImage is also defined in the where clause. Therefor by what I think it should not be possible, but it is. Thanks for everything. 2009/4/17 Lennart Augustsson lenn...@augustsson.net Variables bound in the do block are not in scope in the where. Use a let inside the do for onOpen instead. On Thu, Apr 16, 2009 at 11:53 PM, Tsunkiet Man temp.t...@gmail.com wrote: Hello, I'm trying to create a GUI by using wxHaskell. However I get the weird error message of Not in scope dt, well so I sorted them so that my so called dt was in scope, however it failed. Can someone please tell me how I can solve this error? ... A lot of code that is not relevant in my opinion, if I'm wrong please correct me and I will post my full code --Debug text -- dt - staticText f [text := Hello world!] imagePanel - panel f [position := Point 2 2, clientSize := Size 100 100, tooltip := This is a drawPanel, bgcolor := rgb 255 255 255] set f [ clientSize := Size 700 500, menuBar := [mFile, mHelp], visible := True, on (menu exit) := close f, on (menu open) := onOpen f vFile ] return () where onOpen :: Frame a - Var b - IO () onOpen frame var = do file - fileOpenDialog frame False True Open File [(PGM bestanden (*.pgm),[*.pgm]),(Alle bestanden (*.*),[*.*])] case file of Nothing - return () Just file -set dt [text := HELLO] return () Thank you for your help, I really owe haskell-cafe. Greetings Tsunkiet Man ___ 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] wxHaskell not in scope
Am Freitag 17 April 2009 00:43:18 schrieb Tsunkiet Man: Thank you for your response, however if I can't do that, why can the example of wxHaskell do that? I refer to the following code inside http://darcs.haskell.org/wxhaskell/samples/wx/ (ImageViewer.hs) Line 99 untill 110 openImage sw vbitmap mclose status fname = do -- load the new bitmap bm - bitmapCreateFromFile fname -- can fail with exception closeImage vbitmap set vbitmap [value := Just bm] set mclose [enabled := True] set status [text := fname] -- reset the scrollbars bmsize - get bm size set sw [virtualSize := bmsize] repaint sw `catch` \err - repaint sw if I'm correct the openImage is also defined in the where clause. Therefor by what I think it should not be possible, but it is. Thanks for everything. In your code, the variable dt was bound in the do-block, and you tried to reference it in the definition of onOpen in the where clause, where it is not in scope. The definition of openImage in ImageViewer.hs does not reference any variables bound in the do-block of imageViewer, only its parameters and the bitmap bm bound in its own body. As an alternative to defining onOpen in your main do-block, you could also pass the debug- text dt as a parameter. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] wxHaskell not in scope
Hello, what you suggested worked! Im very happy with it. However another error suddenly came up. It sais the last statement in a 'do' must be an expression, he is refering to line 41:45 I change my code to this: on (menu exit) := close f, on (menu open) := onOpen f dt vFile ] return () where onOpen :: Frame a - staticText c - Var b - IO () onOpen frame stat var = do file - fileOpenDialog frame False True Open File [(PGM bestanden (*.pgm),[*.pgm]),(Alle bestanden (*.*),[*.*])] case file of Nothing - return () Just file -set stat [text := HELLO] return () As far as I can tell, if the file is nothing it will return something of IO () and if the file is something it will return something of IO (). So that error is kind of strange in my opinion. Do you know what caused it? Thanks for your help! 2009/4/17 Lennart Augustsson lenn...@augustsson.net Take a look at the syntax for 'let' inside a 'do'. On Fri, Apr 17, 2009 at 12:57 AM, Tsunkiet Man temp.t...@gmail.com wrote: PS: a small note, sorry for multiple mails. After doing the let ... in function it did not work. =( It gave the error that 'do' has to end with some result. I did: do let the function in all the code that was behind the do and it still didn't work =(. I'm doing something wrong I think. Thanks for your help. 2009/4/17 Tsunkiet Man temp.t...@gmail.com Thank you for your response, however if I can't do that, why can the example of wxHaskell do that? I refer to the following code inside http://darcs.haskell.org/wxhaskell/samples/wx/ (ImageViewer.hs) Line 99 untill 110 openImage sw vbitmap mclose status fname = do -- load the new bitmap bm - bitmapCreateFromFile fname -- can fail with exception closeImage vbitmap set vbitmap [value := Just bm] set mclose [enabled := True] set status [text := fname] -- reset the scrollbars bmsize - get bm size set sw [virtualSize := bmsize] repaint sw `catch` \err - repaint sw if I'm correct the openImage is also defined in the where clause. Therefor by what I think it should not be possible, but it is. Thanks for everything. 2009/4/17 Lennart Augustsson lenn...@augustsson.net Variables bound in the do block are not in scope in the where. Use a let inside the do for onOpen instead. On Thu, Apr 16, 2009 at 11:53 PM, Tsunkiet Man temp.t...@gmail.com wrote: Hello, I'm trying to create a GUI by using wxHaskell. However I get the weird error message of Not in scope dt, well so I sorted them so that my so called dt was in scope, however it failed. Can someone please tell me how I can solve this error? ... A lot of code that is not relevant in my opinion, if I'm wrong please correct me and I will post my full code --Debug text -- dt - staticText f [text := Hello world!] imagePanel - panel f [position := Point 2 2, clientSize := Size 100 100, tooltip := This is a drawPanel, bgcolor := rgb 255 255 255] set f [ clientSize := Size 700 500, menuBar := [mFile, mHelp], visible := True, on (menu exit) := close f, on (menu open) := onOpen f vFile ] return () where onOpen :: Frame a - Var b - IO () onOpen frame var = do file - fileOpenDialog frame False True Open File [(PGM bestanden (*.pgm),[*.pgm]),(Alle bestanden (*.*),[*.*])] case file of Nothing - return () Just file -set dt [text := HELLO] return () Thank you for your help, I really owe haskell-cafe. Greetings Tsunkiet Man ___ 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] wxHaskell not in scope
PS: if the indents are wrong, that's because of gmail copy and past, Im so sorry. 2009/4/17 Tsunkiet Man temp.t...@gmail.com Hello, what you suggested worked! Im very happy with it. However another error suddenly came up. It sais the last statement in a 'do' must be an expression, he is refering to line 41:45 I change my code to this: on (menu exit) := close f, on (menu open) := onOpen f dt vFile ] return () where onOpen :: Frame a - staticText c - Var b - IO () onOpen frame stat var = do file - fileOpenDialog frame False True Open File [(PGM bestanden (*.pgm),[*.pgm]),(Alle bestanden (*.*),[*.*])] case file of Nothing - return () Just file -set stat [text := HELLO] return () As far as I can tell, if the file is nothing it will return something of IO () and if the file is something it will return something of IO (). So that error is kind of strange in my opinion. Do you know what caused it? Thanks for your help! 2009/4/17 Lennart Augustsson lenn...@augustsson.net Take a look at the syntax for 'let' inside a 'do'. On Fri, Apr 17, 2009 at 12:57 AM, Tsunkiet Man temp.t...@gmail.com wrote: PS: a small note, sorry for multiple mails. After doing the let ... in function it did not work. =( It gave the error that 'do' has to end with some result. I did: do let the function in all the code that was behind the do and it still didn't work =(. I'm doing something wrong I think. Thanks for your help. 2009/4/17 Tsunkiet Man temp.t...@gmail.com Thank you for your response, however if I can't do that, why can the example of wxHaskell do that? I refer to the following code inside http://darcs.haskell.org/wxhaskell/samples/wx/ (ImageViewer.hs) Line 99 untill 110 openImage sw vbitmap mclose status fname = do -- load the new bitmap bm - bitmapCreateFromFile fname -- can fail with exception closeImage vbitmap set vbitmap [value := Just bm] set mclose [enabled := True] set status [text := fname] -- reset the scrollbars bmsize - get bm size set sw [virtualSize := bmsize] repaint sw `catch` \err - repaint sw if I'm correct the openImage is also defined in the where clause. Therefor by what I think it should not be possible, but it is. Thanks for everything. 2009/4/17 Lennart Augustsson lenn...@augustsson.net Variables bound in the do block are not in scope in the where. Use a let inside the do for onOpen instead. On Thu, Apr 16, 2009 at 11:53 PM, Tsunkiet Man temp.t...@gmail.com wrote: Hello, I'm trying to create a GUI by using wxHaskell. However I get the weird error message of Not in scope dt, well so I sorted them so that my so called dt was in scope, however it failed. Can someone please tell me how I can solve this error? ... A lot of code that is not relevant in my opinion, if I'm wrong please correct me and I will post my full code --Debug text -- dt - staticText f [text := Hello world!] imagePanel - panel f [position := Point 2 2, clientSize := Size 100 100, tooltip := This is a drawPanel, bgcolor := rgb 255 255 255] set f [ clientSize := Size 700 500, menuBar := [mFile, mHelp], visible := True, on (menu exit) := close f, on (menu open) := onOpen f vFile ] return () where onOpen :: Frame a - Var b - IO () onOpen frame var = do file - fileOpenDialog frame False True Open File [(PGM bestanden (*.pgm),[*.pgm]),(Alle bestanden (*.*),[*.*])] case file of Nothing - return () Just file -set dt [text := HELLO] return () Thank you for your help, I really owe haskell-cafe. Greetings Tsunkiet Man ___ 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: [Announce] primes
Oh, I just remembered, I'm using ghci. I'll bet that's why I'm so slow. Thanks. Michael --- On Thu, 4/16/09, Andrew Coppin andrewcop...@btinternet.com wrote: From: Andrew Coppin andrewcop...@btinternet.com Subject: Re: [Haskell-cafe] RE: [Announce] primes To: haskell-cafe@haskell.org Date: Thursday, April 16, 2009, 4:38 PM Jake McArthur wrote: michael rice wrote: Just curious, what kind of super-cooled processor is this guy running on? I got the same answer but it took almost three minutes (2:43:15). Only took a few seconds on my machine (Core 2 Duo 2.53GHz). Maybe it's the version of GHC that matters? ___ 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] O LANGUAGE DESIGNER, REMEMBER THE POOR USER
This is interesting (and from 1990): http://groups.google.co.uk/group/comp.lang.functional/msg/655bb7bbd0fd8586 (Not sure if this is well-known. It seems like it either is, or it should be. Either way, I just stumbled across it.) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: O LANGUAGE DESIGNER, REMEMBER THE POOR USER
Here are some choice-quotes that are one of {insightful, controversial, arguable}: Starting with my favorite quote ;): The ability to operate on the program as data is basic to the provision of many desirable utilities, e.g. the Boyer-Moore theorem prover, and the program transformation work that was based on Hope, not to mention a compiler. It seems unfortunate that recent functional languages are heteroousian in the sense that they are defined in the usual computer scientist's way of specifying a syntax, and not specifying a representation of a program as a data-structure. This is a manifestation of the besetting vice of computer scientists - they will insist in locking up goodies in a black box... On Lisp: There is a danger that this perspective will adversely affect the design of a language from the user's point of view. The most extreme case is that of LISP, which may be seen as a very flawed implementation of the Lambda Calculus, which preserves the notation rather closely. On Haskell syntax: However, if the use of upper case is not permitted for ordinary variables a conflict arises between the language conventions and the conventions of mathematics, Haskell is also in conflict with established programming conventions in that it it uses double colon to denote membership of a type (e.g. x::Int) rather than the single colon that those millions of existing programmers will be familiar with,.. On Haskell arrays: The Haskell array operation is a related construct, from which a instances of the application of the POP-11 newarray could be implemented - it does however suffer from one practical draw-back, namely it takes an association list as argument, which makes it inefficient as a means of memoising a function, unless a very smart compiler is used. On purity: I want a language that is not purely functional because functional languages do not reflect the basic structure of computers. If you want to write a matrix inversion algorithm it will be hard to do it efficiently without assignment. Matt On Thu, Apr 16, 2009 at 7:04 PM, Matt Morrow moonpa...@gmail.com wrote: This is interesting (and from 1990): http://groups.google.co.uk/group/comp.lang.functional/msg/655bb7bbd0fd8586 (Not sure if this is well-known. It seems like it either is, or it should be. Either way, I just stumbled across it.) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Looking for the fastest Haskell primes algorithm
G'day all. Quoting Eugene Kirpichov ekirpic...@gmail.com: I'd suggest also primesFrom :: Integer - [Integer] This: primes :: [Integer] isn't as useful as you might think for a library, because it must, by definition, leak an uncontrolled amount of memory. This: primesUpTo :: Integer - [Integer] is a better interface in that respect. For the number theory library, I went overboard with a bunch of type classes. I don't have the code handy, but this was the sort of thing: class TestableProperty s a | s - a where is :: s - a - Bool data Prime = Prime class TestableProperty Prime Integer where is Prime n = {- ... -} Then you could add instances for Fibonacci or whatever you wanted. Cheers, Andrew Bromage ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Looking for the fastest Haskell primes algorithm
Unless primesUpTo n goes from highest to lowest prime (ending in 2), I don't see how sharing is possible (in either space or time) between primesUpTo for different n. Is it intended that the primes should therefore be listed in descending order? a...@spamcop.net wrote: primes :: [Integer] isn't as useful as you might think for a library, because it must, by definition, leak an uncontrolled amount of memory. This: primesUpTo :: Integer - [Integer] is a better interface in that respect. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Best text editor
On Thu, Apr 16, 2009 at 4:40 PM, David Leimbach leim...@gmail.com wrote: On Thu, Apr 16, 2009 at 1:32 PM, Nicolas Pouillard nicolas.pouill...@gmail.com wrote: Excerpts from Toby Hutton's message of Wed Apr 15 05:00:16 +0200 2009: On Wed, Apr 15, 2009 at 8:57 AM, Jeff Wheeler j...@nokrev.com wrote: As one of the Yi developers, I'd love to hear some more specific feedback on this. Do you remember any specific Vim features that were missing? My main gripe with the vi emulation in Yi was in vty mode[1] and how it was unable to tell that 'esc' wasn't always 'meta-'. e.g., If I leave insert mode with esc and hit j to go down a line too quickly it interpreted it as meta-j. Quite annoying. This was a little while ago though. I think this one is fixed, at least I cannot reproduce it. Also, I remember the cursor would go beyond the last character in a line in command mode, which is very un-vi-ish. At the time I remember thinking I should try and fix these things myself... but.. umm... This one have been fixed too. [1] vty Yi is the only one I would use--coding must always live inside a screen session :) I really dislike wrapping a GUI around vi(m). I don't want toolbars, tabs, scrollbars nor menus. I don't even want a titlebar. Absolute full screen terminal running screen is perfect. :) +1 Can/Does yi integrate ghci somehow? That'd be most outstanding, but I've not seen it done. I use yi sometimes for SVN commits :-) Dave There is GHC API usage of sorts if you enable shim. But it doesn't do anything very impressive currently; the most impressive thing I've used it for in Yi is to insert the typesig of the top-level function at point. -- gwern ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Parsec question
I want to write a parser that can read a file with this format: the file has sections which are demarcated by keywords. Keywords always begin with two forward slashes and consist of letters, digits, and underscore. The text can be anything, including special characters. For instance: //keyword some text and more text //another_keyword and) some { more text //ya_keyword $$ -- text I'm not sure how to write a parser that considers anything but a double slash to be a valid part of the text. Thanks, Mike ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] REMINDER: Haskell Communities and Activities Report
Dear Haskellers, The deadline for the May 2009 edition of the Haskell Communities and Activities Report is only two weeks away. If you haven't already, please write an entry for your new project, or update your old entry. Please mail your entries to h...@haskell.org in LaTeX format. More information can be found in the original Call for Contributions at: http://www.haskell.org/pipermail/haskell/2009-April/021180.html I look forward to receiving your contributions. Thanks a lot, Janis (current editor) -- Dr. Janis Voigtlaender http://wwwtcs.inf.tu-dresden.de/~voigt/ mailto:vo...@tcs.inf.tu-dresden.de ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe