plutus icon indicating copy to clipboard operation
plutus copied to clipboard

Add Delay type and use it

Open michaelpj opened this issue 1 year ago • 5 comments

Fixes #5908.

Unsure where to put this, it could go in its own module I guess.

michaelpj avatar Apr 17 '24 14:04 michaelpj

Huh, some tests fail. How surprising!

michaelpj avatar Apr 18 '24 09:04 michaelpj

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.

michaelpj avatar Apr 18 '24 10:04 michaelpj

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.

Unisay avatar Apr 19 '24 08:04 Unisay

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.

michaelpj avatar Apr 22 '24 09:04 michaelpj

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.

Unisay avatar Apr 22 '24 15:04 Unisay