Skip to content

Instantly share code, notes, and snippets.

View rexcfnghk's full-sized avatar

Rex Ng rexcfnghk

View GitHub Profile
class Monad m where
return :: a -> m a
(>>=) :: m a -> (a -> m b) -> m b
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
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 }
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 }
var makeObject = function () {
var s = 1;
return {
getState: function() { return s; },
increment: function() {
s++;
}
};
};
function MyObject() {
this.state = 1;
}
MyObject.prototype.getState = function () {
return this.state;
};
MyObject.prototype.increment = function () {
this.state++;
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
void Foo()
{
var list = new[] { 1, 2, 3, 4, 5 };
int i = 0;
while (i < list.Length)
{
list[i] *= 2;
i++;
}
void Foo()
{
var list = new[] { 1, 2, 3, 4, 5 };
for (int i = 0; i < list.Length; i++)
{
list[i] *= 2;
}
}
void Foo()
{
var list = new[] { 1, 2, 3, 4, 5 };
int i = 0;
while (i < list.Length)
{
list[i] *= 2;
i++;
}