Re: [Haskell-cafe] Composition Operator
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Apply parentheses from the right. So: (.) :: (b -> c) -> (a -> b) -> a -> c is the same as: (.) :: (b -> c) -> (a -> b) -> (a -> c) is the same as: (.) :: (b -> c) -> ((a -> b) -> (a -> c)) How you read that is up to you, but here is one way of reading it: "accepts a function a to c and returns a function. The function returned takes a function a to b and returns a function a to c" The expression f(g(x)) in C-style languages is similar to (f . g) x Tony Morris http://tmorris.net/ PR Stanley wrote: > Hi > (.) :: (b -> c) -> (a -> b) -> (a -> c) > While I understand the purpose and the semantics of the (.) operator I'm > not sure about the above definition. > Is the definition interpreted sequentially - (.) is a fun taht takes a > fun of type (b -> c) and returns another fun of type (a -> b) etc? > Any ideas? > Thanks, Paul > > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > > -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFG9JzXmnpgrYe6r60RAjDrAJ0SvkZHtNsctWNYHjqxjp9lnpNvgACfS/2r 9jwUvD29/ZMMot8x3/nvyI8= =xSzA -END PGP SIGNATURE- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Composition Operator
Hello, It's probably easiest to think of composition as a function which takes two arguments (both functions), (g :: b -> c) and (f :: a -> b), and returns a new function of type a -> c. We could write this explicitly as composition :: (b -> c, a -> b) -> a -> c composition (g,f) = \x -> g (f x) then (.) is the currying of composition: (.) = curry composition or (.) g f = \x -> g (f x) -Jeff On 9/21/07, PR Stanley <[EMAIL PROTECTED]> wrote: > Hi > (.) :: (b -> c) -> (a -> b) -> (a -> c) > While I understand the purpose and the semantics of the (.) operator > I'm not sure about the above definition. > Is the definition interpreted sequentially - (.) is a fun taht takes > a fun of type (b -> c) and returns another fun of type (a -> b) etc? > Any ideas? > 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
[Haskell-cafe] Composition Operator
Hi (.) :: (b -> c) -> (a -> b) -> (a -> c) While I understand the purpose and the semantics of the (.) operator I'm not sure about the above definition. Is the definition interpreted sequentially - (.) is a fun taht takes a fun of type (b -> c) and returns another fun of type (a -> b) etc? Any ideas? Thanks, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] GHC 6.7 on Windows / containers-0.1 package?
STG is a very pretty island, but it's just that - an island. If you want to see the Big Picture, I can only recommend SPJ's 1987 (except for the optimization section, almost everything is still true) book: http://research.microsoft.com/~simonpj/papers/slpj-book-1987/slpj-book-1987.djvu Stefan Well, if the sun shines on that island, I wouldn't mind spending a holiday over there ;-) 1987??? Gee, I was still programming in 6502 & 68000 assembler then :-) Of course, I guess one could not use Haskell back then to make a videogame on home computers with 64KB of RAM ;-) Is this still up-to-date with the way GHC/GHCi work internally? Then I'll certainly check it out. Thanks, Peter ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] GHC 6.7 on Windows / containers-0.1 package?
On Fri, Sep 21, 2007 at 05:40:59PM -0300, Felipe Almeida Lessa wrote: > On 9/21/07, Peter Verswyvelen <[EMAIL PROTECTED]> wrote: > > Since I'm used to write heavily multi-threaded/multi-core code in > > imperative languages, I would like to understand more about the existing > > execution models, and those "black holes"... Understanding the low-level > > details helps a lot for me. > > I think you want to know about the STG, the Spineless Tagless > G-Machine. If I'm correct, that's how GHC works behind the scenes. STG is a very pretty island, but it's just that - an island. If you want to see the Big Picture, I can only recommend SPJ's 1987 (except for the optimization section, almost everything is still true) book: http://research.microsoft.com/~simonpj/papers/slpj-book-1987/slpj-book-1987.djvu Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] GHC 6.7 on Windows / containers-0.1 package?
> > All dependencies etc. have changed when going to 6.7/6.8 - you are > > probably better off using 6.6.1 for now. > > > That's a petty. I really would like to experiment with the debugger :-) Me too! A proper release of GHC 6.8 is very nearby, so you should get your wish then. Thanks Neil ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] GHC 6.7 on Windows / containers-0.1 package?
On 9/21/07, Peter Verswyvelen <[EMAIL PROTECTED]> wrote: > Since I'm used to write heavily multi-threaded/multi-core code in > imperative languages, I would like to understand more about the existing > execution models, and those "black holes"... Understanding the low-level > details helps a lot for me. I think you want to know about the STG, the Spineless Tagless G-Machine. If I'm correct, that's how GHC works behind the scenes. -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Win32 Open GL / Glut Applications
Oh yes, it's really confusing, this HOpenGL web-page is completely obsolete :-) It confused me so much I stopped looking at Haskell initially. Luckily this mailing list exists, and the other members of this group already gave you adequate instructions how to get started :-) Some other things that you might find interesting: - The latest SOE implementation comes with a wrapper for the GLFW library, which looks kinda cool at first sight. http://haskell.org/soe/software1.htm - I also liked ANUPlot to quickly get started with a simple graphics library, that nicely wraps GLUT. http://cs.anu.edu.au/people/Ben.Lippmeier/ Cheers, Peter John Wicket wrote: I can take any of these opengl applications or other examples on the web, but I can't get the application to run on Win32? They will compile(except for the GLU ones) but when I launch them, the windows just closes? Is HOpenGL supported well on Win32? http://www.haskell.org/HOpenGL/ I have ghc 6.6 ___ 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] GHC 6.7 on Windows / containers-0.1 package?
All dependencies etc. have changed when going to 6.7/6.8 - you are probably better off using 6.6.1 for now. That's a petty. I really would like to experiment with the debugger :-) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] GHC 6.7 on Windows / containers-0.1 package?
Thanks for the info, very interesting. Yes, I'm using GHCi, and I'm using forkOS, and I'm using OpenGL... Since I'm used to write heavily multi-threaded/multi-core code in imperative languages, I would like to understand more about the existing execution models, and those "black holes"... Understanding the low-level details helps a lot for me. Actually the problem was caused by (yet another) strict pattern match in my code, which should have been lazy. I find it strange that this would cause 0% CPU time... But then again I don't understand the details of how GHCi/GHC works. I did read the book "Modern Compiler Design" (http://www.cs.vu.nl/~dick/MCD.html) which implements a basic Haskell interpreter & compiler, so I got an introduction. Anyway, it's a very good learning experience for me to "redo" FRP from scratch, as I encounter all pitfalls (such as the need for memoization when using recursive streams, the need for lazy pattern matching, the space leaks sneaking up on you, etc). Once I get to understand these in detail, I'll try to re-read the existing papers on FRP, which I hardly understood initially :-) Thanks, Peter Stefan O'Rear wrote: On Wed, Sep 19, 2007 at 10:24:24PM +0100, Neil Mitchell wrote: Hi Peter, So I grabbed ghc-6.7.20070824 (=the latest one for Windows I could find) and the "extra-libs", compiled and installed the GLUT package (which I needed), but when I compile my library, I get Could not find module `Data.Map': it is a member of package containers-0.1, which is hidden All dependencies etc. have changed when going to 6.7/6.8 - you are probably better off using 6.6.1 for now. I also don't think that the debugger will help you track down infinite loop style errors. You might be better off posting the code and asking for help. You said 0% CPU. That's *very* important. It means that you are using the threaded runtime (GHCi?), and that you triggered a blackhole. You should be able to handle this by compiling your program with -prof (do *not* use -threaded!), and running with +RTS -xc. With luck, that will give you a backtrace to the infinite loop. PS. blackholes are a serious dark corner of GHC's execution model, chances are better than even that if you try to use the debugger for this you will discover a new and (for you) crippling bug. I wouldn't recommend it. Stefan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Win32 Open GL / Glut Applications
Oops, one slight omission: 4. Download this custom makefile and put in in the "./src" directory. http://hpaste.org/2841 ** Call this file "Makefile", with no extension. 5. Download this custom def file and put in in the "./src" directory. http://hpaste.org/2842 ** Call this file "freeglut.def". -- Ron ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Win32 Open GL / Glut Applications
John Wicket wrote: > yea, that is probably what I need. Can you post in a step-by-step way. Here is a set of instructions for what I had to do to get FreeGLUT working with GHCi. Just a little warning: my instructions could be wrong in some places. Normally, in order to verify my instructions, I would uninstall everything, start from scratch, follow my instructions step by step, and verify that they work. Unfortunately: * I have low confidence in the accuracy of the following instructions. * I have only one machine. * I went through lots of frustration to get freeglut to work with GHCi. * I am not willing to risk breaking my current installation. * I do not know of any easy way to preserve my current installation and still start over from scratch to test my instuctions. If my instructions are wrong, then please let me know, and I might attempt to fix it. Although I just don't understand why freeglut, the Haskell GLUT library, and GHCi won't work together in the first place. Here's what I would have to do if I were starting from scratch: 7-Zip http://www.7-zip.org/ This is an open source file archiver for Windows that can handle *.gz and *.bz2 files. Download the Windows version and install it. GHC 6.6.1 http://haskell.org/ghc/download_ghc_661.html#windows This is the version of GHC that I'm using. Download and install it. MinGW/MSYS Download all three files, then install them in the order I have listed them. Note: MinGW and MSYS need to "live" in different directories. http://sourceforge.net/project/showfiles.php?group_id=2435 Automated MinGW installer MinGW-5.1.3.exe ** When you run the installer, it will download several more files for you. MSYS: Minimal SystemMSYS-1.0.10.exe http://sourceforge.net/project/showfiles.php?group_id=2435&package_id=67879 MSYS Supplementary ToolsmsysDTK-1.0.1.exe ** Scroll down to find "Current Release: msysDTK-1.0.1" and expand this tab. Select "msysDTK-1.0.1.exe" zlib-1.2.3 http://www.zlib.net/ The links for "zlib source code" are about halfway down the page. After downloading, the process (IIRC) is 1. Unzip the source code. 2. Start MSYS and cd to the source-code directory. 3. Execute "./configure" 4. Execute "make" 5. Execute "make install" I don't remember having any problems with zlib. cURL-7.16.4 http://curl.haxx.se/download.html Note: It appears that cURL just had a minor revision on Sept 13. I guess you can just try the latest version and see of things work. IIRC, the process is exactly the same as the zlib install process, and I didn't have any problems here either. darcs-1.0.9 http://darcs.net/darcs-1.0.9.tar.gz Dependencies that you'll need: cURL and zlib :-) Your darcs installation will have some holes, for example it won't support SSL because we didn't satisfy the SSL dependency. IIRC, the process here is 1. Unzip the source code. 2. Start MSYS and cd to the source-code directory. 3. Execute "autoconf" 4. Execute "./configure" 5. Execute "make" 6. Execute "make install" Freeglut-2.4.0 http://freeglut.sourceforge.net/index.php#download Here's where the hackery starts. 1. Download the Freeglut source code and unzip it. 2. Start MSYS and cd to the source-code directory. 3. Execute "./configure" 4. Download this custom makefile and put in in the "./src" directory. http://hpaste.org/2841 5. Download this custom def file and put in in the "./src" directory. http://hpaste.org/2842 6. Cd to the "./src" directory and then execute "make". 7. Copy the "freeglut.dll" to GHC's bin directory (ghc-6.6.1/bin). 8. Copy the *.h files from "freeglut-2.4.0/include/GL" to "ghc-6.6.1/include/mingw/GL". Note that "glut.h" will be overwritten. GLUT-2.1.1 You need to use darcs to download GLUT-2.1.1. 1. Start MSYS, create a directory for the GLUT source code, and cd to it. 2. Execute "darcs get http://darcs.haskell.org/libraries/GLUT/"; and wait a while. 3. Cd to your new source directory. 4. Execute "autoreconf" and wait a while. 5. Modify "GLUT.cabal" as follows: Locate the line start starts with "build-depends:" and remove the dependencies "array" and "containers" 5. Execute "runghc Setup.hs configure" and wait. 6. Modify "GLUT-2.1.1/Graphics/UI/GLUT/Extensions.hs" as follows: Look at the last two lines: foreign import ccall unsafe "hs_GLUT_getProcAddress" hs_GLUT_getProcAddress :: CString -> IO (FunPtr a) Change "hs_GLUT_getProcAddress" to "glutGetProcAddress" 7. Modify "GLUT-2.1.1/cbits/HsGLUT.c" as follows: Look for "void* hs_GLUT_getProcAddress(char *procName)" and remove the whole function. 8. Execute "runghc Setup.hs build" and wait. 9. Execute "ghc-pkc unregister GLUT". This unregisters the existing GLUT haskell library. Also, search through GHC's directories, locate any glut library files (*.a, *.o, *.hi) that ar
Re: [Haskell-cafe] Sequencing Operations in a Monad
Al Falloon wrote: > > SevenThunders wrote: >> Well it certainly requires some thought here. As I see it, I now have >> two >> reasonable choices. Either I pull all my matrix operations back inside >> the >> IO monad and avoid the matrix action as a matrix variable paradigm (due >> to >> the loss of referential transparency) or I devise some way to guarantee >> 'safety' and use unsafePerformIO. I suppose I can use a somewhat >> generalized version of safety where if I can guarantee that the order of >> operations doesn't matter to the final output then I'm OK. In this case >> if >> I can make it so that reording the computations only reorders the >> locations >> of my matrices on the stack, but otherwise doesn't affect the contents of >> the matrices I think I am golden. >> >> I believe I got burned by following a nice tutorial interpretation of the >> IO >> monad as a way of carrying around an undeclared state variable, the >> world. >> But my little matrix IO variable is not just a world state with some >> matrix >> data in it, rather it appears to be a world state with a chain of >> unapplied >> function evaluations. This is due to laziness I believe. If I had a >> data >> structure that looked more like a world state with a reference to a >> variable >> in that world state, I could find a way to achieve my goals I think. > > I know that you have already made your decision and moved on, but I > think that there is still another alternative that you can consider: > make an abstract interpreter for your matrix operations. > > The basic idea is to use the normal Num et. al. type classes to write > your matrix calculations. However, instead of actually performing the > calculations it instead builds a data structure that represents the > calculations. You then 'interpret' the data structure in a separate > function in the IO monad. > > The advantage of the approach is that you can pre-process the abstract > data structure to recognize intermediate matrices that can be consumed > without copying and other optimizations. > > The other advantage is that the matrix math itself doesn't need to be in > the IO monad, only the interpretation, so you can use all the functional > goodness when writing the matrix operations. > > I was going to whip up a small example, but I am pressed for time. So > here is a post from Oleg that shows the idea. > http://www.haskell.org/pipermail/haskell/2007-January/019012.html > As usual his post is mind-expanding and probably a bit of overkill for > your problem, but I was the best I could come up with, google was not my > friend. You might have better luck (try "higher order abstract syntax" > and "abstract interpretation" and go from there) > > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > That's an interesting approach. However if performance is a main concern (in addition to 'elegance'), I would be concerned about having an interpreter in an inner loop of some operation. I quite frequently write functions that do hundreds of matrix multiplies using hundreds of different indexed matrices, where the function iterates over the matrix index. When I first designed my Matrix library and was interfacing it with Haskell, I considered the possibility of actually using Haskell to compile my computations into C. Thus there would be a matrix data type in Haskell, but the final output of the Haskell operations would be C code. In retrospect that would have had a number of advantages, perhaps both in performance and interoperability with the 'normal' programming world. However I also wanted to take advantage of ghci so that I could interact with my code in real time. That too is probably possible with the current toolset, but it would have taken somewhat longer to develop. -- View this message in context: http://www.nabble.com/Sequencing-Operations-in-a-Monad-tf4446047.html#a12824919 Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Win32 Open GL / Glut Applications
> > > http://www.haskell.org/HOpenGL/ > > try http://www.haskell.org/haskellwiki/Opengl ? > > [Sven: could there please be a link from the old home page > to the wiki page, with a recommendation to improve the > latter?] Since this kind of confusion over the HOpenGL documentation is becoming more common, I have taken the liberty of _moving_ the pages at http://www.haskell.org/HOpenGL/ to a new URL: http://www.haskell.org/HOpenGL-old/ and replacing the pages at many of the original URLs with a simple stub pointing both to the wiki page, and to the revised location of the old documentation. I hope this is acceptable as an interim solution (and perhaps as a forcing function to come up with something better). Regards, Malcolm ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] reverse with foldl
Prelude> :t foldl (\x -> \xs -> xs:x) [] foldl (\x -> \xs -> xs:x) [] :: [b] -> [b] Strange choice of names, though, since x is a list, and xs is an element. I would have gone for: foldl (\xs x -> x:xs) [] although the library opts for: foldl (flip (:)) [] On 21/09/2007, Miguel Mitrofanov <[EMAIL PROTECTED]> wrote: > > reverse = foldl (\x -> \xs -> xs:x) [] > > Doesn't typecheck. > ___ > 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] Win32 Open GL / Glut Applications
> http://www.haskell.org/HOpenGL/ First, the bad news: The HOpenGL site is outdated. Look at [1] and note the date of the most recent release: September 9, *2003*. [1] http://www.haskell.org/HOpenGL/releases.html try http://www.haskell.org/haskellwiki/Opengl ? [Sven: could there please be a link from the old home page to the wiki page, with a recommendation to improve the latter?] claus ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Sequencing Operations in a Monad
SevenThunders wrote: Well it certainly requires some thought here. As I see it, I now have two reasonable choices. Either I pull all my matrix operations back inside the IO monad and avoid the matrix action as a matrix variable paradigm (due to the loss of referential transparency) or I devise some way to guarantee 'safety' and use unsafePerformIO. I suppose I can use a somewhat generalized version of safety where if I can guarantee that the order of operations doesn't matter to the final output then I'm OK. In this case if I can make it so that reording the computations only reorders the locations of my matrices on the stack, but otherwise doesn't affect the contents of the matrices I think I am golden. I believe I got burned by following a nice tutorial interpretation of the IO monad as a way of carrying around an undeclared state variable, the world. But my little matrix IO variable is not just a world state with some matrix data in it, rather it appears to be a world state with a chain of unapplied function evaluations. This is due to laziness I believe. If I had a data structure that looked more like a world state with a reference to a variable in that world state, I could find a way to achieve my goals I think. I know that you have already made your decision and moved on, but I think that there is still another alternative that you can consider: make an abstract interpreter for your matrix operations. The basic idea is to use the normal Num et. al. type classes to write your matrix calculations. However, instead of actually performing the calculations it instead builds a data structure that represents the calculations. You then 'interpret' the data structure in a separate function in the IO monad. The advantage of the approach is that you can pre-process the abstract data structure to recognize intermediate matrices that can be consumed without copying and other optimizations. The other advantage is that the matrix math itself doesn't need to be in the IO monad, only the interpretation, so you can use all the functional goodness when writing the matrix operations. I was going to whip up a small example, but I am pressed for time. So here is a post from Oleg that shows the idea. http://www.haskell.org/pipermail/haskell/2007-January/019012.html As usual his post is mind-expanding and probably a bit of overkill for your problem, but I was the best I could come up with, google was not my friend. You might have better luck (try "higher order abstract syntax" and "abstract interpretation" and go from there) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Interesting folds over bytestring lists?
On 9/21/07, Duncan Coutts <[EMAIL PROTECTED]> wrote: > I should point out that other people who did this year's ICFP contest have > also > looked at structures like this (though mostly after the contest finished), so > you might want to talk or collaborate with them. I used exactly this structure written in Java and merged nodes. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Graphics.SOE
Can scrollbars be attached to windows created with openWindow? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Interesting folds over bytestring lists?
In message <[EMAIL PROTECTED]> "Justin Bailey" <[EMAIL PROTECTED]> writes: > On 9/20/07, Duncan Coutts <[EMAIL PROTECTED]> wrote: > > A lazy bytestring is a list of strict bytestring which externally looks > > like one > > big string. Could you not just use a lazy bytestring and it's take and drop > > functions? Perhaps you can help me understand what it is you're trying to > > do? > > I'm working on the ICFP contest from this year, and the algorithm > frequently prepends long strings to the front of the "DNA" string > being processed. I originally worked only with a lazy bytestring but > it 'append' wasn't fast enough, so I'm trying this representation. But you do realise it's exactly the same representation. Append for a lazy bytestring is O(n) in the number of chunks n, this will also be true for your 'new' representation. > Your email makes me think I should work directly with a list of strict > bytestrings, That's exactly what a lazy bytestring is. You'll not get any performance improvements without changing the data representation. A list is not good enough for what you want to do because so many operations are O(n) in the number of chunks. > but in that case what happens when I want to take a large > chunk of strings out of the middle of the list? Would that be an O(n) > operation? Yes. That's exactly the problem. What you want rather than a list of strict bytestrings is a tree of strict bytestrings. You want a fingertree of strict bytestrings: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/fingertree newtype ByteSequence = BS (FingerTree (Sum Int) Strict.ByteString) instance Measured (Sum Int) Strict.ByteString where measure = Sum . Strict.length You'll have to wrap the operations you need, (like split, take, drop and append) to make the ByteSequence look like a single sequence of bytes rather than a sequence of chunks. You probably want to enforce an invariant that no chunk is ever empty (as we do for lazy bytestrings). For best performance over a large number of inserts and deletes you might need to implement merging adjacent small blocks so that the block size does not degrade too much. An alternative structure if you tend to do lots of inserts and deletes at near the same spot is a zipper structure with a cursor. I'm not so sure what the best structure for that might be, perhaps just a pair of finger trees giving the parts of the sequence before and after the insertion point (since finger trees give fast access to the ends but slower O(log n) access to points n chunks from the closer end). Have fun :-) I should point out that other people who did this year's ICFP contest have also looked at structures like this (though mostly after the contest finished), so you might want to talk or collaborate with them. Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Slightly Off-topic
Hi Does anyone know of a good active list for students and experts in discrete mathematics, in particular, logic? Thanks, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Accumulator value for "and" and "or"
PR Stanley wrote: Hi or = foldl (||) False and = foldl (&&) True I can understand the rationale for the accumulator value - True && [] where [] = True and True || [] where [] = False Other than the practical convenience is there a reason for having the empty list in and and or equating to True and False? Thanks, Paul Another way to think about this is to look at > any p = or . map p > all p = and . map p Now, "all even []" should hold, since everything in that list is even. But not "any even []" because there is no even number in the empty list. Twan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] bindings to the xmms_remote API, GList and something more
On Fri, Sep 21, 2007 at 09:08:13AM +0200, Andrea Rossato wrote: > Hi, > I think there's a huge flaw in the Haskell design: I don't know if this is a feature, the fact that most of the times you can find a solution to your problems by yourself, but only after polluting the haskell-cafe mailing list with your question... > Basically there are two C types I'm having problem with: > > 1. GList: even though I read the gtk2hs code I do not exactly >understand how to create a GList to feed to this function: > > void xmms_remote_playlist_add(gint session, GList * list); > > As far as I understand this function takes a session number and a > list of files' names. Still I seem not to be able to create a > wrapper function around the imported one. Well I used gtk2hs more carefully and that's the wrapper: foreign import ccall unsafe "beepctrl.h xmms_remote_playlist_add" c_xmms_remote_playlist_add :: CInt -> GList -> IO () xmms_remote_playlist_add :: Session -> [String] -> IO () xmms_remote_playlist_add s fns = do l <- mapM newCString fns >>= toGList c_xmms_remote_playlist_add (fromIntegral s) l -- stolen from gtk2hs #include {# context lib="glib" prefix="g" #} {#pointer * GList#} toGList :: [Ptr a] -> IO GList toGList pl = makeList nullPtr pl where makeList :: GList -> [Ptr a] -> IO GList makeList current (x:xs) = do newHead <- {#call unsafe list_prepend#} current (castPtr x) makeList newHead xs makeList current [] = return current > 2. what a "gchar ** list" is? As far as my C goes, it should be an array >of strings, right? What should I use on the Haskell side, newArray? >void xmms_remote_playlist(gint session, gchar ** list, gint num, > gboolean enqueue); yes, indeed: foreign import ccall unsafe "beepctrl.h xmms_remote_playlist" c_xmms_remote_playlist :: CInt -> Ptr CString -> CInt -> {# type gboolean #} -> IO () xmms_remote_playlist :: Session -> [String] -> Bool -> IO () xmms_remote_playlist s l b = do la <- newArray =<< mapM newCString l c_xmms_remote_playlist (fromIntegral s) la (fromIntegral $ length l) (fromBool b) The next two question are still waiting for an answer though...;-) > 3. c2hs v. hsc2hs? Which should I prefer? In c2hs I write {#pointer * >GList#}. What is the equivalent in hsc2hs? > > 4. As I said, I solved my personal problem: I imported enough >functions to create the client I needed. Releasing the library is >just something I would like to do, to give something back to the >Haskell community. So this is something useful if I can provide >robust and well designed code. This is a name space question: what >is the name of the exported module? Sound.XMMS, Sound.XmmsRemote? >Is the some kind of convention I should be referring to? I apologize for the noise. The auto-replay is for documentation (who knows, maybe others searching the list archives may find this info useful). Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] bindings to the xmms_remote API, GList and something more
Hi, I think there's a huge flaw in the Haskell design: if you conceive such a powerful and expressive programming language, one that empowers even the most ignorant computer user to write complex applications, instead of sticking to basic shell scripting - the only domain graspable by such stupid pseudo-coders -, well you end up with messages like this one flooding the mailing list you are providing for your users. This is what I call inevitability... To make a short story long, I needed some client for the Audacious media player, something I could use to remote control it and, since I'm addicted to Haskell, instead of surfing the web to find a suitable client I surfed the web to find the API documentation. With the FFI, in a matter of half an hour I had the client with all the commands I needed. (The long introduction was written just to let you know that you'd better not waste too much time with what follows...;-) So far so good, but, since everything was so easy, I thought: "Why not packaging a library (and the client) for Hackage? Maybe others may be willing to use it, maybe..." And then the problems start, problems due to my basic ignorance of the C language ("How comes you dare to import in Haskell functions written in a language you don't even understand?" you should replay!). Basically there are two C types I'm having problem with: 1. GList: even though I read the gtk2hs code I do not exactly understand how to create a GList to feed to this function: void xmms_remote_playlist_add(gint session, GList * list); As far as I understand this function takes a session number and a list of files' names. Still I seem not to be able to create a wrapper function around the imported one. 2. what a "gchar ** list" is? As far as my C goes, it should be an array of strings, right? What should I use on the Haskell side, newArray? void xmms_remote_playlist(gint session, gchar ** list, gint num, gboolean enqueue); 3. c2hs v. hsc2hs? Which should I prefer? In c2hs I write {#pointer * GList#}. What is the equivalent in hsc2hs? 4. As I said, I solved my personal problem: I imported enough functions to create the client I needed. Releasing the library is just something I would like to do, to give something back to the Haskell community. So this is something useful if I can provide robust and well designed code. This is a name space question: what is the name of the exported module? Sound.XMMS, Sound.XmmsRemote? Is the some kind of convention I should be referring to? Sorry if I was too long. Moreover I'm asking help I need just to publish a piece of software that is probably useless. Do not waste your time. But if you do, well... thank you, I really appreciate. Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] How can I stop GHCi from calling "show" for IOactions?
| I think a more consistent behavior would be to not print the LHS at | all. If you wanted to print the result of the computation you could | just do: | | Prelude> bar 5 | | or, if you also wanted bound variables afterwards: | | Prelude> (x, Just y) <- bar 5 | Prelude> (x, Just y) I've added Ryan's comments to http://hackage.haskell.org/trac/ghc/ticket/1721 Others might want to add further suggestions there. Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe