-
Notifications
You must be signed in to change notification settings - Fork 479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Delay type and use it #5910
base: master
Are you sure you want to change the base?
Conversation
Fixes #5908. Unsure where to put this, it could go in its own module I guess.
|
||
-- | Force the evaluation of the expression delayed by the 'Delay'. | ||
force :: Delay a -> a | ||
force (Delay a) = a @BI.BuiltinUnit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the BuiltinUnit
is necessary in order for it to be compiled into delay
and force
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mysteriously it compiles without it, but I think it's better to be explicit about doing the type instantiation.
plutus-tx/src/PlutusTx/Utils.hs
Outdated
import Prelude as Haskell | ||
|
||
mustBeReplaced :: String -> a | ||
mustBeReplaced placeholder = | ||
error $ | ||
"The " <> show placeholder <> " placeholder must have been replaced by the \ | ||
\core-to-plc plugin during compilation." | ||
|
||
-- | Delay evalaution of the expression inside the 'Delay' constructor. | ||
newtype Delay a = Delay (forall b. a) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michaelpj what is the purpose of forall b
here? I'd appreciate a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
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 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. |
This is exactly how I was thinking about it. Same tool but more explicitly tagged. |
b0da22d
to
7a0fa2c
Compare
a161078
to
db5cabb
Compare
Fixes #5908.
Unsure where to put this, it could go in its own module I guess.