Mon Jun 27 10:51:41 CEST 2011
Getting over do-notation
Problem: I'd like to use standard Haskell Num class operations to
build a code generator for DSP algorithms. The problem is that
ordinary function composition does not allow the encoding of sharing
information. I.e. there is no way to use abstract evaluation using
syntax trees to see the difference between these two pieces of code:
f1 a b = (a + b) * (a + b)
f2 a b = c * c where c = a + b
The 2 lines define functions, and nothing more; they have no other
I've tried before to work around this by adding some kind of sharing
information in the data type. This +- works but is very clumsy, and
I'm not sure if it can be done without leading to a computational
The real problem is that joining 2 values that represent networks,
somehow requires shared nodes to be re-discovered. This is difficult
to do without some central registry.
In Haskell this would require some form of threading or
sequentialization like CPS or another Monad.
Before I was thinking about dropping Haskell altogether because it
would be possible to add this global context in Scheme without
problems. The reason is that Scheme has an _implicit_ threading
mechanism which is just the order of evaluation of the
Isn't it better to make this explicit?
What I am fighting here is my fear of do-notation. Arithmetic in
Haskell is so nice. Tying it down with a hyper-sequential do-notation
seems overkill. Is there a middle ground?