-
Notifications
You must be signed in to change notification settings - Fork 783
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
use ImplicitZero instead of Return unit #773
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1475,6 +1475,49 @@ module EnumPatternWithFunkyTypes_FSharp_1_0_13904 = | |
// This is allowed - 'a is known to be "bool" | ||
let s = seq { for i in T true -> i } | ||
|
||
|
||
module SideEffectListMonad = | ||
type SideEffectListWithReturnBuilder(onReturn, onZero) = | ||
member b.Bind(x:unit,f) :list<'b> = f() | ||
member b.Combine(x:list<'a>,y:list<'a>) :list<'a> = List.append x y | ||
member b.Delay(f:unit->list<'a>) :list<'a> = f() | ||
member b.Return _ :list<'a> = onReturn(); [] | ||
member b.Zero() :list<'a> = onZero(); [] | ||
member b.Yield(x:'a) :list<'a> = [x] | ||
|
||
let sideEffectListWithReturn onReturn onZero = SideEffectListWithReturnBuilder(onReturn, onZero) | ||
|
||
type SideEffectListWithZeroBuilder(onZero) = | ||
member b.Bind(x:unit,f) :list<'b> = f() | ||
member b.Combine(x:list<'a>,y:list<'a>) :list<'a> = List.append x y | ||
member b.Delay(f:unit->list<'a>) :list<'a> = f() | ||
member b.Zero() :list<'a> = onZero(); [] | ||
member b.Yield(x:'a) :list<'a> = [x] | ||
|
||
let sideEffectListWithZero onZero = SideEffectListWithZeroBuilder(onZero) | ||
|
||
module SideEffectListTests = | ||
#if Portable | ||
let printfn s = printfn "%s" s | ||
#endif | ||
|
||
let x0a : list<int> * int * int = | ||
let calledReturn = ref 0 | ||
let onReturn () = calledReturn := !calledReturn + 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the use of |
||
let calledZero = ref 0 | ||
let onZero () = calledZero := !calledZero + 1 | ||
sideEffectListWithReturn onReturn onZero { yield 1 | ||
do! printfn "hello" }, !calledReturn, !calledZero | ||
test "x0a" (x0a = ([1], 1, 0)) | ||
|
||
let x0b : list<int> * int = | ||
let calledZero = ref 0 | ||
let onZero () = calledZero := !calledZero + 1 | ||
sideEffectListWithZero onZero { yield 1 | ||
do! printfn "hello" }, !calledZero | ||
test "x0b" (x0b = ([1], 1)) | ||
|
||
|
||
let aa = | ||
if !failures then (stdout.WriteLine "Test Failed"; exit 1) | ||
else (stdout.WriteLine "Test Passed"; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 know you copy/paste from near tests (good), but maybe this is good opportunity to cleanup this duplication, adding the
printfn
function at top levelThere 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.
@enricosada maybe, or better to get rid of the root cause. I mean why isn't it simply working for
Portable
too?