Add Delay type and use it
Fixes #5908.
Unsure where to put this, it could go in its own module I guess.
Huh, some tests fail. How surprising!
The problem with this is that the Haskell code you write using it is not delayed when used off-chain (and remember that we are using Strict in many places). So if you e.g. try to decode some Data object off-chain, you will end up forcing the error cases early. Annoying.
I'm not entirely sure how to fix this. If we actually want something that behaves differently on- and off-chain, then we probably need to bake it into the compiler.
I'm not entirely sure how to fix this. If we actually want something that behaves differently on- and off-chain, then we probably need to bake it into the compiler.
This is how its done in Purescript https://pursuit.purescript.org/packages/purescript-control/6.0.0/docs/Control.Lazy#v:defer : a thunk is involved at construction time.
Yes, but that's the unit-lambda approach which is what we were trying to avoid here. That said, I think this would still be a handy library tool even if all it does is wrap up that pattern.
That said, I think this would still be a handy library tool even if all it does is wrap up that pattern.
This is exactly how I was thinking about it. Same tool but more explicitly tagged.