Skip to content

Instantly share code, notes, and snippets.

View sergey-tihon's full-sized avatar
🦀

Sergey Tihon sergey-tihon

🦀
View GitHub Profile
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 July 14, 2013 20:20
The N Queens problem!
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) =
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>
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 September 6, 2013 17:41
F# PowerShell Get-Item
#r @"System.Management.Automation.dll"
#r @"PowerShellTypeProvider.dll"
type PS = FSharp.PowerShell.PowerShellTypeProvider< PSSnapIns="", Is64BitRequired=false >
PS.``Get-Item``()
//--------- 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
*** 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 ===
@sergey-tihon
sergey-tihon / gist:8180076
Created December 30, 2013 10:01
simple shift
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 )
)
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"
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'