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
| class Monad m where | |
| return :: a -> m a | |
| (>>=) :: m a -> (a -> m b) -> m b |
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
| module CompositionRoot | |
| let findPlayerNames' = | |
| findPlayerNames "Data Source=localhost; Initial Catalog=MyDb; Integrated Security = True" | |
| module Program | |
| let main _ = | |
| // Database queried once | |
| let playerNames1 = findPlayerNames' () |> Seq.toList |
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
| open System.Data.SqlClient | |
| let findPlayerNames dbConnectionString = | |
| fun () -> | |
| use sqlConnection = new SqlConnection (dbConnectionString) | |
| use sqlCommand = new SqlCommand ("SELECT [Name] FROM Players", sqlConnection) | |
| use reader = sqlCommand.ExecuteReader () | |
| seq { while reader.HasRows do yield reader.["Name"] :?> string } |
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
| open System.Data.SqlClient | |
| let findPlayerNames dbConnectionString () = | |
| use sqlConnection = new SqlConnection (dbConnectionString) | |
| use sqlCommand = new SqlCommand ("SELECT [Name] FROM Players", sqlConnection) | |
| use reader = sqlCommand.ExecuteReader () | |
| seq { while reader.HasRows do yield reader.["Name"] :?> string } |
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
| var makeObject = function () { | |
| var s = 1; | |
| return { | |
| getState: function() { return s; }, | |
| increment: function() { | |
| s++; | |
| } | |
| }; | |
| }; |
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
| function MyObject() { | |
| this.state = 1; | |
| } | |
| MyObject.prototype.getState = function () { | |
| return this.state; | |
| }; | |
| MyObject.prototype.increment = function () { | |
| this.state++; |
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
| void Foo() | |
| { | |
| var list = new[] { 1, 2, 3, 4, 5 }; | |
| for (int i = 0; i < list.Length; i++) | |
| { | |
| list[i] *= 2; | |
| } | |
| // i is not visible here anymore |
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
| void Foo() | |
| { | |
| var list = new[] { 1, 2, 3, 4, 5 }; | |
| int i = 0; | |
| while (i < list.Length) | |
| { | |
| list[i] *= 2; | |
| i++; | |
| } |
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
| void Foo() | |
| { | |
| var list = new[] { 1, 2, 3, 4, 5 }; | |
| for (int i = 0; i < list.Length; i++) | |
| { | |
| list[i] *= 2; | |
| } | |
| } |
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
| void Foo() | |
| { | |
| var list = new[] { 1, 2, 3, 4, 5 }; | |
| int i = 0; | |
| while (i < list.Length) | |
| { | |
| list[i] *= 2; | |
| i++; | |
| } |