Standard escape codes are prefixed with Escape
:
- Ctrl-Key:
^[
- Octal:
\033
- Unicode:
\u001b
- Hexadecimal:
\x1B
- Decimal:
27
// I like this active pattern stuff | |
open System.Globalization | |
let (|ShortDate|_|) s = | |
match DateTime.TryParseExact(s, "ddMMMyyyy", CultureInfo.InvariantCulture, DateTimeStyles.None) with | |
| true, d -> Some d | |
| _ -> None | |
let (|LongDate|_|) s = |
-- Note: There is a more complete explanation at https://github.com/hwayne/lets-prove-leftpad/tree/master/idris | |
import Data.Vect | |
-- `minus` is saturating subtraction, so this works like we want it to | |
eq_max : (n, k : Nat) -> maximum k n = plus (n `minus` k) k | |
eq_max n Z = rewrite minusZeroRight n in rewrite plusZeroRightNeutral n in Refl | |
eq_max Z (S _) = Refl | |
eq_max (S n) (S k) = rewrite sym $ plusSuccRightSucc (n `minus` k) k in rewrite eq_max n k in Refl | |
-- The type here says "the result is" padded to (maximum k n), and is padding plus the original |
open System | |
open System.IO | |
open System.Diagnostics | |
let downloadDependencies deps = | |
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__ | |
if not (File.Exists "paket.exe") then | |
async { | |
let url = "http://fsprojects.github.io/Paket/stable" |
module StringConstraints | |
open System | |
let stringPattern str pattern = | |
if String.IsNullOrEmpty(str) then | |
let msg = sprintf "%s: Must not be null or empty" str | |
Error msg | |
elif System.Text.RegularExpressions.Regex.IsMatch(str, pattern) then | |
Ok (str) | |
else | |
let msg = sprintf "'%s' must match the pattern '%s'" str pattern |
#load @".paket\load\net452\FSharpPlus.fsx" | |
open FSharpPlus | |
open System | |
[<AutoOpen>] | |
module rec IO = | |
let run (IO computation) = computation() | |
type IO<'T> = |
// The famous fast inverse square root approximation from | |
// Quake ported to F#. | |
// Note: this algorithm is not fast on modern computers | |
// and this implementation of it is extremely inefficient: | |
// for educational purposes only! | |
open System | |
let isqrt y = | |
let x2 = y * 0.5f |
[<Measure>] type ms | |
let dotLength = 70<ms> | |
let dot = async { Console.Beep(1000, int dotLength) } | |
let dash = async { Console.Beep(1000, int dotLength * 3) } | |
let blipSpace = async { do! Async.Sleep (int dotLength) } | |
// * 2 since there will be a blip space | |
let charSpace = async { do! Async.Sleep (int dotLength * 6) } | |
// * 4 as there will be a blip (1) and a char (2) |
NOTE: This is an article by Chris Taylor, originally posted on his blog, but the blog was removed at some point. I resurected it from the WayBack Machine without the authors permission, but post it here for posterity's sake, so others may be able to find it.
by Chris Taylor
FEB 10TH, 2013
// This is am example of an immediate write / random access cursor for Excel with basic formatting options. | |
// Implementation is based on a concrete, non generic writer monad with no payload ("do!"" only) (only state). | |
// Instead of directl writing to excel, an alternatives would be a random acces to a | |
// copy-on-write list (or even a mutable array) and then bulk-write the result to excel in one shot. | |
// When only forward access would have been required, a simple seq expression with yields would have been enough. | |
// Anyway, it is a demonstration on how to "hide" pseudo-mutable state that is passed through a computation. | |
// | |
// I personally use it for generating reports based on various data sources. |