Skip to content

Instantly share code, notes, and snippets.

View mwolicki's full-sized avatar

Marcin Wolicki mwolicki

View GitHub Profile
@mwolicki
mwolicki / calc.fs
Last active August 29, 2015 14:21
simple calc parser
#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
[<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
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" }
@mwolicki
mwolicki / tdd.idr
Last active November 9, 2016 01:50
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
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 ();
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
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)
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) {
#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
@mwolicki
mwolicki / cast.cs
Last active December 20, 2016 21:14
using System;
namespace Example
{
class MainClass
{
static void Main()
{
Display(0);
Display(new A(6));