-
Notifications
You must be signed in to change notification settings - Fork 233
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 sequence functions for various monads #296
Conversation
Looks great! Can you throw in the bare minimum SwiftCheck properties for all of these (basically this)? |
Yep no problem. I'll get to that in the next day or so. |
Oh god, that looks like Swift thinks we need rank-2 polymorphism. |
@CodaFi I have some questions with the tests. While looking at your SwiftCheck test for Is the shape of a test for a give type
If so, it seems that |
The file I linked to is on a branch where I fixed the order issue and committed that test. Use it instead of master. |
@ryanbooker If you want me to write the tests for this, I can merge this and do it. |
Do we need to write the sequence function for Reader? I'm worried this may be a language/compiler limitation. |
I can take a crack at it with the tests. |
Sorry. I was totally side tracked by Easter and work. I'm happy to write the tests, but I think I need some pointers/direction. I'm not particularly familiar with QuickCheck style testing. My first question: Is the shape of a test for a give type M supposed to look like the following?
If so, it seems that |
A Haskeller friend also pointed out that |
|
To check my understanding, is this the right track?
|
Yep! It's mostly for the order invariant. |
Tests added. |
Yeah, that's to be expected. What happens if you use |
I'm not sure I understand what you mean. Do you mean basically remove sequence for
|
No, leave it in. But equality on streams is not a thing, but equality on lists is so you see how in the Stream Spec I lower all the equality calls with |
It seems to be the actual |
Yeah, so rather than invoke |
Yeah, ok. That's what I did above. But that's not really testing sequence on |
Not like we can, though. The laws require an equality that necessitates forcing the stream. |
} | ||
|
||
property("sequence occurs in order") <- forAll { (xs : [String]) in | ||
let seq = sequence(xs.map({ x in Stream.pure(x).take(1) })) |
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.
Can this take
an arbitrary head of the sequence (an extra forAll
)?
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.
It slows down to the point of not completing in any reasonable time. Assuming you mean wrapping it like other uses of take
.
return forAll { (n : UInt) in
...
}
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.
What does limiting the size of generated lists do (either with custom arguments or Gen.fromElementsIn(1...10)
, etc.)?
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.
Doesn't make a difference, even with 1...2
.
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.
Damn 😕
Welp, given the issues we discussed seem hard limits, and in the interest of honoring the great work you did here, I feel it's only appropriate to merge this. Thanks for putting up with me through review ❤️ and for the patch ✨ ⛵ |
Thanks. No drama. It was a good learning process. Seems only fair seeing I use the project. :) |
@CodaFi Is this what you were after (re: sequence conversation on Twitter https://twitter.com/CodaFi_/status/707423595601891328)?
sequence added for:
Array
Either
Identity
List
Optional
Proxy
State
String
Stream
Writer
I haven't been able to get
Reader
to type check.