[Haskell-cafe] Re: Profiling nested case

Mitar mmitar at gmail.com
Sat Jul 19 09:48:21 EDT 2008


Hi!

I had to change code somewhat. Now I have a function like:

worldScene point = case redSphere (0,50,0) 50 point of
  v@(Right _) -> v
  Left d1 -> case greenSphere (25,-250,0) 50 point of
    v@(Right _) -> v
    Left d2 -> Left $ d1 `min` d2

(Of course there could be more objects.)

Any suggestion how could I make this less hard-coded? Something which
would take a list of objects (object functions) and then return a
Right if any object function return Right or a minimum value of all
Lefts. But that it would have similar performance? If not on my GHC
version (6.8.3) on something newer (which uses fusion or something).
Is there some standard function for this or should I write my own
recursive function to run over a list of object functions? But I am
afraid that this will be hard to optimize for compiler.

(It is important to notice that the order of executing object
functions is not important so it could be a good candidate for
parallelism.)


Mitar


More information about the Haskell-Cafe mailing list