Skip to content

Instantly share code, notes, and snippets.

View Thorium's full-sized avatar

Tuomas Hietanen Thorium

View GitHub Profile
@Thorium
Thorium / gist:2473882
Created April 23, 2012 21:07 — forked from forki/gist:1400378
Poor mans type classes
// 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
@Thorium
Thorium / NullableBuilder.fs
Created April 19, 2012 17:21
Computational expressions / monad / builder example: Nullable
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
@Thorium
Thorium / gist:2416622
Created April 18, 2012 21:17
F# 3.0 - EntityFramework Type Provider usage with Northwind DB
//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 =
@Thorium
Thorium / gist:2416610
Created April 18, 2012 21:15
Simple NumericLiteral example
(*
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 =
@Thorium
Thorium / gist:2416591
Created April 18, 2012 21:11 — forked from mattpodwysocki/gist:165605
IObservable<T> is close to Async<T>, so why not: F# obs { ... } as async { ... }
#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
@Thorium
Thorium / gist:1972380
Created March 4, 2012 10:52
Team Foundation Server: Check Out a file
//#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
@Thorium
Thorium / gist:1972378
Last active October 1, 2015 10:08
Simple Reactive Extensions Example
// 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"
@Thorium
Thorium / QuickInfo.fs
Created March 4, 2012 10:50
csproj-file parsing with Linq2Xml, two examples
//#r "System.Xml.dll" //for scripts or interactive
//#r "System.Xml.Linq.dll"
open System
open System.Xml.Linq
open System.IO
let getFiles = Directory.GetFiles("c:\\projects\\", "*.csproj", SearchOption.AllDirectories)
|> Array.toSeq
let getProjectInfo (fname:string) =
@Thorium
Thorium / gist:1972368
Created March 4, 2012 10:48
Silverlight asynchronous WebService call with UI-thread syncronization dispatcher
//#r "System.Runtime.Serialization"
//#r "FSharp.PowerPack"
open Microsoft.FSharp.Control.WebExtensions
open System
open System.Runtime.Serialization
open System.Runtime.Serialization.Json
open System.Net
open System.IO
@Thorium
Thorium / MainPage.xaml.cs
Created March 4, 2012 10:46
Simple F# ViewModel for Silverlight MVVM
//View codebehind
using System.Windows.Controls;
namespace HelloApp
{
public partial class MainPage : UserControl
{
public MainPage()
{
// Required to initialize variables