2008/12/21 Peter Todd <pete@petertodd.org>
If I could somehow arrange for the transform function to detect when it
is being applied to a unevaluated thunk, and then modify the thunk in
place, that would basically be the behavior I need. Any suggestions?

That is exactly what is already happening.  Perhaps you want what you think is happening: if a value *is* evaluated, you want to apply the transformation right then instead of making a thunk.

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.

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?

Luke