This file contains 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
//Hi Julie, I liked your article and couldn't resist offering some possible improvements. I don't know | |
//what all the formulae mean but F#'s pattern matching is pretty powerful but also extensible and can | |
//be used to greatly improve readability and your chances of getting the code right in the first go. | |
// | |
//Below you can see the definition of two Active Pattern to extend F#'s pattern matching with a way | |
//to extract information from simple values, in this case floats. | |
let (|GreaterThan|_|) num = function | |
| value when value > num -> Some () | |
| _ -> None |
This file contains 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 @"C:\Projects\Lib\System.Reactive.Interfaces.dll" | |
#r @"C:\Projects\Lib\System.Reactive.Core.dll" | |
#r @"C:\Projects\Lib\System.Reactive.Linq.dll" | |
open System | |
open System.Linq | |
open System.Reactive.Subjects | |
open System.Reactive.Linq | |
let run n m = |
This file contains 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
let inline parse str = (^a: (static member Parse: string -> ^a) (str)) | |
let inline tryParse str = | |
let mutable value = Unchecked.defaultof<_> | |
let result = (^a: (static member TryParse: string * byref< ^a > -> bool) (str, &value)) | |
result, value | |
(tryParse "3": bool * int) | |
(tryParse "2.3": bool * float) | |
(tryParse "2.3": bool * decimal) |
This file contains 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
let cell init = | |
MailboxProcessor.Start(fun inbox -> | |
let rec loop n = | |
async { | |
let! result = inbox.Receive() | |
printfn "Received %d" result | |
return! loop result | |
} | |
loop init |
This file contains 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 "System.Management" | |
open System.Management | |
do | |
use ma = new ManagementObjectSearcher("Select * from Win32_Processor") | |
for item in ma.Get() do | |
try | |
printfn "%A" item.["NumberOfCores"] | |
with _ -> () |
This file contains 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
#if INTERACTIVE | |
let (++) a b = System.IO.Path.Combine(a, b) | |
let source = __SOURCE_DIRECTORY__ ++ __SOURCE_FILE__ | |
let args = sprintf "--platform:x86 %s -o:%s" source <| source.Replace("fs", "exe") | |
System.Diagnostics.Process.Start(System.AppDomain.CurrentDomain.BaseDirectory ++ "fsc", args) | |
#endif | |
let time f x = | |
let ts = System.Diagnostics.Stopwatch.StartNew() | |
let result = f x |
This file contains 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
[<Inline "$v.toString(16)">] | |
let toHex (v: int) = X<_> | |
let guid() = | |
let rx = EcmaScript.RegExp("[xy]", "g") | |
EcmaScript.String("xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx").Replace(rx, As (fun c -> | |
let r = EcmaScript.Math.Random() * 16.0 |> int | |
let v = |
This file contains 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
type T = T with | |
static member (<@>) (x, y: int) = x * y | |
static member (<@>) (x, y: float) = x * int y | |
let inline helper (_: ^o) (left: ^t) (right: ^u) = ((^o or ^t): (static member (<@>): ^t * ^u -> int) (left, right)) | |
let inline (<@>) left right = helper T left right | |
1 <@> 2 | |
1 <@> 2.3 |
This file contains 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 @"C:\Projects\Streams\src\Streams.Core\bin\Release\Streams.Core.dll" | |
open Nessos.Streams.Core | |
let data = | |
[| | |
let rnd = System.Random().NextDouble >> (*) 1e3 | |
for x in -10.0 .. 10.0 do | |
yield System.DateTime.Now.AddDays (rnd()) | |
|] |
This file contains 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
var objUserInfo = new ActiveXObject("WScript.network"); | |
if (objUserInfo.UserName == "dgrenier") | |
debugger; |
OlderNewer