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 | |
#I @"/Users/kevin/Projects/FSParsec/packages/FParsec.1.0.1/lib/net40-client/" | |
#r @"FParsecCS.dll" | |
#r @"FParsec.dll" | |
#endif | |
open FParsec | |
type Expr = Op of string * Expr * Expr | Num of float |
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
[<RequireQualifiedAccess>] | |
module Trie = | |
[<Struct>] | |
type Trie<'a, 'b when 'a : comparison> = | |
{ Value : 'b option | |
Childrens : Map<'a, Trie<'a, 'b>> } | |
with | |
member trie.ToSeq () = | |
let rec toSeq trie l = | |
seq { if trie.Value.IsSome then yield l, trie.Value.Value |
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 Brainfuck = | |
type State = { currentIndex : int | |
data : Map<int, byte> } | |
type Op = IncPointer | DecPointer | Inc | Dec | Print | Read | While of Op list | |
module private Eval = | |
type IO = { read : unit -> byte | |
print : byte -> unit } | |
with static member def = { read = fun () -> System.Console.Read() |> byte | |
print = fun i -> char i |> printf "%O" } |
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
import Data.Vect | |
total isEven : Nat -> Bool | |
isEven Z = True | |
isEven (S k) = not (isEven k) | |
fourInts : Vect 4 Nat | |
fourInts = [1,2,3,4] | |
sixInts : Vect 6 Nat |
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
static class BrainFuck | |
{ | |
public static void Process (string txt) | |
{ | |
var code = txt.Where (Single.AllowedChars.Union (Loop.AllowedChars).Contains); | |
var state = new State (); |
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 | |
open System.Drawing | |
let getImage path = | |
let image = Image.FromFile path :?> Bitmap | |
Array2D.init image.Width image.Height (fun w h -> image.GetPixel(w,h)) | |
let saveImage path (a:Color[,]) = | |
let w = a.GetLength 0 | |
let h = a.GetLength 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
class MainClass { | |
static void Main () { | |
var text = "abcdef"; | |
System.Console.WriteLine (text); | |
Mutate (text); | |
System.Console.WriteLine (text); | |
} | |
unsafe static void Mutate (string text) { | |
fixed (char* t = text) |
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
class MainClass { | |
static void Main() { | |
System.Console.WriteLine("abcdef"); | |
Mutate("abcdef"); | |
System.Console.WriteLine("abcdef"); | |
} | |
unsafe static void Mutate(string text) { | |
var newLen = text.Length * 2; | |
fixed (char* t = text) { |
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
#nowarn "9" | |
let mutate (txt:string) : unit = | |
use ch = fixed txt | |
for i = 0 to txt.Length - 1 do | |
Microsoft.FSharp.NativeInterop.NativePtr.set ch i 'z' | |
let text = "abcd" | |
printfn "%s" text | |
mutate text | |
printfn "%s" text |
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
using System; | |
namespace Example | |
{ | |
class MainClass | |
{ | |
static void Main() | |
{ | |
Display(0); | |
Display(new A(6)); |
OlderNewer