[Haskell-cafe] Announce: Blip, a bytecode compiler for Python 3 (implemented in Haskell)
I'm pleased to announce Blip version 0.1.0, a bytecode compiler for Python 3. https://github.com/bjpop/blip Blip compiles Python 3 source files to bytecode. The output bytecode is compatible with the CPython interpreter (the standard Python implementation). For example, given a Python 3 source file called foo.py, the command: blip foo.py produces a bytecode file called foo.pyc. The bytecode can be executed by passing it as an argument to a CPython interpreter: python3 foo.pyc This is an early development release of Blip, so it is not ready for serious use, however it supports most of the Python 3 language already. It has been tested on OS X 10.7.5 with GHC 7.4.2. The output has been tested with Python 3.3.0. Currently implemented features: https://github.com/bjpop/blip/wiki/Currently-implemented-features Features not yet implemented (but are on the way): https://github.com/bjpop/blip/wiki/Not-yet-implemented-features Wiki for more information: https://github.com/bjpop/blip/wiki Cheers, Bernie Pope. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] On the purity of Haskell
On 29 December 2011 10:51, Steve Horne sh006d3...@blueyonder.co.uk wrote: As Simon Baron-Cohen says in Tackling the Awkward Squad... I think you've mixed up your Simons; that should be Simon Peyton Jones. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANNOUNCE: iterIO-0.1 - iteratee-based IO with pipe operators
On 16 May 2011 19:56, Simon Marlow marlo...@gmail.com wrote: On 13/05/2011 21:12, Bernie Pope wrote: Could you please point me to more information about the sequential consistency of IORefs? I was looking for something about this recently but couldn't find it. I don't see anything in the Haddock for Data.IORef. Yes, it's not actually documented as far as I know, and we should fix that. Thanks Simon. I was thinking about this in the context of a blog post by Lennart Augustsson: http://augustss.blogspot.com/2011/04/ugly-memoization-heres-problem-that-i.html He says that There's no guarantee about readIORef and writeIORef when doing multi-threading.. But I was wondering if that was true, and if it were, what the consequences would be. If you read his reply to my question on the blog, then I believe that he was saying that sequential consistency was not guaranteed. If you have time to read his blog article, I wonder if you could comment on the need (or lack of need) for MVars or atomicModifyIORef? If I understand correctly, it would be okay to use readIORef/writeIORef, assuming that it is okay for some computations to be repeated. But if you think about it, sequential consistency is really the only sensible policy: suppose one processor creates a heap object and writes a reference to it in the IORef, then another processor reads the IORef. The writes that created the heap object must be visible to the second processor, otherwise it will encounter uninitialised memory and crash. So sequential consistency is necessary to ensure concurrent programs can't crash. Yes, I agree, and that was what I was thinking. Otherwise well-typed programs could go horribly wrong. For some background there was a discussion about this on the haskell-prime mailing list a few years ago, I think. Thanks, I try to dig it up. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANNOUNCE: iterIO-0.1 - iteratee-based IO with pipe operators
On 13 May 2011 19:06, Simon Marlow marlo...@gmail.com wrote: As far as memory consistency goes, we claim to provide sequential consistency for IORef and IOArray operations, but not for peeks and pokes. Hi Simon, Could you please point me to more information about the sequential consistency of IORefs? I was looking for something about this recently but couldn't find it. I don't see anything in the Haddock for Data.IORef. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] help with dynamic load
On 26 March 2011 05:57, Rob Nikander rob.nikan...@gmail.com wrote: I'm trying to use the 'plugins' package. Since I already posted to stackoverflow I'll just link to that. I posted a simple program that I thought would work, but mostly doesn't. Any pointers, appreciated. http://stackoverflow.com/questions/542/help-with-haskell-dynamic-plugin-load Hi Rob, I don't have a stack overflow account, so I will give a partial answer here. I'm not sure what the issue is with runhaskell, but you are getting a segfault with dynload. The comments on dynload in the source of the plugins package reveal the probable cause: \begin{comment} -- A work-around for Dynamics. The keys used to compare two TypeReps are -- somehow not equal for the same type in hs-plugin's loaded objects. -- Solution: implement our own dynamics... -- -- The problem with dynload is that it requires the plugin to export -- a value that is a Dynamic (in our case a (TypeRep,a) pair). If this -- is not the case, we core dump. Use pdynload if you don't trust the -- user to supply you with a Dynamic \end{comment} So it seems that, to use dynload, you must export a pair containing a typerep and a value, rather than just a value. Plugins also provides pdynload, which is apparently a super-replacement for dynload, though I didn't look into it in detail. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Byte Histogram
On 6 February 2011 02:40, Andrew Coppin andrewcop...@btinternet.com wrote: Then again, if you could actually single-step through a Haskell program's execution, most strictness issues would become quite shallow. You can single-step through a Haskell program's execution with the GHCi debugger. It can provide considerable insight into evaluation order. A proper stack tracer would make it even more useful. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] [ANNOUNCE] haskell-mpi-1.0.0
Done. Cheers, Bernie. On 14 December 2010 13:13, Thomas Schilling nomin...@googlemail.com wrote: Could you please add your package to the wiki section at http://haskell.org/haskellwiki/Applications_and_libraries/Concurrency_and_parallelism#MPI ? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Regression test utility suggestions?
On 22 October 2010 08:38, Peter Schmitz ps.hask...@gmail.com wrote: I am seeking suggestions for a regression test utility or framework to use while developing in Haskell (in a MS Windows environment). [snip] For this kind of task I use shelltestrunner http://hackage.haskell.org/package/shelltestrunner It can do recursive search through directories to find test cases, which I find particularly handy. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] An interesting paper from Google
On 17 October 2010 11:25, Dan Doel dan.d...@gmail.com wrote: On Saturday 16 October 2010 7:04:23 pm Ben Millwood wrote: On Fri, Oct 15, 2010 at 9:28 PM, Andrew Coppin andrewcop...@btinternet.com wrote: I'm still quite surprised that there's no tool anywhere which will trivially print out the reduction sequence for executing an expression. You'd think this would be laughably easy, and yet nobody has done it yet. I tried to do something a bit like this: http://github.com/benmachine/stepeval but it could be charitably described as crude: has three failing testcases and a bagful of unimplemented functionality. I believe the Buddha debugger could do something like this, as well, although normally you wouldn't dump the entire sequence. Buddha is/was a declarative debugger. The basic idea is to build a computation tree, and then search the tree for buggy nodes. Normally the debugger would decide how to traverse the tree, and the user would simply make judgements about the correctness of reductions stored in the visited nodes. However, buddha also allowed the user to explore the tree manually. None of this was particularly unique to buddha, and most other declarative debuggers allow you to do this too. Unfortunately most declarative debuggers don't make it far past the proof of concept stage. The HAT tracer also supports/supported declarative debugging and has many useful trace exploration tools. But it has bit rotted, unfortunately (it's quite tied to GHC internals, as far as I can tell). As the author of buddha I can confirm that it hasn't been maintained. The main dependency on GHC is a small amount of code for printing data structures. In fact some of that could would be easier to do now than it was then, because GHC includes data constructor names by default in compiled code (this was added to support the ghci breakpoint debugger). I never used it, but I've had at least one person tell me it was the best debugger they'd ever used. You type in an expression, and continually step into different parts of the reduction sequence until you find some core source of whatever error you're looking for. I'm happy to hear someone like it so much. Declarative debugging is a very nice idea (invented for Prolog by Ehud Shapiro - he is now famous for DNA computing), but it is hard to make practical. Probably the best declarative debugger I know of is the one provided for the Mercury programming language. However, Mercury is a strict language, which simplifies some aspects of the design. The problem is that it is hard to scale to long running computations, because the computation tree can become huge. HAT tackles this problem by saving a trace record to file, although this can have rather high runtime overheads. The declarative debugger for Mercury language tackles this problem by piecemeal construction of the computation tree, and by regenerating parts of it on demand by re-execution of code. Re-execution in a lazy language is quite challenging (I tried to do it in buddha). I have some ideas about interspersing declarative debugging with computation, but never had the time to implement it (though I think it would make a great research project). If someone were to revive it, I'm sure many people would be appreciative. I think it might be better to put more effort into HAT. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Thunks
On 15 October 2010 07:53, Mihai Maruseac mihai.marus...@gmail.com wrote: Hi, Is there a way to determine the order in which thunks are created and expanded/evaluated in Haskell (GHC)? I'm looking mainly at some existing interface but if there is only something in the GHC source it will suffice. You can use side effects to observe the order of evaluation, by wrapping observed expressions (thunks) with some IO computation inside unsafePerformIO. This is roughly what HOOD does, and it can be used to provide some clues about evaluation order, and maybe even GHood can help you visualise it. I've no idea if they work at the moment, but Hood and GHood are available on Hackage. You have to be careful of observer effects whereby the observation wrappers change the evaluation order of the observed code. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Shared thunk optimization. Looking to solidify my understanding
On 25 September 2010 07:58, David Sankel cam...@gmail.com wrote: Thanks everyone for your responses. I found them very helpful. This is my current understanding, please correct me where I am wrong: When using Launchbury's Natural Semantics (LNS) as an operational model, this optimization is called sharing which would lie in a category of optimizations called common subexpression elimination. Holger Siegel's email provided steps of an evaluation using LNS to show the different runtimes between test1 and test2. Because Haskell98 does not specify an operational semantics, there is no guarantee that an implementation will provide a sharing optimization. On the other hand, Haskell implementations are all similar enough that the sharing optimization can be depended on. LNS was indeed written to model what is common in implementations for languages characteristically like Haskell. When compiled with ghc with optimizations, test1 and test2 result in identical runtime behaviors. This is an artifact of another, more aggressive, optimization that falls within common subexpression elimination optimizations. It is not easy to describe or predict when this optimization occurs so depending on it when writing code is problematic. wren ng thornton provided an evaluation using another operational semantics (reference?). Under this semantics, this optimization would be called partial evaluation. Unfortunately I couldn't follow the steps or the reasoning behind them, perhaps a reference to the semantics would help. Thanks again! Hi David, If you are interested in exploring operational semantics you might also get some use out of MiniSTG: http://www.haskell.org/haskellwiki/Ministg It implements the push-enter and eval-apply semantics for the STG machine. Perhaps the most useful part is that it can generate a HTML trace of a small-step reduction. The trace shows the code, stack and heap, so you can see how structures are shared. It might help to read the fast curry paper if you want to play with MiniSTG: http://research.microsoft.com/en-us/um/people/simonpj/papers/eval-apply/ Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] cabal problem on OS X
On 10 June 2010 01:08, Gregory Collins g...@gregorycollins.net wrote: Jeroen Weijers jeroenweijers+haskellc...@gmail.com writes: Hi, For me it turned out to be some problem with MacPorts, removing MacPorts (with all its installed ports) solved the problem regarding ZLib. I assume that a less drastic measure would also work (only remove selected ports or remove the ports from your path). This specific error happens when you try to link with a 64-bit library from 32-bit GHC. So the odds are good either your flags aren't set right in /usr/bin/ghc and friends (which was an issue on 6.10), or you're linking to a non-universal copy of zlib (like the one macports will build). I was having this problem too, so I searched through my mail and found this thread. I upgraded to the latest Haskell Platform 2010.2.0.0, but the problem persisted. I noticed that macports has a universal variant of zlib, so I installed that: sudo port install zlib +universal Then I rebuild cabal, and now it works properly. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Actors and message-passing a la Erlang
On 26 July 2010 06:55, Yves Parès limestr...@gmail.com wrote: I've been studying Erlang and Scala, and I was wondering if someone has already implemented an actors and message passing framework for concurrent and distributed programs in Haskell. I've recently been working on MPI bindings for Haskell: http://github.com/bjpop/bindings-mpi They are incomplete, but usable. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] How to set a GHC option for a single module and a specific version of GHC?
Hi, I'm looking for a way to set a GHC compile option on a specific module (not every module in the program) but only for a specific version of GHC. Ideally within the confines of cabal, and in a portable way. GHC provides the OPTIONS_GHC pragma, but it does not appear to provide a way for the pragma to fire for specific versions of GHC. Also, I can't use an #ifdef trick because File-header pragmas are read once only, before pre-processing the file (e.g. with cpp). Cabal provides conditional statements and a way to check the version of GHC, but I can't see a way to get it to only use certain compiler options for a particular module. In summary, what I really want is a modified version of the OPTIONS_GHC pragma: {-# OPTIONS_GHC ==6.12.1 ... #-} or a way to tell cabal to use certain compiler options for a particular module under certain conditions. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Announce: berp, an implementation of Python 3, in Haskell
I'm pleased to announce the first public release of berp, version 0.0.2. Berp is (the beginnings of) an implementation of Python 3, written in Haskell. It provides a compiler and an interpreter. In both cases the input Python program is translated into Haskell code. The compiler turns the Haskell code into machine code. The interpreter runs the Haskell code immediately via the GHCi interpreter. The user interface of the interpreter imitates the one provided by CPython. A cabal package is available: http://hackage.haskell.org/package/berp The source code is hosted on github: http://github.com/bjpop/berp Documentation is available on a github wiki: http://wiki.github.com/bjpop/berp/ Note: berp is known to work with GHC 6.10.4, but it may not work with 6.12.x, due to issues with GHC's memory usage when compiling the language-python package (ticket #3972 on the GHC trac). As you can see by the very low version number (0.0.2), berp is still young; there is lots of room for improvement. However, it does support a fairly wide variety of Python's features, and some extensions such as callCC and tail call optimisation. Read more about it on the github wiki mentioned above. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Getting used and available memory
On 27 April 2010 17:55, Don Stewart d...@galois.com wrote: We could bind to Rts.c in the GHC runtime, and get all the stats programmatically that you can get with +RTS -s A long time ago I made a simple binding which has been packaged for cabal by Gwern Branwen. The package is called highWaterMark: http://hackage.haskell.org/package/highWaterMark As the name suggests it tells you the upper limit of RTS allocated memory. It does not tell you about memory allocated by foreign calls. I can't test it at the moment, but it is probably bit-rotten. Maybe it is something to start with? Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] multi-ghc: Managing Multiple GHC Distributions
On 8 April 2010 19:00, Sean Leather leat...@cs.uu.nl wrote: I created a few tools to help me manage multiple GHC distributions in a Bash shell environment. Perhaps it's useful to others. http://github.com/spl/multi-ghc Feedback welcome. I'd also like to know if something similar exists. Hi Sean, I wonder if you could achieve the desired result with the Modules Project: http://modules.sourceforge.net/ We use it at work for managing multiple versions of lots of different programs on a shared machine. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] GHC vs GCC
On 27 March 2010 04:46, Rafael Cunha de Almeida almeida...@gmail.com wrote: During a talk with a friend I came up with two programs, one written in C and another in haskell. snip The Haskell version: real 0m45.335s user 0m45.275s sys 0m0.004s against the C version: real 0m6.021s user 0m6.004s sys 0m0.004s Could you please report which version of each compiler, which operating system, and which CPU? Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: Salvia-1.0.0
On 22 March 2010 11:05, Carter Schonwald carter.schonw...@gmail.com wrote: apparently sometimes even though cabal can figure out the dependencies for a package you want, it gets confused (or something) when it needs to figure out the transitive dependencies (that which needs to be installed for the direct dependencies to also install). So try doing a cabal install of that version of template haskell with the explicit version cabal install template-haskell-2.4.0.0 that should solve it Yes, I tried that, but unfortunately it falls over with: Language/Haskell/TH/Quote.hs:31:12: Not in scope: data constructor `CharConstr' cabal: Error: some packages failed to install: template-haskell-2.4.0.0 failed during the building phase. The exception was: exit: ExitFailure 1 In the version of Data.Data on my machine there does not appear to be a CharConstr. It looks to me like there is an incorrect dependency in Template Haskell. I can see from the hackage build logs that I'm not the only one who has this problem. I will report a bug. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: Salvia-1.0.0
On 25 March 2010 14:23, Ivan Miljenovic ivan.miljeno...@gmail.com wrote: On 25 March 2010 12:21, Bernie Pope florbit...@gmail.com wrote: Yes, I tried that, but unfortunately it falls over with: Language/Haskell/TH/Quote.hs:31:12: Not in scope: data constructor `CharConstr' cabal: Error: some packages failed to install: template-haskell-2.4.0.0 failed during the building phase. The exception was: exit: ExitFailure 1 TH-2.4 comes with/needs GHC 6.12. The problem here appears to by with syb-with-class: using a lower version of that should work, as 0.6.1 appears to be a compatability release just to get it working on 6.12 (whereas 0.6 works with 6.10). Thanks Ivan. cabal install syb-with-class-0.6 fixed the problem. I note that you did mention this before, and sorry I missed it the first time. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: Salvia-1.0.0
On 22 March 2010 03:05, Sebastiaan Visser sfvis...@cs.uu.nl wrote: Straight from Zurihac: I'm very pleased to announce the 1.0.0 release of the Salvia web server. Salvia is a feature rich web server and web application framework that can be used to write dynamic websites in Haskell. From the lower level protocol code up to the high level application code, everything is written as a Salvia handler. This approach makes the framework extremely modular and extensible. To do a full install first run `cabal update' followed by `cabal install salvia-demo'. Now you can run the salvia-demo command and point your browser to http://localhost:8080/ . Hi Sebastiaan, I was looking forward to a new version of Salvia. Do you have minumum requirements for GHC? I tried to 'cabal install salvia-demo', but with no luck: cabal install salvia-demo Resolving dependencies... cabal: cannot configure syb-with-class-0.6.1. It requires template-haskell ==2.4.* For the dependency on template-haskell ==2.4.* there are these packages: template-haskell-2.4.0.0. However none of them are available. template-haskell-2.4.0.0 was excluded because template-haskell-2.3.0.1 was selected instead template-haskell-2.4.0.0 was excluded because ghc-6.10.4 requires template-haskell ==2.3.0.1 Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Proposal: Australian Hackathon
On 16 March 2010 16:28, Ivan Miljenovic ivan.miljeno...@gmail.com wrote: Would other Australians be interested in having our own Hackathon (why should all those northerners have all the fun)? I'm thinking about organising it to be in the July break between university semesters. Yes, I am interested. It would have to be overlap a weekend for me due to work commitments. I'll advertise it in the Melbourne FPU when more details are available. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Alex Lexer: Trying to get rid of Alex
On 23 February 2010 20:15, Amit Deshwar amit.desh...@gmail.com wrote: Hi Haskell-cafe My problem: I'm trying to obtain the current position of the lexer once it reaches the end of the file (line and row number). I'm trying to do this in a function: getEndPosition = do (a,b,c) - alexGetInput return a Unfortunately, the type of a is 'Alex AlexPosn' instead of just 'AlexPosn' How do I strip the Alex so I'm left with just a AlexPosn object? Hi Amit, Are you sure about the type of a? It looks like you are using the monad wrapper, described here: http://www.haskell.org/alex/doc/html/wrappers.html If that is true, then: alexGetInput :: Alex AlexInput and type AlexInput = (AlexPosn, Char, String) From that we can infer from your code: getEndPosition :: Alex AlexPosn and thus: a :: AlexPosn If you want to manipulate the value bound to a, you can simply apply a function to it in the body of getEndPosition, and return the result of that application (still inside the Alex type). Or you can use the function: runAlex :: String - Alex a - Either String a Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] haskell-src type inference algorithm?
On 12 February 2010 10:13, Niklas Broberg niklas.brob...@gmail.com wrote: Anyone know of a type inference utility that can run right on haskell-src types? or one that could be easily adapted? This is very high on my wish-list for haskell-src-exts, and I'm hoping the stuff Lennart will contribute will go a long way towards making it feasible. I believe I can safely say that no such tool exists (and if it does, why haven't you told me?? ;-)), but if you implement (parts of) one yourself I'd be more than interested to see, and incorporate, the results. A long time ago I worked on hatchet: http://www.cs.mu.oz.au/~bjpop/hatchet/src/hatchet.tar.gz which I believe was incorporated into JHC. Hatchet was based on thih and haskell-src. I gave up on it when I figured out a way to do what I wanted without type information. If I was going to do it again then I'd consider using Chameleon as a starting point, (I don't know where the most up-to-date sources are). Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] parallel and distributed haskell?
On 17 December 2009 06:21, Scott A. Waterman tswater...@gmail.com wrote: I feel there is quite a bit of latent interest in the subject here, but relatively little active development (compared to erlang, clojure, etc.) Can anyone involved give a quick overview (or pointers to one)? It would be good to hear what directions people are taking, and why, and where it's going. I've recently moved into HPC and am now quite interested in using Haskell on large clusters. My first goal was to get hMPI working (HaskellMPI). The original version appears to be from Michael Weber: http://www.foldr.org/~michaelw/hmpi/ which was followed up by Hal Daume III: http://hal3.name/newhmpi.tar.gz It doesn't appear to be cabalised. I wonder if anyone else has been using it? Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] getting data through foreign layer without marshalling
2009/12/14 Donn Cave d...@avvanta.com: I'm working with a C++ application library, of the sort where you instantiate a subclass of the library object and it dispatches your functions on receipt of various events. With multiple OS threads, by the way. This works all right so far, with some C++ boilerplate and Haskell FunPtrs created via the foreign wrapper option, but I am not crazy about marshalling the application data, to get it to the C++ object and back to my application functions. So, I'm wondering if the way I'm trying to thread application data through the C++ layer is reasonably fool-proof - I mean, empirically it works in a simple test, but are there going to be storage issues, etc.? Is there a better way to do it? Briefly, - my callbacks AppData - CPlusObjectPtr - P0 ... - IO Pn - the FunPtr inserted into C++ object FunPtr (CPlusObjectPtr - P0 ... - IO Pn) ... i.e, I apply the AppData parameter first - I rewrite the C++ object's FunPtrs every time I update the application data (freeHaskellFunPtr prior values.) I'm just not sure where AppData lives while it's referenced in a FunPtr via partial application, if there might be multiple copies, etc. I don't fully understand what you want to do, but perhaps you can use a StablePtr: http://www.haskell.org/ghc/docs/latest/html/libraries/base/Foreign-StablePtr.html Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Is anyone reading Pattern Calculus by Barry Jay?
2009/12/7 Duane Johnson duane.john...@gmail.com: I just bought a copy of Pattern Calculus [1] by Barry Jay and I would like to discuss the lambda- and pattern-calculus with anyone who is interested. Is there anyone else here who is reading the book and would like to discuss here (if it is appropriate) or take the discussion elsewhere? My knowledge of types has come primarily through reading this Haskell Cafe list, so I am by no means an expert. Just a tinkerer :) Regards, Duane Johnson [1] http://lambda-the-ultimate.org/node/3695 Hi Duane, The Melbourne FPU (functional programming union) is interested in topics like this, and some of us have a copy, or are about to get a copy of the book. http://groups.google.com.au/group/fpunion There's already a short thread on the topic - please feel free to sign up to the group. We welcome stimulating discussion. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Announce: language-python version 0.2 now available
I'm pleased to announce that version 0.2 of the language-python package is now available on hackage: http://hackage.haskell.org/package/language-python language-python provides lexical analysis and parsing for Python. Major features of this release: - Support for versions 2.x and 3.x of Python (previously only 3.x was supported). - Lexical tokens and AST nodes are annotated with accurate source span information. - Comments are retained as tokens, and are collected by the parser. Main shortcomings of this release: - Support for Unicode is limited (waiting on Unicode support in Alex). - It has only undergone minimal testing (testing infrastructure is still being built). I've also written a small client of the package, called language-python-colour, which renders Python source code as XHTML for colouring etc. The main purpose of this is to demonstrate how to use language-python, and the utility of accurate source spans. http://hackage.haskell.org/package/language-python-colour Example output: http://www.cs.mu.oz.au/~bjpop/code/lsystem.py.html Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Announce: language-python version 0.2 now available
2009/11/5 Tom Tobin korp...@korpios.com: On Wed, Nov 4, 2009 at 7:03 AM, Bernie Pope florbit...@gmail.com wrote: I'm pleased to announce that version 0.2 of the language-python package is now available on hackage: http://hackage.haskell.org/package/language-python language-python provides lexical analysis and parsing for Python. Thanks for working on this; coming from a Python background (and still using Python at work), this sounds like a fun way to combine my efforts at learning Haskell with something that might actually prove useful for my day job (as I haven't been happy with any of the Python lint tools out there). :-) I'm keen for people to write Python tools using language-python, so please let me know if you do, or if you have any good ideas. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Announce: language-python version 0.2 now available
2009/11/5 Deniz Dogan deniz.a.m.do...@gmail.com: 2009/11/4 Bernie Pope florbit...@gmail.com: Main shortcomings of this release: - Support for Unicode is limited (waiting on Unicode support in Alex). There was an announcement a while back on this list from Jean-Philippe Bernardy about successfully adding Unicode support to Alex. http://www.mail-archive.com/haskell-cafe@haskell.org/msg62848.html Thanks Deniz, Yes, I saw that posting a while ago. I'm waiting for it to be included in the main branch of Alex (and looking forward to it too). Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANNOUNCE: graphtype — A simple tool to illustrate dependencies between Haskell types
2009/8/24 Max Desyatov explicitc...@googlemail.com: graphtype was developed to visualise type declarations in you Haskell source files. It produces .dot-file for subsequent processing with graphviz. Anyway, graphtype is fairly usable. Leave here your questions, suggestions and have fun looking at type dependencies in your code. Neat. You could probably get some leverage from the GHC API for reading .hi files to find out information about imported types. It looks to me like you generate one image file for the whole graph. It could get quite big. I think dot supports hyperlinks, and so do some image formats (SVG I believe). Maybe you could split it up into pieces with hyperlinks between them. Browser support for SVG appears to be getting better these days. I've sometimes mused about the idea of graphing the static function call graph of programs and annotating arcs with type information. For that the GHC API would be the way to go (might need to do a little type reconstruction along the way to figure out the concrete types at which polymorphic functions are used.) Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANNOUNCE: ministg-0.2, an interpreter for STG operational semantics
I'm pleased to announce the first public release of Ministg. Ministg is an interpreter for a high-level, small-step, operational semantics for the STG machine. The STG machine is the abstract machine at the core of GHC. The operational semantics used in Ministg is taken from the paper Making a fast curry: push/enter vs. eval/apply for higher-order languages by Simon Marlow and Simon Peyton Jones. Ministg implements both sets of evaluation rules from the paper. One of the main features of Ministg is the ability to record a trace of the execution steps as a sequence of html files. And example trace can be viewed here: http://www.cs.mu.oz.au/~bjpop/trace/step0.html The example shows the execution of a program which sums a list of three integers, using the well-known space-leaky version of sum. Follow the next and previous links to step forwards and backwards through the trace. The main reason I wrote Ministg is to explore various extensions to the STG machine. The current release features a simple extension in the form of call-stack tracing, which is strongly influenced by the cost-centre stacks of GHC. I expect it will also be a useful tool for people who are interested in learning more about the STG machine. More detailed information is available from the haskellwiki page: http://www.haskell.org/haskellwiki/Ministg You can download it from hackagedb: http://hackage.haskell.org/package/ministg Or you can get the latest code from patch-tag: darcs get http://patch-tag.com/r/ministg/pullrepo ministg Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Keeping an indexed collection of values?
2009/8/19 Job Vranish jvran...@gmail.com: My first hacked up attempt is as follows: data IndexedCollection a = IndexedCollection { nextKey :: Int, availableKeys :: [Int], items :: (IntMap Int a) } deriving (Show) emptyIndexedCollection :: IndexedCollection a emptyIndexedCollection = IndexedCollection 0 [] empty addItem :: a - IndexedCollection a - (Int, IndexedCollection a) addItem a (IndexedCollection nextKey' [] t) = (nextKey', IndexedCollection (nextKey' + 1) [] (insert nextKey' a t)) addItem a (IndexedCollection nextKey' (k:ks) t) = (k, IndexedCollection nextKey' ks (insert k a t)) removeItem :: Int - IndexedCollection a - IndexedCollection a removeItem k (IndexedCollection nextKey' ks t) = IndexedCollection nextKey' (k:ks) (delete k t) lookupItem :: Int - IndexedCollection a - Maybe a lookupItem k (IndexedCollection _ _ t) = lookup k t It might be the case for IntMap (I haven't checked) that it is better to do a modify operation than to do a deletion followed by an insertion on the same key. One possible improvement is to delay deletions by putting them in a pending queue. A pending deletion followed by an addItem could be coalesced into a modify operation on the key to be deleted. You could even push lookupItems through pending deletions, assuming that they aren't on the same key (if they are on the same key then the lookup would fail). One question is how big should the pending deletion queue be allowed to become? A long queue might not be a good idea. One problem with delaying deletions is that it could introduce a space leak (same as unintended lazy evaluation). Maybe a queue of max length one is sufficient? I'm not sure it is worth the trouble, but it might be fun to try. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] unsafeDestructiveAssign?
2009/8/12 Job Vranish jvran...@gmail.com: Does anybody know if there is some unsafe IO function that would let me do destructive assignment? Something like: a = 5 main = do veryUnsafeAndYouShouldNeverEveryCallThisFunction_DestructiveAssign a 8 print a 8 I doubt you will be able to achieve that in Haskell, but there is another language which does support what you want which is very close to Haskell. It is called Disciple, and there is a compiler for it called DDC: http://www.haskell.org/haskellwiki/DDC DDC is rather young, so it depends on what you are doing as to whether it will fulfil all your needs. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] A voyage of undiscovery
2009/7/17 Andrew Coppin andrewcop...@btinternet.com: I've been working hard this week, and I'm stumbled upon something which is probably of absolutely no surprise to anybody but me. Consider the following expression: (foo True, foo 'x') Is this expression well-typed? Astonishingly, the answer depends on where foo is defined. If foo is a local variable, then the above expression is guaranteed to be ill-typed. However, if we have (for example) foo :: x - x as a top-level function, then the above expression becomes well-typed. Some useful reading material: Section 22.7 of the book Types and Programming Languages by Benjamin Pierce. The classic paper Basic Polymorphic Typechecking by Luca Cardelli: http://lucacardelli.name/Papers/BasicTypechecking.pdf Both of these are very readable introductions to the let-style polymorphism found in the Hindley/Milner type system. Haskell's type system is essentially an elaboration of that idea. Pierce's book shows how to achieve let-polymorphism by inlining non-recursive let bindings during type checking/inference, which is a nice way to understand what is going on. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How i use GHC.Word.Word8 wit Int ?
2009/5/20 z_a...@163.com z_a...@163.com: Hi, friends rollDice :: Word8 - IO Word8 rollDice n = do bracket (openFile /dev/random ReadMode) (hClose) (\hd - do v - fmap B.unpack (B.hGet hd 1) let v1 = Data.List.head v return $ (v1 `mod` n) + 1) . blueIdx - rollDice $ length [1..33] Couldn't match expected type `Word8' against inferred type `Int' In the second argument of `($)', namely `length yesBlue I know length [1..33] is Int not Word8, but Word8 is enough here. Sincerely! You can use fromIntegral to convert Integral types to other numeric types: fromIntegral :: (Integral a, Num b) = a - b Prelude Data.Word (fromIntegral (3 :: Int)) :: Word8 3 Watch out for overflow. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Writing a compiler in Hakell
2009/5/6 Rouan van Dalen rvda...@yahoo.co.uk I know about Happy. Is that a good tool to use? Alex and Happy are used in (at least) these two packages: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/language-python http://hackage.haskell.org/cgi-bin/hackage-scripts/package/language-c You should be able to find lots of useful code to start with in both of those. You can get good performance out of Alex and Happy. Of course there are more considerations than just performance, and you will get different opinions about those other aspects. I wrote the python parser above and I was quite pleased with Alex and Happy from a usability perspective. LLVM is a nice framework for building the backend of a compiler, and the Haskell bindings are quite useful: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/llvm The amount of work you have to do depends on your runtime system (GC, threads, exceptions etc). If your language has fairly conventional semantics (a typical imperative language) then you can reuse a lot of the existing infrastructure that LLVM provides. On another note, how is the operator + implemented in haskell? It is good to differentiate Haskell the language specification from compilers (and other tools) which implement it. The language specification does not say exactly how the primitive operations should be implemented; that is a detail which is up to the compiler writer to decide. GHC's implementation is the best documented, and there are many research papers which describe aspects of it (some outdated). For numerical primitives, you could start by looking at this paper: Unboxed values as first class citizens in a non-strict functional language Peyton Jones and Launchbury. http://research.microsoft.com/en-us/um/people/simonpj/papers/unboxed-values.ps.Z Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Few Alex questions
2009/5/1 Dimitry Golubovsky golubov...@gmail.com snip Can beginning of line (caret) be recognized by Alex? You can match the start of a line using a (left) context on a rule. See the docs here: http://www.haskell.org/alex/doc/html/alex-files.html#contexts Where it says: The left context matches the character which immediately precedes the token in the input stream. The character immediately preceding the beginning of the stream is assumed to be ‘\n’. The special left-context ‘^’ is shorthand for ‘\n^’. Alex also supports right contexts too. snip Is this correct understanding that if we want to match any character except for an asterisk, then Alex would like to see [^\*] rather than [^*]? And [^\/] rather than [^/]? Or would it be better to use a hex code for the asterisk and slash? In a character set you must escape certain special characters. The list of special characters is specified in the docs here: http://www.haskell.org/alex/doc/html/syntax.html#lexical The key line is: $special= [\.\;\,\$\|\*\+\?\#\~\-\{\}\(\)\[\]\^\/] I'd try to avoid character codes where possible. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Recommending Design concepts in programming languages
2009/4/30 Eugene Kirpichov ekirpic...@gmail.com Hi. To all those people who are in any sense interested in PL theory I'd like to recommend the book Design concepts in programming languages, because I am extremely impressed with it and because I, surprisingly, have not heard much about it. I concur, it is a wonderful book; a great resource. Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ghci debugger problem with :continue. is it broken, or is it me?
2009/4/28 Thomas Hartman tphya...@gmail.com I suppose this means that the points-free/pattern binding-style version is a bit less work for ghc to execute (fewer reductions), whereas the version with lambda bound variables is easier to debug. I don't think there is any (significant) difference between them in the amount of work done at runtime. The observed difference in behaviour is more a matter of how the debugging transformation in GHCi interprets the command set a breakpoint on f, and how the code for f is generated. I think my previous email was slightly misleading, and we should be careful to distinguish between 'evaluating f' and 'evaluating applications of f'. In both cases f is already a value (either a partial application or a lambda function). So f itself doesn't really undergo 'reduction', in the theoretical sense. However, a compiler, such as GHC, may generate code which does a little bit of work at runtime, and the debugger may be able to observe that work. When f is written in the pattern binding style, the breakpoint on f reveals the 'evaluation of f', which is just the little bit of work at runtime I was talking about. When f is written in function binding style, the breakpoint on f reveals 'an evaluation of an application of f' (which may happen more than once). Normally, when people attach a breakpoint on a function, they want to see the evaluation of applications of the function. So the behaviour of the debugger for functions defined in the pattern binding style can be confusing. The debugger could arrange things so that both styles of definition give the same behaviour wrt breakpoints, for example by eta-expanding definitions. On balance, I think I'll frequently write my functions with lambda bound variables then. It does seem a shame to modify your code style for the sake of the debugger, but I guess that is inevitable with procedural debuggers anyway. 2009/4/26 Bernie Pope florbit...@gmail.com: 2009/4/25 Thomas Hartman tphya...@gmail.com In the program below, can someone explain the following debugger output to me? After :continue, shouldn't I hit the f breakpoint two more times? Why do I only hit the f breakpoint once? Is this a problem in the debugger? thart...@ubuntu:~/haskell-learning/debuggercat debugger.hs -- try this: -- ghci debugger.hs -- :break f -- :trace t -- :history -- should show you that f was called from h t = h . g . f $ hey! t2 = h . g . f $ heh! t3 = h . g . f $ wey! f = (f -- ++) g = (g -- ++) h = (h -- ++) ts = do putStrLn $ t putStrLn $ t2 putStrLn $ t3 What you are observing is really an artifact of the way breakpoints are attached to definitions in the debugger, and the way that GHCi evaluates code. f is clearly a function, but its definition style is a so-called pattern binding. The body contains no free (lambda bound) variables, so it is also a constant. GHCi arranges for f to be evaluated at most once. The breakpoint associated with the definition of f is fired if and when that evaluation takes place. Thus, in your case it fires exactly once. You can re-write f to use a so-called function binding instead, by eta-expansion (introduce a new fresh variable, and apply the function to it on both sides): f x = (f -- ++) x This denotes the same function, but the breakpoint on f works differently. In this case, a breakpoint attached to f will fire whenever an application of f is reduced. If you write it this way you will see that the program stops three times instead of one. You might ask: if both definitions denote the same function, why does the debugger behave differently? The short answer is that the debugger in GHCi is an operational debugger, so it exposes some of the operational details which may be invisible in a denotational semantics. In this case it revels that GHCi treats the two definitions of f differently. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Question about implementing an off-side rule in Parsec 2
2009/4/28 Bas van Gijzel neneko...@gmail.com I'm doing a bachelor project focused on comparing parsers. One of the parser libraries I'm using is Parsec (2) and I'm going to implement a very small subset of haskell with it, with as most important feature the off-side rule (indentation based parsing) used in function definitions and possibly in where clauses. But I'm still a bit stuck on how to implement this cleanly. I tried to search for some examples on blogs but I haven't found anything yet. As far as I can see the way to go would be using getState and updateState methods defined in Parsec.Prim and to use the methods in Parsec.Pos to compare the difference in indendation for tokens. But I haven't completely wrapped my head around any state monad yet and I don't understand Parsec enough yet to see how to use the methods Parsec.Pos and state easily. Some examples or pointers to something to read would really be helpful. Parsing a simple form of the offside rule is discussed in the paper: Monadic Parser Combinators, Hutton and Meijer, 1996 http://www.cs.nott.ac.uk/~gmh/monparsing.pdf see section 8, page 30. Their parsers are similar in style to Parsec, but you may need to do some translation. I haven't thought about it hard, but I suspect their approach is not efficient for deeply nested examples, due to repeated processing of the token stream (but I could be wrong, and maybe it doesn't matter for what you are trying to do). I followed their approach in a toy language once, and the result was very pleasing to read in code. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ghci debugger problem with :continue. is it broken, or is it me?
2009/4/25 Thomas Hartman tphya...@gmail.com In the program below, can someone explain the following debugger output to me? After :continue, shouldn't I hit the f breakpoint two more times? Why do I only hit the f breakpoint once? Is this a problem in the debugger? thart...@ubuntu:~/haskell-learning/debuggercat debugger.hs -- try this: -- ghci debugger.hs -- :break f -- :trace t -- :history -- should show you that f was called from h t = h . g . f $ hey! t2 = h . g . f $ heh! t3 = h . g . f $ wey! f = (f -- ++) g = (g -- ++) h = (h -- ++) ts = do putStrLn $ t putStrLn $ t2 putStrLn $ t3 What you are observing is really an artifact of the way breakpoints are attached to definitions in the debugger, and the way that GHCi evaluates code. f is clearly a function, but its definition style is a so-called pattern binding. The body contains no free (lambda bound) variables, so it is also a constant. GHCi arranges for f to be evaluated at most once. The breakpoint associated with the definition of f is fired if and when that evaluation takes place. Thus, in your case it fires exactly once. You can re-write f to use a so-called function binding instead, by eta-expansion (introduce a new fresh variable, and apply the function to it on both sides): f x = (f -- ++) x This denotes the same function, but the breakpoint on f works differently. In this case, a breakpoint attached to f will fire whenever an application of f is reduced. If you write it this way you will see that the program stops three times instead of one. You might ask: if both definitions denote the same function, why does the debugger behave differently? The short answer is that the debugger in GHCi is an operational debugger, so it exposes some of the operational details which may be invisible in a denotational semantics. In this case it revels that GHCi treats the two definitions of f differently. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Is there a way to see the equation reduction?
2009/4/1 Daryoush Mehrtash dmehrt...@gmail.com I am trying to write out the execution of the recursive calls in mkDList examplehttp:/http://www.haskell.org/haskellwiki/Tying_the_Knot/www.haskell.org/haskellwiki/Tying_the_Knotfor different size lists. Is there a way in ghc, or ghci where for a given list I can see the intermediate recursive and evaluation steps? Have you tried stepping through the code using the GHCi debugger? http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-debugger.html If you have tried, but it didn't satisfy your needs, could you explain what is lacking? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Announce: language-python
Language-python provides a parser (and lexer) for Python written in Haskell. Currently it only supports version 3 of Python (the most recent version), but it will support version 2 in the future. The parser is implemented using Happy, and the lexer is implemented using Alex. Web page: http://projects.haskell.org/language-python/ Hackage: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/language-python Darcs: darcs get http://code.haskell.org/language-python/ Example: $ ghci Prelude :m Language.Python.Version3.Parser Prelude Language.Python.Version3.Parser parseModule def inc(x): return x + 1\n [] Right (Module [Fun {fun_name = Ident inc, fun_args = [Param {param_name = Ident x, param_annotation = Nothing, param_default = Nothing}], fun_result_annotation = Nothing, fun_body = [Return {return_expr = Just (BinaryOp {operator = Plus, left_op_arg = Var (Ident x), right_op_arg = Int 1})}]}]) Prelude Language.Python.Version3.Parser :m Language.Python.Version3.Lexer Prelude Language.Python.Version3.Lexer lexOneToken def inc(x): return x + 1\n [] Right (Def (Sloc {sloc_filename = , sloc_row = 1, sloc_column = 1}), inc(x): return x + 1\n) This is the first release of the package (version 0.1.1) and there is still much to be improved, in particular: - Unicode support is incomplete. - Source locations are sub-optimal, and will eventually become source spans. - The pretty printer needs polish. - The parser only supports version 3 of Python. Support for Version 2 is a major goal, and should be straightforward. - Only minimal performance tuning and correctness testing has been performed. Version 0.1.1 is not intended for production use. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Operational semantics. Was: [Haskell-cafe] What unsafeInterleaveIO is unsafe
On 17/03/2009, at 1:13 PM, Jonathan Cast wrote: [Totally OT tangent: How did operational semantics come to get its noun? The more I think about it, the more it seems like a precís of the implementation, rather than a truly semantic part of a language specification.] I haven't followed the whole thread, so perhaps I'm missing some important context to this question. It is true that operational semantics are often used to summarise or explain an _implementation_ of a language feature, but I wouldn't say that they are always used in this way. An operational semantics may be used to define a behaviour function: (program x input) - outcome. The big-step style of operational semantics style tends to be less like an implementation, and more like a specification. Perhaps the more crucial part of operational semantics is that it just deals with syntactic terms as its values. Apologies if this has nothing to do with your question. Cheers, Bernie.___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Need an overview of FP-related research topics
On 17/03/2009, at 10:59 PM, Yitzchak Gale wrote: I would like some links that would give such a person a nice overview of the various active areas of FP-related research these days, leaning towards Haskell. I want to give him a fairly broad view of what is interesting and exciting, why various topics are important, where to find ideas for collaboration and applications to other areas, etc. Some ideas off the top of my head: - Lambda the Ultimate (not Haskell or fp specific) http://lambda-the-ultimate.org/ - Browse recent editions of the Journal of Functional Programming (perhaps they even subscribe to it at the Uni in question) and perhaps TOPLAS. - Browse the recent proceedings of various conferences and workshops such as International Conference on Functional Programming, Trends in Functional Programming, the Haskell Symposium, Practical Aspects of Declarative Languages, Principles and Practice of Declarative Programming, International Summer School on Advanced Functional Programming (and many others). - Check the home pages and blogs of well-known and active researchers (I won't list them). - Maybe http://www.readscheme.org/, though not Haskell specific. (not sure if http://haskell.readscheme.org/ is working anymore). - There's quite a list of papers on haskell.org, under http://www.haskell.org/haskellwiki/Research_papers . Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] jhc speed
On 23/02/2009, at 2:22 AM, Luke Palmer wrote: By the way, coming up pretty soon, I will need a desugared annotated Haskell for Dana. If anybody has something like this in the works, I'd love to help with it. If it does not exist by the time I need it, I will make it, so if anyone is interested in working on it with me, let me know :-) Luke Hi Luke, Any progress on that front? How much desugaring do you want? What kind of annotations do you want? Can you get what you need from the GHC API? Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Memory
On 17/02/2009, at 3:56 PM, Jeff Douglas wrote: Hello All, The kind people at #haskell suggested I come to haskell-cafe for questions about haskell performance issues. I'm new to haskell, and I'm having a hard time understanding how to deal with memory leaks. I've been playing with some network server examples and I noticed with each new connection, the memory footprint increases by about 7k However, the leaks don't seem to have anything to do with the networking code. Actually I get a huge leak just from using using 'forever'. import Control.Monad import System.IO main = forever $ putStrLn hi When I run it for a few seconds with profiling... total time =0.36 secs (18 ticks @ 20 ms) total alloc = 54,423,396 bytes (excludes profiling overheads) Can this be right? I don't think there should be a space leak in the code you posted. On my mac, OS X 10.5.6, GHC version 6.8.3, it appears to run in constant space with or without optimisation. GHCi seems to gobble a little bit of memory (but that could be incidental). My terminal application does gobble memory for a while (and then frees it), but that is presumably because it is hammering the buffer (and it nearly sets my lap on fire when running). Perhaps you could post more details about how it is compiled, and what versions of things are being used. How are you detecting the leak (via top?). Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Monad explanation
On 10/02/2009, at 4:45 AM, Tillmann Rendel wrote: A Haskell runtime system is a somewhat vaguely specified interpreter for (IO a) values. While it would be nice to a have a better specification of that interpreter, it is not part of the semantics of the language Haskell. While not official, there is always Tackling the awkward squad: monadic input/output, concurrency, exceptions, and foreign-language calls in Haskell by Simon Peyton Jones. https://research.microsoft.com/en-us/um/people/simonpj/papers/marktoberdorf/ Another nice aspect of that paper is that it discusses some of the difficulties in coming up with a denotation for values of type IO a, see particularly section 3.1. It suggests a set of event traces as a possible way forward: type IO a = (a, Set Trace) type Trace = [Event] data Event = PutChar Char | GetChar Char | ... (Incidentally, this view is quite useful in a declarative debugger, which emphasises the denotational semantics of a program.) In the end the paper goes for an operational semantics, on the grounds that the author finds it simpler and easier to understand. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Question re: denotational semantics in SPJ's Implementation of FPLs book
On 01/02/2009, at 8:49 PM, Devin Mullins wrote: I'm reading SPJ's The Implementation of Functional Programming Languages, and on page 32, it defines the multiplication operator in its extended lambda calculus as: Eval[[ * ]] a b = a x b Eval[[ * ]] _|_ b = _|_ Eval[[ * ]] a _|_ = _|_ Is that complete? What are the denotational semantics of * applied to things not in the domain of the multiplication operator x, such as TRUE (in the extended lambda defined by this book) and functions (in normal lambda calc)? Do these things just eval to bottom? Or is this just to be ignored, since the extended calculus will only be applied to properly typed expressions in the context of this book? Hi Devin, I don't think that the section of the book in question is intended to be rigorous. (page 30. this account is greatly simplified). As noted in the text, the domain of values produced by Eval is not specified, so it is hard to be precise (though there is a reference to Scott's Domain Theory). However, I agree with you that the equation for multiplication looks under-specified. Obviously any reasonable domain will include (non- bottom) values on which multiplication is not defined. Without any explicit quantification, it is hard to say what values 'a' and 'b' range over. It is possible that they range over the entire domain, or some proper subset. The text also assumes we all agree on the definition of the 'x' (multiplication) function. Though it ought to be specified in a more rigorous exposition. As you suggest, it may be possible to work around this by imposing some kind of typing restriction to the language, though this does not appear to be stated in this particular section of the book. Perhaps this is mentioned elsewhere; I have not checked. Another possible solution is to sweep it all into the definition of the 'x' function. But if that were so, why bother handling bottom explicitly, but not the other possible cases? I guess the best we can say is that the meaning of multiplication applied to non-bottom non-numeric arguments is not defined (in this section of the text). Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Compilers
On 27/11/2008, at 8:35 AM, Andrew Coppin wrote: Jake McArthur wrote: Andrew Coppin wrote: Don Stewart wrote: Noteworthy, * lhc-20081121: “Lhc Haskell Compiler” Interesting. I can't find out any information about this... It is a fork of the JHC compiler, which should be easier to look up. There is also Hugs, as you mentioned. In addition, you may want to look at YHC and NHC. Yeah, the implementations page on the Wiki basically says that there's GHC and Hugs, and there's also these things called YHC, NHC and JHC. All the documentation I've read makes these latter compilers sound highly experimental and unusable. (I don't recall specifically which of them, but I remember hearing it can't even compile the Prelude yet.) They seem like small projects which are probably interesting to hack with, but not much use if you're trying to produce production-grade compiled code to give to a customer... OTOH, I haven't ever attempted to *use* any of these compilers. I only read about them... Don't forget hbc. There's plenty of information about all the compilers in the history of haskell paper, including a timeline: http://research.microsoft.com/users/simonpj/papers/history-of-haskell/index.htm Cheers, Bernie.___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Garbage collection as a dual of laziness?
On 23/11/2008, at 9:18 PM, Robin Green wrote: It occurs to me that garbage collection can be seen as some kind of dual of laziness. Laziness means deferring the creation of values until later in the future (or even never). A program optimisation might also have the same effect (of avoiding a computation/work). Also note: if you want to take an extreme position, then most (all?) programming languages can be seen to be somewhat lazy, since computations are goal directed, and therefore functions (or procedures) are only evaluated on points in their domain which are needed by the rest of the computation (consider a function defined on an infinite domain). However, that is not the traditional definition of lazy. Garbage collection means eagerly destroying data created in the past, and reclaiming the memory used by it, before some other event which would do so (in most garbage-collected languages, I think process destruction is the only other thing that frees memory, leaving aside foreign functions). Don't forget the stack. Besides, I'm not sure how eager most GCs are. If you don't have enough laziness (e.g. because of strict pattern matching on tuples) your program might do unnecesssary work (time wastage); if you don't have enough garbage collection (e.g. because a value will never be accessed again but is still referred to from something live), your program might leak memory (space wastage). Of course, space wastage can lead to time wastage, and vice-versa. Can this intuition be made any more formal? Is it merely of pedagogical use, or does anything interesting follow from it? If you are looking for interesting (and perhaps unconventional) musings on GC, then you might enjoy this paper: Thermodynamics and Garbage Collection, Henry G Baker. http://home.pipeline.com/~hbaker1/ThermoGC.html Maybe that will spark some new ideas. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] the ghc reflection thing?
Hi Vasili, Perhaps you are looking for GHC as a library: http://www.haskell.org/haskellwiki/GHC/As_a_library Cheers, Bernie. On 13/10/2008, at 2:26 PM, Galchin, Vasili wrote: hello, Several months ago I saw on the wiki or maybe it was a discussion on mechanism to get the ghc compiler's state. I can't remember enough to ask even well. I know there is a wiki entry. Sorry ... I can only hint at this ... ?? Thanks, Vasili ___ 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] Laziness leaks
On 04/06/2008, at 10:12 AM, Ronald Guida wrote: I would ask, how do I examine the evaluation order of my code, but the answer is already available: use a debugger. Haskell already has debugging tools that do exactly what I need. (http://www.haskell.org/haskellwiki/Debugging) In particular, HOOD looks extremely interesting. I would recommend the GHCi debugger for looking at the evaluation order of code. Single stepping can be very illuminating. Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] monadic debugging
On 16/04/2008, at 10:16 AM, Thomas Davie wrote: On 16 Apr 2008, at 00:04, Bulat Ziganshin wrote: Hello Vasili, Wednesday, April 16, 2008, 2:53:32 AM, you wrote: I have an Linux executable of my Haskell library and test case. I see there are several debuggers, e.g. Buddha, Hat, etc. Which debugger is currently preferred for monadic (imperative) code? Thanks. i use print mainly :) btw, there is also built-in ghci debugger, i suspect that it's closest one to the usual debuggers and most useful one for imperative code (but i never tried anything, so don't trust me :) Having worked lots on Hat, and studied all (I hope or I've got a hole in my research) of the debuggers out there, I'd have to say that debugging monadic code is still very much an unsolved problem. Putting print statements in is probably your best option. You may want to try hat-delta, or buddha's functional mapping mode -- both of them should be capable of reducing sequences of monadic operations to a single operation and a function map. I agree with Tom, that debugging monadic code is an open problem. From a practical level, I doubt buddha is going to be much help, because it has bit rotted, and is unsupported. Hat allows you to debug the program in different ways, and it gives you reduction traces, which can often be useful, so you may get some traction there. But I would try the ghci debugger first. Be warned: it forces you to be aware of lazy evaluation, which can be quite hard to understand, so you need a bit of practice with it. As for debugging monads, it depends on the complexity of the monad. If you are using standard monads (and that usually means transformers) then a lot of the plumbing will be invisible in the debugger, because breakpoints and stepping don't work in the libraries (you would have to copy the library code into your workspace, if you wanted to see the underlying monad code in action). I've successfully found bugs in code using the ghci debugger, where the code used a continuation transformer, over a state transformer, over an IO monad. It was easy enough to follow because I wasn't forced to see the plumbing underneath. In particular I wasn't forced to see the continuation, or the state, which really helps. Of, course, if I did want to see those things then I would have been in trouble. One question that has been in my head for a while now is that if you used the Unimo way to build monads, maybe they are easier to debug? The Unimo style is intentionally operational, and that may be a better fit to debugging, especially in the ghci debugger, which requires an operational way of thinking. Here's a link to the Unimo paper: http://web.cecs.pdx.edu/~cklin/ papers/unimo-143.pdf If you do make some progress with any of the debugging tools it would be very useful to hear how it went. We get very little feedback on successful debugging endeavours where tools were involved (maybe because the tools aren't helpful, it is hard to say). Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] retrospective on 'seq' - 'unsafeSeq' ?
On 14/04/2008, at 9:22 PM, pepe wrote: Alternatively, with some effort one can create a type-agnostic version of unsafeShow, which would print things in a more raw format, but probably sufficient anyway. I don't think it would work with unboxed values in general, although it can be made to work with the standard types. Actually, Bernie Pope wrote some code for this [1, see GHC Heap Printing library] some time ago, although with the new primitives and changes made for :print in GHC 6.8, this would be way easier nowadays. No need to use StablePtrs, no need to turn on profiling, and above all, no C needed :) And as a bonus this would work out of GHCi too. Yes, an almost-universal printer would be possible now that we have data constructor names attached to info tables. I'd sort of planned to do that, and then got side-tracked. Of course, this won't be able to print functions in any helpful way, unless we attach source code information to functions as well (which may be worth doing anyway?). One thing to watch out for is cycles in data structures. You may not want to try to detect them, but at least you should be lazy in generating the printable representation of values. And then there is the question of whether to evaluate thunks during printing. Perhaps such a printer would also be useful for the GHCi debugger in cases where it can't infer the right types? Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] help understanding pj-lester-book
On 13/04/2008, at 12:09 AM, minh thu wrote: Hi! I don't understand something in there : pj-lester-book : Implementing functional languages: a tutorial by Simon Peyton Jones and David Lester, available at http://research.microsoft.com/~simonpj/Papers/pj- lester-book/ eval/apply : Making a Fast Curry: Push/Enter vs. Eval/Apply for Higher-order Languages by Simon Marlow and Simon Peyton Jones, available at http://www.haskell.org/~simonmar/papers/ The introduction in eval/apply states the arity of a function and the number of arguments in a call can match or differs (and it should be dealt with). In pj-lester-book (bottom of page 46 and top of page 47), it is stated that if the program has been type-cheched, the underflow check is unnecessary. When continuing to the G-machine then to the TIM-machine chapters, I haven't found discussion of an arity-mismatch. What am I missing ? Hi Minh, If I understand the pj-lester book properly, what they are saying is: if you have an expression which is a function application, and type checking has determined that the result of the expression is _not a function_, then you can be sure that the outermost redex in the expression has enough arguments. If it is not a function then it cannot be a partial application. Thus you don't have to do the underflow check for that redex. You either have a saturated application or an over saturated application, but either way there is guaranteed to be enough arguments. Unfortunately, instead of saying not a function, they say a number, or say, a list. If you are writing a compiler, and you are about to generate code for a function application, and the type checker tells you the result is not a function, then you can omit generating the code for the underflow test - which is a performance gain. I believe the eval/apply paper is referring to the general case of a function application, where you don't always know that the result is not a function. For example, suppose you are generating code for the map function. In the body of map you have: case list of Nil - Nil Cons x xs - Cons (f x) (map f xs) In the application (f x), you can't statically determine if it is saturated or not, because it depends on the arity of the function subsituted for f, which is of course unknown. (You could turn it into a known by doing an arity-based specialisation of the program, but that is a fairly heavyweight option, which would require multiple versions of functions like map.) Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] coerce (safe!)
On 03/03/2008, at 8:30 AM, Luke Palmer wrote: 2008/3/2 Roman Cheplyaka [EMAIL PROTECTED]: * Krzysztof Skrzętnicki [EMAIL PROTECTED] [2008-03-02 01:21:42 +0100] Well, it is simply coerce :: a - b coerce _ = undefined so coerce is simply empty function. But still, it is possible to write a function of type (a-b). Well, possibly I didn't write anything particularly new, but please excuse me for I'm still in sort of a shock after I've discovered it. Also there's nice possibility of defining Maybe a without ADT. type Maybe a = (a, Bool) just x = (x, True) nothing = (undefined, False) That's a hack. This is my favorite: type Maybe a = forall b. (a - b) - b - b just x = \j n - j x nothing = \j n - n For something slightly different, I've always enjoyed lists (or integer indexed structures) as functions: type List a = Integer - Maybe a You've got to watch out for non-contiguous lists. It's a good challenge to write head, tail, nil and cons for this type. Then write conversions to/ from normal lists. Bernie.___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Announce: Melbourne Functional Programming Union
Hello Haskellers, After a few years hiatus, I'm pleased to announce that the Melbourne Functional Programming Union (FPU) is back. What is the FPU? It is a group of people who are interested in all things functional programming. We hold regular informal talks, and have friendly discussions afterwards. We are situated at the University of Melbourne (Australia), but the Union is open to all comers. Obviously it helps if you live near this part of the World. To give you an idea of the kinds of things we talk about, here is a list of our most recent topics: - the GHCi debugger - Arrows for parser combinators - a curious stack overflow in Haskell - a demonstration of Coq - deriving monads from vague ideas in several easy steps (this coming Friday) Here is our old outdated web page for historical reference: http://www.cs.mu.oz.au/fpu/ A new page is under construction. At the moment, talks are held on Fridays, 1-2pm, in the ICT Building at Melbourne Uni. Contact Bernie Pope if you are interested in participating in the FPU. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Somewhat random history question - chicken and egg
On 12/11/2007, at 4:32 AM, Neil Mitchell wrote: Hi bear no resemblence to any machine-level constructs, and it seems unthinkable that you could possibly write such a compiler in anything but Haskell itself. Hugs is written in C. Really? :-. Really :-) (Seriously, how big is Hugs? It must be quite large...) 56111 lines, with an additional 5917 for the WinHugs bit. If I remember correctly, the early versions of the Clean compiler were written in C. Then at some stage they re-wrote it in Clean. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Somewhat random history question - chicken and egg
On 12/11/2007, at 9:26 AM, [EMAIL PROTECTED] wrote: But... tell me please, ANYONE, who takes part in this inspiring exchange: How many COBOL programs have you written in your life? How many programs in Cobol have you actually SEEN? I saw a lot of COBOL when I worked for a stock broking company. I was a lowly main frame printer operator, so I didn't have anything to do with the code except print it out. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Somewhat random history question - chicken and egg
On 12/11/2007, at 4:08 PM, Michael Vanier wrote: Bernie Pope wrote: If I remember correctly, the early versions of the Clean compiler were written in C. Then at some stage they re-wrote it in Clean. You could say they cleaned it up. It was a dirty job, but now it is self cleaning. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] About Fibonacci again...
You can make it pretty short too, if you allow yourself fix: rs=1:fix(\f p n-n++f(p++n)p)[1][0] I came up with this on the train home, but then I realised it was the same as your solution :) On 08/11/2007, at 12:57 PM, Alfonso Acosta wrote: How about this, infiniteRS :: [Int] infiniteRS = let acum a1 a2 = a2 ++ acum (a1++a2) a1 in 1 : acum [1] [0] it certainly fits in one line but it's not really elegant ___ 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] About Fibonacci again...
Is this what you are looking for: mrs = [0] : [1] : zipWith (++) (tail mrs) mrs then you can get the one you want with: mrs !! index given a suitable value for index It seems I didn't read the question carefully - you want the infinite list. You can recover the solution from mrs if you want, but its not very pretty: infrs = [(mrs !! n) !! (n-1) | n - [1..]] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Why can't Haskell be faster?
On 01/11/2007, at 2:37 AM, Neil Mitchell wrote: My guess is that the native code generator in Clean beats GHC, which wouldn't be too surprising as GHC is currently rewriting its CPS and Register Allocator to produce better native code. I discussed this with Rinus Plasmeijer (chief designer of Clean) a couple of years ago, and if I remember correctly, he said that the native code generator in Clean was very good, and a significant reason why Clean produces (relatively) fast executables. I think he said that they had an assembly programming guru on their team. (Apologies to Rinus if I am mis-remembering the conversation). At the time I was impressed by how fast Clean could recompile itself. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Function Types
I have implemented a reasonably simple language and interpreter called baskell. The language is essentially a very small subset of Haskell. It was designed to show students how type checking works. You can find it here: http://www.cs.mu.oz.au/~bjpop/code.html Cheers, Bernie. On 23/10/2007, at 11:31 AM, PR Stanley wrote: Hi What are the rules for calculating function types? Is there a set procedure ? Thanks, Paul ___ 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] will the real quicksort please stand up? (or: sorting a million element list)
On 23/10/2007, at 8:09 AM, Thomas Hartman wrote: (Prelude sort, which I think is mergesort, just blew the stack.) GHC uses a bottom up merge sort these days. It starts off by creating a list of singletons, then it repeatedly merges adjacent pairs of lists until there is only one list left. I was teaching sorting to my first year students, and I also bumped into the stack overflow at one million elements, using GHC's merge sort. I have been meaning to look into the cause of this, but my suspicion is that strictness (or lack thereof) might be an issue. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New slogan for haskell.org
On 08/10/2007, at 8:54 PM, Thomas Conway wrote: I just had a conversation today that seems relevant to this thread. I was chatting with a friend who is working in the academic sector, and I was observing that Melbourne Uni (my old school), is switching in the new year from teaching Haskell as a first language, to teaching Python. I was dismayed, but not surprised. Anyway, I was talking about this with my friend said that he understood the main reason for the change was that students were not being switched on or excited learning Haskell as they used to be learning C. He put it down to the fact that in C, you are more obviously making the computer do stuff, and that Haskell is sufficiently high level and abstract that beginner programmers don't get that thrill of feeling like you're making the computer work for you. I must say, I get that! but at the same time, of course, the high level abstraction is exactly what *we* love about Haskell. Presently, at Melbourne Uni we teach Haskell as a second language after C. In their first year, my class has two and a half semesters of C, followed by half a semester of Haskell. There is a parallel stream, where the split between C and Haskell is 50-50 (the so-called advanced stream). My general feeling is that students are responding well to Haskell, and it is a welcome break from segfault-land. However, it is hard for them to evaluate the merits of pure functional programming, when they've seen so little of the alternatives. We get the occasional early convert, but most of the students remain sceptical (and rightly so, I think). Also, first year students spend all their time concentrating on programming in the small, which means that they don't see _as much_ benefit from the kinds of abstraction that Haskell offers over C. In my opinion, the move to Python is motivated by other concerns, which come about because the undergraduate program is going through a radical change across the whole university. There is a corresponding shift in our first-year demographic, which motivates a change in the focus of the first year program. I'm not so concerned about losing Haskell in the first year (especially to Python). Personally, I would like to see functional/declarative programming gain more prominence later in the curriculum - at the point where students are at a higher level of programming sophistication, and are more likely to appreciate the material. I have spent a reasonable amount of time extolling the virtues of functional programming to first year students over the years. The one thing which seems to get the best response, and makes them sit up and listen, is when I tell them that GHC is maintained largely by people who work at MS research! Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] isWHNF :: a - IO Bool ?
Hi Tristan, I've implemented it for earlier versions of GHC, by calling some C code which then peeps at the internal representation of a value. From memory, I needed to pass a stable pointer to the value to the C code, so that it can be polymorphic, without having to make it a primitive in GHC. Have a look at the reify code on this page: http://www.cs.mu.oz.au/ ~bjpop/code.html - its more than what you want, but you can trim it down easily. Let me know if you get stuck. The internal representation in GHC tends to change between releases, so it might need a bit of polishing up. Cheers, Bernie. On 27/09/2007, at 10:07 PM, Tristan Allwood wrote: Hi, Does anyone know if there is a function that tells you if a haskell value has been forced or not? e.g. isWHNF :: a - IO Bool let x = (map succ [0..]) in do putStrLn . show (isWHNF x)-- False putStrLn . show . head $ x putStrLn . show (isWHNF x)-- True putStrLn . show (isWHNF (Just undefined)) -- True If not, would it be hard/easy/possible to implement on-top-of or using GHC? I'm happy (if it's possible) to have a stab at implementing it myself, so any pointers to right directions would be helpful. I'm thinking it could be useful to allow creation of sparse-check [1] like libraries without needing a separate logic encoding, or things along those lines / in that area. Cheers, Tris [1] http://www-users.cs.york.ac.uk/~mfn/sparsecheck/index.html#lim -- Tristan Allwood PhD Student Department of Computing Imperial College London ___ 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] Perfect example
That's a tough one, If I want a small example to show to people I usually use zipWith. It is higher-order and lazy, and I include a discussion of lists as loops, which means zipWith is a loop combiner. When my audience is C programmers I ask them to implement it in C, which is always amusing. As an added bonus it has a lovely type signature, which can be used as a lead-in to a discussion on types. If I want a more realistic example, then I usually show people a piece of haskell gtk code, again comparing it to C or whatever language the audience knows. The Haskell gtk code tends to read very nicely, and it is type safe. It also emphasises the fact that Haskell is not only able to to real things, but able to do them really well. I doubt either are perfect, but maybe they will inspire you to dream up something which suits your needs. Cheers, Bernie. On 03/08/2007, at 5:02 AM, Jon Harrop wrote: Any suggestions for a perfect example that uniquely demonstrates the benefits of the Haskell language compared to other languages? -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. OCaml for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/?e ___ 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] Very freaky
On 11/07/2007, at 9:02 AM, Brandon S. Allbery KF8NH wrote: On Jul 10, 2007, at 15:59 , Andrew Coppin wrote: I find myself wondering... A polymorphic type signature such as (a - b) - a - b says given that a implies b and a is true, b is true. But what does, say, Maybe x - x say? Actually, because parentheses naturally group to the right in type expressions in Haskell, (a - b) - a - b is in fact (a - b) - (a - b), a tautology. (This should be reasonably obvious.) Maybe x - x is a risky proposition, in a number of senses. :) It asserts that given something that may or may not be true, it is in fact guaranteed to be true. In the Haskell library this is the fromJust function, which throws an exception if x is *not* true (since it clearly can't satisfy the proposition). This reminds me of a little joke that Conor McBride had in a post a while ago: unJust :: Maybe wmd - wmd Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] folds with escapes
On 05/07/2007, at 10:08 AM, Michael Vanier wrote: Can you do dropWhile in terms of foldr? I don't see how. Mike I considered that very question in an article I wrote for the Monad.Reader magazine: http://www.haskell.org/sitewiki/images/1/14/TMR-Issue6.pdf If you are really keen, you might want to try altering the working backwards with tuples version into one which is properly lazy (many people who read the paper pointed out the omission). Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] Type checking with Haskell
Hi Joel, You may like to check out my mini-interpreter called (cheekily) baskell: http://www.cs.mu.oz.au/~bjpop/code.html It has type inference, and it is pretty straightforward. I wrote it for teaching purposes. First, I pass over the AST and generate a set of typing constraints. They are just equality constraints. Then I solve the constraints. Couldn't be much simpler than that. Mind you, the input language is pretty minimal (no type classes etcetera). Cheers, Bernie. -Original Message- From: [EMAIL PROTECTED] [mailto:haskell-cafe- [EMAIL PROTECTED] On Behalf Of Joel Reymont Sent: 12 April 2007 13:04 To: Haskell Cafe Subject: [Haskell-cafe] Type checking with Haskell Folks, The ghc/compiler/typecheck directory holds a rather large body of code and quick browsing through did not produce any insight. How do you implement type checking in haskell? Assume I have an Expr type with a constructor per type and functions can take lists of expressions. Do I create a function taking an Expr, pattern-matching on appropriate constructor and returning True on a match and False otherwise? Thanks, Joel -- http://wagerlabs.com/ ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] Application of iterate
It is :- my_sqrt t = last (take 20 (iterate (\n - n/2 + t/(2 * n)) t)) It is a bit crude though. 20 iterations is a bit arbitrary. I don't suppose there is a easy way to iterate until the results stop changing. Here's something for you to play with: my_sqrt t = fix (\n - n/2 + t/(2 * n)) t fix :: (Double - Double) - Double - Double fix f x | x == fx = x | otherwise = f (fix f fx) where fx = f x My numerical analysis is a bit on the dodgy side, but you probably don't want to use == to test for convergence. Maybe you can find a nice way to write fix using some prelude functions? Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] Newbie: Is'type' synonym hiding two much?
Dmitri writes: Now, in the 17.5 section of a book one may see the following declarations: succeed :: b - Parse a b *Before looking at 'succeed' function definition* one may think that 'succeed' is a function of *one* argument of type 'b' that returns object of type 'Parse a b'. Yet, function definition given in the book is: succeed val inp = [(val, inp)] I may not answer all your questions, but I will make a few observations. I think the main issue here is that from the user's perspective the Parse type should be (or is) abstract. Users of Parse should not really have to know how it is internally implemented. But implementors of Parse will (of course) be concerned with those details. How you look at the Parse type depends on which camp you belong to: implementor or user. The definition of succeed is the concern of the implementor, since it is a primitive of the Parse library. So an implementor will know that Parse is internally a function type. It may be nicer if they wrote: succeed val = \inp - [(val, inp)] But that is a matter of style. If the library is written correctly, the user should not care about what the Parse synonym unfolds to. They will mostly care about how to build atomic parsers, how to combine parsers together to form new ones, and how to run parsers. It is very liberating for the user if they don't have to know what goes on inside the Parse type. Perhaps the textbook focuses mostly on the implementor's point of view, where you are forced to be aware of the gory details. Haskell uses abstract types in other places, most notably the IO type. There is quite a bit of complexity hidden in that type, but its user interface is relatively simple. If Haskell has taught me anything, it's that abstraction rules! Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] Partial Evaluation
I think you are confusing partial application and partial evaluation. Though they are conceptually related. The former is what happens when you apply a function of arity N to M arguments, where M N. In Haskell the partially applied function is suspended, pending the rest of its arguments. The latter is a way of taking a program and _some_ of its inputs and transforming/compiling/specialising it into a residual program, by evaluating as much as possible, given the inputs you have available. An interesting example of partial evaluation is to take an interpreter for a language and a sample source program, and partially evaluate the interpreter with respect to the program. The result is a version of the interpreter which acts effectively as a compiled version of the source program. In Hudak's paper(s), if I remember correctly, they have an interpreter for a functional language (in continuation passing style), which is parameterised by a monitor function. I think they are trying to argue that you can make the system more efficient if you partially evaluate the interpreter with respect to a particular monitor. It is better than running the interpreter directly. The problem is that I think it is hard to scale to a language like Haskell, though there might have been advances that I am not familiar with. Wikipedia has an entry on partial evaluation which is somewhat useful, though you should probably follow the references at the bottom. Cheers, Bernie. -Original Message- From: [EMAIL PROTECTED] [mailto:haskell-cafe- [EMAIL PROTECTED] On Behalf Of jim burton Sent: 21 March 2007 18:47 To: haskell-cafe@haskell.org Subject: [Haskell-cafe] Partial Evaluation I am reading Hudak's paper Modular Domain Specific Languages and Tools [1] and am confused by his use of the term `Partial Evaluation'. I understand it to mean supplying some but not all arguments to a function, e.g. (+3) but it seems to mean something else too. This is in the context of optimising performance: We have used existing partial evaluation techniques to do this...Unfortunately, there does not currently exist a suitable, easy-to-use partial evaluator for Haskell. Our approach was to convert the Haskell program to Scheme, partially evaluate the Scheme program, and then translate back into Haskell. What does P.E, mean here? Thanks, [1] Available http://wiki.ittc.ku.edu/lambda/Image:Hudak- Modular_Domain_Specific_Languages_and_Tools.pdf ___ 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] Strange memory consumption problems in something that should be tail-recursive
Duncan Coutts wrote: On Tue, 2007-02-13 at 15:27 -0500, Jefferson Heard wrote: Hi, I am running the following code against a 210 MB file in an attempt to determine whether I should use alex or whether, since my needs are very performance oriented, I should write a lexer of my own. I thought that everything I'd written here was tail-recursive Isn't that exactly the problem - that it's tail recursive? You do not want it to be tail recursive since then it must consume the whole input before producing any output. You want it to be as lazy as possible so that it can start producing tokens as soon as possible without having to consume everything. Duncan is right, and I will just elaborate a little bit. Consider the pass1 function: pass1 :: String - String - String pass1 left [] = left pass1 left ('':right) = pass1 left (stripTagOrComment right) pass1 left (' ':right) = pass1 left right pass1 left (c:right) | Set.member c punct = pass1 (' ':c:' ':left) right | otherwise = pass1 (c:left) right It accumulates its result in the left parameter. So it chomps down the right string building up a bigger and bigger solution until it reaches the base case, and hands the solution over to the calling function. The calling function gets nothing back from pass1 until pass1 has processed the whole input. And that accumulated solution in left could grow quite big. A much better approach would be: pass1 :: String - String pass1 [] = [] pass1 ('':right) = pass1 (stripTagOrComment right) pass1 (' ':right) = pass1 right pass1 (c:right) | Set.member c punct = ' ':c:' ': pass1 right | otherwise = c : pass1 right This way, pass1 will be producing output as early as possible, which can be consumed earlier by the calling function. Lazy evaluation gives you a kind of co-routining between producers and consumers, but you have to write good producers and good consumers. You should also write the pass2 in this style as well. Your memory consumption should drop to something very small. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Strange memory consumption problems in something that should be tail-recursive
Creighton Hogg wrote: On 2/13/07, *Duncan Coutts* [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: On Tue, 2007-02-13 at 15:27 -0500, Jefferson Heard wrote: Hi, I am running the following code against a 210 MB file in an attempt to determine whether I should use alex or whether, since my needs are very performance oriented, I should write a lexer of my own. I thought that everything I'd written here was tail-recursive Isn't that exactly the problem - that it's tail recursive? You do not want it to be tail recursive since then it must consume the whole input before producing any output. You want it to be as lazy as possible so that it can start producing tokens as soon as possible without having to consume everything. This may be silly of me, but I feel like this is an important point: so you're saying that tail recursion, without strictness, doesn't run in constant space? It is an important point, and a classic space bug (see foldl in the Prelude). It it not the fault of tail recursion per se, in fact tail recursion is often important in Haskell too. So for example in the case of, facTail 1 n' = n' facTail n n' = facTail (n-1) (n*n') The problem with this example is that it will build up an expression of the form: (n1 * n2 * n3 .) in the second argument. It's size will be proportional to the number of recursive calls made (n). You'll just be building a bunch of unevaluated thunks until you hit the termination condition? To fix it you will want the function to evaluate its second argument eagerly: facTail n n' = facTail (n-1) $! (n*n') Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Foldr tutorial, Inspired by Getting a Fix from a Fold
Nicolas Frisby wrote: Guess this is a tricky choice for a foldr intro, since it requires a paramorphism (see bananas lenses wires etc.) para :: (a - [a] - b - b) - b - [a] - b para f e [] = e para f e (x:xs) = f x xs (para f e xs) -- note that the original tail of the list (i.e. xs and not xs') is used in the else-branch dropWhile' p = para (\x xs xs' - if p x then xs' else (x:xs)) [] Actually, several people tried to use para, but of course it is not in the spirit of the challenge :) Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Foldr tutorial, Inspired by Getting a Fix from a Fold
Lennart Augustsson wrote: Sure, but we also have para f e xs = snd $ foldr (\ x ~(xs, y) - (x:xs, f x xs y)) ([], e) xs Nice one. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANNOUNCE: The Monad.Reader - Issue 6
David House wrote: It was a great article though, seeing fix's definition in terms of foldr was one of those mind-bending moments which makes learning Haskell what it is. It's nice to see so many new solutions posted in the cafe. The great thing about Haskell is that it keeps on giving :) Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Stupid newbie question
On 06/01/2007, at 12:58 PM, Jeremy Shaw wrote: Because you never demand the value of any element in the list, Haskell never bothers to calculate it. So you have a list that looks like: [ i, i - 1, (i - 1) - 1, ((i - 1) - 1 - 1), .. ] So, by the time you get up to some big numbers, you have built up a very large thunk. For some reason this is causing a stack overflow. Right. And to clarify, the reason is that the thunk is one big chain of applications of (-). Imagine what will happen when the topmost application is evaluated. Because (-) is strict in its arguments they must be evaluated before the minus can proceed. So the left and right arguments are evaluated. The left argument is itself an application of (-) and so on. The whole left branch eventually gets pushed onto the stack. Because the left branch is so long, the stack eventually overflows. This is one of those examples where optimistic evaluation would be a win. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Newbie question
On 30/12/2006, at 1:33 PM, Pieter Laeremans wrote: Hi, I'm reading the Haskell school of expression by Paul Hudok. Great book. Hudak. And I concur, a great book. However I would like some feedback about a solution to an exercise The problem is quite simple : define f1 and f2 (using higher order functions ) such that f1 (f2 (*) [1..4]) 5 = [5,10,15,20] I have come up with the following solution : f2 :: (a-b)-[a] - [b] f2 f xs = map f xs That's fine, but what you are really saying is that f2 is the same as map, so you can make that connection more obvious like this: f2 = map f1 fs a = map (applyOp a) fs applyOp b f = f b That's also fine. You can avoid applyOp in numerous ways. One way is to use the function called $ from the Prelude; it implements function application. f $ x = f x So you could write: f1 fs a = map ($ a) fs Of course, there are also other ways of implementing f1 and f2 such that you get the desired result, but the map approach seems to be what the question was angling for. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Efficient way to break up a lazy bytestring
On 30/12/2006, at 1:32 PM, Matthew Brecknell wrote: In my (limited) Haskell experience, I was continually being surprised by inexplicable stack blowouts until I spent a little time doing some focussed experiments, mainly involving folds over large lists. If you haven't done that, I would recommend it. I think this is very good advice. Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell Side Effect
I thought this email might be interesting for the Spanish speaking part of the Haskell community, so I have written it in Spanish for them: (Since learning Haskell, I can now count in Spanish! See: one in Spanish, two in Spanish, three in Spanish, four in Spanish.. -- Ashley Yakeley) in Spanish ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Reversing a string of words: C# v Perl V Ruby v Haskell
On 12/12/2006, at 11:13 AM, Brandon S. Allbery KF8NH wrote: On Dec 11, 2006, at 18:48 , Steve Downey wrote: the typical good solution to this problem in c or c++ is to use a string reverse function on the entire buffer, then re-reverse each word. this leaves multiple spaces correctly embedded in the larger string. that approach, of course, won't work in haskell, since it relies on updates. but if the challenge includes transforming one two three four into four three two one, how could this be done? Off the top of my head, the C++ one translates to: *Main concatMap reverse . groupBy (\l r - (l == ' ') == (r == ' ')) . reverse $ one two three four four three two one There are almost certainly more idiomatic ways to do it, but I'm still learning. Perhaps something like this is close to the algorithm you describe: import Data.Char (isSpace) rev :: String - String rev str = revAcc (reverse str) [] where revAcc [] acc = acc revAcc (x:xs) acc | isSpace x = acc ++ (x : revAcc xs []) | otherwise = revAcc xs (x : acc) Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Beginner: IORef constructor?
On 05/12/2006, at 1:00 PM, Benjamin Franksen wrote: Bernie Pope wrote: If you want a global variable then you can use something like: import System.IO.Unsafe (unsafePerformIO) global = unsafePerformIO (newIORef []) But this is often regarded as bad programming style (depends who you talk to). Besides, isn't this example /really/ unsafe? I thought, at least the IORef has to be monomorphic or else type safety is lost? Perhaps your question is rhetorical, but in case it is not, then yes, we ought to make it a monomorphic type. This little example seg-faults on my mac, and no doubt on other machines as well: import System.IO.Unsafe (unsafePerformIO) import Data.IORef global = unsafePerformIO (newIORef []) main = do modifyIORef global (id :) x - readIORef global print ((head x + 1) :: Int) It writes the identity function onto the front of the global variable, and then reads it back as an int, and tries to do addition on it. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to get subset of a list?
On 01/12/2006, at 12:47 PM, Huazhi (Hank) Gong wrote: Like given a string list s=This is the string I want to test, I want to get the substring. In ruby or other language, it's simple like s [2..10], but how to do it in Haskell? If your indices are in ascending order, and unique, then something like this might do the trick: els1 indexes list = els' (zip [0..] list) indexes where els' [] _ = [] els' _ [] = [] els' ((j,x):xs) indexes@(i:is) | i == j = x : els' xs is | otherwise = els' xs indexes Of course this is a right fold, so you ought to be able to use foldr. Here's an attempt: els2 indexes list = foldr comb undefined [0..] list indexes where comb _ _ [] _ = [] comb _ _ _ [] = [] comb j rec (x:xs) indexes@(i:is) | j == i = x : rec xs is | otherwise = rec xs indexes Bonus marks for figuring out why I used undefined. Warning: this is largely untested code. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Beginner: IORef constructor?
On 01/12/2006, at 6:08 PM, TJ wrote: First of all, sorry if this is a really silly question, but I couldn't figure it out from experimenting in GHCi and from the GHC libraries documentation (or Google). Is there an IORef consturctor? Or is it just internal to the Data.IORef module? I want a global variable, so I did the following: -- module VirtualWorld where import Data.IORef theWorld = IORef [] -- This will be writeIORef'ed with a populated list as the user modifies the world. - It doesn't work. GHCi says that the IORef constructor is not in scope. I did a :module Data.IORef and then IORef [] and it still gives me the same error. I'm using GHC 6.6 on Windows. Hi TJ, IORef is an abstract data type, so you cannot refer to its constructors directly. Instead you must use: newIORef :: a - IO (IORef a) which will create an IORef on your behalf. Note that the result is in the IO type, which limits what you can do with it. If you want a global variable then you can use something like: import System.IO.Unsafe (unsafePerformIO) global = unsafePerformIO (newIORef []) But this is often regarded as bad programming style (depends who you talk to). So you should probably avoid this unless it is really necessary (perhaps you could use a state monad instead?) Read the comments about unsafePerformIO on this page: http://www.haskell.org/ghc/docs/latest/html/libraries/base/System- IO-Unsafe.html especially the notes about NOINLINE and -fno-cse Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Very Small Program
On 02/11/2006, at 9:56 PM, [EMAIL PROTECTED] wrote: G'day all. Quoting Bernie Pope [EMAIL PROTECTED]: This is a weird example of a pattern binding, and it is surprising (to me) that the syntax is valid. Maybe. But you wouldn't balk at this: numzeroes xs = sum [ 1 | 0 - xs ] ...even if you wouldn't naturally express it that way. Patterns like this are useful in places other than lets. I'd find it more surprising if lets were treated as a special case. In this case you are defining the function which is bound to the variable called +. Though thanks to n+k patterns, this is well-understood to be a confusing and controversial case. One would normally expect to see at least one variable inside the pattern on the left-hand-side of a pattern binding (otherwise what point would there be to the definition?). If the pattern is demanded (as it may well be in a list comprehension generator, do block generator or a lambda), then it can be very useful. The programmer is asking for an error/empty list/monad fail if the conformality check fails. I agree with what you say. When I said pattern binding, I was using the terminology of the Haskell Report, which means only declarations of the form pat = exp. Generator statements and lambdas are a different story, as you rightly point out. Nonetheless, I still believe that it is surprising for pattern bindings that this syntax is allowed, since there doesn't seem to be any purpose to them. (A cursory glance at the Report suggests that this kind of pattern binding is allowed). Then again, since the bindings are benign, maybe one could argue that it is better to have one less rule in the language definition? Then again, such a declaration could be the sign of a buggy program, and it might be better to give a compile time error. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Very Small Program
On 02/11/2006, at 4:45 PM, Jason Dagit wrote: Hello, I just found it (in ghci and hugs) that this is a valid haskell program: let 0 = 1 in 0 This program evaluates to 0 (to my surprise). This is a weird example of a pattern binding, and it is surprising (to me) that the syntax is valid. Because there are no variables on the left-hand-side of the equation, the definition is much the same as: let _ = 1 in 0 The definition that you give suggests that we evaluate the expression 1, then compare it to 0, and then do nothing with the result of the comparison (because it doesn't bind any variables). Though it is weird, it is rather benign, since pattern bindings are evaluated lazily, and in this case never. I expected something similar to how this works: let { 1 + 1 = 3; 3 + 1 = 7 } in 1 + 1 + 1 Where you get 7. In this case you are defining the function which is bound to the variable called +. So, if the 0 is not used as an identifier (ie, defining a function or name of a value), then why doesn't this count as a parse error? And, why didn't I get to locally redefine it? In the first case the definition is pattern matching against 0, and in the second case the definition is giving the meaning of a variable. While numerical constants are a little bit special in Haskell (they are overloaded), they act much like regular data constructors. When they appear inside a pattern, you are matching against them, rather than re-defining them. One would normally expect to see at least one variable inside the pattern on the left-hand-side of a pattern binding (otherwise what point would there be to the definition?). It may very well be the case that the syntax for Haskell in the Report requires this, but I haven't bothered to check it up. If the Report does require at least one variable in the pattern, it may be the case that hugs and ghc are using a slightly more liberal interpretation of the grammar. Or it could be the case that the Haskell Report does in fact allow such pointless, but benign pattern bindings. Perhaps you could chase this up and see what the Report really does require? Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] instance of String illegal
On 29/09/2006, at 12:44 PM, Donald Bruce Stewart wrote: Alternatively, use -fglasgow-exts :) instance Foo String where mkFoo = id $ ghci -fglasgow-exts A.hs *Main mkFoo foo foo And just to follow up what Don said, this feature of GHC is described here: http://www.haskell.org/ghc/docs/latest/html/users_guide/type- extensions.html ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: [Haskell] MR details (was: Implicit type of numeric constants)
My understanding of the MR is heavily influenced by the work I did on Hatchet, which is based directly on Mark Jones' paper (and code) Typing Haskell in Haskell. I thought I would go back to that paper and see how he defines simple pattern bindings and the MR. I now quote directly from the relevent sections of the paper: He represents function bindings with the Alt type, which is defined on page 9: The representation of function bindings in following sections uses alternatives, represented by values of type Alt : type Alt = ([Pat], Expr) An Alt specifies the left and right hand sides of a function definition. On page 12 he defines what simple means with repsect to the Alt type and the MR: A single implicitly typed binding is described by a pair con- taining the name of the variable and a list of alternatives: type Impl = (Id , [Alt]) The monomorphism restriction is invoked when one or more of the entries in a list of implicitly typed bindings is simple, meaning that it has an alternative with no left-hand side patterns. restricted :: [Impl] - Bool retricted bs = any simple bs where simple (i, alts) = any (null . fst) alts Curiously, his Alt type does not offer any way to represent pattern bindings where the lhs is a non-variable pattern. But he addresses this point later on page 13: In addition to the function bindings that we have seen al- ready, Haskell allows variables to be defined using pattern bindings of the form pat = expr . We do not need to deal di- rectly with such bindings because they are easily translated into the simpler framework used in this paper. For example, a binding: (x,y) = expr can be rewritten as: nv = expr x = fst nv y = snd nv where nv is a new variable. The precise definition of the monomorphism restriction in Haskell makes specific refer- ence to pattern bindings, treating any binding group that includes one as restricted. So, at first glance, it may seem that the definition of restricted binding groups in this pa- per is not quite accurate. However, if we use translations as suggested here, then it turns out to be equivalent: even if the programmer supplies explicit type signatures for x and y in the original program, the translation will still contain an implicitly typed binding for the new variable nv. It is not obvious that this is consistent with the Report; I'll have to think about it more. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: [Haskell] MR details (was: Implicit type of numeric constants)
On 23/09/2006, at 4:33 AM, Christian Sievers wrote: Hello, I don't take my advice to go to haskell-cafe :-) I will take your advice :) The discussion continued outside the mailing list, and now I have two questions myself: 1. Why do the rules of the monomorphism restriction explicitly mention *simple* pattern bindings? Where is the difference, especially as there is a translation to simple pattern bindings? Why should p | a==b = 2 | otherwise = 3 be treated different than p = if a==b then 2 else 3 They are the same (both are simple pattern bindings). The report says in section 4.4.3.2 that the first can be translated into the second. A simple pattern binding is one where the lhs is a variable only. If a pattern binding is not simple, it must have a data constructor on the lhs, therefore it cannot be overloaded. So the (dreaded) MR only applies to simple pattern bindings. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: [Haskell] MR details (was: Implicit type of numeric constants)
On 24/09/2006, at 1:46 AM, Michael Shulman wrote: On 9/23/06, Bernie Pope [EMAIL PROTECTED] wrote: If a pattern binding is not simple, it must have a data constructor on the lhs, therefore it cannot be overloaded. So the (dreaded) MR only applies to simple pattern bindings. I thought it was simple pattern bindings that could be *exempted* from the MR by supplying an explicit type signature, while non-simple pattern bindings are always subject to it. Actually, I realised after I posted my message that what I wrote was dubious. I'm sorry about that, please ignore it. This section from the Report seems to clear things up: In Motivation, section 4.5.5: Rule 1 prevents ambiguity. For example, consider the declaration group [(n,s)] = reads t Recall that reads is a standard function whose type is given by the signature reads :: (Read a) = String - [(a,String)] Without Rule 1, n would be assigned the type forall a. Read a =a and s the type forall a. Read a =String. The latter is an invalid type, because it is inherently ambiguous. It is not possible to determine at what overloading to use s, nor can this be solved by adding a type signature for s. Hence, when non-simple pattern bindings are used (Section 4.4.3.2), the types inferred are always monomorphic in their constrained type variables, irrespective of whether a type signature is provided. In this case, both n and s are monomorphic in a. Sorry for the confusion, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe