On Sun, Dec 21, 2008 at 10:27 AM, Peter Todd <pete@petertodd.org> wrote:
| ElementThunk T Element
data Element = Element {
elementOrigin :: V,
elementSubs :: [Element]
}
transform :: T -> Element -> Element
transform t (ElementThunk t2 e) = ElementThunk (tmul t t2) e
transform t e = ElementThunk t e
transform t e = Element {This gives a behavior close to what I want, applying a transform to an
elementOrigin = tmulv t (elementOrigin e),
elementSubs = map (transform t) (elementSubs e)
}
element results in a "thunk", and subsequent transforms simply modify
the thunk, the problem is that I don't see a way to implicitly coerce an
ElementThunk into an Element on demand for all the other code in the
program that expects elements. (such as the elementOrigin function)
Yes, but this part of the program is library code, that will be used by
> By the way, this is very operational thinking for Haskell. Haskell tries
> quite hard to abstract away operational thinking, so thinking on this level
> will be difficult and more work than you should be doing to write a program.
a whole pile of other stuff, so if I can get the right behavior
"magically" the rest of the program will be a lot easier to write.
FWIW this is EDA software, those "elements" refer to elements of a
printed circuit board layout, and the transform operations correspond to
stuff like moving a chip on the board. The representation of a simple IC
would consist of something like an element, with a bunch of sub-elements
for each pin, all of which have geometry data.
I've written a previous version of this program in Python actually,
> May I ask why you want this behavior? Have you just tested it and observed
> that it is running too slowly and you are trying to speed it up?
where I explicitly modeled the lazy evaluation behavior that I wanted.
It all worked great, but the overall speed was still quite slow. I was
hoping that Haskell, built around lazy evaluation already, would be a
better fit.
That, and in any case, other aspects of the program that I've re-written
in Haskell saw about a 5-1 redunction in code length... :)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFJTnx03bMhDbI9xWQRAhWvAJoD8JeQg/3Q3Oy5FNEAaVjbNDbg3QCfe5jJ
Ob2IGxR4YDfiVpoTeOFcnBM=
=RS6B
-----END PGP SIGNATURE-----