Navigation Menu

Skip to content
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

scanRight returns result in the wrong order #4161

Closed
scabug opened this issue Jan 15, 2011 · 5 comments
Closed

scanRight returns result in the wrong order #4161

scabug opened this issue Jan 15, 2011 · 5 comments
Assignees

Comments

@scabug
Copy link

scabug commented Jan 15, 2011

=== What steps will reproduce the problem (please be specific and use wikiformatting)? ===

  List(1, 1, 1, 1).scanRight(0)(_+_)

=== What is the expected behavior? ===

As in Haskell:

Hugs> scanr (+) 0 [1, 1, 1, 1]
[4,3,2,1,0]

=== What do you see instead? ===

scala> List(1,1,1,1).scanRight(0)(_+_)
res1: List[Int] = List(0, 1, 2, 3, 4)

=== Additional information ===

scanRight is implemented at TraversableLike and also at TraversableViewLike, TraversableProxyLike and ParSeqViewLike, though all of these just reference TraversableLike.

No other part of Scala's source make use of it, but it has been available since Scala 2.8.0, and merits a migration warning.

The present documentation is not very clear about the direction of the result, though I personally think it describes how it is presently working, not how it should (IMO) work.

Unfortunately, neither reduceRight nor foldRight serve as a parameter, since neither produce collections as result.

=== What versions of the following are you using? ===

  • Scala: 2.9.0.r0-b20101218005140
  • Java: Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_23
  • Operating system: Windows Vista 64
@scabug
Copy link
Author

scabug commented Jan 15, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4161?orig=1
Reporter: @dcsobral

@scabug
Copy link
Author

scabug commented Jan 18, 2011

@lindydonna said:
Daniel, we think this warrants a mailing list discussion first. Could you please post such a message to scala-user? For now I've marked it as an enhancement, but this can be changed based on the community's response.

@scabug
Copy link
Author

scabug commented Jan 18, 2011

Jim Balter (jibal) said:

neither reduceRight nor foldRight serve as a parameter

The Haskell documentation for [http://www.haskell.org/ghc/docs/7.0.1/html/libraries/base-4.3.0.0/Prelude.html#v:scanr scanr] says

head (scanr f z xs) == foldr f z xs.

It seems clear that scanRight should do the same, that it is coded incorrectly, and that the inadequate Scala documentation -- and documentation standards and documentation culture -- contributed to this error. Those are process errors, and that this is viewed as an enhancement rather than a defect suggests another process error.

@scabug
Copy link
Author

scabug commented Jan 18, 2011

@lindydonna said:
Apologies, I should have closed as needinfo, rather than marked as enhancement.

@scabug
Copy link
Author

scabug commented Jan 18, 2011

@lindydonna said:
per mailing list discussion, semantics should be changed with a migration warning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants