[Haskell-cafe] Correct way to catch all exceptions

2013-07-10 Thread Michael Snoyman
There's a pattern that arises fairly often: catching every exception thrown by code. The naive approach is to do something like: result - try someCode case result of Left (e :: SomeException) - putStrLn $ It failed: ++ show e Right realValue - useRealValue This seems

Re: [Haskell-cafe] Promoting Haskell via Youtube movies

2013-07-10 Thread Alfredo Di Napoli
Thanks guys, lots of interesting material I wasn't aware of! A. On 22 June 2013 14:42, Mihai Maruseac mihai.marus...@gmail.com wrote: On Wed, Jun 19, 2013 at 3:03 AM, Carlo Hamalainen ca...@carlo-hamalainen.net wrote: On 18/06/13 04:23, Mihai Maruseac wrote: I was wondering if we have

Re: [Haskell-cafe] Array, Vector, Bytestring

2013-07-10 Thread Alfredo Di Napoli
To make the transition easier I have an experimental library which defines a ByteString as a type synonym of a Storable.Vector of Word8 and provides the same interface as the bytestring package: https://github.com/basvandijk/vector-bytestring That's interesting Bas. What bothers me about

Re: [Haskell-cafe] Array, Vector, Bytestring

2013-07-10 Thread Bas van Dijk
On 10 July 2013 08:57, Alfredo Di Napoli alfredo.dinap...@gmail.com wrote: To make the transition easier I have an experimental library which defines a ByteString as a type synonym of a Storable.Vector of Word8 and provides the same interface as the bytestring package:

[Haskell-cafe] Non-recursive let [Was: GHC bug? Let with guards loops]

2013-07-10 Thread oleg
Andreas wrote: The greater evil is that Haskell does not have a non-recursive let. This is source of many non-termination bugs, including this one here. let should be non-recursive by default, and for recursion we could have the good old let rec. Hear, hear! In OCaml, I can (and often do)

Re: [Haskell-cafe] Non-recursive let [Was: GHC bug? Let with guards loops]

2013-07-10 Thread Andreas Abel
Hi Oleg, just now I wrote a message to haskell-pr...@haskell.org to propose a non-recursive let. Unfortunately, the default let is recursive, so we only have names like let' for it. I also mentioned the ugly workaround (- return $) that I was shocked to see the first time, but use myself

Re: [Haskell-cafe] Non-recursive let [Was: GHC bug? Let with guards loops]

2013-07-10 Thread Edward Z. Yang
In my opinion, when you are rebinding a variable with the same name, there is usually another way to structure your code which eliminates the variable. If you would like to write: let x = foo input in let x = bar x in let x = baz x in instead, write baz . bar . foo $ input If

Re: [Haskell-cafe] Non-recursive let [Was: GHC bug? Let with guards loops]

2013-07-10 Thread Ertugrul Söylemez
o...@okmij.org wrote: Hear, hear! In OCaml, I can (and often do) write let (x,s) = foo 1 [] in let (y,s) = bar x s in let (z,s) = baz x y s in ... In Haskell I'll have to uniquely number the s's: let (x,s1) = foo 1 [] in let (y,s2) = bar x s1 in

Re: [Haskell-cafe] Correct way to catch all exceptions

2013-07-10 Thread Ertugrul Söylemez
Michael Snoyman mich...@snoyman.com wrote: shouldBeCaught :: SomeException - Bool One first stab at such a function would be to return `False` for AsyncException and Timeout, and `True` for everything else, but I'm not convinced that this is sufficient. Are there any thoughts on the

Re: [Haskell-cafe] Correct way to catch all exceptions

2013-07-10 Thread John Lato
I think 'shouldBeCaught' is more often than not the wrong thing. A whitelist of exceptions you're prepared to handle makes much more sense than excluding certain operations. Some common whitelists, e.g. filesystem exceptions or network exceptions, might be useful to have. I like Ertugrul's

Re: [Haskell-cafe] Correct way to catch all exceptions

2013-07-10 Thread Erik Hesselink
Hi Michael, We do this as well. In addition to AsyncException, we ignore BlockedIndefinitelyOnSTM, BlockedIndefinitelyOnMVar and Deadlock. I'm not sure you can ignore Timeout, since the type is not exported from System.Timeout. I'm not sure how to classify these, though. They are in some sense

Re: [Haskell-cafe] Non-recursive let [Was: GHC bug? Let with guards loops]

2013-07-10 Thread Andreas Abel
On 10.07.2013 10:16, Ertugrul Söylemez wrote: o...@okmij.org wrote: Hear, hear! In OCaml, I can (and often do) write let (x,s) = foo 1 [] in let (y,s) = bar x s in let (z,s) = baz x y s in ... In Haskell I'll have to uniquely number the s's: let (x,s1) =

[Haskell-cafe] Proposal: Non-recursive let

2013-07-10 Thread oleg
Jon Fairbairn wrote: It just changes forgetting to use different variable names because of recursion (which is currently uniform throughout the language) to forgetting to use non recursive let instead of let. Let me bring to the record the message I just wrote on Haskell-cafe

Re: [Haskell-cafe] Non-recursive let [Was: GHC bug? Let with guards loops]

2013-07-10 Thread Alberto G. Corona
I think that a non-non recursive let could be not compatible with the pure nature of Haskell. Let is recursive because, unlike in the case of other languages, variables are not locations for storing values, but the expressions on the right side of the equality themselves. And obviously it is not

Re: [Haskell-cafe] Correct way to catch all exceptions

2013-07-10 Thread Erik Hesselink
On Wed, Jul 10, 2013 at 10:39 AM, John Lato jwl...@gmail.com wrote: I think 'shouldBeCaught' is more often than not the wrong thing. A whitelist of exceptions you're prepared to handle makes much more sense than excluding certain operations. Some common whitelists, e.g. filesystem exceptions

[Haskell-cafe] Non-recursive let [Was: GHC bug? Let with guards loops]

2013-07-10 Thread oleg
If you would like to write let (x,s) = foo 1 [] in let (y,s) = bar x s in let (z,s) = baz x y s in instead, use a state monad. Incidentally I did write almost exactly this code once. Ironically, it was meant as a lead-on to the State monad. But there have been other cases

Re: [Haskell-cafe] Array, Vector, Bytestring

2013-07-10 Thread Alfredo Di Napoli
Hello Bas, sorry for being unclear. What you say is correct, I was referring (and I realised this after posting :D ) that the real annoying thing is fragmentation in memory. Due to the fact the GC can't move those objects, if we have long running processes our memory will become more and more

Re: [Haskell-cafe] Correct way to catch all exceptions

2013-07-10 Thread Alberto G. Corona
Don´t tried it and probably it does not even compile, but a possibility could be along these lines: catchExcept excepts handle e= do if not . null $ filter ( \(SomeException e') - typeOf e= typeOf e') excepts then throw e else handle e use: u= undefined excluded=

Re: [Haskell-cafe] Non-recursive let [Was: GHC bug? Let with guards loops]

2013-07-10 Thread Ertugrul Söylemez
o...@okmij.org wrote: If you would like to write let (x,s) = foo 1 [] in let (y,s) = bar x s in let (z,s) = baz x y s in instead, use a state monad. Incidentally I did write almost exactly this code once. Ironically, it was meant as a lead-on to the State monad. But

Re: [Haskell-cafe] Correct way to catch all exceptions

2013-07-10 Thread John Lato
On Wed, Jul 10, 2013 at 5:02 PM, Erik Hesselink hessel...@gmail.com wrote: On Wed, Jul 10, 2013 at 10:39 AM, John Lato jwl...@gmail.com wrote: I think 'shouldBeCaught' is more often than not the wrong thing. A whitelist of exceptions you're prepared to handle makes much more sense than

Re: [Haskell-cafe] Optimization flag changing result of code execution

2013-07-10 Thread kudah
Yes, it does. Without optimizations the result is ndgorsfesnywaiqraloa, while with optimizations the result is always aabb. On Wed, 10 Jul 2013 02:21:10 +0400 Aleksey Khudyakov alexey.sklad...@gmail.com wrote: On 10.07.2013 01:38, kudah wrote: I've attached the script that I

Re: [Haskell-cafe] Correct way to catch all exceptions

2013-07-10 Thread Michael Snoyman
On Wed, Jul 10, 2013 at 1:01 PM, John Lato jwl...@gmail.com wrote: On Wed, Jul 10, 2013 at 5:02 PM, Erik Hesselink hessel...@gmail.comwrote: On Wed, Jul 10, 2013 at 10:39 AM, John Lato jwl...@gmail.com wrote: I think 'shouldBeCaught' is more often than not the wrong thing. A whitelist of

Re: [Haskell-cafe] Correct way to catch all exceptions

2013-07-10 Thread kudah
I think that new SomeAsyncException type in base is supposed to make it possible to ignore all asynchronous exceptions. https://github.com/ghc/packages-base/blob/master/GHC/IO/Exception.hs#L113 On Wed, 10 Jul 2013 09:28:12 +0300 Michael Snoyman mich...@snoyman.com wrote: There's a pattern that

Re: [Haskell-cafe] Is the following implemented by a sparse matrix representation? type Graph n w = Array (n, n) (Maybe w)

2013-07-10 Thread Thomas Horstmeyer
Looks like the graph is represented by an adjacency matrix, where the element at (a, b) tells you whether there is an edge from node a to node b with weight x or not by having the value (Just x) or Nothing, respectively. Whether the matrix is sparse depends on the data, i.e. how many edges are

Re: [Haskell-cafe] Correct way to catch all exceptions

2013-07-10 Thread Ertugrul Söylemez
Michael Snoyman mich...@snoyman.com wrote: Any thoughts on this? I'm not sure exactly what would be the right method to add to the Exception typeclass, but if we can come to consensus on that and there are no major objections to my separate package proposal, I think this would be something

[Haskell-cafe] Engineering position at Vector Fabrics

2013-07-10 Thread Stefan Holdermans
Vector Fabrics has another position open for a functional programmer. See below and http://www.vectorfabrics.com/company/career/functional_programmer for details. This time, we particularly welcome applications from experienced developers, the position providing a fair share of opportunities

Re: [Haskell-cafe] ANNOUNCE: MFlow 3.0

2013-07-10 Thread Adrian May
Oh how nice! I have been looking at MFlow a lot lately and I think it's got something quite special that Yesod, Happstack, etc don't seem to have, at least, not as far as I know. I mean, look at this: sumWidget= pageFlow sum $ do n1 - p Enter first number ++ getInt Nothing **

Re: [Haskell-cafe] Parsec error message not making any sense

2013-07-10 Thread David McBride
First, I want to say you'd have a lot better luck with these questions by posting to stackoverflow. This really isn't the right place for it. As for why your parser is not working, you need to realize that parsec does not backtrack by default. It does this to conserve memory (so it doesn't have

Re: [Haskell-cafe] ANNOUNCE: MFlow 3.0

2013-07-10 Thread Alberto G. Corona
Thanks Adrian. The racket people where pioneers in this idea I think. There is another web framework in Ocaml, Osigen that it is also continuation based. MFlow is not continuation-based but it also define the navigation as a sequence. But only Seaside (and now MFlow) supports many flows in the

[Haskell-cafe] Music / MIDI help

2013-07-10 Thread Mark Lentczner
I'm a little lost in the bewildering array of music packages for Haskell, and need some help. I'm looking to recreate one of my algorithmic music compositions from the 1980s. I can easily code the logic in Haskell. I'm looking for a the right set of packages and SW so that I can: a) generate

Re: [Haskell-cafe] Is the following implemented by a sparse matrix representation? type Graph n w = Array (n, n) (Maybe w)

2013-07-10 Thread Twan van Laarhoven
The standard array types, such as Array (n,n) (Maybe w) will be implemented as a dense array. If you want to use a sparse matrix, you will explicitly have to ask for it. For instance by using something like IntMap (IntMap w) or Map (n,n) w or Array n (IntMap w). Each of these representations is

Re: [Haskell-cafe] Non-recursive let [Was: GHC bug? Let with guardsloops]

2013-07-10 Thread Donn Cave
quoth Alberto G. Corona, Let is recursive because, unlike in the case of other languages, variables are not locations for storing values, but the expressions on the right side of the equality themselves. And obviously it is not possible for a variable-expression to be two expressions at the

Re: [Haskell-cafe] Is the following implemented by a sparse matrix representation? type Graph n w = Array (n, n) (Maybe w)

2013-07-10 Thread KC
Thank you :) On Wed, Jul 10, 2013 at 8:33 AM, Twan van Laarhoven twa...@gmail.comwrote: The standard array types, such as Array (n,n) (Maybe w) will be implemented as a dense array. If you want to use a sparse matrix, you will explicitly have to ask for it. For instance by using something

Re: [Haskell-cafe] Music / MIDI help

2013-07-10 Thread Anton Kholomiov
For midi you can try my packages: temporal-music-notation and temporal-music-notation-demo (and maybe temporal-music-notation-western). It looks like Haskore but different inside. It tries to be clear, minimal, more efficient and documented (as far as my english goes though). Anton 2013/7/10

Re: [Haskell-cafe] Proposal: Non-recursive let

2013-07-10 Thread Ezra e. k. Cooper
I support Oleg's proposal. A shadowing, non-recursive let would be a useful tool. As starter suggestions for the keyword or syntax, I submit: let new x = expr in body -- Not the old x! let shadowing x = expr in body shadow x = expr in body let x =! expr in body -- The explosive

Re: [Haskell-cafe] Non-recursive let [Was: GHC bug? Let with guardsloops]

2013-07-10 Thread Ertugrul Söylemez
Donn Cave d...@avvanta.com wrote: Let is recursive because, unlike in the case of other languages, variables are not locations for storing values, but the expressions on the right side of the equality themselves. And obviously it is not possible for a variable-expression to be two

Re: [Haskell-cafe] Proposal: Non-recursive let

2013-07-10 Thread Ertugrul Söylemez
Ezra e. k. Cooper e...@ezrakilty.net wrote: As starter suggestions for the keyword or syntax, I submit: let new x = expr in body -- Not the old x! It's not the old x in either case (recursive and non-recursive). let shadowing x = expr in body shadow x = expr in body It's

Re: [Haskell-cafe] ANNOUNCE: MFlow 3.0

2013-07-10 Thread Alexander Kjeldaas
Here are some common-lisp web frameworks using continuations: http://common-lisp.net/project/cl-weblocks/ http://common-lisp.net/project/ucw/features.html What always worried me with these frameworks is how they could be made robust in case of failures. Storing all state in a database backend

Re: [Haskell-cafe] Music / MIDI help

2013-07-10 Thread Brent Yorgey
Maybe Euterpea? http://haskell.cs.yale.edu/euterpea/download/ On Wed, Jul 10, 2013 at 08:20:08AM -0700, Mark Lentczner wrote: I'm a little lost in the bewildering array of music packages for Haskell, and need some help. I'm looking to recreate one of my algorithmic music compositions from

Re: [Haskell-cafe] Proposal: Non-recursive let

2013-07-10 Thread Carter Schonwald
theres a very simple way to do non recursive let already! do notation in the identity monad. I use it quite a lot lately. On Wed, Jul 10, 2013 at 1:49 PM, Ertugrul Söylemez e...@ertes.de wrote: Ezra e. k. Cooper e...@ezrakilty.net wrote: As starter suggestions for the keyword or syntax, I

Re: [Haskell-cafe] ANNOUNCE: MFlow 3.0

2013-07-10 Thread Alberto G. Corona
My plan is to synchronize MFlow servers using cloud Haskell since the state serialization is small. I´m working on it. However continuation based frameworks can not synchronize state. There is swarm in scala that generate portable continuations but this is not used in the context of web

[Haskell-cafe] Netwire bouncing ball

2013-07-10 Thread Just
Hello, I'm trying to get a grasp of netwire by implementing a bouncing ball simulation and I'm failing. The ball starts from the ground with a given velocity and when hitting the ground the wire inhibits successfully. Now I'm kinda stuck. How can I make the ball bounce? Here is the code:

Re: [Haskell-cafe] Netwire bouncing ball

2013-07-10 Thread Jason Dagit
On Wed, Jul 10, 2013 at 2:15 PM, Just hask...@justnothing.org wrote: Hello, I'm trying to get a grasp of netwire by implementing a bouncing ball simulation and I'm failing. The ball starts from the ground with a given velocity and when hitting the ground the wire inhibits successfully. Now

Re: [Haskell-cafe] Netwire bouncing ball

2013-07-10 Thread Ertugrul Söylemez
Just hask...@justnothing.org wrote: I'm trying to get a grasp of netwire by implementing a bouncing ball simulation and I'm failing. The ball starts from the ground with a given velocity and when hitting the ground the wire inhibits successfully. Now I'm kinda stuck. How can I make the ball

Re: [Haskell-cafe] Non-recursive let [Was: GHC bug? Let with guardsloops]

2013-07-10 Thread Andreas Abel
Totality checking will generate a lot of false positives. One would like an analysis that prints an error message if an expression is *definitely* looping in all cases. While I have studied termination, I have not studied non-termination analyses. It is harder than termination. For

Re: [Haskell-cafe] Proposal: Non-recursive let

2013-07-10 Thread Andreas Abel
On 10.07.13 9:31 PM, Carter Schonwald wrote: theres a very simple way to do non recursive let already! do notation in the identity monad. I use it quite a lot lately. Yeah, the hack x - return $ e instead of let x = e has been discussed already. If you put everything into the Identity

Re: [Haskell-cafe] Non-recursive let [Was: GHC bug? Let with guardsloops]

2013-07-10 Thread Andreas Abel
On 10.07.13 6:00 PM, Donn Cave wrote: quoth Alberto G. Corona, Let is recursive because, unlike in the case of other languages, variables are not locations for storing values, but the expressions on the right side of the equality themselves. And obviously it is not possible for a

Re: [Haskell-cafe] Non-recursive let [Was: GHC bug? Let with guards loops]

2013-07-10 Thread Andreas Abel
On 10.07.13 11:42 AM, Ertugrul Söylemez wrote: I think we are all aware that shadowing is a bad idea, no matter whether you do it through Identity or non-recursive let. WHAT?? [This is Richard Bird's WHAT?? when someone said that using folds is like programming in assembly language.]

Re: [Haskell-cafe] Non-recursive let [Was: GHC bug? Let with guardsloops]

2013-07-10 Thread Donn Cave
quoth Andreas Abel andreas.a...@ifi.lmu.de, ... I would doubt that nhc98 would interpret let xs = 0 : xs differently than ghc if it implemented anything close to the Haskell 98 standard. What I (so vaguely) remember was a compile error, for some reuse of an identifier where GHC permitted

Re: [Haskell-cafe] Correct way to catch all exceptions

2013-07-10 Thread John Lato
Hi Michael, I don't think those are particularly niche cases, but I still think this is a bad approach to solving the problem. My reply to Erik explicitly covers the worker thread case, and for running arbitrary user code (as in your top line) it's even simpler: just fork a new thread for the

Re: [Haskell-cafe] Non-recursive let [Was: GHC bug? Let with guards loops]

2013-07-10 Thread Richard A. O'Keefe
On 10/07/2013, at 8:42 PM, Andreas Abel wrote: Hear, hear! In OCaml, I can (and often do) write let (x,s) = foo 1 [] in let (y,s) = bar x s in let (z,s) = baz x y s in ... I really wish you wouldn't do that. After reading Dijkstra's paper on the fact that we have

Re: [Haskell-cafe] Non-recursive let [Was: GHC bug? Let with guardsloops]

2013-07-10 Thread Richard A. O'Keefe
On 11/07/2013, at 4:00 AM, Donn Cave wrote: I've gone to some trouble to dig up an nhc98 install (but can't seem to find one among my computers and GHC 7 won't build the source thanks to library re-orgs etc.) Because, I vaguely recall that nhc98's rules were different here? Anyone in a

Re: [Haskell-cafe] Non-recursive let [Was: GHC bug? Let with guardsloops]

2013-07-10 Thread Richard A. O'Keefe
On 11/07/2013, at 11:09 AM, Donn Cave wrote: let x = t + 1 in let y = x in let x = y + 1 in x Still no cigar. nhc98 v1.16 Program: main = print $ (let t = 0 in let x = t + 1 in let y = x in let x = y + 1 in x) Output: 2 ___

Re: [Haskell-cafe] Non-recursive let [Was: GHC bug? Let with guards loops]

2013-07-10 Thread oleg
Alberto G. Corona wrote: I think that a non-non recursive let could be not compatible with the pure nature of Haskell. I have seen this sentiment before. It is quite a mis-understanding. In fact, the opposite is true. One may say that Haskell is not quite pure _because_ it has recursive let.