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 rec AsyncAcceptMessages(client : WebSocket) = | |
async { | |
let! message = client.AsyncReadMessage | |
if(not(isNull message)) then | |
let s = | |
use reader = new StreamReader(message) | |
reader.ReadToEnd() | |
do | |
use writer = new StreamWriter(client.CreateMessageWriter(WebSocketMessageType.Text), Encoding.UTF8) | |
writer.Write s |
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 binarySearch value (array: 'T[]) = | |
let rec loop lo hi = | |
if lo <= hi then | |
let mid = lo + ((hi - lo) >>> 1) | |
match array.[mid] with | |
| x when x = value -> Some mid | |
| x when x < value -> loop (mid + 1) hi | |
| _ -> loop lo (mid - 1) | |
else None | |
loop 0 (array.Length - 1) |
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
open System | |
let MAX_TIME = 60 | |
type Toy = | |
| Toy of string * int | |
type Direction = | |
| Start | |
| End |
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 groupsOf n (items: seq<_>) = | |
use e = items.GetEnumerator() | |
let rec loop i acc = | |
seq { | |
match i, acc, e.MoveNext() with | |
| 0, [], _ | _, [], false -> () | |
| _, _, false -> | |
yield seq (List.rev acc) | |
| 0, _, true -> | |
yield seq (List.rev acc) |
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
module SqlAst = | |
open System | |
type BinaryOp = | |
| Add | |
| Sub | |
| Mul | |
| Div | |
| Mod |
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 cosine n (x:^a) : ^a = | |
let one = LanguagePrimitives.GenericOne | |
let two = one + one | |
Seq.unfold (fun (twoIp1, t) -> Some(t, (twoIp1+two, -t*x*x/(twoIp1*(twoIp1+one))))) (one,one) | |
|> Seq.take n | |
|> Seq.sum |