Skip to content

Instantly share code, notes, and snippets.

View gist:5665600
type Message =
| Sleep of int*int
| SyncPoint of AsyncReplyChannel<unit>
let agent =
MailboxProcessor.Start(fun inbox ->
let rec loop() =
async {
let! msg = inbox.Receive()
match msg with
@sergey-tihon
sergey-tihon / gist:5995802
Created Jul 14, 2013
The N Queens problem!
View gist:5995802
type ChessboardState =
{Row:bool[]; DiagPlus:bool[]; DiagMin:bool[]}
let inline diagMinInd (chessboard:ChessboardState) (x,y) =
if x-y>=0 then x-y else x-y+chessboard.DiagMin.Length
let canPlaceOn (chessboard:ChessboardState) (x,y) =
chessboard.Row.[y] && chessboard.DiagPlus.[x+y] && chessboard.DiagMin.[diagMinInd chessboard (x,y)]
let changeState (chessboard:ChessboardState) (x,y) =
View gist:6263997
type I<'T> = interface end
type I1<'T> = inherit I<'T>
type I2<'T> = inherit I<'T>
type A =
inherit I1<int>
inherit I2<double>
View gist:6264090
interface I<T>
{}
interface I1<T> : I<T>
{}
interface I2<T> : I<T>
{}
class A : I1<int>, I2<double>
{}
@sergey-tihon
sergey-tihon / gist:6467164
Created Sep 6, 2013
F# PowerShell Get-Item
View gist:6467164
#r @"System.Management.Automation.dll"
#r @"PowerShellTypeProvider.dll"
type PS = FSharp.PowerShell.PowerShellTypeProvider< PSSnapIns="", Is64BitRequired=false >
PS.``Get-Item``()
View tailoptimized.fs
//--------- Sample 1 -------------
/// Factorial
let rec fact n =
if n = 1 then 1
else n*fact(n-1)
/// Tail optimized Factorial
let fact n =
let rec factImpl n acc = // acc = accumulator
View gist:7239881
*** Assembly Binder Log Entry (10/30/2013 @ 11:29:27 PM) ***
The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable D:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe
--- A detailed error log follows.
=== Pre-bind state information ===
View gist:8180076
let shift (s:string) (k:int) =
System.String(
s.ToCharArray()
|> Array.map (function
| x when 'a' <= x && x <='z' ->
let code = int(x)-int('a')
char(int('a') + (code + k + 26) % 26)
| x -> x )
)
View staticProp.fs
type BaseProvidedType() =
static let mutable _host = ""
static member Host
with get() = _host
and set(value) = _host <- value
type ProvidedType() = inherit BaseProvidedType()
ProvidedType.Host <- "1"
BaseProvidedType.Host // = "1"
View gist:8d4486a8e3c0ce50d7f38dee910c039b
Microsoft (R) F# Interactive version 14.0.23413.0
Copyright (c) Microsoft Corporation. All Rights Reserved.
For help type #help;;
>
--> Referenced 'D:\GitHub\FsProjectsAdmin\src\../.paket/paket.exe'