-
Notifications
You must be signed in to change notification settings - Fork 476
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
[Builtins] Add the 'dropList' builtin #6468
base: master
Are you sure you want to change the base?
Conversation
017e9d4
to
df4dea7
Compare
df4dea7
to
7be8e1f
Compare
…to effectfully/builtins/add-dropList
7be8e1f
to
e22a57b
Compare
…to effectfully/builtins/add-dropList
16db02d
to
41ea9b6
Compare
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've added some comments based on a quick look. I may have another look later.
@@ -1557,6 +1558,18 @@ instance uni ~ DefaultUni => ToBuiltinMeaning uni DefaultFun where | |||
nullListDenotation | |||
(runCostingFunOneArgument . paramNullList) | |||
|
|||
toBuiltinMeaning _semvar DropList = | |||
let dropListDenotation :: Int -> SomeConstant uni [a] -> BuiltinResult (Opaque val [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.
The time taken for this will probably be linear in the value (not the size!) of the first argument. That'll mean susing some newtype wrapper, like this . We already have IntegerCostedLiterally, but this has an Int
so that may need another wrapper.
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.
^ @ramsay-t FYI
but this has an
Int
so that may need another wrapper.
Actually, why did I even make it Int
, what's the point? Looks like a thinko.
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.
The time taken for this will probably be linear in the value (not the size!) of the first argument.
No, I think it's gonna be a minimum of
- linear in the value of the first argument
- linear in the length of the second argument
since drop maxBound []
equals []
.
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.
Actually, why did I even make it
Int
, what's the point? Looks like a thinko.
It's proper Integer
in there now.
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.
No, I think it's gonna be a minimum of
linear in the value of the first argument
linear in the length of the second argument
since drop maxBound [] equals [].
I deliberately ignored that case! If we include the length of the list in the cost calculation then we'll have to traverse the entire list to measure the length when we're about to calculate the cost, and that'll slow things down. If we just base it on the number of things we want to drop then we'll still get a conservative estimate of the cost, and it'll be faster. Also, if you drop the whole of the list then you've probably done something wrong, and people probably won't submit scripts where that actually happens (or at least not often).
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.
Oh I see. OK, that's clever. Yeah, I think I agree, although I'd perhaps prefer to store lists together with their length, although that'd perhaps slow everything else down. Fair enough!
@ramsay-t ignore what I said and only consider the original comment in this thread.
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'd perhaps prefer to store lists together with their length
I've wondered about doing that in the past (and maybe something similar with Data for instance), but what happens if someone lies about the length of a list in their script? Maybe that could be checked during deserialisation ...
@@ -82,6 +82,7 @@ module PlutusTx.Builtins ( | |||
, headMaybe | |||
, BI.head | |||
, BI.tail | |||
, BI.drop |
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.
Should this also go in PlutusTx.Prelude? I seem to remember that the contents of that file are kind of random though.
@@ -408,6 +409,10 @@ chooseList :: BuiltinList a -> b -> b -> b | |||
chooseList (BuiltinList []) b1 _ = b1 | |||
chooseList (BuiltinList (_:_)) _ b2 = b2 | |||
|
|||
{-# OPAQUE drop #-} | |||
drop :: Integer -> BuiltinList a -> BuiltinList 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.
Why not dropList
? So that it just replaces the Haskell version with minimal effort from the user?
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.
For consistency, we also have head
(and not headList
) and tail
(and not tailList
) in this file.
…to effectfully/builtins/add-dropList
/benchmark validation |
f999164
to
e8c0b9d
Compare
/benchmark validation |
Click here to check the status of your benchmark. |
Comparing benchmark results of 'validation' on 'ac8c225aeb' (base) and 'd36d0f87f4' (PR) Results table
|
Click here to check the status of your benchmark. |
Comparing benchmark results of 'validation' on 'ac8c225aeb' (base) and 'd36d0f87f4' (PR) Results table
|
/benchmark validation |
1 similar comment
/benchmark validation |
Click here to check the status of your benchmark. |
Comparing benchmark results of 'validation' on 'ac8c225aeb' (base) and 'd36d0f87f4' (PR) Results table
|
Click here to check the status of your benchmark. |
Comparing benchmark results of 'validation' on 'ac8c225aeb' (base) and 'd36d0f87f4' (PR) Results table
|
Oh, come on! |
This experiment adds the
dropList
builtin so that folks can play with it. Not intended for merging.