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
// Rx 1.0: | |
//#r "System.CoreEx" //for interactive and scripts | |
//#r "System.Reactive.dll" | |
//open System | |
//open System.Collections.Generic | |
//Rx 2.1: | |
#r "System.ComponentModel.Composition.dll" | |
#r "../packages/Rx-Interfaces.2.1.30214.0/lib/Net45/System.Reactive.Interfaces.dll" | |
#r "../packages/Rx-Core.2.1.30214.0/lib/Net45/System.Reactive.Core.dll" |
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
//#r "Microsoft.TeamFoundation.Client" | |
//#r "Microsoft.TeamFoundation.VersionControl.Client" | |
//#r "Microsoft.TeamFoundation.VersionControl.Common" | |
open Microsoft.TeamFoundation.Client | |
open Microsoft.TeamFoundation.VersionControl.Client | |
let tfsCheckOut filename = | |
let workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo filename | |
let workspace = RegisteredTfsConnections.GetProjectCollections().First() | |
|> TfsTeamProjectCollectionFactory.GetTeamProjectCollection |
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
#I @"C:\Tools\System.Reactive" | |
#r "System.Core.dll" | |
#r "System.Reactive.dll" | |
type observable<'a> = System.Collections.Generic.IObservable<'a> | |
type observer<'a> = System.Collections.Generic.IObserver<'a> | |
module Observable = | |
open System | |
open System.Linq |
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
(* | |
You can use numeric literals, constant expressions and operator overloading to make your own arithmetics. Useful in DSL languages. | |
With NumericLiterals, you can use any of Q, R, Z, I, N, G. | |
Basic syntax: [Number][Letter] will forward the call to the type NumericLiteral[Letter] to FromInt32 [Number] (or FromInt64 or FromString...) | |
*) | |
//----------------------------------------------------- | |
//First example: | |
module NumericLiteralN = |
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
//A small sample how to use F# 3.0 Entity Framework (EF) Type Provider. Visual Studio 11 Beta (and Northwind sample database) needed. | |
(* | |
#r "System.Data.Entity.dll" | |
#r "FSharp.Data.TypeProviders.dll" | |
*) | |
open System | |
open Microsoft.FSharp.Data.TypeProviders | |
module Queries = | |
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 BuilderExample | |
open System | |
//Example: nullable { ... } with combining functionality | |
type NullableBuilder() = | |
let hasValue (a:Nullable<'a>) = a.HasValue | |
member t.Return(x) = Nullable(x) | |
member t.Bind(x, rest) = | |
match hasValue x with |
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
// Mimic type classes with additional param | |
type 'a Num = { | |
zero: 'a | |
add: 'a -> 'a -> 'a | |
mult: 'a -> 'a -> 'a | |
fromInteger: int -> 'a } | |
let intNum = { | |
zero = 0 |
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
// This shows how you can: | |
// 1) Code from top-down, give high level picture first and then go to details | |
// 2) Define LINQ outside EF-context and still convert it to SQL: | |
// - Don't hammer the database! | |
// 3) Have small independend classes (/parts) | |
// 4) Have state-less code with no global/class-variables outside entities | |
// 5) Easy to test: | |
// - Integration test with EF-DbContext. | |
// - LINQ logics unit tests without DbContext (with unit tests InternalsVisibleToAttribute). |
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
// Erlang-style message-passing: | |
// Agent that can upgrade its functionality on the fly. | |
// Note: static typing, this agent can't upgrade its state data type (so better to use obj or custom interface)... | |
// Also this runs only in localhost... | |
// So this is more a technical demo than something useful | |
open System | |
type Methods<'state, 'x, 'reply> = | |
| Upgrade of |
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 | |
open System.IO | |
open System.Net | |
open System.Drawing | |
let ImageSize = 300 | |
let fetchImage (url : Uri) = | |
let req = WebRequest.Create (url) :?> HttpWebRequest | |
use stream = req.GetResponse().GetResponseStream() |