Re: [Haskell-cafe] parsing currency amounts with parsec
Very helpful -- thanks everyone! The handling of currency amounts in hledger is what I was looking for in terms of alternate ways to parse and represent dollar amounts in Haskell. On Wed, May 11, 2011 at 6:05 PM, Simon Michael si...@joyful.com wrote: On 5/10/11 2:52 PM, Roman Cheplyaka wrote: You could read hledger[1] sources for inspiration: it's written in Haskell and contains some (quite generic) currency parsing. Hi Eric.. here's the code in question: http://hackage.haskell.org/packages/archive/hledger-lib/0.14/doc/html/src/Hledger-Read-JournalReader.html#postingamount and some related docs: http://hledger.org/MANUAL.html#amounts It's probably more complicated and less efficient than you need, but a source of ideas. ___ 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] Using cmake with haskell
On Wed, May 11, 2011 at 6:13 PM, Gregory Crosswhite gcr...@phys.washington.edu wrote: [snip] 1) Cabal is a tool that can only be used to build Haskell packages with some supporting C/C++ code thrown in and 2) Cabal is currently the only tool that can realistically be used to properly build and install Haskell packages due to the great complexity involved with getting all the details right I agree with much of what you said. I created this feature request for cabal, that I think would go quite aways towards addressing the problem, but someone marked it as wontfix: http://hackage.haskell.org/trac/hackage/ticket/815 In my opinion, the two most valuable things about cabal are its good dependency calculation and it allowed hackage to gain momentum. Unfortunately, we are also forced to use it as a build system and it's quite inadequate for that task. I say forced because there is no standard way to extract the dependency calculations from it. You have to write a Setup.hs file to extract it and it's not trivial. If you succeed at that task, then you can't even reuse the code without copypasting it later. In fact, I never invoke cabal-install directly anymore. I've corrupted my package databases too many times. I make sure to always use cabal-dev for everything. I think that says something about cabal's efficacy as a build system. Jason ps. As soon as I figure out a way to get infinite free time I'll implement the translation to makefiles myself... ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANNOUNCE: iterIO-0.1 - iteratee-based IO with pipe operators
On 11/05/2011 23:57, dm-list-haskell-c...@scs.stanford.edu wrote: At Wed, 11 May 2011 13:02:21 +0100, Simon Marlow wrote: However, if there's some simpler way to guarantee that= is the point where exceptions are thrown (and might be the case for GHC in practice), then I basically only need to update the docs. If someone with more GHC understanding could explain how asynchronous exceptions work, I'd love to hear it... There's no guarantee of the form that you mention - asynchronous exceptions can occur anywhere. However, there might be a way to do what you want (disclaimer: I haven't looked at the implementation of iterIO). Control.Exception will have a new operation in 7.2.1: allowInterrupt :: IO () allowInterrupt = unsafeUnmask $ return () which allows an asynchronous exception to be thrown inside mask (until 7.2.1 you can define it yourself, unsafeUnmask comes from GHC.IO). So to answer my own question from earlier, I did a bit of benchmarking, and it seems that on my machine (a 2.4 GHz Intel Xeon 3060, running linux 2.6.38), I get the following costs: 9 ns - return () :: IO () -- baseline (meaningless in itself) 13 ns - unsafeUnmask $ return () -- with interrupts enabled 18 ns - unsafeUnmask $ return () -- inside a mask_ 13 ns - ffi -- a null FFI call (getpid cached by libc) 18 ns - unsafeUnmask ffi -- with interrupts enabled 22 ns - unsafeUnmask ffi -- inside a mask_ Those are lower than I was expecting, but look plausible. There's room for improvement too (by inlining some or all of unsafeUnmask#). However, the general case of unsafeUnmask E, where E is something more complex than return (), will be more expensive because a new closure for E has to be created. e.g. try return x instead of return (), and try to make sure that the closure has to be created once per unsafeUnmask, not lifted out and shared. 131 ns - syscall -- getppid through FFI 135 ns - unsafeUnmask syscall -- with interrupts enabled 140 ns - unsafeUnmask syscall -- inside a mask_ So it seems that the cost of calling unsafeUnmask inside every liftIO would be about 22 cycles per liftIO invocation, which seems eminently reasonable. You could then safely run your whole program inside a big mask_ and not worry about exceptions happening between= invocations. Though truly compute-intensive workloads could have issues, the kind of applications targeted by iterIO will spend most of their time doing I/O, so this shouldn't be an issue. Better yet, for programs that don't use asynchronous exceptions, if you don't put your whole program inside a mask_, the cost drops roughly in half. It's hard to imagine any real application whose performance would take a significant hit because of an extra 11 cycles per liftIO. Is there anything I'm missing? For instance, my machine only has one CPU, and the tests all ran with one thread. Does unmaskAsyncExceptions# acquire a spinlock that could lock the memory bus? Or is there some other reason unsafeUnmask could become expensive on NUMA machines, or in the presence of concurrency? There are no locks here, thanks to the message-passing implementation we use for throwTo between processors. unmaskeAsyncExceptions# basically pushes a small stack frame, twiddles a couple of bits in the thread state, and checks a word in the thread state to see whether any exceptions are pending. The stack frame untwiddles the bits again and returns. Cheers, Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] parMap doesn't work fine
Hello! I've just started using parallel computations in Haskell. parMap works fine, it is so easy to use. However, parMap fails with functions returning lazy structures, e.g. tuples. This code works as expected: (parMap rpar) bm tvalues bm :: Double - Double is some heavy function. But if I want to return list of pairs (t, bm t) it doesn't use cpu cores fine (only one is in use): (parMap rpar) (\t - (t, bm t)) tvalues The same is valid for functions returning lists. How do I use multiple cores with functions returning tuples? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] how to generate source code from TH Exp?
hi, i was wondering if it's possible to directly generate Haskell source code from a Template Haskell `Q Exp', i.e. use TH as a kind of preprocessor? i am asking because currently the iOS port of ghc doesn't support TH and i need to generate some instances for the persistent package [1,2]. i've been toying with fmap ppr . runQ $ q but the result needs to be edited by hand quite a bit. any ideas where to start? thanks, sk [1] http://hackage.haskell.org/package/persistent [2] http://hackage.haskell.org/package/persistent-template ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] how to generate source code from TH Exp?
Just pretty-print a Exp. It seems that show $ ppr exp will produce exactly what you need. The same goes for Dec (declarations), etc. 2011/5/12 Stefan Kersten s...@k-hornz.de: hi, i was wondering if it's possible to directly generate Haskell source code from a Template Haskell `Q Exp', i.e. use TH as a kind of preprocessor? i am asking because currently the iOS port of ghc doesn't support TH and i need to generate some instances for the persistent package [1,2]. i've been toying with fmap ppr . runQ $ q but the result needs to be edited by hand quite a bit. any ideas where to start? thanks, sk [1] http://hackage.haskell.org/package/persistent [2] http://hackage.haskell.org/package/persistent-template ___ 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] parMap doesn't work fine
Hello! I've just started using parallel computations in Haskell. parMap works fine, it is so easy to use. However, parMap fails with functions returning lazy structures, e.g. tuples. This code works as expected: (parMap rpar) bm tvalues Using rpar is redundant. That strategy schedules a value to maybe be computed later in parallel, but parMap already distributed work between cores, so you might as well use rseq or something. bm :: Double - Double is some heavy function. But if I want to return list of pairs (t, bm t) it doesn't use cpu cores fine (only one is in use): (parMap rpar) (\t - (t, bm t)) tvalues That's only evaluating the pair in parallel. bm t will only be computed when you open up the pairs afterwards. Try rdeepseq instead. Brandon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Hash table constructors return table in IO Monad. Why?
Is there some reason why ALL the ways to create a hash table return one in the IO Monad, but all the functions for retrieving a value from a hash table take as an argument a hash table NOT in the IO Monad? Michael = Prelude Data.HashTable let ht = fromList id [(5,'a'),(6,'b')]Prelude Data.HashTable fmap ((flip Data.HashTable.lookup) 6) htPrelude Data.HashTable Prelude Data.HashTable :t fmap ((flip Data.HashTable.lookup) 6) htfmap ((flip Data.HashTable.lookup) 6) ht :: IO (IO (Maybe Char)) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANNOUNCE: iterIO-0.1 - iteratee-based IO with pipe operators
On 12/05/2011 16:04, David Mazieres expires 2011-08-10 PDT wrote: At Thu, 12 May 2011 09:57:13 +0100, Simon Marlow wrote: So to answer my own question from earlier, I did a bit of benchmarking, and it seems that on my machine (a 2.4 GHz Intel Xeon 3060, running linux 2.6.38), I get the following costs: 9 ns - return () :: IO () -- baseline (meaningless in itself) 13 ns - unsafeUnmask $ return () -- with interrupts enabled 18 ns - unsafeUnmask $ return () -- inside a mask_ 13 ns - ffi -- a null FFI call (getpid cached by libc) 18 ns - unsafeUnmask ffi -- with interrupts enabled 22 ns - unsafeUnmask ffi -- inside a mask_ Those are lower than I was expecting, but look plausible. There's room for improvement too (by inlining some or all of unsafeUnmask#). Do you mean inline unsafeUnmask, or unmaskAsyncExceptions#? I tried inlining unsafeUnmask by writing my own version and giving it the INLINE pragma, and it didn't affect performance at all. Right, I meant inlining unmaskAsyncExceptions#, which would require compiler support. However, the general case of unsafeUnmask E, where E is something more complex than return (), will be more expensive because a new closure for E has to be created. e.g. try return x instead of return (), and try to make sure that the closure has to be created once per unsafeUnmask, not lifted out and shared. Okay. I'm surprised by getpid example wasn't already stressing this, but, indeed, I see a tiny difference with the following code: ffi= return . (1 +) -- where ffi calls getpid 13 ns - no unmasking 20 ns - unsafeUnmask when not inside _mask 25 ns - unsafeUnmask when benchmark loop in inside one big _mask So now we're talking about 28 cycles or something instead of 22. Still not a huge deal. Ok, sounds reasonable. There are no locks here, thanks to the message-passing implementation we use for throwTo between processors. Okay, that sounds good. So then there is no guarantee about ordering of throwTo exceptions? That seems like a good thing since there are other mechanisms for synchronization. What kind of ordering guarantee did you have in mind? We do guarantee that in throwTo t e1 throwTo t e2 Thread t will receive e1 before e2 (obviously, because throwTo is synchronous and only returns when the exception has been raised). Pending exceptions are processed in LIFO order (for no good reason other than performance), so there's no kind of fairness guarantee of the kind you get with MVars. One thread doing throwTo can be starved by others. I don't think that's a serious problem. Cheers, Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Hash table constructors return table in IO Monad. Why?
The hashtable needs to be been created in IO, after that, think of the 'hashtable' as a analogous to a file handle. You have to pass it around to do anything with it - but the only things you can do with it are in IO. (That's why no-one really likes it, of course...) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] how to generate source code from TH Exp?
On 5/12/11 4:03 PM, Serguey Zefirov wrote: Just pretty-print a Exp. It seems that show $ ppr exp will produce exactly what you need. The same goes for Dec (declarations), etc. ah ok, thanks! fwiw, here's a way to extract a list of module names that need to be imported, adapted from an example by Neil Mitchell using generics: extractModules :: Data a = a - [String] extractModules = sort . nub . everything (++) ([] `mkQ` f) where f (NameQ x) = [modString x] f (NameG _ _ x) = [modString x] f _ = [] which can be used to output a source code module: mkModule :: (Data a, Ppr a) = [String] - String - a - String mkModule exts name e = unlines ([ {-# LANGUAGE ++ intercalate , exts ++ #-} , module ++ name ++ where ] ++ map (import qualified ++) (extractModules e)) ++ show (ppr e) good enough for now ;) sk ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] how to generate source code from TH Exp?
On Thu, May 12, 2011 at 2:04 PM, Stefan Kersten s...@k-hornz.de wrote: extractModules = sort . nub . everything (++) ([] `mkQ` f) where f (NameQ x) = [modString x] f (NameG _ _ x) = [modString x] f _ = [] Minor nitpick: instead of doing 'sort . nub', please use 'import qualified Data.Set as S' and do 'S.toAscList . S.fromList'. This should be a lot faster. Cheers, =) -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Exception for NaN
How do I make my program stop whenever it gets somewhere NaN as a result during a calculation? If there is no appropriate flag for ghc maybe there exist flags for C to use in optc. I don't want NaN to propagate, it is merely stupid, it should be terminated. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANNOUNCE: iterIO-0.1 - iteratee-based IO with pipe operators
At Thu, 12 May 2011 16:45:02 +0100, Simon Marlow wrote: There are no locks here, thanks to the message-passing implementation we use for throwTo between processors. Okay, that sounds good. So then there is no guarantee about ordering of throwTo exceptions? That seems like a good thing since there are other mechanisms for synchronization. What kind of ordering guarantee did you have in mind? We do guarantee that in throwTo t e1 throwTo t e2 Thread t will receive e1 before e2 (obviously, because throwTo is synchronous and only returns when the exception has been raised). ... Pending exceptions are processed in LIFO order (for no good reason other than performance)... I mean, suppose you have three CPUs, A, B, and C running threads ta, tb, and tc. Then should the following order of events be permitted? AB C throwTo tc e1 throwTo tb e2 catch e2 poke p x peek p (sees x) catch e1 I would argue that this is just fine, that one should rely on MVars if one cares about ordering. But I'm not sure what Pending exceptions are processed in LIFO order means in the presence of relaxed memory consistency. The reason I'm asking is that I want to make sure I never end up having to pay the overhead of an MFENCE instruction or equivalent every time I use unmaskAsyncExceptions#... David ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] how to generate source code from TH Exp?
On Thursday 12 May 2011 19:14:09, Felipe Almeida Lessa wrote: On Thu, May 12, 2011 at 2:04 PM, Stefan Kersten s...@k-hornz.de wrote: extractModules = sort . nub . everything (++) ([] `mkQ` f) where f (NameQ x) = [modString x] f (NameG _ _ x) = [modString x] f _ = [] Minor nitpick: instead of doing 'sort . nub', please use 'import qualified Data.Set as S' and do 'S.toAscList . S.fromList'. This should be a lot faster. Or `map head . group . sort', which may be faster than building an intermediate Set (haven't benchmarked, may be faster, slower or mkae no difference). Cheers, =) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] No fish, please
Both Hackage and Cabal seem to assume as a matter of course that I want to use Haddock to generate all my documentation. Suppose I decide to violate this assumption. Then what? 1. Is there some way I can include my own HTML documentation in the package tarball and have Hackage/Cabal use it? 2. Is there a way to tell Hackage/Cabal to use some tool besides Haddock? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] No fish, please
No, you should be using Haddock. If you wish to generate docs some other way, you are free to host that on your own site, and link to it from the Hackage page. On Thu, May 12, 2011 at 10:45 AM, Andrew Coppin andrewcop...@btinternet.com wrote: Both Hackage and Cabal seem to assume as a matter of course that I want to use Haddock to generate all my documentation. Suppose I decide to violate this assumption. Then what? 1. Is there some way I can include my own HTML documentation in the package tarball and have Hackage/Cabal use it? 2. Is there a way to tell Hackage/Cabal to use some tool besides Haddock? ___ 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] Hash table constructors return table in IO Monad. Why?
On Thu, May 12, 2011 at 9:22 AM, Stephen Tetley stephen.tet...@gmail.comwrote: The hashtable needs to be been created in IO, after that, think of the 'hashtable' as a analogous to a file handle. You have to pass it around to do anything with it - but the only things you can do with it are in IO. The appropriate pure package to be using instead is unordered-containers. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Exception for NaN
On 2011-05-12 21:14 +0400, Grigory Sarnitskiy wrote: How do I make my program stop whenever it gets somewhere NaN as a result during a calculation? If there is no appropriate flag for ghc maybe there exist flags for C to use in optc. Under IEEE 754 floating point arithmetic, any operation which produces a quiet NaN from non-NaN inputs will also raise the invalid floating point exception. Unfortunately, GHC provides no support whatsoever for IEEE 754 floating point exceptions. You may neverthelesss be able to hack it, assuming appropriate hardware and software support. The result will not be portable. For example, the GNU C library provides the feenableexcept function. Completely untested, but on such systems, if you call feenableexcept(FE_INVALID) from C at the start of your program, your program should receive SIGFPE whenever the invalid floating point exception is raised by a floating point operation. This will likely cause the program to terminate. Other systems may provide a similar mechanism. Whether this hack actually works properly with GHC's runtime system is another issue entirely. Furthermore, GHC may perform program transformations that affect the generation of these exceptions in a negative way. I don't want NaN to propagate, it is merely stupid, it should be terminated. NaN propagation is not stupid. Frequently, components of a computation that end up being NaN turn out to be irrelevant at a later point, in which case the NaNs can be discarded. Cheers, -- Nick Bowler, Elliptic Technologies (http://www.elliptictech.com/) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Exception for NaN
On 12/05/2011 06:14 PM, Grigory Sarnitskiy wrote: How do I make my program stop whenever it gets somewhere NaN as a result during a calculation? If there is no appropriate flag for ghc maybe there exist flags for C to use in optc. I don't want NaN to propagate, it is merely stupid, it should be terminated. There is an isNaN function somewhere. You could make a newtype over Double which performs an isNaN after every operations and throws an exception if necessary... ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Hash table constructors return table in IO Monad. Why?
Thanks, Bryan and Stephan. I seem to remember playing around with a data structure that accumulates (in a list) different values associated with an identical key, i.e., insert data-structure abc 5insert data-structure abc 6 retrieve data-structure abc - [5,6] HashTable doesn't do it. Neither does Map. Was I dreaming? Michael --- On Thu, 5/12/11, Bryan O'Sullivan b...@serpentine.com wrote: From: Bryan O'Sullivan b...@serpentine.com Subject: Re: [Haskell-cafe] Hash table constructors return table in IO Monad. Why? To: Stephen Tetley stephen.tet...@gmail.com Cc: haskell-cafe@haskell.org Date: Thursday, May 12, 2011, 2:22 PM On Thu, May 12, 2011 at 9:22 AM, Stephen Tetley stephen.tet...@gmail.com wrote: The hashtable needs to be been created in IO, after that, think of the 'hashtable' as a analogous to a file handle. You have to pass it around to do anything with it - but the only things you can do with it are in IO. The appropriate pure package to be using instead is unordered-containers. -Inline Attachment Follows- ___ 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] Hash table constructors return table in IO Monad. Why?
On 12 May 2011 20:59, michael rice nowg...@yahoo.com wrote: HashTable doesn't do it. Neither does Map. Was I dreaming? I suppose you could implement this functionality on top of either. HTH, Ozgur ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] No fish, please
On Thu, May 12, 2011 at 11:00 AM, Don Stewart don...@gmail.com wrote: No, you should be using Haddock. If you wish to generate docs some other way, you are free to host that on your own site, and link to it from the Hackage page. Or improve haddock if you think it's lacking something. Jason ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Hash table constructors return table in IO Monad. Why?
On Thu, May 12, 2011 at 12:59 PM, michael rice nowg...@yahoo.com wrote: HashTable doesn't do it. Neither does Map. Was I dreaming? multiInsert k v m = insertWith' (++) k [v] m ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] No fish, please
On Thu, May 12, 2011 at 12:45 PM, Andrew Coppin andrewcop...@btinternet.com wrote: Both Hackage and Cabal seem to assume as a matter of course that I want to use Haddock to generate all my documentation. Suppose I decide to violate this assumption. Then what? 1. Is there some way I can include my own HTML documentation in the package tarball and have Hackage/Cabal use it? 2. Is there a way to tell Hackage/Cabal to use some tool besides Haddock? Why do you want to do this? Maybe there is some other way to get what you need. Is Haddock doing something wrong? In addition, it would be pretty easy to break the links from the Hackage page for your package into the documentation - it is all done by convention. That said, you can change your Setup.hs to call 'defaultMainWithHooks yourHooks' instead of 'defaultMain'. The 'yourHooks' indetifier would by of type Distribution.Simple.UserHooks (you would want to extend the 'simpleUserHooks' value). The record field you want to change is the 'haddockHook'. I think you would also need to update your package description file to indicate that you've customized the build, but I'm not 100% on that step. I have no idea how this interacts with the scripts currently run on Hackage, so it might not even work for that. Antoine ___ 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] Exception for NaN
On 12/05/2011 19:41, Nick Bowler wrote: On 2011-05-12 21:14 +0400, Grigory Sarnitskiy wrote: I don't want NaN to propagate, it is merely stupid, it should be terminated. NaN propagation is not stupid. Frequently, components of a computation that end up being NaN turn out to be irrelevant at a later point, in which case the NaNs can be discarded. Unfortunately, if a NaN reaches a comparison operation, it can lead to an end result that doesn't contain NaNs, but was still influenced by one. Ganesh ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Exception for NaN
On Friday 13 May 2011 01:19:52, Ganesh Sittampalam wrote: On 12/05/2011 19:41, Nick Bowler wrote: On 2011-05-12 21:14 +0400, Grigory Sarnitskiy wrote: I don't want NaN to propagate, it is merely stupid, it should be terminated. NaN propagation is not stupid. Frequently, components of a computation that end up being NaN turn out to be irrelevant at a later point, in which case the NaNs can be discarded. Unfortunately, if a NaN reaches a comparison operation, it can lead to an end result that doesn't contain NaNs, but was still influenced by one. Ganesh For example: Prelude Data.List maximum [0,-1,0/0,-5,-6,-3,0/0,-2] 0.0 Prelude Data.List minimum [0,-1,0/0,-5,-6,-3,0/0,-2] -2.0 Prelude Data.List sort [0,-1,0/0,-5,-6,-3,0/0,-2] [-6.0,-5.0,-2.0,NaN,-3.0,NaN,-1.0,0.0] As usual, when dealing with floating point numbers, you have to know what you're doing. There are situations where the appearence of NaNs is harmless, in others, they're poisonous. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Hash table constructors return table in IO Monad. Why?
I guess everyone has weighed in. I must have been hallucinating. Yes, this will work. Thanks, Michael --- On Thu, 5/12/11, Bryan O'Sullivan b...@serpentine.com wrote: From: Bryan O'Sullivan b...@serpentine.com Subject: Re: [Haskell-cafe] Hash table constructors return table in IO Monad. Why? To: michael rice nowg...@yahoo.com Cc: Stephen Tetley stephen.tet...@gmail.com, haskell-cafe@haskell.org Date: Thursday, May 12, 2011, 6:04 PM On Thu, May 12, 2011 at 12:59 PM, michael rice nowg...@yahoo.com wrote: HashTable doesn't do it. Neither does Map. Was I dreaming? multiInsert k v m = insertWith' (++) k [v] m ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: Newt - command-line template instantiation tool library
On Mon, May 9, 2011 at 8:25 AM, Rogan Creswick cresw...@gmail.com wrote: Indeed :) The tag syntax is controlled by two command-line flags: --prefix=... and --suffix=... It can be difficult to get the desired strings past both the shell and the regular expression compiler (although that last bit is changing... Josh Hoyt sent a patch that switches to basic string inspection, which should make this much simpler to use.) I've just released newt-0.0.3.0, which has the patch from Josh (It also uses a much nicer command-line syntaxt - it's backwards compatible, but you can leave off the --source / --dest specifiers now.) With Josh's patch, things like this just work: $ newt --prefix=*** --suffix=*** You can also look at the configuration structure with --verbose to help debug problems with these flags: $ newt --list some input file --prefix=*** --suffix=*** --verbose Using configuration: Config {source = Just tests/testFiles/simpleTest/alternate1.txt, dest = Nothing, rawTable = [], list = True, inplace = False, prefix = Just ***, suffix = Just ***, verb = Loud} This release also fixes a pretty important bug relating to binary files... you couldn't have any binary content in your templates -- 0.0.3.0 doesn't try to perform template replacements on binary files now (which failed immediately in hGetContents in the previous version). Feedback / suggestions are always appreciated :) Thanks! --Rogan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe