[Haskell-cafe] ideas for a phd in the area of paralleism?
Hello, currently I'm searching for a topic for my phd-thesis or at least for a workshop-paper (as a starting point, to get my feet wet...). My academic group has specialized itself on (practical, i.e. not too theoretical stuff like verification, etc...) parallel programming and related topics, so my future thesis has to be in this area, but as long as its related I'm free to choose whatever I want. Since I've been interested in FP in general for a few years as a private hobby and since Haskell has as a pure language a lot of potential in the area of parallelism, and it's community (esp. #haskell and this list) is really nice and supportive I'd like to do something in this area; I've been hacking in Haskell more intensive for about six month now. I've looked at the different parallelism/concurrency models in Haskell (dph, gph, nested data parallelism) and (after a preliminary overview-reading) it seems that a lot of research has already been done on the basic topics, except for distributed Haskell, where I could not found current papers (i.e. newer than ~2003). If anyone could give me further advice, tips, or hints in general, what could be interesting or where I should take a more deeper look to find a niche I'd really be thankful (and you'll get a special thanks in my foreword in 3 years! ;-)). Best regards, Michael -- Dipl.-Inf. Michael C. Lesniak University of Kassel Programming Languages / Methodologies Research Group Department of Computer Science and Electrical Engineering Wilhelmshöher Allee 73 34121 Kassel Phone: +49-(0)561-804-6269 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Updating doubly linked lists
Dan Weston wrote: I hope the code is better than my description! :) The structure is more like Nothing(RK 0 _) Nothing(RK 1 _) A(RK 2 4) B(RK 3 6) C(RK 2 0) The root of the tree is the center and you can descend on the right. But with this structure, walking from A to B is O(d) = O(n) (where d is the distance from the origin, n the side length of the grid) instead of O(1). No. The tree is [[Node]], where the outer list has one element for each radius that has an occupied node and each inner list has the number of nodes at the given radius. You descend the spine of the outer list radially in O(deltaR) time, which for incremental moves is O(1). Then you search for an existing inner list element in O(nk(r)), which stays fairly constant for reasonable paths (basically, the width of a path swath). Ah, so you're using a sparse representation for grids. That's a good idea! Unfortunately, it doesn't help when the grid is a full rectangle, i.e. when nk(r) becomes proportional to r. The (most likely unattainable) goal I had in mind is to create a zipper for the full grid that supports O(1) operations. I mean, O(d) may be fine for you, but it's not O(1) for everything as advertised. :) d is not the distance from the origin, it is nk(r), the number of nodes at a given radius: d(2) = 2, d(3) = 1. Oh, right. An outward radial path will only expand the tree linearly, not quadratically, in size. Well, that's still linear in the side length of a full grid. Directly using Data.Map (Integer,Integer) a would improve that to a logarithm. Of course, your structure can be enhanced by using a Data.Map instead of a linked list for each ring à la [Data.Map Integer a] This will give O(log nk(r)) movements, but that's still not constant time. Regards, H. Apfelmus ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ideas for a phd in the area of paralleism?
On Wed, Jan 07, 2009 at 10:35:25AM +0100, Michael Lesniak wrote: Hello, currently I'm searching for a topic for my phd-thesis or at least for a workshop-paper (as a starting point, to get my feet wet...). My academic group has specialized itself on (practical, i.e. not too theoretical stuff like verification, etc...) parallel programming and related topics, so my future thesis has to be in this area, but as long as its related I'm free to choose whatever I want. GPU programming seems to be hot: http://www.cse.unsw.edu.au/~chak/papers/gpugen.pdf http://www.cs.chalmers.se/Cs/Education/Courses/svh/Slides/may-15-Obsidian-short.pdf Regards, Frederik ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Maintaining laziness
This is great. I am working on the very same topic for quite a while now. My aim is to develop a tool that tells you whether a function is least strict. My work is based on an idea by Olaf Chitil: http://www.cs.kent.ac.uk/people/staff/oc/ I think he was the first who introduced the idea of least strictness. In a paper in the pre-proceedings of IFL 2006 he introduced the term least strict and presented the idea behind a tool called StrictCheck. This tool was supposed to check whether a function is least strict. The problem with this tool was that it proposes non-sequential function definitions that are not implementable in Haskell. The main example in the StrictCheck paper is the definition of unzip by using foldr. This one is very similar to your partition example as it is too strict if you do not use lazy pattern matching for the tuple structure. unzip2 :: [(a, b)] - ([a], [b]) unzip2 = foldr (\(x,y) (xs,ys) - (x:xs,y:ys)) ([],[]) My favorite example right now is the multiplication of Peano numbers. Suppose the definition of a data type for Peano numbers and addition and multiplication. data Natural = Z | S Natural (+) :: Natural - Natural - Natural Z + y = y S x + y = S (x + y) (*) :: Natural - Natural - Natural Z * _ = Z S x * y = y + (x * y) Now we can define an infinite Peano number as follows infinity :: Natural infinity = S infinity The evaluation of Z * infinity yields Z while infinity * Z does not terminate. The tool I am working on is supposed to yield the following information. Natural strictCheck2 (*) 5 100 You have to fulfil f (S _|_) Z = Z (_|_) This states that the evaluation of S _|_ * Z yields _|_ but it could yield Z. Therefore we can improve the function as follows (*) :: Natural - Natural - Natural Z * _ = Z S _ * Z = Z S x * y = y + (x * y) Now the evaluation of infinity * Z yields Z as we wanted it to. If we test this new implementation using StrictCheck we get *Natural strictCheck2 (*) 5 100 The function seems to be least strict The non least strict definition of (*) is taken from the module Data.Number.Natural which was published by Lennart Augustsson in the numbers package at hackage. I mention this here because I think it clearly shows that it is even hard for experienced Haskell programmers to define least strict functions. An even more promising area of application are functional logic programs as least strict functions result in smaller search spaces. For example I was able to improve the enumeration of pythagorean triples in Curry by a factor of 4 only by making a function least strict. Cheers, Jan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Maintaining laziness
On Wed, 7 Jan 2009, Jan Christiansen wrote: The non least strict definition of (*) is taken from the module Data.Number.Natural which was published by Lennart Augustsson in the numbers package at hackage. I mention this here because I think it clearly shows that it is even hard for experienced Haskell programmers to define least strict functions. very interesting ... It's the third time within about 2 months were I was pointed to a lack of laziness in my own Peano implementation! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Blitting one IOUArray into another
Hi all, I'm seeing a lot of unexpected memory allocation with some simple code that copies the contents of one vector (IOUArray Int Int64) into another of the same type and dimensions. In particular, profiling reveals that `copyInto' is allocating oodles and oodles of memory. My small test case creates two 5-element arrays and performs 1 copies from one into the other. Since the elements are Int64s and the arrays are unboxed, each array should be 5 elements * 8 bytes per element = 400,000 bytes and so the arrays should only take 800,000 bytes total. I understand there's some overhead for thunks and whatnot, but the profiler reported allocation is around 40 billion bytes. And almost all of that allocation is in my copying function, not in main (main allocates the arrays). I've attached two versions of the code, just for comparison. The only difference is the way the copying is done. One calls `getBounds' to figure out the bounds, and one is given the bounds for copying. They're both about the same speed and allocation (originally I was using IOUArray Int64 Int64, and there was a much greater allocation difference between the two versions; but that went away. Oh well). So, does anyone know why copying takes so much allocation? I expect there is _some_ way to just move memory from one array to another, like a memcpy -- how can I do that? Denis ArrayCopyGetBounds.hs Description: ArrayCopyGetBounds.hs arraycopygetbounds.prof Description: arraycopygetbounds.prof ArrayCopyWithBounds.hs Description: ArrayCopyWithBounds.hs arraycopywithbounds.prof Description: arraycopywithbounds.prof ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Blitting one IOUArray into another
Hello Denis, Wednesday, January 7, 2009, 6:56:36 PM, you wrote: memory allocated for i :))) each new copy of i needs one word. the situation was much worse with Int64, of course :) Hi all, I'm seeing a lot of unexpected memory allocation with some simple code that copies the contents of one vector (IOUArray Int Int64) into another of the same type and dimensions. In particular, profiling reveals that `copyInto' is allocating oodles and oodles of memory. My small test case creates two 5-element arrays and performs 1 copies from one into the other. Since the elements are Int64s and the arrays are unboxed, each array should be 5 elements * 8 bytes per element = 400,000 bytes and so the arrays should only take 800,000 bytes total. I understand there's some overhead for thunks and whatnot, but the profiler reported allocation is around 40 billion bytes. And almost all of that allocation is in my copying function, not in main (main allocates the arrays). I've attached two versions of the code, just for comparison. The only difference is the way the copying is done. One calls `getBounds' to figure out the bounds, and one is given the bounds for copying. They're both about the same speed and allocation (originally I was using IOUArray Int64 Int64, and there was a much greater allocation difference between the two versions; but that went away. Oh well). So, does anyone know why copying takes so much allocation? I expect there is _some_ way to just move memory from one array to another, like a memcpy -- how can I do that? Denis -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Maintaining laziness
On Wed, 7 Jan 2009, Jan Christiansen wrote: This is great. I am working on the very same topic for quite a while now. My aim is to develop a tool that tells you whether a function is least strict. My work is based on an idea by Olaf Chitil: http://www.cs.kent.ac.uk/people/staff/oc/ Although it seems to be overkill for a single module - How about a cabalized version on Hackage and a darcs repository? It would simplify using and updating it. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Maintaining laziness
On Wed, 7 Jan 2009, Henning Thielemann wrote: On Wed, 7 Jan 2009, Jan Christiansen wrote: This is great. I am working on the very same topic for quite a while now. My aim is to develop a tool that tells you whether a function is least strict. My work is based on an idea by Olaf Chitil: http://www.cs.kent.ac.uk/people/staff/oc/ Although it seems to be overkill for a single module - How about a cabalized version on Hackage and a darcs repository? It would simplify using and updating it. ... I meant StrictCheck.hs ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Blitting one IOUArray into another
You can of course memcpy unboxed arrays fairly easily. bulat.ziganshin: Hello Denis, Wednesday, January 7, 2009, 6:56:36 PM, you wrote: memory allocated for i :))) each new copy of i needs one word. the situation was much worse with Int64, of course :) Hi all, I'm seeing a lot of unexpected memory allocation with some simple code that copies the contents of one vector (IOUArray Int Int64) into another of the same type and dimensions. In particular, profiling reveals that `copyInto' is allocating oodles and oodles of memory. My small test case creates two 5-element arrays and performs 1 copies from one into the other. Since the elements are Int64s and the arrays are unboxed, each array should be 5 elements * 8 bytes per element = 400,000 bytes and so the arrays should only take 800,000 bytes total. I understand there's some overhead for thunks and whatnot, but the profiler reported allocation is around 40 billion bytes. And almost all of that allocation is in my copying function, not in main (main allocates the arrays). I've attached two versions of the code, just for comparison. The only difference is the way the copying is done. One calls `getBounds' to figure out the bounds, and one is given the bounds for copying. They're both about the same speed and allocation (originally I was using IOUArray Int64 Int64, and there was a much greater allocation difference between the two versions; but that went away. Oh well). So, does anyone know why copying takes so much allocation? I expect there is _some_ way to just move memory from one array to another, like a memcpy -- how can I do that? Denis -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ICFP: Child care at conference
Potential ICFP attendees: The ACM-SIGPLAN Executive Committee, which oversees and sponsors ICFP, is considering expanding its travel grants for event participants in need of child care assistance. (Such expansion would also apply to other major SIGPLAN-sponsored conferences, such as PLDI, POPL, OOPSLA.) The purpose of this message is to solicit feedback from potential attendees regarding the desirability for child care assistance and what forms of assistance be most appropriate. If child care assistance at ICFP (or other SIGPLAN events) is of interest to you, please contact me (at icfp.public...@gmail.com -or- fl...@tti-c.org) with your comments. Some questions of particular interest: * What age groups of children are most appropriate to cover? * What types of costs might SIGPLAN cover to facilitate your participation in events? Sincerely, -Matthew Fluet (ICFP Publicity Chair) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] Blitting one IOUArray into another
Ooh, great -- could you point me in the right direction for that? From: Don Stewart [d...@galois.com] Sent: Wednesday, January 07, 2009 9:23 AM To: Bulat Ziganshin Cc: Bueno, Denis; haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] Blitting one IOUArray into another You can of course memcpy unboxed arrays fairly easily. bulat.ziganshin: Hello Denis, Wednesday, January 7, 2009, 6:56:36 PM, you wrote: memory allocated for i :))) each new copy of i needs one word. the situation was much worse with Int64, of course :) Hi all, I'm seeing a lot of unexpected memory allocation with some simple code that copies the contents of one vector (IOUArray Int Int64) into another of the same type and dimensions. In particular, profiling reveals that `copyInto' is allocating oodles and oodles of memory. My small test case creates two 5-element arrays and performs 1 copies from one into the other. Since the elements are Int64s and the arrays are unboxed, each array should be 5 elements * 8 bytes per element = 400,000 bytes and so the arrays should only take 800,000 bytes total. I understand there's some overhead for thunks and whatnot, but the profiler reported allocation is around 40 billion bytes. And almost all of that allocation is in my copying function, not in main (main allocates the arrays). I've attached two versions of the code, just for comparison. The only difference is the way the copying is done. One calls `getBounds' to figure out the bounds, and one is given the bounds for copying. They're both about the same speed and allocation (originally I was using IOUArray Int64 Int64, and there was a much greater allocation difference between the two versions; but that went away. Oh well). So, does anyone know why copying takes so much allocation? I expect there is _some_ way to just move memory from one array to another, like a memcpy -- how can I do that? Denis -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] Blitting one IOUArray into another
Oh, do you mean by actually calling memcpy via ffi? From: Don Stewart [d...@galois.com] Sent: Wednesday, January 07, 2009 9:23 AM To: Bulat Ziganshin Cc: Bueno, Denis; haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] Blitting one IOUArray into another You can of course memcpy unboxed arrays fairly easily. bulat.ziganshin: Hello Denis, Wednesday, January 7, 2009, 6:56:36 PM, you wrote: memory allocated for i :))) each new copy of i needs one word. the situation was much worse with Int64, of course :) Hi all, I'm seeing a lot of unexpected memory allocation with some simple code that copies the contents of one vector (IOUArray Int Int64) into another of the same type and dimensions. In particular, profiling reveals that `copyInto' is allocating oodles and oodles of memory. My small test case creates two 5-element arrays and performs 1 copies from one into the other. Since the elements are Int64s and the arrays are unboxed, each array should be 5 elements * 8 bytes per element = 400,000 bytes and so the arrays should only take 800,000 bytes total. I understand there's some overhead for thunks and whatnot, but the profiler reported allocation is around 40 billion bytes. And almost all of that allocation is in my copying function, not in main (main allocates the arrays). I've attached two versions of the code, just for comparison. The only difference is the way the copying is done. One calls `getBounds' to figure out the bounds, and one is given the bounds for copying. They're both about the same speed and allocation (originally I was using IOUArray Int64 Int64, and there was a much greater allocation difference between the two versions; but that went away. Oh well). So, does anyone know why copying takes so much allocation? I expect there is _some_ way to just move memory from one array to another, like a memcpy -- how can I do that? Denis -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Blitting one IOUArray into another
Am Mittwoch, 7. Januar 2009 16:56 schrieb Bueno, Denis: Hi all, I'm seeing a lot of unexpected memory allocation with some simple code that copies the contents of one vector (IOUArray Int Int64) into another of the same type and dimensions. In particular, profiling reveals that `copyInto' is allocating oodles and oodles of memory. My small test case creates two 5-element arrays and performs 1 copies from one into the other. Since the elements are Int64s and the arrays are unboxed, each array should be 5 elements * 8 bytes per element = 400,000 bytes and so the arrays should only take 800,000 bytes total. I understand there's some overhead for thunks and whatnot, but the profiler reported allocation is around 40 billion bytes. And almost all of that allocation is in my copying function, not in main (main allocates the arrays). I think you've run into a profiling/optimising incopatibility. Compiling the code just with -O2 --make and running with -sstderr, both report 899,944 bytes allocated in the heap 1,272 bytes copied during GC (scavenged) 0 bytes copied during GC (not scavenged) 16,384 bytes maximum residency (1 sample(s)) 2 collections in generation 0 ( 0.00s) 1 collections in generation 1 ( 0.00s) 2 Mb total memory in use which looks reasonable, but it is dog slow on my box, 26.7/26.9 seconds :( Compiled with -prof -auto-all -O2 --make, both allocate madly (~40G) and take nearly ten times as long. It is known that profiling and optimising don't mix too well, but this is remarkable, maybe it's worth an investigation. Cheers, Daniel ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ideas for a phd in the area of paralleism?
Frederik Deweerdt wrote: On Wed, Jan 07, 2009 at 10:35:25AM +0100, Michael Lesniak wrote: Hello, currently I'm searching for a topic for my phd-thesis or at least for a workshop-paper (as a starting point, to get my feet wet...). My academic group has specialized itself on (practical, i.e. not too theoretical stuff like verification, etc...) parallel programming and related topics, so my future thesis has to be in this area, but as long as its related I'm free to choose whatever I want. GPU programming seems to be hot: http://www.cse.unsw.edu.au/~chak/papers/gpugen.pdf http://www.cs.chalmers.se/Cs/Education/Courses/svh/Slides/may-15-Obsidian-short.pdf Make OpenCL bindings please, please ... pretty please. Martin Regards, Frederik ___ 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] Template Haskell question
It doesn't typecheck, no, but it also doesn't check out in scope. It complains in [FunD 'mousePosition [| mousePositionf |] ... that mousePositionf isn't in scope. What I believe I need to do is use mkName mousePositionf, but how do I bind the record getter mousePositionf that is defined by the code in the function named additions to mousePosition -- a.k.a. how do I write that template? Is it a ConE? And how do I encode a{ mousePositionf = b } in template haskell without using the [| |] syntax, so that I can use mkName? -- Jeff On Tue, Jan 6, 2009 at 6:23 PM, Eelco Lempsink ee...@lempsink.nl wrote: On 6 jan 2009, at 18:08, Jeff Heard wrote: Alright... I *think* I'm nearly there, but I can't figure out how to derive a class instance using record accessors and updaters... Can anyone help? There are [| XXXf |] instances at the end of the module and they all need replaced, but I can't figure out what to replace them with. ... -- usage: $(deriveUIState ''MyTypeWithUIState) {- - Derive an instance of UIState from some type that has had UIState fields added to it. -} deriveUIState tp = do return [InstanceD [] (appUIState $ appType tp []) [FunD 'mousePosition [| mousePositionf |] ... ,FunD 'setMousePosition[| \b a - a{ mousePositionf=b } |] ... Quick guess: this doesn't typecheck? FunD :: Name - [Clause] - Dec while [| ... |] will return something of type ExpQ (which is the same as Q Exp). You're indeed nearly there, but if you use the quotation brackets you need to write monadic code (for the Q monad) and use functions like clause and funD. The tutorials on the wiki (you've probably seen them, http://www.haskell.org/haskellwiki/Template_Haskell) or pretty good and you could also look at packages at hackage for inspiration/examples, e.g. http://hackage.haskell.org/packages/archive/haxr-th/3000.0.0/doc/html/src/Network-XmlRpc-THDeriveXmlRpcType.html -- Regards, Eelco Lempsink ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] template haskell
Smart constructors sometimes need to generate errors like Foo.Bar.Baz.create: invalid value, etc. Can TH generate the module and function names? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Blitting one IOUArray into another
Bueno, Denis wrote: Oh, do you mean by actually calling memcpy via ffi? http://www.haskell.org/ghc/docs/latest/html/libraries/base/Foreign-Marshal-Utils.html ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Taking Exception to Exceptions
I'm trying to use the new (for me at least) extensible exceptions and I am little amazed that I cannot get catch, try or mapException to work without telling them which exceptions I want to catch. What is the rationale behind this? How does bracket manage to catch all exceptions? What should onException do? Is there some example code that uses these exceptions, or better documentation? Thanks in advance, Immanuel ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Taking Exception to Exceptions
Excerpts from Immanuel Litzroth's message of Wed Jan 07 16:53:30 -0600 2009: I'm trying to use the new (for me at least) extensible exceptions and I am little amazed that I cannot get catch, try or mapException to work without telling them which exceptions I want to catch. What is the rationale behind this? The rational is that it's normally not a good idea to simply gobble all exceptions; although the library makes it possible to do this anyway. You can either use the ScopedTypeVariables extension and do: ... `catch` \(e::SomeException) - ... Or without an extension you can do: ... `catch` handler where handler :: SomeException - IO a handler e = ... (It's really a matter of taste if you want to use a non-haskell98 extension, although considering that the new extensible exceptions library uses deriving data/typeable and existentials anyway, I think ScopedTypeVariables are the way to go.) How does bracket manage to catch all exceptions? What should onException do? onException takes an IO action and what to do if it fails - if the IO action fails, it is caught and your 'failure action' is run, followed by onException re-throwing the error. Is there some example code that uses these exceptions, or better documentation? The GHC docs don't have source-code links (don't know why,) but luckily in order to aid in using the new extensions system with older GHCs there has been a hackage package uploaded that provides the identical functionality: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/extensible-exceptions The source is here: http://hackage.haskell.org/packages/archive/extensible-exceptions/0.1.1.0/doc/html/src/Control-Exception-Extensible.html As for documentation e.g. haddock stuff, this is currently a bug as there is none: http://hackage.haskell.org/trac/ghc/ticket/2655 I recommend this paper for info, it's very easy to follow: http://www.haskell.org/~simonmar/papers/ext-exceptions.pdf Austin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Linking in GMP as a Windows DLL w/ GHC
Hi, a number of folks have been asking/looking for ways to avoid statically linking in GMP into GHC binaries under Windows. I've written up some notes on how to go about doing this, which are now available from http://haskell.forkio.com/gmpwindows Let me know if it is useful (or works ;-) ) enjoy --sigbjorn ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Hypothetical Haskell job in New York
Hello Haskellers, I'm trying to convince my boss to use Haskell. His main concern is finding people who know Haskell when hiring. He is comfortable with Java because he knows he can always find a Java developer. So if I advertised we were looking for Haskell programmers in New York City, how many would respond? Please reply to this email if you would respond. Email me privately if you like and I will post the results to haskell-cafe later. Thanks, Tony ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Hypothetical Haskell job in New York
Let me give you more information about this hypothetical job posting. Our company is a startup CDN ( http://en.wikipedia.org/wiki/Content_Delivery_Network) about 3 years old and doing well. You would hythothetically be one of 7 programmer who write all the software involved in a CDN including http server, dns server, monitoring, load balancing, customer and operator user interface, etc. The pay depends on experience but is good. I already got a few replies, keep them coming. Thanks, Tony On Wed, Jan 7, 2009 at 7:01 PM, Tony Hannan tonyhann...@gmail.com wrote: Hello Haskellers, I'm trying to convince my boss to use Haskell. His main concern is finding people who know Haskell when hiring. He is comfortable with Java because he knows he can always find a Java developer. So if I advertised we were looking for Haskell programmers in New York City, how many would respond? Please reply to this email if you would respond. Email me privately if you like and I will post the results to haskell-cafe later. Thanks, Tony ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] State Monad - using the updated state
Hi, I¹m a newbie looking to get my head around using the State Monad for random number generation. I¹ve written non-monad code that achieves this no problem. When attempting to use the state monad I can get what I know to be the correct initial value and state, but can¹t figure out for the life of me how to then increment it without binding more calls there and then. Doing several contiguous calls is not what I want to do here and the examples I¹ve read all show this (using something like liftM2 (,) myRandom myRandom). I want to be able to do: Get_a_random_number a whole load of other stuff Get the next number as defined by the updated state in the first call some more stuff Get another number, and so on. I get the first number fine, but am lost at how to get the second, third, forth etc without binding there and then. I just want each number one at a time where and when I want it, rather than saying give 1,2,10 or even n¹ numbers now. I¹m sure it¹s blindly obvious! Note: I¹m not using Haskell¹s built in Random functionality (nor is that an option), I¹ll spare the details of the method I¹m using (NRC¹s ranq1) as I know it works for the non-Monad case, and it¹s irrelevent to the question. So the code is: ranq1 :: Word64 - ( Double, Word64 ) ranq1 state = ( output, newState ) where newState = ranq1Increment state output = convert_to_double newState ranq1Init :: Word64 - Word64 ranq1Init = convert_to_word64 . ranq1Increment . xor_v_init -- I¹ll leave the detail of how ranq1Increment works out for brevity. I know this bit works fine. Same goes for the init function it¹s just providing an initial state. -- The Monad State Attempt getRanq1 :: State Word64 Double getRanq1 = do state - get let ( randDouble, newState ) = ranq1 state put newState return randDouble _ And then in my main _ -- 124353542542 is just an arbitrary seed main :: IO() main = do let x = evalState getRanq1 (ranq1Init 124353542542) print (x) As I said this works fine; x gives me the correct first value for this sequence, but how do I then get the second and third without writing the giveMeTenRandoms style function? I guess what I want is a next() type function, imperatively speaking. Many thanks for any help, Phil. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Template Haskell question
On Wed, Jan 7, 2009 at 12:58 PM, Jeff Heard jefferson.r.he...@gmail.com wrote: And how do I encode a{ mousePositionf = b } in template haskell without using the [| |] syntax, so that I can use mkName? Whenever I have a question like that, I just ask ghci: $ ghci -fth ghci :m Control.Monad.Identity Language.Haskell.TH ghci runQ [| 1 + 1 |] InfixE (Just (LitE (IntegerL 1))) (VarE GHC.Num.+) (Just (LitE (IntegerL 1))) ghci runQ [| \x - x { runIdentity = 1 } |] LamE [VarP x_1] (RecUpdE (VarE x_1) [(Control.Monad.Identity.runIdentity,LitE (I ntegerL 1))]) Note that GHCi shows TH names without mkName or quotes, so you need to add those. But it shows you the structure you want to generate. You can also use $() and [| |] inside [| |] to generate additional data in TH directly: ghci runQ $ do { VarE n - [| runIdentity |] ; [| \x - $(recUpdE [| x |] [ fmap (\e - (n,e)) [| 1 |] ]) |] } LamE [VarP x_2] (RecUpdE (VarE x_2) [(Control.Monad.Identity.runIdentity,LitE (I ntegerL 1))]) Note the VarE n - [| identifier |] trick to extract the name from an identifier. -- ryan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] State Monad - using the updated state in an adhoc manner
Hi, I¹m a newbie looking to get my head around using the State Monad for random number generation. I¹ve written non-monad code that achieves this no problem. When attempting to use the state monad I can get what I know to be the correct initial value and state, but can¹t figure out for the life of me how to then increment it without binding more calls there and then. Doing several contiguous calls is not what I want to do here and the examples I¹ve read all show this (using something like liftM2 (,) myRandom myRandom). I want to be able to do: Get_a_random_number a whole load of other stuff Get the next number as defined by the updated state in the first call some more stuff Get another number, and so on. I get the first number fine, but am lost at how to get the second, third, forth etc without binding there and then. I just want each number one at a time where and when I want it, rather than saying give 1,2,10 or even n¹ numbers now. I¹m sure it¹s blindly obvious! Note: I¹m not using Haskell¹s built in Random functionality (nor is that an option), I¹ll spare the details of the method I¹m using (NRC¹s ranq1) as I know it works for the non-Monad case, and it¹s irrelevent to the question. So the code is: ranq1 :: Word64 - ( Double, Word64 ) ranq1 state = ( output, newState ) where newState = ranq1Increment state output = convert_to_double newState ranq1Init :: Word64 - Word64 ranq1Init = convert_to_word64 . ranq1Increment . xor_v_init -- I¹ll leave the detail of how ranq1Increment works out for brevity. I know this bit works fine. Same goes for the init function it¹s just providing an initial state. -- The Monad State Attempt getRanq1 :: State Word64 Double getRanq1 = do state - get let ( randDouble, newState ) = ranq1 state put newState return randDouble _ And then in my main _ -- 124353542542 is just an arbitrary seed main :: IO() main = do let x = evalState getRanq1 (ranq1Init 124353542542) print (x) As I said this works fine; x gives me the correct first value for this sequence, but how do I then get the second and third without writing the giveMeTenRandoms style function? I guess what I want is a next() type function, imperatively speaking. Many thanks for any help, Phil. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] State Monad - using the updated state
Hi Phil. First a quick style comment, then I'll get to the meat of your question. getRanq1 is correct; although quite verbose. A simpler definition is this: getRanq1 = State ranq1 This uses the State constructor from Control.Monad.State: State :: (s - (a,s)) - State s a What it sounds like you want is this: main = do x - getARandomNumber ... do some other stuff y - getAnotherRandomNumber .. etc. using State. There are two ways to go about this; the first is, if the entire computation is pure, that is, the do some other stuff doesn't do IO, you can embed the whole computation in State: seed = 124353542542 main = do result - evalState randomComputation (ranq1Init seed) ... some IO using result ... randomComputation = do x - getRanq1 let y = some pure computation using x z - getRanq1 w - something that uses x, y, and z that also uses the random source ... etc. return (some result) The other option, if you want to do IO in between, is to use a transformer version of State: type MyMonad a = StateT Word64 IO a main = withStateT (ranq1Init seed) $ do x - getRanq1_t liftIO $ print x ... y - getRanq1_t ... getRanq1_t :: MyMonad Double getRanq1_t = liftStateT getRanq1 liftStateT :: State s a - MyMonad a liftStateT m = StateT $ \s - return (runState m s) withStateT :: Word64 - MyMonad a - IO a withStateT s m = evalStateT m s -- can also just use withStateT = flip evalStateT This uses these functions from Control.Monad.State: liftIO :: MonadIO m = IO a - m a This takes any IO action and puts it into any monad that supports IO. In this case, StateT s IO a fits. runState :: StateT s a - s - (a,s) This evaluates a pure stateful computation and gives you the result. StateT :: (s - m (a,s)) - StateT s m a This builds a StateT directly. You could get away without it like this: liftStateT m = do s - get let (a, s') = runState m s put s' return a (note the similarity to your getRanq1 function!) evalStateT :: StateT s m a - s - m a This is just evalState for the transformer version of State. In our case it has the type (MyMonad a - Word64 - IO a) This said, as a beginner I recommend trying to make more of your code pure so you can avoid IO; you do need side effects for some things, but while learning it makes sense to try as hard as you can to avoid it. You can make a lot of interesting programs with just interact and pure functions. If you're just doing text operations, try to make your program look like this: main = interact pureMain pureMain :: String - String pureMain s = ... You'll find it will teach you a lot about laziness the power of purity! A key insight is that State *is* pure, even though code using it looks somewhat imperative. -- ryan P.S. If you can't quite get out of the imperative mindset you can visit imperative island via the ST boat. 2009/1/7 Phil pbeadl...@mail2web.com: Hi, I'm a newbie looking to get my head around using the State Monad for random number generation. I've written non-monad code that achieves this no problem. When attempting to use the state monad I can get what I know to be the correct initial value and state, but can't figure out for the life of me how to then increment it without binding more calls there and then. Doing several contiguous calls is not what I want to do here – and the examples I've read all show this (using something like liftM2 (,) myRandom myRandom). I want to be able to do: Get_a_random_number a whole load of other stuff Get the next number as defined by the updated state in the first call some more stuff Get another number, and so on. I get the first number fine, but am lost at how to get the second, third, forth etc without binding there and then. I just want each number one at a time where and when I want it, rather than saying give 1,2,10 or even 'n' numbers now. I'm sure it's blindly obvious! Note: I'm not using Haskell's built in Random functionality (nor is that an option), I'll spare the details of the method I'm using (NRC's ranq1) as I know it works for the non-Monad case, and it's irrelevent to the question. So the code is: ranq1 :: Word64 - ( Double, Word64 ) ranq1 state = ( output, newState ) where newState = ranq1Increment state output = convert_to_double newState ranq1Init :: Word64 - Word64 ranq1Init = convert_to_word64 . ranq1Increment . xor_v_init -- I'll leave the detail of how ranq1Increment works out for brevity. I know this bit works fine. Same goes for the init function it's just providing an initial state. -- The Monad State Attempt getRanq1 :: State Word64 Double getRanq1 = do state - get let ( randDouble, newState ) = ranq1 state put newState return randDouble _ And then in my main _ -- 124353542542 is just an arbitrary seed main :: IO() main = do let x = evalState getRanq1 (ranq1Init 124353542542)
Re: [Haskell-cafe] Re: Tying a simple circularly STM linked list
Thanks Chris, The undefined works for me. -John On Wed, Jan 7, 2009 at 11:11 AM, ChrisK hask...@list.mightyreason.comwrote: You can use undefined or error ... : {-# LANGUAGE RecursiveDo #-} import Control.Concurrent.STM import Control.Monad.Fix -- Transactional loop. A loop is a circular link list. data Loop a = ItemLink { item :: a , prev :: TVar (Loop a) , next :: TVar (Loop a) } -- Create a new empty transactional loop. newLoop :: a - STM (TVar (Loop a)) newLoop item = do tLoop - newTVar undefined writeTVar tLoop (ItemLink item tLoop tLoop) return tLoop Hmmm.. STM does not have a MonadFix instance. But IO does: -- Use MonadFix instance of newLoopIO newLoopIO :: a - IO (TVar (Loop a)) newLoopIO item = mfix (\ tLoop - newTVarIO (ItemLink item tLoop tLoop)) But mfix (like fix) is difficult to read in large amounts, so there is mdo: -- Use RecursiveDo notation newLoopMDO :: a - IO (TVar (Loop a)) newLoopMDO item = mdo tLoop - newTVarIO (ItemLink item tLoop tLoop) return tLoop Cheers, Chris ___ 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] databases in Haskell type-safety
On Sat, Jan 03, 2009 at 10:48:44AM +0100, Gour wrote: So, considering that HDBC nicely abstracts API enabling one to easily switch from e.g. Sqlite3 to Postgres, and it is used as in example for database programming, it seems as logical (and the only) choice for Haskell database programming in a real-world? Sorry to come to this late, but I figured I'd jump in a bit, as someone that uses HDBC in the real world. I would say that database interactions are typically limited to a small part of code. In small programs, I generally have a DB module that does the queries, and marshals everything to/from the rich Haskell types I define. Any possible type issues are thus constrained to that small part of code. HDBC is a low-level abstraction, which can be used on its own or, of course, as a layer underlying HaskellDB or some such. I do not dispute the use of tools such as HaskellDB or others that try to automate the business of representing a database's schema -- and queries against it -- using a language's type system. There are a lot of these systems in a lot of languages. I've used some of them. And, almost universally, they annoy me. I find it takes longer to write code with them than without, and often they have issues representing some query that I know I can do easily in SQL but maybe can't as easy in the toolkit. As an example, when I last looked at HaskellDB in 2005, I found that it was impossible to do a SELECT without a DISTINCT [1]. There are many situations where such a thing is necessary, so I had to discard it for my projects. HDBC is more similar to Perl's DBI or Python's DB-API (or perhaps a sane version of JDBC). It is a standard interface to SQL RDBMS engines that provides some tools for marshaling data back and forth, but generally leaves you to construct the queries. It does not really solve the same problem as HaskellDB. I wrote HDBC because of some issues with HSQL. I had trouble with segfaults, referencing returned data by column number instead of name, and it did not support replacable parameters. HDBC supports all of that, and as a result, does not provide any functions to escape data for a SQL engine because its design renders such functions unnecessary. I have not followed HSQL development since. So, this was not intended as an HDBC commercial, just more of a braindump as to why I wrote it. Hope it helps. HDBC is actively used in mission-critical applications where I work. We use both the PostgreSQL and ODBC backends in production. We even use the ODBC backend along with the particularly nefarious ODBC interface for the Progress 4GL database. I use the Sqlite3 backend quite a bit in my own personal projects, such as hpodder and twidge. I'm not familiar with Takusen which says: Takusen's unique selling point is safety and efficiency... and I would appreciate if someone could shed some more light to its 'safety' and the present status? [1] http://www.haskell.org/pipermail/haskell-cafe/2005-August/011026.html -- John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Template Haskell question
On Wed, Jan 7, 2009 at 8:54 PM, Ryan Ingram ryani.s...@gmail.com wrote: You can also use $() and [| |] inside [| |] to generate additional data in TH directly: ghci runQ $ do { VarE n - [| runIdentity |] ; [| \x - $(recUpdE [| x |] [ fmap (\e - (n,e)) [| 1 |] ]) |] } LamE [VarP x_2] (RecUpdE (VarE x_2) [(Control.Monad.Identity.runIdentity,LitE (I ntegerL 1))]) Note the VarE n - [| identifier |] trick to extract the name from an identifier. You can use the single quote to get the name of a value. ghci runQ [| \x - $(recUpdE [| x |] [ fmap (\e - ('runIdentity, e)) [| 1 |] ]) |] LamE [VarP x_1] (RecUpdE (VarE x_1) [(Control.Monad.Identity.runIdentity,LitE (IntegerL 1))]) There's more in section 8.9.1 of the GHC manual. -- Dave Menendez d...@zednenem.com http://www.eyrie.org/~zednenem/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] data declarations should provide fold functions
I've had to use some fold functions recently and I've come to the conclusion that Haskell should automatically generate fold functions for data definitions. To clarify what I mean, for the data definition: data MyData = This Int Char | That String Int Int there should be a matching function definition: foldMyData f g (This a b) = f a b foldMyData f g (That a b c) = g a b c This definition is as natural as the constructors This and That. Consider the tuple definition and its fold: data (,) a b = (a, b) foldTuple f (x, y) = f x y and the definition of Either and its fold: data Either a b = Left a | Right b foldEither f g (Left x) = f a foldEither f g (Right x) = g x In logic these constructors define the introduction rules ((,), Left and Right) and the folds define the elimination rules (exactly for Either, indirectly for tuples) for conjunction and disjunction. Further, while pattern-matching is very convenient for accessing the constituents of the data type, patterns are not first-class objects in Haskell. Fold functions, on the othe hand, are. They can be passed around and used in higher-order functions to extract constituents in a points-free manner. I know the short-term answer is use TH to derive folds if I want them, but I think such an important concept should probably be part of the language. Tim Newsham http://www.thenewsh.com/~newsham/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Staged evaluation, names?
Dear Cafe, Every now and then I find myself in the position where I'd like to define some hairy value as a CAF instead of a literal, but I'd like for it to be fully evaluated at compile-time rather than postponed until runtime. It'd be possible to bludgeon the CPP into doing this, but it seems easier to use an autocannon like Template Haskell to swat this fly. This seems like a common thing for folks to want but the TH documentation targets much higher-hanging fruit, which actually made it harder to figure out how to do something this basic (which would have been transparent with MetaML/MetaOCaml-like syntax). I've figured it out and circumvented the gotchas, and I was thinking of releasing the code as a counterpoint to all the very-high level TH tutorials. The question for y'all is what should I call it? I've been calling the template-function qaf (for Compiled Applicative Form ;) and the type class with that function would be the only thing in the package, but I'm not sure where QAF.hs should be in the module hierarchy. Thoughts? -- Live well, ~wren ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] data declarations should provide fold functions
Tim Newsham wrote: I know the short-term answer is use TH to derive folds if I want them, but I think such an important concept should probably be part of the language. If you don't mind the hairy code, there's always this generic answer from #haskell almost a year ago: http://hpaste.org/7682 You'd need to hook it up with a preprocessor script since it's a String-String function. It should be pretty easy to rewrite that into TH code in order to clean it up. I agree, it'd be nice to have it as a standard deriving clause, but since every fold has a different type it's challenging to make it fit into the language rather than being a wart. Some of the stuff in Data.Generics, Data.Typable, etc might could help. If you come up with anything you like, it shouldn't be too hard to (convince someone to) convert the logic into a language extension. -- Live well, ~wren ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] State Monad - using the updated state in an adhoc manner
On 2009 Jan 7, at 20:58, Phil wrote: -- 124353542542 is just an arbitrary seed main :: IO() main = do let x = evalState getRanq1 (ranq1Init 124353542542) print (x) You're throwing away the state you want to keep by using evalState there. But you're also missing the point of using State; done right the evalState *is* what you want. What you want to do is run all of your operations within State, exiting it only when you're done: main = do print (evalState doRanqs (ranq1init 124353542542)) doRanqs = do r - getRanq1 -- do something involving it another - getRanq1 -- do more stuff Alternately you may use a tail recursive function or a fold, etc., depending on what exactly you're trying to accomplish. You do *not* want to execState or runState every individual time you want a random number; if you do that you'll have to carry the random state around yourself (in effect you'd be rewriting the State monad by hand, poorly). Stay in State and let it do the carrying for you. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon universityKF8NH ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe