Skip to content

Instantly share code, notes, and snippets.

open Microsoft.FSharp.Quotations
open System
type TypeTemplate() =
static member create ([<ReflectedDefinition(false)>] f : Expr<'a -> 'b>) : Type list -> ('a -> 'b) =
let rec extractCall e =
match e with
| Patterns.Lambda(_,body) -> extractCall body
| Patterns.Call(_o,minfo,_args) -> minfo
| _ -> failwithf "Expression not of expected form %A" e
#r @"..\packages\NETStandard.Library.NETFramework.2.0.0-preview2-25405-01\build\net461\lib\netstandard.dll"
#r @"..\packages\Google.Protobuf.3.5.1\lib\net45\Google.Protobuf.dll" //Google.Protobuf
#r @"..\packages\Microsoft.ML.0.1.0\lib\netstandard2.0\Microsoft.ML.dll" //Microsoft.ML
#r @"..\packages\Microsoft.ML.0.1.0\lib\netstandard2.0\Microsoft.ML.Api.dll" //Microsoft.ML.Api
#r @"..\packages\Microsoft.ML.0.1.0\lib\netstandard2.0\Microsoft.ML.Core.dll" //Microsoft.ML.Core
#r @"..\packages\Microsoft.ML.0.1.0\lib\netstandard2.0\Microsoft.ML.CpuMath.dll" //Microsoft.ML.CpuMath
#r @"..\packages\Microsoft.ML.0.1.0\lib\netstandard2.0\Microsoft.ML.Data.dll" //Microsoft.ML.Data
open System
type Temp(d,fmt,build) =
member val Build = build with get,set
member x.Dictionary : System.Collections.Generic.Dictionary<string, obj> = d
member x.Formatters : ResizeArray<obj -> string option> = fmt
member x.Content() = x.Build x
new() = Temp(System.Collections.Generic.Dictionary<string, obj>(), ResizeArray(), fun _ -> Some "")
open System
open System.Collections.Generic
open System.IO
open CNTK
let dataFolder = @"E:\Temp\CNTK\Tests\EndToEndTests\Text\SequenceClassification\Data"
let inputDim = 2000
@kevmal
kevmal / overload.fsx
Last active November 24, 2015 14:07
Return type overloading to overload F# function
type A = A with static member Instance = A
type B = B with static member Instance = B
type C = C with static member Instance = C
type D = D with static member Instance = D
type E = E with static member Instance = E
let inline chooseType< ^a when ^a : (static member Instance : ^a) > = (^a : (static member Instance : ^a) ())
type F = F with
static member inline (?<-)(F,A,a) : int = a
[<System.Runtime.CompilerServices.Extension>]
type ExtensionMethods() =
[<System.Runtime.CompilerServices.Extension>]
static member inline GetOption< ^a,'k,'v when 'a : (member TryGetValue : 'k * ('v byref) -> bool)>(this : ^a, key : 'k) =
let mutable v = Unchecked.defaultof<'v>
let scc = ( ^a : (member TryGetValue : 'k * ('v byref) -> bool) this, key, &v)
if scc then
Some v
else
None