drop and negative indexes
#712
Replies: 3 comments 6 replies
-
|
I like this. Also relevant: #601 |
Beta Was this translation helpful? Give feedback.
-
|
Also annoying is that For example, in principle, it should be that:
However, that's not the case in Copilot. Drops don't cross I wonder whether this is just a different problem, or whether there's a more elegant variant of drop we could potentially come up with. |
Beta Was this translation helpful? Give feedback.
-
|
Going back to what Putting the fact that Copilot is an EDSL in Haskell, is there a reason why silent behavior might be better than a static error? To put it another way: are there scenarios where |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In Haskell, calling
drop n xswith a negative integernis equivalent to callingdrop 0 xs, i.e., returning the original listxsunchanged:In Copilot, however, the
dropfunction over streams is a bit more inconsistent. There are times where callingdropwith a negative index works, e.g.,{-# LANGUAGE NoImplicitPrelude #-} module Main (main) where import Language.Copilot spec :: Spec spec = do let s :: Stream Bool s = drop (-1) true trigger "example" s [arg s] main :: IO () main = interpret 5 specOn the other hand, there are other streams for which calling
drop (-1)will cause Copilot to crash:Moreover, if you try to compile this specification to C99 or Bluespec, then
-1will underflow and result in generated code that looks like this:We should figure out a coherent story for what Copilot's
dropfunction should do with negative indexes. Personally, I would propose makingdrop (-1)equal todrop 0, just like it is in Haskell, as this seems like the least surprising choice. Implementation-wise, this would only require a very small change todrop's implementation to achieve.Beta Was this translation helpful? Give feedback.
All reactions