Re: [Haskell-cafe] Re: module names
Hello S, Friday, December 16, 2005, 6:32:47 AM, you wrote: SKC> Why not do this: name none of those modules Main.hs, and have an empty SKC> module Main.hs with only "import MainDeJour" and "main = SKC> MainDeJour.main" so you can just edit just that file. ghc has option "-main-is" which is just what needed in this case -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] Re: Tutorial uploaded
Hello Neil, Tuesday, December 20, 2005, 11:52:51 PM, you wrote: NM> Hi, >> Hugs Interpreter onlySuitable for learning. You'll need GHC for >> serious work. NM> This is putting Hugs down quite a bit. I personally prefer Hugs, and NM> use it for serious work (including developing a Haskell compiler, and NM> 4 years of academic study and counting). for me, Hugs and especiall WinHugs is an amazing tool to develop programs that then will be compiled by GHC. they have a greatest level o compatibility while Hugs loads programs 10 times faster than GHCi and have much more helpful environment (especially WinHugs 2005) -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Substring replacements
From: Bulat Ziganshin <[EMAIL PROTECTED]> Reply-To: Bulat Ziganshin <[EMAIL PROTECTED]> To: "Branimir Maksimovic" <[EMAIL PROTECTED]> CC: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] Substring replacements Date: Tue, 20 Dec 2005 23:55:22 +0300 Hello Branimir, Tuesday, December 20, 2005, 9:48:48 PM, you wrote: BM> I've finally performed test on amd64 and result is a same as on intel. BM> KMP always wins. So KMP is best suited for non indexed strings BM> and I guess should be used in library as prefered search/replace method. BM> This test favors straightforward search. i'm 90% sure that straightforward method must be faster for one-time searches. KMP is O(m) while straightforward is O(m*n). your test may give better results with KMP algorithm just because you repeat the same search many times and it was automatically "run-time compiled" as described on the wiki page about KMP My test favors straightforward, in any other case KMP wins by order of magnitude. I think that straightfoirward is better then KMP with optimisations off is due more complex program. try to add {-# NOINLINE replace #-} to both programs and repeat comparision These are tests: No optimisations (no -O): Intel hyperthreaded,windows $ time ./KMP Working:seasearch replace able seaseasearch baker seasearch charlie True Done real0m34.766s user0m0.015s sys 0m0.000s [EMAIL PROTECTED] ~/tutorial $ time ./straightforward Working:seasearch replace able seaseasearch baker seasearch charlie True Done real0m14.719s user0m0.031s sys 0m0.000s AMD 64 bit: [EMAIL PROTECTED] myhaskell]$ time ./KMP Working:seasearch replace able seaseasearch baker seasearch charlie True Done real1m58.066s user1m57.939s sys 0m0.128s [EMAIL PROTECTED] myhaskell]$ time ./straightforward Working:seasearch replace able seaseasearch baker seasearch charlie True Done real0m41.565s user0m41.527s sys 0m0.040s with optimisations (-O): Intel hyperthreaded,windows $ time ./KMP Working:seasearch replace able seaseasearch baker seasearch charlie True Done real0m8.625s user0m0.015s sys 0m0.015s [EMAIL PROTECTED] ~/tutorial $ time ./straightforward Working:seasearch replace able seaseasearch baker seasearch charlie True Done real0m11.735s user0m0.015s sys 0m0.000s AMD 64 bit, linux: [EMAIL PROTECTED] myhaskell]$ time ./KMP Working:seasearch replace able seaseasearch baker seasearch charlie True Done real0m10.546s user0m10.529s sys 0m0.016s [EMAIL PROTECTED] myhaskell]$ time ./straightforward Working:seasearch replace able seaseasearch baker seasearch charlie True Done real0m11.796s user0m11.785s sys 0m0.012s Greetings, Bane. _ FREE pop-up blocking with the new MSN Toolbar - get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Learning about haskell compilers
On Wed, 21 Dec 2005, Bernard Pope wrote: > On Tue, 2005-12-20 at 16:58 -0800, John Meacham wrote: > > On Tue, Dec 20, 2005 at 10:36:36AM -0600, Creighton Hogg wrote: > > > I was wondering where I should get started in learing about > > > how to implement a haskell compiler? > > Warning: a whole Haskell compiler is a LOT of work. Oh I figured it would be, but I'm not really planning on implementing all of Haskell 98 by myself. > Nonetheless there are examples of mostly-single-person compilers and > interpreters out there, so it is possible to do one on your own. Though > I don't think reading their source code is necessarily the best way to > get started. > > I agree with what John said, especially this: > > > there are various other abstract machines out there, the Lazy Virtual > > Machine used by Helium described in Daan Leijen's Phd thesis is quite > > interesting, and might make a better first target than G-machine code. > > If you want to write a compiler, > targeting LVM is (I believe) the easiest way to get something working. > You could get the source code for hatchet from him to give you a front > end. > > Another approach is to write a simple interpreter for a small functional > language and add features in bit-by-bit, as your enthusiasm dictates. > That way, you get the satisfaction of having something work early on. If > you write a compiler it might take weeks or months before it does > anything interesting. Then you can custom build your language with > whatever features take your fancy. For instance you can add a better > record system, or play with meta-programming facilities. I started a > little project like this a while ago, called baskell, which you can get > from here: > >http://www.cs.mu.oz.au/~bjpop/code.html > > It has a rudimentary type checker, and a little REPL interface. Feel > free to hack it to pieces. I really like your idea of implementing an interpreter for just some kindof functional language. That sounds like it'd be pretty instructive and have less frustration factor than a whole compiler. Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Learning about haskell compilers
On Tue, 20 Dec 2005, John Meacham wrote: > On Tue, Dec 20, 2005 at 10:36:36AM -0600, Creighton Hogg wrote: > > I was wondering where I should get started in learing about > > how to implement a haskell compiler? Wow! That was a great response, with more references than I could have ever hoped for. I am totally saving that e-mail. I have learned the basics of compilers. I just finished a class on it that I took basically for the purpose of being able to work on a functional language like haskell. I really want to be able to help with all the work in Haskell and help improve both its performance and capabilities. Haskell & lisp are the two languages I love most and I really want to be able to use them in my own native land of physics. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Learning about haskell compilers
On Tue, 2005-12-20 at 16:58 -0800, John Meacham wrote: > On Tue, Dec 20, 2005 at 10:36:36AM -0600, Creighton Hogg wrote: > > I was wondering where I should get started in learing about > > how to implement a haskell compiler? Warning: a whole Haskell compiler is a LOT of work. Nonetheless there are examples of mostly-single-person compilers and interpreters out there, so it is possible to do one on your own. Though I don't think reading their source code is necessarily the best way to get started. I agree with what John said, especially this: > there are various other abstract machines out there, the Lazy Virtual > Machine used by Helium described in Daan Leijen's Phd thesis is quite > interesting, and might make a better first target than G-machine code. If you want to write a compiler, targeting LVM is (I believe) the easiest way to get something working. You could get the source code for hatchet from him to give you a front end. Another approach is to write a simple interpreter for a small functional language and add features in bit-by-bit, as your enthusiasm dictates. That way, you get the satisfaction of having something work early on. If you write a compiler it might take weeks or months before it does anything interesting. Then you can custom build your language with whatever features take your fancy. For instance you can add a better record system, or play with meta-programming facilities. I started a little project like this a while ago, called baskell, which you can get from here: http://www.cs.mu.oz.au/~bjpop/code.html It has a rudimentary type checker, and a little REPL interface. Feel free to hack it to pieces. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Tutorial uploaded
On Tue, 2005-12-20 at 20:58 +0100, Peter Simons wrote: > Curiously enough, if you check out the reference > documentation at: > > > http://haskell.org/ghc/docs/latest/html/libraries/base/Control-Monad-ST.html#t%3ARealWorld > > ..., you'll find that a "World" type actually exists. While that is true in GHC it is not required by Haskell. The concrete implementation of IO is compiler specific. Also worth noting is that there are (two that I know of) languages that employ an explicit world parameter to do IO: Clean and Mercury. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: [Haskell] A simple server (or how to do io).
On Tuesday 20 December 2005 23:43, Einar Karttunen wrote: > Your problem is that the ghci prompt *is* blocking everything. ghci is > builded non-threaded. Ghci uses a blocking call to read the lines > which means that all other computations are stopped. Ok, then pressing enter each time I want one of my servers to reply. I can live with that. > > I compile it and run it. It returns immediately and the server of course, > > is not running. > > It spawns the server threads and returns immediately. Indeed. > > I think what I am missing is that server, after running runStreamServer > > should block and be able to reply to all the queries (in the final > > version I'll also have runDgramServer as well) and be able to receive a > > signal, upon which it should close the socket and finish. How can do that > > ? Any help will be appreciated. > > Catch the signal and kill the listening threads. If you > are using the new 0.3.1 release then you can use the > killServer call. Oh, new release, I am downloading it right now! So, I install a signal handler with installHandler... and then ? how do I prevent the program for quiting ? am I missing some kind of event loop here ? > ps. I think it may be best to continue on haskell-cafe@ rather > than the main list. I am posting to there as well (to continue there). -- Pupeno <[EMAIL PROTECTED]> (http://pupeno.com) pgpTGml6i1rJa.pgp Description: PGP signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Killer pickler combinators (was Time leak)
I still get timeouts with 5k threads. Not as often as with 1k before, though. On Dec 21, 2005, at 3:35 AM, Donald Bruce Stewart wrote: It looks like with the 1000s of threads that get run, the problem is just getting enough cpu time for each thread. All the solutions that appear to work involve some kind of blocking (on Handles, MVars, ffi calls), allowing the scheduler to switch. So why don't we just increase the scheduler switch rate ourselves? Using +RTS -C -RTS we can convince the rts to switch on every alloc, and with 4000 threads running this seems to remove the timeout alerts, and give all threads enough time to get things done. -- http://wagerlabs.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Killer pickler combinators (was Time leak)
joelr1: > About the only universal solution seems to pace the threads by > passing trace to read. Even then I got 1 alert. Now, can someone > explain why the lock eliminates the time leak? It looks like with the 1000s of threads that get run, the problem is just getting enough cpu time for each thread. All the solutions that appear to work involve some kind of blocking (on Handles, MVars, ffi calls), allowing the scheduler to switch. So why don't we just increase the scheduler switch rate ourselves? Using +RTS -C -RTS we can convince the rts to switch on every alloc, and with 4000 threads running this seems to remove the timeout alerts, and give all threads enough time to get things done. This can be baked into the using an rts hook, a small C file containing a C string that is added to the cmd line: char *ghc_rts_opts = "-C0"; Cheers, Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Killer pickler combinators (was Time leak)
About the only universal solution seems to pace the threads by passing trace to read. Even then I got 1 alert. Now, can someone explain why the lock eliminates the time leak? On Dec 21, 2005, at 2:41 AM, Cale Gibbard wrote: Using forkOS with -threaded seems to work, at least on linux and openbsd. -- http://wagerlabs.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Killer pickler combinators (was Time leak)
Does not help me on Mac OSX Tiger. ./a.out trace.dat a.out: user error (ORANGE ALERT: 0s, 4s, SrvServerInfo, ix1: 6, size: 49722) a.out: internal error: scavenge_stack: weird activation record found on stack: 9 Please report this as a bug to glasgow-haskell-bugs@haskell.org, or http://www.sourceforge.net/projects/ghc/ On Dec 21, 2005, at 2:41 AM, Cale Gibbard wrote: Using forkOS with -threaded seems to work, at least on linux and openbsd. -- http://wagerlabs.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Killer pickler combinators (was Time leak)
Using forkOS with -threaded seems to work, at least on linux and openbsd. - Cale On 20/12/05, Joel Reymont <[EMAIL PROTECTED]> wrote: > The original paper is at http://research.microsoft.com/ ~akenn/fun/ > picklercombinators.pdf > > My adaptation is at http://wagerlabs.com/timeleak.tgz. This is a full > repro case, data included. > > The issue is that with 1000 threads my serialization is taking a few > seconds. > > Inserting a delay or passing in trace (see README and code) gets > serialization time down to 0-1s, the way it should be. > > What gives? Try it for yourself and please let me know! > > Thanks, Joel > > -- > http://wagerlabs.com/ > > > > > > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Killer pickler combinators (was Time leak)
The original paper is at http://research.microsoft.com/ ~akenn/fun/ picklercombinators.pdf My adaptation is at http://wagerlabs.com/timeleak.tgz. This is a full repro case, data included. The issue is that with 1000 threads my serialization is taking a few seconds. Inserting a delay or passing in trace (see README and code) gets serialization time down to 0-1s, the way it should be. What gives? Try it for yourself and please let me know! Thanks, Joel -- http://wagerlabs.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Learning about haskell compilers
On Tue, Dec 20, 2005 at 10:36:36AM -0600, Creighton Hogg wrote: > I was wondering where I should get started in learing about > how to implement a haskell compiler? Well, the way I learned was by just making the decision that one way or another, I was going to write a haskell compiler and then reading and reading and coding and tossing code and recoding until I succeeded. :) it is sort of how I learn, choose something I have no idea how to do, and do it anyway learning what I need to along the way out of neccesity. in any case, assuming you know something about basic compilers, lexing, parsing, and code generation and are interested in how you get parsed haskell source into a form that you can generate code from, I'd highly recommend the following (in order) (of course, this is just my experience) * The haskell report itself: this will give the rules on how to desugar 'complicated' haskell into simple haskell. things like getting rid of list comprehensions and do notation and turning complicated pattern matching into simple pattern matching (the most complicated of the desugaring transformations). I'd recommend desugaring and expanding type synonyms as soon as possible for your first attempt even though it gives worse error messages because it _greatly_ simplifies the later steps and you will likely go through several iterations of the typechecker before you get one you are happy with. you can always extend your typechecker later and postpone certain desugarings until you reach a balance of good error messages you are comfortable with. * typing haskell in haskell: http://www.cse.ogi.edu/~mpj/thih/ this will tell you how to go from haskell source to explicitly typed haskell source, which is now in a form suitable for transforming into an intermediate language. the explicitly typed, desugared haskell can be converted directly to core. It may take several readings to fully understand and looking at the source to hatchet could help considerably (it did for me) * then you have a couple choices, basically, You want to learn about ghc core. there are a lot of papers on ghc optimizations that are great because they give examples of how core is used which really helps get an intuitive understanding of why core is a good intermediate language: recommend are: Secrets of the GHC inliner. http://www.research.microsoft.com/~simonpj/Papers/inlining/index.htm this is by far the most important, the simplifier is the key to any other optimizations and this paper goes into a lot of the details other things leave out. http://haskell.org/ghc/docs/papers/unboxed-values.ps.gz very good paper. my main regret about jhc development is that I didn't incorperate unboxed values right from the start thinking of them as an optimization rather than an essential part of expressing program properties. I just accumulated hack-after-hack which would have gone away with unboxed values in the core. http://research.microsoft.com/copyright/accept.asp?path=/users/simonpj/papers/float.ps.gz&pub=ACM let floating, not only an important optimization, but will get you thinking about what it means to preserve lazyness and some of the trickiness of not breaking performance by accident. http://research.microsoft.com/copyright/accept.asp?path=/users/simonpj/papers/comp-by-trans.ps.gz&pub=18 great overview, either read this, or all of the above. (or ideally everything) starting out with this one is probably the best idea because it will give you an idea what you are in for. * next you have your simplified optimized core and you want to turn it into machine code, there are various choices you can make, the most well understood is G-machine based implementations like nhc or the more advanced STG machine used in ghc. the lester book mentioned in another email is a great introduction and highly recommended even if the source there is a lot of practical info out there on how to implement these and you have pretty much a straight shot from core to G-machine code either to be compiled directly or interpreted. for jhc I used boquist's GRIN: http://www.cs.chalmers.se/~boquist/phd/ which is not the simplest way of getting things working right away, but could be very interesting. there are various other abstract machines out there, the Lazy Virtual Machine used by Helium described in Daan Leijen's Phd thesis is quite interesting, and might make a better first target than G-machine code. so, I'd recommend, at least _understand_ the G-machine, enough to write an interpreter for it. (if you already have core, translating and interpreting G-machine code shouldn't be more than a few hundreds of lines of code). then read about the LVM, STG, and GRIN, and any other ones anyone recommends? and decide where you want to go from there. whichever one inspires you. Hopefully this helps you, this is just the route I would recommend based on my experience with jhc, I read a whole lot of papers and books, and there are a ton more great ones out there but I thin
Re: [Haskell-cafe] Re: Tutorial uploaded
On Tue, Dec 20, 2005 at 08:07:29PM +0100, Sebastian Sylvan wrote: > I'm still looking for a good *practical* tutorial that I could > recommend to newcomers. > IO, data types and QuickCheck in the very first chapter, I say! Real > program examples from the get go, and go into the theory on why this > has been hard in FP before Haskell (or Monadic IO rather) much much > later, so as to not scare people away. Indeed, I have been wanting to write something like this for a long time. perhaps using ginsu or (a simplified) jhc as a long running example throughout the tutorial. unfortunatly my prose is worse than my code. But I think such a tutorial (book?) describing how to write a real-world haskell program from scratch without glossing over details like IO would be a really great addition to the haskell bookshelf. John -- John Meacham - ⑆repetae.net⑆john⑈ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Proposal for a first tutorial.
On Tue, Dec 20, 2005 at 03:38:17PM -0800, Hal Daume III wrote: > Incidentally, the version on the web site now is a recent (few weeks old) > revision. I think it should have fixed all the problems people have sent > in over the last year (thanks!) and most (but not all) of the stupid > spelling errors, etc. Yeah, I had not seen that tutorial before, it looks very good. I am not sure what you are using to format it, but it seems to have no problems with breaking up code blocks randomly between pages which is quite anoying. I don't know how easy that would be to convince whatever you use not to do. LaTeX maybe? hmm.. John -- John Meacham - ⑆repetae.net⑆john⑈ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Proposal for a first tutorial.
Hal Daume III wrote: Fair enough. The silly form has disappeared :). You can just make the form optional. Something like this: ---//--- Here's a link to my tutorial Also, I love hearing about who is using this tutorial. Please consider filling out this form. ---//--- You get the idea. Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/I am not over-weight, I am under-tall. / ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Proposal for a first tutorial.
John Meacham wrote: Even though I know this to be true, whenever I encounter a form like this on the web I just immediatly press 'back' unless I am specifically looking for what I know is behind it. It is not for any particular ideological reasons, it is just my default action and I think it is for many other people too. In particular, I would immediatly just go to the next tutorial on the list when presented with such a page. I can't really defend it with any particular reasoning, I am just saying it how it is. At a minimum, there are usability reasons why the vast majority of people will tend to do that exactly. I don't have the reference on me right now, but I read this in a usability book called "Don't make me Think" :) It's very good. The case becomes even stronger when the particular form is asking you for something you might consider personal information. My first reaction is that it's none of their business and makes me want to go elsewhere. Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/I am not over-weight, I am under-tall. / ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Proposal for a first tutorial.
> Even though I know this to be true, whenever I encounter a form like > this on the web I just immediatly press 'back' unless I am specifically > looking for what I know is behind it. It is not for any particular > ideological reasons, it is just my default action and I think it is for > many other people too. In particular, I would immediatly just go to the > next tutorial on the list when presented with such a page. I can't > really defend it with any particular reasoning, I am just saying it how > it is. Fair enough. The silly form has disappeared :). Incidentally, the version on the web site now is a recent (few weeks old) revision. I think it should have fixed all the problems people have sent in over the last year (thanks!) and most (but not all) of the stupid spelling errors, etc. -- Hal Daume III | [EMAIL PROTECTED] "Arrest this man, he talks in maths." | www.isi.edu/~hdaume ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Proposal for a first tutorial.
On Tue, Dec 20, 2005 at 06:54:27AM -0800, Hal Daume III wrote: > So basically what you're saying is: someone who wants to learn Haskell but > doesn't want to fill out a 10 second form can't find the information to do > so. There's no requirement that the form be filled out correctly -- you > can enter whatever invalid information you want. Even though I know this to be true, whenever I encounter a form like this on the web I just immediatly press 'back' unless I am specifically looking for what I know is behind it. It is not for any particular ideological reasons, it is just my default action and I think it is for many other people too. In particular, I would immediatly just go to the next tutorial on the list when presented with such a page. I can't really defend it with any particular reasoning, I am just saying it how it is. John -- John Meacham - ⑆repetae.net⑆john⑈ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Substring replacements
Hello Branimir, Tuesday, December 20, 2005, 9:48:48 PM, you wrote: BM> I've finally performed test on amd64 and result is a same as on intel. BM> KMP always wins. So KMP is best suited for non indexed strings BM> and I guess should be used in library as prefered search/replace method. BM> This test favors straightforward search. i'm 90% sure that straightforward method must be faster for one-time searches. your test may give better results with KMP algorithm just because you repeat the same search many times and it was automatically "run-time compiled" as described on the wiki page about KMP try to add {-# NOINLINE replace #-} to both programs and repeat comparision -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Tutorial uploaded
On 20/12/05, Benjamin Franksen <[EMAIL PROTECTED]> wrote: > On Tuesday 20 December 2005 20:58, Peter Simons wrote: > > Daniel Carrera writes: > > > I'm scared of monads :) I really don't know what a monad > > > is. > > > > Neither do I, but that doesn't mean that I can't use just > > fine. ;-) > > > > >> putStrLn :: String -> World -> World > > > > > > That seems less scary. > > > > Things become a lot clearer when you think about how to > > print _two_ lines with that kind of function. You'd write: > > > > f :: World -> World > > f world = putStrLn "second line" (putStrLn "first line" world) > > > > The 'world' parameter forces the two functions into the > > order you want, because printing "second line" needs the > > result of printing "first line" before it can be evaluated. > > > > However, writing complex applications with that kind of API > > would drive you nuts, > > and would also be unsafe without some kind of strong guarantee that each > single 'world' value is unique. (This is how they do it in Clean.) > Imagine > > g :: World -> World > g world = let world' = putStrLn "first line" world > in putStrLn "second line" world -- oops, forgot the "'" > Well, this would just cause the first line to be ignored, wouldn't it? I suppose it depends on one's perspective, and what the World type really looks like. If you're cheating by threading a trivial value, and getting what are supposed to be pure functions to have side effects, then this is a problem. If World is a suitable type for holding information about the actions to eventually perform based on user input, then this will work just fine (though it's likely a bug the way that it's written). To me, this view doesn't seem any less scary than the monadic approach. You've just moved the scary part (if any) into the World type. I believe that a type somewhat along the lines of [Request] -> [Response] was at one point used for this. At some point you should really stop caring exactly how it's implemented though, and simply regard these IO actions as the sum of their parts. You have a bunch of primitives (getChar :: IO Char, putChar :: Char -> IO (), etc) that describe actions to be performed, and some operations, the monad operations on IO included, for combining them into composite actions. A simple example of one of these combining operations is the sequencing operation: (>>) :: IO a -> IO b -> IO b If x and y are IO actions, then (x >> y) is just an IO action which performs x, throws away any result, and then performs y, returning the result of that. For example, (putStrLn xs) is an action which prints the string xs on the screen, and (putStrLn "Hello" >> putStrLn "World") will print the strings "Hello" and "World" on subsequent lines. What if we don't want to throw away the result of the first operation? Well, there is a slightly more complicated version of the sequencing operation for that: (>>=) :: IO a -> (a -> IO b) -> IO b Now, this might seem scary at first, but all that it is doing is chaining actions together in sequence. The expression (x >>= f) produces the action which executes the action x, and applies f to the result of that action, which gives a new action that it executes in turn. As an example, getLine :: IO String, is an action which gets a line of text from the user. (getLine >>= \x -> putStrLn x) is an action which gets a line of text from the user, and then prints it back out. By understanding the primitives and the combiners, it's possible to understand everything there is to know about IO in Haskell. You don't actually need to look at how it's implemented (and probably shouldn't rely on one implementation too much). Let the RTS worry about the data structures used to represent your actions, exposing the implementation details just makes things more complicated. This is not to say that understanding monads in general isn't worthwhile, it very much is. It's also not to say that monads should always be treated like black boxes, as most often they aren't at all black boxes. However, it's possible for the library designer to give you a monad whose inner workings you can't inspect directly, and in the case of IO, that's basically what has been done. It should be respected, because it actually simplifies matters not to worry about the implementation. - Cale ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: infix functions
On Tue, Dec 20, 2005 at 09:12:51PM +, Daniel Carrera wrote: > No, I haven't. That's neat, very neat. Thanks for the tip. > > I just tried it, and all these are valid: > > (a `divides`) b > (`divides` b) a The annoyance in this business (which *is* very cool) is that you really have to decide when you name your functions whether they're meant to be infix or not. At least I've never come up with a verb form that makes sense either infix or prefix... :( -- David Roundy http://www.darcs.net ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] First steps in Haskell
Chris Kuklewicz <[EMAIL PROTECTED]> writes: > Prelude> let { fac :: Integer -> Integer; fac 0 = 1; fac n | n > 0 = n * fac > (n-1) } As somebody made me aware just the other day, the bracer are only necessary for nested expressions. So you can just use ; for line breaks: Prelude> let fac :: Integer -> Integer; fac 0 = 1; fac n | n > 0 = n * fac (n-1) -k -- If I haven't seen further, it is by standing in the footprints of giants ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] First steps in Haskell
On Mon, Dec 19, 2005 at 01:17:35PM -, Simon Peyton-Jones wrote: > | Actually, I have sometimes wished that the various interactive Haskell > | interfaces had the possibility to enter also declarations interactively > > GHCi does. > > ghci> let f x = "hello" > ghci> f True > True > > But there's no editor -- it's strictly a one-line definition Consider this: Prelude> :def read readFile Prelude> :!cat input let f x = "hello" Prelude> :read input Prelude> f () "hello" If we had a program that would: - move top-level definitions to a "let" - convert layout to explicit { ; } then it would be quite simple to define (with :def) a command that would allow to enter some code in the editor and load it into ghci, even without clearing the older definitions (as :load does). However, no datatype/class/... declarations, etc. Unless we could allow them in "let"? These should be possible to do with haskell-src-ext, programmatica or GHC itself. Best regards Tomasz -- I am searching for a programmer who is good at least in some of [Haskell, ML, C++, Linux, FreeBSD, math] for work in Warsaw, Poland ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Haskell-Cafe Digest, Vol 28, Issue 66
Scherrer, Chad wrote: Have you used Haskell's infix notation? It can help keep the order straight for operators like these. You can write a `mod` b -- instead of mod a b a `divides` b -- instead of divides a b. This can help with readability, too. No, I haven't. That's neat, very neat. Thanks for the tip. I just tried it, and all these are valid: (a `divides`) b (`divides` b) a That's neat because then you can make derived functions and compositions and all sorts of neat stuff. Cheers, Daniel -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/I am not over-weight, I am under-tall. / ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Tutorial uploaded
On Tuesday 20 December 2005 20:58, Peter Simons wrote: > Daniel Carrera writes: > > I'm scared of monads :) I really don't know what a monad > > is. > > Neither do I, but that doesn't mean that I can't use just > fine. ;-) > > >> putStrLn :: String -> World -> World > > > > That seems less scary. > > Things become a lot clearer when you think about how to > print _two_ lines with that kind of function. You'd write: > > f :: World -> World > f world = putStrLn "second line" (putStrLn "first line" world) > > The 'world' parameter forces the two functions into the > order you want, because printing "second line" needs the > result of printing "first line" before it can be evaluated. > > However, writing complex applications with that kind of API > would drive you nuts, and would also be unsafe without some kind of strong guarantee that each single 'world' value is unique. (This is how they do it in Clean.) Imagine g :: World -> World g world = let world' = putStrLn "first line" world in putStrLn "second line" world -- oops, forgot the "'" > so instead you can say > > f :: IO () > f = do putStrLn "first line" > putStrLn "second line" > > and it means the exact same thing. /and/ it guarantees that 'world' cannot be accidentally duplicated because it is not directly accessible to the program, thus there is only one 'world' ever existing at the same time, thus all IO actions are cleanly sequenced according to the data dependencies. > Curiously enough, if you check out the reference > documentation at: > > > http://haskell.org/ghc/docs/latest/html/libraries/base/Control-Monad- >ST.html#t%3ARealWorld > > ..., you'll find that a "World" type actually exists. Ben ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] First steps in Haskell
Daniel Carrera wrote: > Hello all, > > I'm trying to write the simplest possible Haskell program, and I'm not > getting anywhere. > > I have installed Hugs, GHC and GHCI. I want to run the following program: > > fac :: Integer -> Integer > fac 0 = 1 > fac n | n > 0 = n * fac (n-1) > $ ghci Prelude> let { fac :: Integer -> Integer; fac 0 = 1; fac n | n > 0 = n * fac (n-1) } Prelude> fac 12 479001600 > > This is a real problem for Haskell. I expect that a lot of people try > Haskell and give up because they can't even write the simplest function. > It's hard not to be put off by this. I love the theory behind Haskell, > but the practice of it seems to be a real problem. > > I hope someone will show me how to make this program work. Even better, > I hope someone will fix the compilers and interpreters if they need > fixing, or fix the documentation if that's what needs fixing. > > Best, > Daniel. Almost everything is explained under http://www.haskell.org/ghc/docs/6.4.1/html/users_guide/ghci.html The main things is: The ghci prompt accepts either command, starting with a color such as :load "filename" or haskell IO code, since it is in a do-block. Thus let is required. The 2-D Layout syntax does not work at the ghci prompt, thus the braces-and-semicolon style I used. More typically you would write your code in a file, as shown in: http://www.haskell.org/ghc/docs/6.4.1/html/users_guide/ch03s02.html ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: module names
Scherrer, Chad wrote: module Main where import A import B main = A.f >> B.f module A where f = ... module B where f = ... in a single file. This example is straight from chapter 5 of the Report, and no mention is made (that I could find) about modules needing to be in separate files. But this won't load in ghci! (Even if ... is changed to putStr "hi"). Eventually I figured out that it works fine if it's split over three separate files. The report says that they make up a single program, so that does not imply that they are in a single file. But, you are right: it's a good idea to be explicit about this. So here's what I'm trying to figure out: If every file corresponds to exactly one module (is that true?), then why must the module name be given again in the text of the file? When I'm using ghci, I have lots of modules that I sometimes want to load "as Main", and sometimes I only want them loaded as a dependency from another module. Currently, I have to go into each file to change the "module Foo where" line to do this. Section 9.5 of the report seems to show that stands for the compilation unit and it defines a single module. I suppose the standard allows you to name your module freely no matter your filesystem allows, but ghc requires (afaik) that module M exist in M.hs or M.lhs. Why not do this: name none of those modules Main.hs, and have an empty module Main.hs with only "import MainDeJour" and "main = MainDeJour.main" so you can just edit just that file. Cheers, Koray ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Tutorial uploaded
Hi, > Hugs Interpreter onlySuitable for learning. You'll need GHC for > serious work. This is putting Hugs down quite a bit. I personally prefer Hugs, and use it for serious work (including developing a Haskell compiler, and 4 years of academic study and counting). About the only thing it doesn't do is produce standalone binaries. I would have actually said Hugs, and especially the Windows front end WinHugs was a lot more suitable for beginners than GHC, but the wiki page very much gives the other impression. Thanks Neil ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Tutorial uploaded
On Tue, 2005-12-20 at 20:07 +0100, Sebastian Sylvan wrote: . . . > I'm still looking for a good *practical* tutorial that I could > recommend to newcomers. > IO, data types and QuickCheck in the very first chapter, I say! Real > program examples from the get go, and go into the theory on why this > has been hard in FP before Haskell (or Monadic IO rather) much much > later, so as to not scare people away. I second this motion. I've been interested in Haskell for some time, experimented with it several years ago, and then moved on to other things. That first time around I saw no comprehensible discussions of monadic IO (for example, I thought that the fact that when you're in a monad you can't get out was characteristic of monads in general, not a peculiarity of IO). The state of available knowledge for beginners has clearly improved since I last looked. I applaud this discussion for making Haskell more accessible for the newbie. (Now, if someone would just explain how to get reliable performance information while jumping through only a bounded number of hoops ... :-) -- Bill Wood ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Prime numbers
On Tue, 2005-12-20 at 16:53 +, Daniel Carrera wrote: > Henning Thielemann wrote: > >>factors :: Integer -> Integer -> Bool > >>factors m n | m == n = False > >> | m < n = divides m n || factors (m+1) n > > > > > > Btw. I find the recursion harder to understand than the explicit > > definition: > > > > factors n = any (divides n) [2..(n-1)] > > For what it's worth, I also found this function un-intuitive. What I'd > expect a function called "factors" to do is exactly what yours does, and > not what the one in the example does. It helped me to read "factors m n" as "there is an integer between m and n-1 inclusive that divides n". Then the recursion made sense. Thielemann's "factors n" would read "there is an integer between 2 and n-1 inclusive that divides n". -- Bill Wood ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Tutorial uploaded
Daniel Carrera writes: > I'm scared of monads :) I really don't know what a monad > is. Neither do I, but that doesn't mean that I can't use just fine. ;-) >> putStrLn :: String -> World -> World > > That seems less scary. Things become a lot clearer when you think about how to print _two_ lines with that kind of function. You'd write: f :: World -> World f world = putStrLn "second line" (putStrLn "first line" world) The 'world' parameter forces the two functions into the order you want, because printing "second line" needs the result of printing "first line" before it can be evaluated. However, writing complex applications with that kind of API would drive you nuts, so instead you can say f :: IO () f = do putStrLn "first line" putStrLn "second line" and it means the exact same thing. Curiously enough, if you check out the reference documentation at: http://haskell.org/ghc/docs/latest/html/libraries/base/Control-Monad-ST.html#t%3ARealWorld ..., you'll find that a "World" type actually exists. Peter ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] +RTS -M800M
On 17 December 2005 21:57, Ketil Malde wrote: > "Simon Marlow" <[EMAIL PROTECTED]> writes: > >> On 16 December 2005 10:05, Joel Reymont wrote: >> >>> I'm trying to restrict GHC to 800Mb of heap at runtime by passing in >>> +RTS -M800M, the machine has 1Gb of memory and top shows free >>> physical memory dropping below 175Mb. > >> -M800m should do more or less the right thing, but it is possible for >> GHC to exceed this figure by a small percentage. > > Is there any chance there is a bug in recent GHCs (or perhaps Linux?) > affecting this? I'm fairly sure I've lately seen Haskell programs > consuming significantly larger amounts of memory than they should be > allowed to, and I can try to isolate a test case if it is of > interest. Please do isolate it if you can. I'd be interested in investigating. Cheers, Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Learning about haskell compilers
> You could also learn from the code and documentation of the various > implementations of Haskell: GHC, hugs, nhc, and > > - YHC (http://www-users.cs.york.ac.uk/~ndm/yhc/) (an nhc derivatibe) > including a portable bytecode compiler With Yhc, there is also a quite useful wiki at http://www.haskell.org/hawiki/Yhc. In particular the runtime system is documented reasonably thorougly in http://www.haskell.org/hawiki/Yhc/RTS . There are also C, Python and Java implementations of the runtime system, which might help you figure out how it works. Thanks Neil ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] RE: Haskell-Cafe Digest, Vol 28, Issue 66
> From: Daniel Carrera <[EMAIL PROTECTED]> > Robert Dockins wrote: > > -divides a b = (mod a b == 0) > > +divides a b = (mod b a == 0) > > Oh, thanks. My program assumed one way to define 'divides' > and the example assumed the other. > > When I wrote it I was thinking of (divides a) being a > function that tells me if the input divides 'a'. > > Thanks! > > Cheers, > Daniel. Daniel, Have you used Haskell's infix notation? It can help keep the order straight for operators like these. You can write a `mod` b -- instead of mod a b a `divides` b -- instead of divides a b. This can help with readability, too. Chad Scherrer ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Tutorial uploaded
Peter Simons wrote: In my humble opinion, it's unfortunate that many tutorials and introductionary texts leave the impression that monadic code would be something utterly different than "normal" Haskell code. I feel it intimidates the reader by making a monad appear like black magic, even though it's little more than syntactic sugar to describe implicit function arguments. I'm scared of monads :) I really don't know what a monad is. All I know is that you need it for IO because IO implies side-effects and I know that "Monad" is a very scary-looking word :) If we'd have an opaque "World" type instead of the IO monad, 'putStrLn' would be: putStrLn :: String -> World -> World That seems less scary. Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/I am not over-weight, I am under-tall. / ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Tutorial uploaded
On 20 Dec 2005 19:52:31 +0100, Peter Simons <[EMAIL PROTECTED]> wrote: > > == So how do I write "Hello, world"? == > > > > Well, the first thing you need to understand that in a > > functional language like Haskell, this is a harder > > question than it seems. Most of the code you will write > > in Haskell is "purely functional", which means that it > > returns the same thing every time it is run, and has no > > side effects. Code with side effects is referred to as > > "imperative", and is carefully isolated from functional > > code in Haskell. > > I believe this description is a bit misleading. Code written > in the IO monad is purely functional just the same. Haskell > knows no other code than purely functional one. In my humble > opinion, it's unfortunate that many tutorials and > introductionary texts leave the impression that monadic code > would be something utterly different than "normal" Haskell > code. I feel it intimidates the reader by making a monad > appear like black magic, even though it's little more than > syntactic sugar to describe implicit function arguments. > > If we'd have an opaque "World" type instead of the IO monad, > 'putStrLn' would be: > > putStrLn :: String -> World -> World > > How is this function any different from any other function? > So why should > > putStrLn :: String -> IO () > > be different from any other function? > It's sometimes beneficial to "lie" a bit when starting out. Perhaps say something like "this is a simplified view of things, for all the gory details see chapter 19". Monadic IO is pretty darn cool, sadly that means that many tutorial authors are tempted to spend pages upon pages explaining exactly why it's cool and how it works, but that is NOT what most people starting out with the language need to read. I'm still looking for a good *practical* tutorial that I could recommend to newcomers. IO, data types and QuickCheck in the very first chapter, I say! Real program examples from the get go, and go into the theory on why this has been hard in FP before Haskell (or Monadic IO rather) much much later, so as to not scare people away. /S -- Sebastian Sylvan +46(0)736-818655 UIN: 44640862 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Tutorial uploaded
> == So how do I write "Hello, world"? == > > Well, the first thing you need to understand that in a > functional language like Haskell, this is a harder > question than it seems. Most of the code you will write > in Haskell is "purely functional", which means that it > returns the same thing every time it is run, and has no > side effects. Code with side effects is referred to as > "imperative", and is carefully isolated from functional > code in Haskell. I believe this description is a bit misleading. Code written in the IO monad is purely functional just the same. Haskell knows no other code than purely functional one. In my humble opinion, it's unfortunate that many tutorials and introductionary texts leave the impression that monadic code would be something utterly different than "normal" Haskell code. I feel it intimidates the reader by making a monad appear like black magic, even though it's little more than syntactic sugar to describe implicit function arguments. If we'd have an opaque "World" type instead of the IO monad, 'putStrLn' would be: putStrLn :: String -> World -> World How is this function any different from any other function? So why should putStrLn :: String -> IO () be different from any other function? Peter ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Substring replacements
I've finally performed test on amd64 and result is a same as on intel. KMP always wins. So KMP is best suited for non indexed strings and I guess should be used in library as prefered search/replace method. This test favors straightforward search. [EMAIL PROTECTED] myhaskell]$ time ./KMP Working:seasearch replace able seaseasearch baker seasearch charlie True Done real0m10.783s user0m10.769s sys 0m0.016s [EMAIL PROTECTED] myhaskell]$ time ./straightforward Working:seasearch replace able seaseasearch baker seasearch charlie True Done real0m11.769s user0m11.741s sys 0m0.028s [EMAIL PROTECTED] myhaskell]$ uname -a Linux devel64.office.kom 2.6.14-skas3-v8.2 #2 Fri Nov 11 21:19:36 CET 2005 x86_64 x86_64 x86_64 GNU/Linux Greetings, Bane. _ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: First steps in Haskell
Donn Cave wrote: I understand that interactive mode can be useful, I'm just wondering whether it belongs with Hello world in the scheme of things, or if at that first step it would be better to focus on the language. Let's compare sample instructions: Interactive mode: - 1. Write this on a file and save it as prog.hs fac 0 = 1 fac n | n > 0 = n * fac(n-1) 2. Type ghci on a terminal. 3. Load the program with ":load prog.hs" 4. Type "fac 12" Compiled mode: --- 1. Write this on a file and save it as "prog.hs" main = print fac 12 fac 0 = 1 fac n | n > 0 = n * fac(n-1) 2. Type "ghc prog.hs -o prog" on a terminal. 3. Run the program with "./prog" Comparison: ~~~ 1. The "compiled mode" instructions are only 1 step smaller, and that's because that step was moved into the program itself. You still need to explain that bit. 2. The "compiled mode" instructions also introduce "main" and "print". Over-all, I think that the compiled mode instructions are *marginally* more complicated. Not enough to choose one over the other. I would choose the interactive mode because it is friendlier to experimentation. Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/I am not over-weight, I am under-tall. / ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Learning about haskell compilers
You are braver than me, but I must confess I've had the same desire. Here's a great place to start: Simon Peyton Jones, David Lester, Implementing functional languages: a tutorial http://research.microsoft.com/Users/simonpj/Papers/pj-lester-book/ It's long, (sort of old) and written in Miranda (TM of Research Ltd.) which is sort of a precursor to Haskell, but it should get you a lot closer to understanding how lazy, pure functional languages work inside. You could also learn from the code and documentation of the various implementations of Haskell: GHC, hugs, nhc, and - jhc (http://repetae.net/john/computer/jhc/) - YHC (http://www-users.cs.york.ac.uk/~ndm/yhc/) (an nhc derivatibe) including a portable bytecode compiler Or you could use GHC and hs-plugins to sort of embed a haskell compiler into any Haskell program. Jared. -- [EMAIL PROTECTED] http://www.updike.org/~jared/ reverse ")-:" On 12/20/05, Creighton Hogg <[EMAIL PROTECTED]> wrote: > Hi guys, > I was wondering where I should get started in learing about > how to implement a haskell compiler? > Are there papers, wiki entries, or other things people think > would be helpful or should I just start looking at the > source of one of the compilers? > ___ > 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: First steps in Haskell
On Tue, 20 Dec 2005, Bayley, Alistair wrote: ... > There should be a "getting started" page which says: > - download and install this interpreter (Hugs or GHCi) > - run it, type these expressions, and see the results > - create a HelloWorld program, compile and execute. > - now start the following tutorial... (BTW, the link to Hal Daume's > tutorial from the Learning page needs fixing) Is the interactive interpreter exercise worth the trouble? Don't ask me, I have barely learned to use any of the interpreters in interactive mode, but I have the impression that they're different (where we came in), and you absolutely have to learn some things about them that don't otherwise contribute to your ability to write programs, and after all there are significant limits to what you can do there. I understand that interactive mode can be useful, I'm just wondering whether it belongs with Hello world in the scheme of things, or if at that first step it would be better to focus on the language. Donn Cave, [EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Prime numbers
Henning Thielemann wrote: factors :: Integer -> Integer -> Bool factors m n | m == n = False | m < n = divides m n || factors (m+1) n Btw. I find the recursion harder to understand than the explicit definition: factors n = any (divides n) [2..(n-1)] For what it's worth, I also found this function un-intuitive. What I'd expect a function called "factors" to do is exactly what yours does, and not what the one in the example does. Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/I am not over-weight, I am under-tall. / ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Prime numbers
Robert Dockins wrote: -divides a b = (mod a b == 0) +divides a b = (mod b a == 0) Oh, thanks. My program assumed one way to define 'divides' and the example assumed the other. When I wrote it I was thinking of (divides a) being a function that tells me if the input divides 'a'. Thanks! Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/I am not over-weight, I am under-tall. / ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Learning about haskell compilers
Hi guys, I was wondering where I should get started in learing about how to implement a haskell compiler? Are there papers, wiki entries, or other things people think would be helpful or should I just start looking at the source of one of the compilers? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Prime numbers
Daniel Carrera <[EMAIL PROTECTED]> writes: > This function seems to produce a wrong result on the number 38466629 > (warning, slow computation). Here is an easier-to-find problem: it tells me the number 4 is prime. Regards, Malcolm ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Prime numbers
-divides a b = (mod a b == 0) +divides a b = (mod b a == 0) On Dec 20, 2005, at 11:09 AM, Daniel Carrera wrote: John Peterson wrote: Add a type signature: prime :: Integer -> Bool It's defaulting to Int and you're getting overflows Thanks. Hmm... it's still not working. Btw, I mis-reported the problem. The offending number is 38466629, which is /not/ prime but the sample program reports as prime. 38466629 = 31 * 1240859 The offending program is: --//-- prime :: Integer -> Bool prime n = not (factors 2 n) factors :: Integer -> Integer -> Bool factors m n | m == n = False | m < n = divides m n || factors (m+1) n divides :: Integer -> Integer -> Bool divides a b = (mod a b == 0) --//-- The math behind the program seems correct... :( Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/I am not over-weight, I am under-tall. / ___ 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] Proposal for a first tutorial.
On 12/20/05, Hal Daume III <[EMAIL PROTECTED]> wrote: > It seems a bit unfair to say that there are no good ways of learning > information about Haskell. Yes, I'm shamelessly plugging my own tutorial, > but that's because I think it's pretty good. I agree, it is. I read it and found it a great help when I was learning. > But, yes, here's the solution: > > haskell.org people, please just link to the .pdf > > I think this solution should please everyone. You're probably right. (BTW, the link is currently broken - there may have been a typo made when the change was being made...) > p.s., I apologize for the rant. No problem. Sadly, there's so much email harvesting and the like on the internet these days, that no matter how innocent, a "please give your email address" form attracts a disproportionate amount of suspicion. But ironically, I can't quite convince myself that lying about my email address is acceptable, even so :-) Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Prime numbers
Daniel, Could it be that the arguments to either divides or mod should be reversed? Currently it seems to be testing whether the candidate prime (n) divides the possible factor (m). Or am I to tired to read the code straight? Regards, Maarten On 12/20/05, Daniel Carrera <[EMAIL PROTECTED]> wrote: > John Peterson wrote: > > Add a type signature: > > > > prime :: Integer -> Bool > > > > It's defaulting to Int and you're getting overflows > > Thanks. Hmm... it's still not working. > > Btw, I mis-reported the problem. The offending number is 38466629, which > is /not/ prime but the sample program reports as prime. > > 38466629 = 31 * 1240859 > > The offending program is: > --//-- > prime :: Integer -> Bool > prime n = not (factors 2 n) > > factors :: Integer -> Integer -> Bool > factors m n | m == n = False > | m < n = divides m n || factors (m+1) n > > divides :: Integer -> Integer -> Bool > divides a b = (mod a b == 0) > --//-- > > The math behind the program seems correct... :( > > Cheers, > Daniel. > > > > -- > /\/`) http://oooauthors.org > /\/_/ http://opendocumentfellowship.org > /\/_/ > \/_/I am not over-weight, I am under-tall. > / > ___ > 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] Prime numbers
Hi Daniel! You just have to change the arguments of the 'mod'-function: old: divides a b = (mod a b == 0) new: divides a b = (mod b a == 0) Regards, Jens ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Prime numbers
Jens Fisseler wrote: What about this: 38466629 = 31 x 1240859 Yes, I wrote backwards. The offending program says that it's prime but it's not. Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/I am not over-weight, I am under-tall. / ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Prime numbers
John Peterson wrote: Add a type signature: prime :: Integer -> Bool It's defaulting to Int and you're getting overflows Thanks. Hmm... it's still not working. Btw, I mis-reported the problem. The offending number is 38466629, which is /not/ prime but the sample program reports as prime. 38466629 = 31 * 1240859 The offending program is: --//-- prime :: Integer -> Bool prime n = not (factors 2 n) factors :: Integer -> Integer -> Bool factors m n | m == n = False | m < n = divides m n || factors (m+1) n divides :: Integer -> Integer -> Bool divides a b = (mod a b == 0) --//-- The math behind the program seems correct... :( Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/I am not over-weight, I am under-tall. / ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Prime numbers
Hi Daniel! > How do I know that 38466629 is prime? What about this: 38466629 = 31 x 1240859 Regards, Jens ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Prime numbers
Hello all, Trying to learn Haskell here... In a Haskell tutorial I found a function deciding if a number is prime: --//-- prime n = not (factors 2 n) factors m n | m == n = False | m < n = divides m n || factors (m+1) n divides a b = (mod a b == 0) --//-- Reference: http://www.cs.chalmers.se/Cs/Grundutb/Kurser/d1pt/d1pta/Function%20Definition%20by%20Cases%20and%20Recursion/sld038.htm This function seems to produce a wrong result on the number 38466629 (warning, slow computation). This number is prime but the function says that it's not. How do I know that 38466629 is prime? Beause: * http://www.rsok.com/~jrm/printprimes.html says that it is. * I wrote another prime function that says that it is. This is my function: --//-- prime 1 = False prime 2 = True prime n = filter (divides n) primes == [] where numbers = [x | x <- [2..n-1], x*x <= n] primes = filter prime numbers divides a b = (mod a b == 0) --//-- I can't figure out what's wrong with the first one. Can anyone spot the problem? (I'm just curious - trying to learn Haskell). Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/I am not over-weight, I am under-tall. / ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] Tutorial uploaded
> From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Daniel Carrera > > Hi all, > > I've finished a first draft of what I call "First steps in Haskell". > It's intended to be the very first thing a new user sees when they > decide to try out Haskell. > > http://www.haskell.org/hawiki/FirstSteps?action=show > > Thoughts and comments? There's not much wrong with doing a Hello World: main = putStrLn "Hello World" Or: fac n = if n <= 0 then 1 else n * fac (n-1) main = print (fac 12) Compiling, or at least running a haskell script (via runhaskell) should also get a mention, so you show how to achieve things outside of the interactive prompt. Alistair * Confidentiality Note: The information contained in this message, and any attachments, may contain confidential and/or privileged material. It is intended solely for the person(s) or entity to which it is addressed. Any review, retransmission, dissemination, or taking of any action in reliance upon this information by persons or entities other than the intended recipient(s) is prohibited. If you received this in error, please contact the sender and delete the material from any computer. * ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Proposal for a first tutorial.
> > Daniel -- can you tell me what was missing from YAHT that wasn't > > sufficient for starting to use Haskell? It was really intended to solve > > these problems, at least partially, so if it's missing out, I'd like to > > fix it! > > I haven't read it. I refuse to give out personal information to read a > tutorial. I don't mean to be obnoxious, but given: > This is a real problem for Haskell. I expect that a lot of people try > Haskell and give up because they can't even write the simplest function. and > Thank you. I did find that page, and it was very easy to find. The > problem is that the content of that page, and its links, didn't show me > how to write a Haskell program (like you did). and > Well, I tried all three (Hugs, GHCI, GHC). The problem is that the > tutorials I found didn't tell me how to run a Haskell program once it > was written. and > Any of the following would be an apt solution: > > 1) Update the tutorials linked to tell the user how to run a program. and > You see, as a site visitor, I have to assume that the tutorials you are > giving me are the ones you expect I should read. and > There's no way for a new user to figure out how to successfully run > the simplest Haskell program. and > I just Googled for "Introduction to C". The first link was: >http://www.le.ac.uk/cc/tutorials/c/ > It includes a brief section on both MS Visual C++ and the Unix CC. The fifth link for "Haskell Tutorial" is the pdf version of YAHT. and > I do suggest that the "Learning Haskell" page could be improved with a > brief (couple of paragraph) tutorial to get someone through Hello world. > Or perhaps update the tutorials to say that. (Please feel free to skip down to ) It seems a bit unfair to say that there are no good ways of learning information about Haskell. Yes, I'm shamelessly plugging my own tutorial, but that's because I think it's pretty good. It also answers all of the questions you've posted to the list, I believe. These sorts of questions come up *all the time*. A quick perusal of the mailing list archives will show that. This is part of the whole motivation for putting YAHT together: so all the nice Haskell people who do spend their time answering these questions repeatedly don't have to! So basically what you're saying is: someone who wants to learn Haskell but doesn't want to fill out a 10 second form can't find the information to do so. There's no requirement that the form be filled out correctly -- you can enter whatever invalid information you want. Also, as you can see above, just searching for "Haskell Tutorial" will turn you up with a PDF version freely. If you spend another 30 seconds, you can find a version translated into Portuguese or Chinese, if you prefer that. I know your argument was that you should *have* to do that work, but it is *your* choice not to fill out a silly little form that means nothing, and if you don't want to do that, then you can find another way. The tutorial is mirrored like 100 times and it's not hard to find one of those. The amount of effort to find a non-formed version is < than the effort to send lots of emails to the mailing list asking questions answered in the first chapter. But, yes, here's the solution: haskell.org people, please just link to the .pdf I think this solution should please everyone. - Hal p.s., I apologize for the rant. Although I don't spend my time mailing on this list recently, I still read it regularly and have updated YAHT several times in the past year to improve it via user comments. And everyone here has always been really friendly to me and other beginners, which is one of the many reasons why I like Haskell so much. I just felt that the above quoted lines (among others) were a misrepresentation of the situation, and given that I put a non-trivial amount of effort into making the situation better, I got somewhat annoyed. -- Hal Daume III | [EMAIL PROTECTED] "Arrest this man, he talks in maths." | www.isi.edu/~hdaume ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Tutorial uploaded
On 12/20/05, Daniel Carrera <[EMAIL PROTECTED]> wrote: > Hi all, > > I've finished a first draft of what I call "First steps in Haskell". > It's intended to be the very first thing a new user sees when they > decide to try out Haskell. > > http://www.haskell.org/hawiki/FirstSteps?action=show > > It's a bit longer than I'd like, but I don't inmediately see anything I > can take out without losing something valuable (given the purpose of > this document). > > Thoughts and comments? It looks very good. The length isn't a problem to me, if anything I'd be happy expanding a little. One thing I'd consider adding is something along the lines of a section: == So how do I write "Hello, world"? == Well, the first thing you need to understand that in a functional language like Haskell, this is a harder question than it seems. Most of the code you will write in Haskell is "purely functional", which means that it returns the same thing every time it is run, and has no side effects. Code with side effects is referred to as "imperative", and is carefully isolated from functional code in Haskell. To deal with the distinction between functional and imperative code, Haskell uses a construct called the "IO monad". It's not hard to understand - basically, it's just a way of "wrapping up" imperative code so that there's a clear boundary between it and functional code - but most tutorial presentations of Haskell start with functional code, and introduce the IO monad later. As a taster, though, here is "Hello, world" in Haskell: {{{ module Main where main :: IO () main = putStrLn "Hello, World!" }}} Put this in a file called hello.hs, and compile it with `ghc -make hello.hs -o hello`. You'll get an executable called hello (or hello.exe on Windows). Run it to see the output. There will be plenty more on writing standalone programs, IO, and other aspects of the IO monad, as you learn more about Haskell. The point is, people *will* want to write "hello, world", so don't put them off by making it seem "hard". Show them how, explain where they will find out more, and explain why things like this come naturally at a later stage when learning Haskell than they do with, say, C. Paul. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Proposal for a first tutorial.
Bayley, Alistair wrote: From this page http://haskell.org/hawiki/LearningHaskell there's a link to the tutorial http://www.isi.edu/~hdaume/htut/tutorial.pdf which seems to make no informational demands. I suggest updating this page: http://www.haskell.org/learning.html To point to that file. Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/I am not over-weight, I am under-tall. / ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] Proposal for a first tutorial.
> From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Daniel Carrera > > Hal Daume III wrote: > > Daniel -- can you tell me what was missing from YAHT that wasn't > > sufficient for starting to use Haskell? It was really > intended to solve > > these problems, at least partially, so if it's missing out, > I'd like to > > fix it! > > I haven't read it. I refuse to give out personal information > to read a > tutorial. >From this page http://haskell.org/hawiki/LearningHaskell there's a link to the tutorial http://www.isi.edu/~hdaume/htut/tutorial.pdf which seems to make no informational demands. Alistair * Confidentiality Note: The information contained in this message, and any attachments, may contain confidential and/or privileged material. It is intended solely for the person(s) or entity to which it is addressed. Any review, retransmission, dissemination, or taking of any action in reliance upon this information by persons or entities other than the intended recipient(s) is prohibited. If you received this in error, please contact the sender and delete the material from any computer. * ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Proposal for a first tutorial.
Hal Daume III wrote: Daniel -- can you tell me what was missing from YAHT that wasn't sufficient for starting to use Haskell? It was really intended to solve these problems, at least partially, so if it's missing out, I'd like to fix it! I haven't read it. I refuse to give out personal information to read a tutorial. Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/I am not over-weight, I am under-tall. / ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Proposal for a first tutorial.
> I've almost finished my proposal for a very first Haskell tutorial. I > notice that the Wiki is restricted. How can I upload it to show it to > you? Can I send it to the list as an attachment? (it's only 4k). Hi Daniel, all -- I've been tracking about 80% of this thread. Daniel -- can you tell me what was missing from YAHT that wasn't sufficient for starting to use Haskell? It was really intended to solve these problems, at least partially, so if it's missing out, I'd like to fix it! - Hal -- Hal Daume III | [EMAIL PROTECTED] "Arrest this man, he talks in maths." | www.isi.edu/~hdaume ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Tutorial uploaded
[EMAIL PROTECTED] wrote: hi daniel, the link about german (deutsch) haskel courses is in fact a link to a dutch (nederlands) page. For the rest it looks good! Thanks. Fixed. I removed the wrong link. Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/I am not over-weight, I am under-tall. / ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Tutorial uploaded
hi daniel, the link about german (deutsch) haskel courses is in fact a link to a dutch (nederlands) page. For the rest it looks good! Peter > Hi all, > > I've finished a first draft of what I call "First steps in Haskell". > It's intended to be the very first thing a new user sees when they > decide to try out Haskell. > > http://www.haskell.org/hawiki/FirstSteps?action=show > > It's a bit longer than I'd like, but I don't inmediately see anything I > can take out without losing something valuable (given the purpose of > this document). > > Thoughts and comments? > > Cheers, > Daniel. > -- > /\/`) http://oooauthors.org > /\/_/ http://opendocumentfellowship.org > /\/_/ > \/_/I am not over-weight, I am under-tall. > / > ___ > 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] Tutorial uploaded
Hi all, I've finished a first draft of what I call "First steps in Haskell". It's intended to be the very first thing a new user sees when they decide to try out Haskell. http://www.haskell.org/hawiki/FirstSteps?action=show It's a bit longer than I'd like, but I don't inmediately see anything I can take out without losing something valuable (given the purpose of this document). Thoughts and comments? Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/I am not over-weight, I am under-tall. / ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Battling time leaks
These are the stats with -O2: COST CENTREMODULE %time %alloc read Script.PokerClient20.1 13.6 timestamp Script.Trace 12.05.7 unstuffScript.PokerClient 8.04.4 puTableInfoScript.PicklePlus 6.96.4 trace_ Script.Trace 5.61.5 readQ Script.Queue 5.0 21.3 reverse_ Script.Endian 4.92.0 writeQ Script.Queue 4.94.4 wrap Script.Pickle 4.61.9 dispatch Script.Engine 4.32.8 unpickle Script.Pickle 3.80.5 lift Script.Pickle 2.94.5 appU_wstr Script.Endian 2.62.4 storable Script.Pickle 2.23.1 doSSLHandshake Script.PokerClient 1.10.0 fetch Script.Engine 1.0 18.9 dispatch_ Script.Engine 1.00.2 pair Script.Pickle 0.91.2 post_ Script.Engine 0.42.8 On Dec 20, 2005, at 11:01 AM, Joel Reymont wrote: Folks, It looks like I successfully squashed my time leaks and moving my serialization to Ptr Word8 got me as close to the metal as possible. I'm still getting wierd results, though, and they look like a time leak. ORANGE ALERT: 0s, 6s, SrvServerInfo ORANGE ALERT: 0s, 8s, SrvServerInfo ORANGE ALERT: 0s, 9s, SrvServerInfo ORANGE ALERT: 0s, 9s, SrvServerInfo ORANGE ALERT: 0s, 7s, SrvServerInfo unstuff :: Ptr Word8 -> Int -> IO Command unstuff ptr ix = do TOD time1 _ <- getClockTime (kind, ix1) <- unpickle puCmdType ptr ix TOD time2 _ <- getClockTime (cmd', _) <- unpickle (puCommand kind) ptr ix1 TOD time3 _ <- getClockTime when (time3 - time1 > 3) $ -- fail here with the messages above -- http://wagerlabs.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Proposal for a first tutorial.
Hi, We had to make the wiki not editable to users not logged in, due to excessive spam. If you create a user account, you can edit freely. (Click the UserPreferences link in the upper right.) cheers, - Cale On 20/12/05, Daniel Carrera <[EMAIL PROTECTED]> wrote: > Hello, > > I've almost finished my proposal for a very first Haskell tutorial. I > notice that the Wiki is restricted. How can I upload it to show it to > you? Can I send it to the list as an attachment? (it's only 4k). > > Cheers, > Daniel. > -- > /\/`) http://oooauthors.org > /\/_/ http://opendocumentfellowship.org > /\/_/ > \/_/I am not over-weight, I am under-tall. > / > ___ > 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] Proposal for a first tutorial.
Hello, I've almost finished my proposal for a very first Haskell tutorial. I notice that the Wiki is restricted. How can I upload it to show it to you? Can I send it to the list as an attachment? (it's only 4k). Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/I am not over-weight, I am under-tall. / ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Battling time leaks
Folks, It looks like I successfully squashed my time leaks and moving my serialization to Ptr Word8 got me as close to the metal as possible. I'm still getting wierd results, though, and they look like a time leak. ORANGE ALERT: 0s, 6s, SrvServerInfo ORANGE ALERT: 0s, 8s, SrvServerInfo ORANGE ALERT: 0s, 9s, SrvServerInfo ORANGE ALERT: 0s, 9s, SrvServerInfo ORANGE ALERT: 0s, 7s, SrvServerInfo unstuff :: Ptr Word8 -> Int -> IO Command unstuff ptr ix = do TOD time1 _ <- getClockTime (kind, ix1) <- unpickle puCmdType ptr ix TOD time2 _ <- getClockTime (cmd', _) <- unpickle (puCommand kind) ptr ix1 TOD time3 _ <- getClockTime when (time3 - time1 > 3) $ -- fail here with the messages above I would like to know where the time is going but how do I troubleshoot something like this? My understanding is that regular profiling will give me the total time spent by cost-center so if I add cost-center annotations it will not give me the average time per run. Come to think about it, the profiling report gives me the # of entries and the total time so I can get the average. Any other suggestions on how to figure out what is going on here? Thanks, Joel -- http://wagerlabs.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] First steps in Haskell
Benjamin Franksen wrote: What I meant was that a certain mindset (that I, in principle, share and value) leads to a culture where the primary values somewhat differ from the mainstream, thereby sometimes creating hurdles for newcomers, particularly newcomers without a strong academic background. And even newcomers *with* a strong academic background. I am a mathematecian. I find Haskell attractive because it expresses problems in the way I would naturally formulate them. But I still expect a beginner tutorial to have enough info to get a basic program runing. To me that seems very logical. Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/I am not over-weight, I am under-tall. / ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] First steps in Haskell
On Tuesday 20 December 2005 09:45, Simon Peyton-Jones wrote: > | (mild) culture shock here. It is typical for people in the Haskell > | community to view things in a rather principled way. A language > | tutorial is supposed to introduce /the language/. If you want to > | know how to compile or execute a Haskell program, well then, look > | at the appropriate tutorial on the /implementation/. At first this > | may appear like deliberately creating hurdles, but it isn't, it's > | merely the way many (though not all) Haskell people tend to think. > | They take it for granted that a new user is at least educated > | enough to be aware of the difference between the language itself, > | and its concrete implementation in the form of an interpretation or > | a compilation system. > > I, for one, don't take it for granted! Furthermore, I think the > Haskell community is pretty friendly; for example, a great deal of > entirely non-condescending advice is given to newcomers on Haskell > Café. I'm certain there are hurdles, but I think on the whole they > are there by accident rather than design. After reading again what I wrote above I see that it could be misunderstood. I was not talking about arrogance or any other form of unfriendlyness. I was merely formulating a theory for the reasons some of those hurdles are there in the first place (and occasionally get defended by some). What I meant was that a certain mindset (that I, in principle, share and value) leads to a culture where the primary values somewhat differ from the mainstream, thereby sometimes creating hurdles for newcomers, particularly newcomers without a strong academic background. Cheers Ben ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: First steps in Haskell
Bayley, Alistair wrote: For someone getting started, in IMO the Learning Haskell page has too much stuff on it. The total beginner doesn't have the knowledge they need to decide which implementation to install, which tutorial to read, or which textbook to buy. At the risk of alienating some tutorials and implementations, we ought to pick one of each and say "here, start with these". There's a balance to be struck between being fair to all resource producers (be it implementation, textbook, tutorial, or reference), and being as easy as possible for someone to get started, and I think the needle is currently too far over to the "fair" side of the scale. As a newbie I agree with Bayley. I didn't say that before because I didn't want to be more critical than I had already been. There should be a "getting started" page which says: - download and install this interpreter (Hugs or GHCi) - run it, type these expressions, and see the results - create a HelloWorld program, compile and execute. - now start the following tutorial... (BTW, the link to Hal Daume's tutorial from the Learning page needs fixing) I'll try to put something together on the Wiki. Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/I am not over-weight, I am under-tall. / ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] First steps in Haskell
Simon Peyton-Jones wrote: I'm certain there are hurdles, but I think on the whole they are there by accident rather than design. Why certainly. I have never seen any on-line community that had hurdles by design. Hurdles are usually due to the fact that the people who design the website/community/whatever already know how everything works. As an example, I also participate in the OpenOffice.org community. The website is *impossible* to use. To be able to get anywhere you need to already have fairly in-depth knowledge of the structural organization of the project. Sure, the site makes perfect sense to those who designed it. That's because it's organized in a way that reflects the internal bureocracy, not the questions a visitor is likely to have in mind when he arrives. It turns out that there are a couple of introductory Wiki pages already: http://www.haskell.org/hawiki/HaskellNewbie http://www.haskell.org/hawiki/HaskellDemo Thanks! It'd be great if someone would like to improve them in the light of this thread. (Anyone can do this.) I'll take a look. I'm handy with documentation and usability (though not a trained expert in either). Cheers, Daniel -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/I am not over-weight, I am under-tall. / ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell trickery
joelr1: > Folks, > > How is one to interpret the following? I'm particularly interested in > the "IO $ \ s -> " notatoin as I have never seen that before. > > allocaBytes :: Int -> (Ptr a -> IO b) -> IO b > allocaBytes (I# size) action = IO $ \ s -> > case newPinnedByteArray# size s of { (# s, mbarr# #) -> > case unsafeFreezeByteArray# mbarr# s of { (# s, barr# #) -> > let addr = Ptr (byteArrayContents# barr#) in > case action addrof { IO action -> > case action s of { (# s, r #) -> > case touch# barr# s of { s -> > (# s, r #) > } > > Lemmih suggested that this is unrolling the code (manual inlining?) > but how much speedup is that buying you? Doesn't this style come from the fact that unboxed primops are being called, which require explicit state args to be threaded (the multiple, shadowed 's' results in the unboxed tuples)? If we check the type of the various primops: newPinnedByteArray# :: Int# -> State# s -> (# State# s, MutByteArr# s #) unsafeFreezeByteArray# :: MutByteArr# s -> State# s -> (# State# s, ByteArr# #) and so on , we see that they're all set up to have a state token threaded explicitly, so the sequencing works. So the type forces you to step inside the IO container. The primops are used for efficiency (and this is low level code anyway), but stepping inside IO is just so the typing works. All the primops then get boxed up into a nice little IO action. The only place I've ever seen this style are when threading state to primop calls. -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Array performance is killing me
Converting to Ptr Word8 and storables took about an hour and gave me a more favorable profile. COST CENTREMODULE %time %alloc reverse_ Script.Endian 14.4 13.4 sequ Script.Pickle 14.39.3 read Script.PokerClient10.99.1 storable Script.Pickle 10.8 10.7 timestamp Script.Trace 7.13.8 dispatch Script.Engine 6.34.3 unstuffScript.PokerClient 4.42.9 appU_wstr Script.Endian 4.43.2 trace_ Script.Trace 3.91.2 readQ Script.Queue 3.3 13.0 lift Script.Pickle 2.95.3 writeQ Script.Queue 2.82.7 wrap Script.Pickle 2.21.2 $!!Script.DeepSeq 1.80.5 puTableInfoScript.PicklePlus 1.72.6 puCommand Script.PickleCmd 1.10.1 fetch Script.Engine 0.9 11.6 post_ Script.Engine 0.21.7 Any suggestions on how to optimize reverseBytes below? Would specializing it help? isBigEndian :: Bool isBigEndian = $(lift $ (1::CChar) /= (unsafePerformIO $ with (1::CInt) $ peekByteOff `flip` 0) ) :: Bool reverse_ :: (Storable a, Endian a) => a -> a reverse_ a = if isBigEndian then reverseBytes a else a --- Endian conversion class (Bits a, Integral a, Num a) => Endian a where reverseBytes :: a -> a instance Endian Word16 where reverseBytes v = (v `shiftR` 8) + ((v .&. 0xFF) `shiftL` 8) instance Endian Int16 where reverseBytes v = (v `shiftR` 8) + ((v .&. 0xFF) `shiftL` 8) instance Endian Word32 where reverseBytes v = ( v `shiftR` 24) + ((v .&. 0x00FF) `shiftL` 24) + ((v .&. 0xFF00) `shiftL` 8) + ((v .&. 0x00FF) `shiftR` 8) instance Endian Int32 where reverseBytes v = ( v `shiftR` 24) + ((v .&. 0x00FF) `shiftL` 24) + ((v .&. 0xFF00) `shiftL` 8) + ((v .&. 0x00FF) `shiftR` 8) instance Endian Word64 where reverseBytes v = ( v `shiftR` 56) + ((v .&. 0x00FF) `shiftL` 56) + ((v .&. 0x00FF) `shiftR` 40) + ((v .&. 0xFF00) `shiftL` 40) + ((v .&. 0xFF00) `shiftR` 24) + ((v .&. 0x00FF) `shiftL` 24) + ((v .&. 0x00FF) `shiftR` 8) + ((v .&. 0xFF00) `shiftL` 8) -- http://wagerlabs.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: First steps in Haskell
> From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Paul Moore > > I suspect that the reference documentation is fine, and the tutorials > are great, given what they are trying to do. But there is scope for a > very prominent "Getting going" document. Daniel's "40-second intro to > Haskell" looks good. Expand it a little with a few lines showing tow > to build and compile a "Hello, world" program in GHC and Hugs (with a > disclaimer that the code itself is magic for now, you'll understand > when you read about monads and the IO monad) to help people who need > to get over the "but how do I write a *program*" hump, and you're > pretty much there. For someone getting started, in IMO the Learning Haskell page has too much stuff on it. The total beginner doesn't have the knowledge they need to decide which implementation to install, which tutorial to read, or which textbook to buy. At the risk of alienating some tutorials and implementations, we ought to pick one of each and say "here, start with these". There's a balance to be struck between being fair to all resource producers (be it implementation, textbook, tutorial, or reference), and being as easy as possible for someone to get started, and I think the needle is currently too far over to the "fair" side of the scale. There should be a "getting started" page which says: - download and install this interpreter (Hugs or GHCi) - run it, type these expressions, and see the results - create a HelloWorld program, compile and execute. - now start the following tutorial... (BTW, the link to Hal Daume's tutorial from the Learning page needs fixing) As an example (checking out the competition), the Ruby community have a good free book. The book is fairly easy to find from the ruby-lang.org homepage, although it could be more prominent. The preface contains a brief tutorial for working with the interpreter (how to build & install, the REPL, and a Hello World program): http://www.rubycentral.com/book/preface.html And there's this interesting site, which demos a interpreter running in your browser (although it really seems to be showcasing some AJAX-ish javascript libraries): http://tryruby.hobix.com/ The Ruby community have put quite a bit of effort into easing beginners into the langauge and tools. Alistair * Confidentiality Note: The information contained in this message, and any attachments, may contain confidential and/or privileged material. It is intended solely for the person(s) or entity to which it is addressed. Any review, retransmission, dissemination, or taking of any action in reliance upon this information by persons or entities other than the intended recipient(s) is prohibited. If you received this in error, please contact the sender and delete the material from any computer. * ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Haskell trickery
Folks, How is one to interpret the following? I'm particularly interested in the "IO $ \ s -> " notatoin as I have never seen that before. allocaBytes :: Int -> (Ptr a -> IO b) -> IO b allocaBytes (I# size) action = IO $ \ s -> case newPinnedByteArray# size s of { (# s, mbarr# #) -> case unsafeFreezeByteArray# mbarr# s of { (# s, barr# #) -> let addr = Ptr (byteArrayContents# barr#) in case action addrof { IO action -> case action s of { (# s, r #) -> case touch# barr# s of { s -> (# s, r #) } Lemmih suggested that this is unrolling the code (manual inlining?) but how much speedup is that buying you? Last but not least, what is case action addrof { IO action -> case action s of { (# s, r #) -> Thanks, Joel -- http://wagerlabs.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] First steps in Haskell
| (mild) culture shock here. It is typical for people in the Haskell | community to view things in a rather principled way. A language | tutorial is supposed to introduce /the language/. If you want to know | how to compile or execute a Haskell program, well then, look at the | appropriate tutorial on the /implementation/. At first this may appear | like deliberately creating hurdles, but it isn't, it's merely the way | many (though not all) Haskell people tend to think. They take it for | granted that a new user is at least educated enough to be aware of the | difference between the language itself, and its concrete implementation | in the form of an interpretation or a compilation system. I, for one, don't take it for granted! Furthermore, I think the Haskell community is pretty friendly; for example, a great deal of entirely non-condescending advice is given to newcomers on Haskell Café. I'm certain there are hurdles, but I think on the whole they are there by accident rather than design. (Apart from functional programming itself, which often is a bit of a hurdle, but that's the reason we are here!) It turns out that there are a couple of introductory Wiki pages already: http://www.haskell.org/hawiki/HaskellNewbie http://www.haskell.org/hawiki/HaskellDemo It'd be great if someone would like to improve them in the light of this thread. (Anyone can do this.) Ideally there should be a single Wiki page that the Haskell.org web site can point to; perhaps the editing could bear that in mind? Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe