Skip to content

Instantly share code, notes, and snippets.

module Bug where
type Adress = {city :: String}
type Person = {adress::Adress}
getCity :: Person -> String
getCity { adress = {city = c} } = c
billy = {adress: {city : "SFO" }}
let toSystemPath (s:String) = s.Split([|'/'|])|> String.concat (System.IO.Path.DirectorySeparatorChar.ToString())
type DataTipElement(wrapped:obj) =
member x.Wrapped = wrapped
let (|DataTipElementNone|DataTipElement|DataTipElementGroup|DataTipElementCompositionError|) (el:DataTipElement) =
if el.Wrapped?IsDataTipElementNone then
DataTipElementNone
elif el.Wrapped?IsDataTipElement then
let (s:string) = el.Wrapped?Item1
let xml = XmlComment(el.Wrapped?Item2)
DataTipElement(s, xml)
@nrolland
nrolland / gist:3731883
Created September 16, 2012 10:20
zipper test
module test =
open Zipper
let t = Branch("a", Branch("b", Leaf, Branch("c", Leaf, Leaf)), Leaf)
let focus1 = t |> fromTree |> move [Left;Right]
let same1 = t |> fromTree |> move [Left;Right;Right;Up;Up;Up]
let same2 = t |> fromTree |> move [Left;Right;Right] |> Zipper.top
let xx = focus1 |> top
let newz = {(move [Left;Right;Right] xx) with focus = t} |> top
@nrolland
nrolland / gist:3731738
Created September 16, 2012 09:24
zipper module
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module Zipper =
let up z = match z.path with
| (d,v,other)::ep -> match d with
| TDirection.Left -> {focus=Branch(v,z.focus,other); path=ep}
| TDirection.Right -> {focus=Branch(v,other,z.focus); path=ep}
| [] -> failwith "can't go up" // because ep only goes down and is empty
let rec top z = match z.path with [] -> z | _ -> top (up z)
@nrolland
nrolland / gist:3731734
Created September 16, 2012 09:23
zipper
type 'a Zipper = { focus:'a Tree; path: (TDirection * 'a * 'a Tree) list}
type ZDirection = Up | Left | Right
@nrolland
nrolland / gist:3731642
Created September 16, 2012 08:47
insertbst
let rec insertBST x = function
| Leaf -> Branch(x , Leaf, Leaf)
| Branch(v, l, r) when x < v -> Branch(v, insertBST x l, r )
| Branch(v, l, r) as b when x > v -> Branch(v, l, insertBST x r )
| b -> b
@nrolland
nrolland / gist:3731548
Created September 16, 2012 08:19
a tree
type 'a Tree=
| Leaf
| Branch of 'a * 'a Tree * 'a Tree
@nrolland
nrolland / scriptSetup.fsx
Created August 18, 2012 15:19
Script for loading dependencies in fsx file from a solution/project
//This script generates
//a file named __project.fsx, for each proejct which can be #load "__project.fsx" in script intending to use the same dependency graph as the code in VS
//a file named __solmerged.fsx, at the solution root which can be #load "__solmerged.fsx" in script intending to use the same dependency graph as the code in VS
//In both cases, this enforce that a script compiling in VS should work from within FSI
#if INTERACTIVE
#r "System.Xml"
#r "System.Xml.Linq"
#endif
@nrolland
nrolland / gist:3352821
Created August 14, 2012 20:46
Install your packages for a solution from its project's packages.config
#if INTERACTIVE
#r "System.Xml"
#r "System.Xml.Linq"
#endif
open System
open System.IO
open System.Xml.Linq
open System.Text.RegularExpressions