[Haskell-cafe] Re: How to use Control.Failure?

2009-12-19 Thread ntupel
On Dec 19, 5:14 pm, Michael Snoyman wrote: > > Well, here's one way of doing it. You have lots of choices here; these are > the decisions I made in implementing the code: > > * myFuncB no longer lives in the IO monad. I wasn't sure if you specifically > wanted that, but now it can work with *any*

[Haskell-cafe] How to use Control.Failure?

2009-12-19 Thread ntupel
I have looked at the recently released Control.Failure library but I admit, I couldn't understand it completely. So given the example below, how would Control.Failure help me here? Thanks, nt -- Theirs (other library code stubs) data TheirError = TheirErrorCase deriving Show data TheirData = Th

Re: [Haskell-cafe] How to implement this? A case for scoped record labels?

2009-05-27 Thread ntupel
On Tue, 2009-05-26 at 18:09 -0400, wren ng thornton wrote: > GADTs can easily cover record selectors that apply to all constructors, > and selectors that apply to one constructor (or a set of constructors > producing the same type). If the family of selector sets forms a nice > tree hierarchy, y

Re: [Haskell-cafe] How to implement this? A case for scoped record labels?

2009-05-26 Thread ntupel
On Tue, May 26, 2009 at 4:32 AM, wren ng thornton wrote: > One alternative is to use Haskell's support for ad-hoc overloading. Define a > typeclass for each selector (or group of selectors that must always occur > together) which is polymorphic in the record type. [...] > It's not pretty, but it g

[Haskell-cafe] How to implement this? A case for scoped record labels?

2009-05-25 Thread ntupel
Hi, I would like to get some advice on how to best implement a protocol. The protocol in question is "Bayeux": http://svn.cometd.org/trunk/bayeux/bayeux.html. The details don't matter here - it defines a couple of requests and responses in JSON format, basically JSON objects with different propert

[Haskell-cafe] Text.JSON idiomatic use

2008-09-12 Thread ntupel
As a follow up to my previous JSON serialization post I came up with a first draft of some simple record type serialization/deserialization. What I would like to know is, whether this is the right approach or what better ways there are to make a custom data type an instance of class JSON. Any cha

[Haskell-cafe] JSON serialization/deserialization

2008-09-12 Thread ntupel
Dear list members, I try to use Text.JSON (http://hackage.haskell.org/cgi-bin/hackage-scripts/package/json) to serialize and deserialize record types. As I understand it, the data types need to be instances of class JSON. However I have difficulties to come up with a nice implementation of showJSO

Re: [Haskell-cafe] Performance problem with random numbers

2007-10-17 Thread ntupel
On Sat, 2007-10-13 at 18:33 -0300, Isaac Dupree wrote: > GHC StdGen's random and randomR are somewhat slow. I found that > changing to a custom ((x*a + b) `mod` c) random-generator (instance of > RandomGen) much sped things up (since nothing depended on the random > numbers being good quality).

Re: Laziness (was: [Haskell-cafe] Performance problem with random numbers)

2007-10-15 Thread ntupel
On Mon, 2007-10-15 at 10:48 -0400, David Roundy wrote: > I have no idea if this example will help your actual code, but it > illustrates that at least in this example, it's pretty easy to gain an > order of magnitude in speed. (That "func" is a weird function, by the > way.) > Thanks for your re

Laziness (was: [Haskell-cafe] Performance problem with random numbers)

2007-10-14 Thread ntupel
On Sat, 2007-10-13 at 09:56 -0400, Brandon S. Allbery KF8NH wrote: > Now you need to start forcing things; given laziness, things tend to > only get forced when in IO, which leads to time being accounted to > the routine where the forcing happened. If random / randomR are > invoked with larg

Re: [Haskell-cafe] Performance problem with random numbers

2007-10-13 Thread ntupel
On Sat, 2007-10-13 at 14:37 -0700, Don Stewart wrote: > I've seen similar results switching to the SIMD mersenne twister C > implementation for randoms: > > http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/index.html > > If there's interest, I can package up the bindings for hackage.

Re: [Haskell-cafe] Performance problem with random numbers

2007-10-13 Thread ntupel
On Sat, 2007-10-13 at 13:35 -0400, Brandon S. Allbery KF8NH wrote: > For starters, look into "seq". Try applying it to any expression > using a generated random number. This should force evaluation to > occur somewhere other than when random is trying to figure out what > StdGen value it's b

Re: [Haskell-cafe] Performance problem with random numbers

2007-10-13 Thread ntupel
On Sat, 2007-10-13 at 12:42 -0400, Brandon S. Allbery KF8NH wrote: > Your apparently simple StdGen argument is actually a sort of program > state (represented by unevaluated thunks, not by a state monad; see > below) which gets altered with every invocation of random. If > nothing is forced

Re: [Haskell-cafe] Performance problem with random numbers

2007-10-13 Thread ntupel
On Sat, 2007-10-13 at 09:56 -0400, Brandon S. Allbery KF8NH wrote: > Now you need to start forcing things; given laziness, things tend to > only get forced when in IO, which leads to time being accounted to > the routine where the forcing happened. If random / randomR are > invoked with larg

Re: [Haskell-cafe] Performance problem with random numbers

2007-10-13 Thread ntupel
On Fri, 2007-10-12 at 20:25 -0700, Stefan O'Rear wrote: > On Sat, Oct 13, 2007 at 12:09:57AM +0200, ntupel wrote: > > setup :: (Ord a, IArray a2 a, IArray a1 e, Num a) => [e] -> [a] -> (a1 Int > > e, a1 Int e, a2 Int a) > > calcAlias :: (Ord e, Num e, IArray a

[Haskell-cafe] Performance problem with random numbers

2007-10-12 Thread ntupel
Dear all, I have implemented a small module to generate random items with a given probability distribution using the alias approach [1] and unfortunately compared to similar implementations in C++ or Java it is about 10 times slower. I have to confess that I am still in the early stages of writing