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.IO | |
type Walker(p) = | |
let root = new DirectoryInfo(p) | |
let root_path = root.FullName | |
let link (f:FileInfo) = | |
let relative_path = f.FullName.Replace(root_path, "").TrimStart('\\') | |
printfn "<p><a href='%s'>%s</a></p>" relative_path f.Name |
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
(* First, a few dumb extensions on IEnumerable *) | |
type System.Collections.Generic.IEnumerable<'a> with | |
member xs.ChopHead = (Seq.head xs, Seq.skip 1 xs) | |
member xs.Cut f = (Seq.takeWhile f xs, Seq.skipWhile f xs) | |
(* Given a sequence, I want to partition it according to some fairly complex rules. | |
I'm using a pair of sequence expressions depending on what's at the head of the sequence. | |
Unfortunately, this code is prohibitively slow for the large inputs I'm sending it. |
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 FReplace (remove:string) (replace:string) (input:string) = input.Replace(remove, replace) | |
let Insert sql s1 s2 = | |
sql | |
|> FReplace "step1" s1 | |
|> FReplace "step2" s2 | |
(* OR, possibly more concise: *) | |
let PipeInsert s1 s2 = |
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 awesome (x:string) = | |
if x.Contains "awesome" then | |
5 | |
else | |
0 | |
(* everything is fine so far... *) | |
let mutable guyFuckedUp = false |
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
(* In this weird case I need to write a stream but also keep track of how long ago a linefeed was written *) | |
member s.WriteStream (from:Stream) = | |
use reader = new StreamReader(from) | |
let mutable buffer = Array.zeroCreate<char>(BUFFER_LENGTH) | |
let mutable len = 0 | |
while not reader.EndOfStream do | |
len <- reader.ReadBlock(buffer, 0, buffer.Length) | |
s.OutputWriter.Write(buffer, 0, len) | |
(* Now, walk backwards through the buffer looking for linefeeds *) |
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 set = Set.ofList | |
let map = Map.ofList | |
let w = set [1; 2; 2; 5] | |
let x = map [("foo", 1); ("bar", 2)] | |
let (~~) = set | |
let (!!) = map | |
let y = ~~ [1; 2; 2; 5] |
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
xUnit.net console test runner (32-bit .NET 4.0.30319.1) | |
Copyright (C) 2007-9 Microsoft Corporation. | |
xunit.dll: Version 1.5.0.1479 | |
Test assembly: e:\svn\dtc\Tests\UnitTests\bin\Local\UnitTests.dll | |
..................................................................................................................................................................FFFFFFF......F..FF.FFF.F................................................................................................................................................................................................................................... | |
Total tests: 413, Failures: 14, Skipped: 0, Time: 5.457 seconds |
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 f x = sprintf "[%A]" x | |
let g x = sprintf "{%A}" x | |
(* So you have two functions (string -> string) | |
Now, you want to do let result = f g "hi" | |
However, f doesn't take a function string -> string, it takes a string. | |
So you need to tell the compiler about your precedence. | |
Normal "idiomatic" ways: *) |
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
(* | |
A parser needs to compress input as it receives it, | |
but it may receive the characters in small chunks. | |
How does the .NET System.IO.Compression namespace | |
deal with small chunks? Let's see the worst case! | |
*) | |
let streamToString (x:MemoryStream) = |
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 x_X = (+) "ouch" | |
let (---) x y = x + " don't" + y | |
let (!^-^) x = " punch" + x | |
let Q = " face" | |
let O = " please" | |
let emoticon = (x_X) O---(!^-^Q) |