Created
October 31, 2013 09:24
-
-
Save mavnn/7246744 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| let ones = | |
| seq { | |
| while true do | |
| yield 1 | |
| } | |
| // seq [1; 1; 1; 1; ...] |
This file contains hidden or 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
| // Can't do this, unfortunately | |
| // seq { 1 .. } | |
| // | |
| // or this: | |
| // seq { 1 .. 0 .. 2 } | |
| // | |
| // Which I thought might be a nice hack. |
This file contains hidden or 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
| let notInfiniteOrOnes = seq { 1 .. System.Int32.MaxValue } | |
| // seq [1; 2; 3; 4; ...] | |
| let notInfinite = seq { for _ in 1 .. System.Int32.MaxValue -> 1 } | |
| // seq [1; 1; 1; 1; ...] |
This file contains hidden or 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
| let ones' = | |
| let rec gen () = | |
| seq { | |
| yield 1 | |
| yield! gen () | |
| } | |
| gen () | |
| // seq [1; 1; 1; 1; ...] |
This file contains hidden or 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
| let ones'' = Seq.initInfinite (fun _ -> 1) | |
| // seq [1; 1; 1; 1; ...] |
This file contains hidden or 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
| let ones''' = Seq.unfold (fun _ -> Some (1, ())) () | |
| // seq [1; 1; 1; 1; ...] |
This file contains hidden or 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
| let moreInterestingUnfold = | |
| Seq.unfold | |
| (fun state -> | |
| Some (state, state + 1)) 1 | |
| // seq [1; 2; 3; 4; ...] |
This file contains hidden or 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
| type Time = | |
| { | |
| Hour : int | |
| Minute : int | |
| } | |
| let addMinute time = | |
| match time with | |
| | { Hour = 23; Minute = 59 } -> | |
| { Hour = 0; Minute = 0 } | |
| | { Minute = 59 } -> | |
| { Hour = time.Hour + 1; Minute = 0 } | |
| | _ -> | |
| { Hour = time.Hour; Minute = time.Minute + 1 } | |
| let unfold' = | |
| Seq.unfold | |
| (fun state -> | |
| Some (sprintf "%02d:%02d" state.Hour state.Minute, addMinute state) | |
| ) { Hour = 22; Minute = 59 } | |
| // seq ["23:59"; "00:00"; "00:01"; "00:02"; ...] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment