View deriv.ml
open Printf | |
type expr = | |
| Int of int | |
| Var of string | |
| Add of expr * expr | |
| Mul of expr * expr | |
| Pow of expr * expr | |
| Ln of expr |
View deriv.swift
enum Expr { | |
case Int(n: Int) | |
case Var(x: String) | |
indirect case Add(f: Expr, g: Expr) | |
indirect case Mul(f: Expr, g: Expr) | |
indirect case Pow(f: Expr, g: Expr) | |
indirect case Ln(f: Expr) | |
} | |
func pown(a: Int, b: Int) -> Int { |
View InstallOCaml.sh
# .NET Core 2.1 with Ubuntu Server 18.04 - Version 1.0 - ami-f4f4cf91 | |
sh <(curl -sL https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh) | |
sudo apt-get update | |
sudo apt-get install make m4 gcc zip aspcud emacs libssl-dev ncurses-dev pkg-config tuareg-mode libffi-dev bubblewrap linux-tools-common linux-tools-aws | |
opam init | |
eval $(opam env) | |
opam install ocamlfind core async async_ssl cohttp yojson ppx_deriving ocp-indent merlin cohttp-async |
View ConcestorMap.fs
// This code implements a persistent dictionary similar to Map except the | |
// internal representation is a Dictionary + diffs. This offers different | |
// performance tradeoffs and, in particular, much faster add and remove when | |
// used linearly. | |
// | |
// For more details, see the following articles from the F# Journal: | |
// | |
// http://fsharpnews.blogspot.co.uk/2017/10/the-concestor-set.html | |
// http://fsharpnews.blogspot.co.uk/2017/10/a-simple-concestor-dictionary.html |
View FemtoMLParserUsingActivePatterns.fs
> let alpha = set['a'..'z'] + set['A'..'Z'];; | |
> let num = set['0'..'9'];; | |
> let alphanum = alpha + num;; | |
> let (|Char|_|) alphabet = function | |
| c::cs when Set.contains c alphabet -> Some(c, cs) | |
| _ -> None;; |
View FemtoMLParserUsingFSLexAndYacc.fs
{ | |
open Parse | |
open Lexing | |
let ident = function | |
| "let" -> LET | |
| "rec" -> REC | |
| "in" -> IN | |
| "fun" -> FUN | |
| "if" -> IF | |
| "then" -> THEN |
View FemtoMLParserUsingFParsec.fs
> let pInt : Parser<_, unit> = puint32 |>> int .>> spaces;; | |
> let str s = pstring s >>. spaces;; | |
> let keywords = | |
"if then else let rec in fun".Split ' ' | |
|> set;; | |
> let pIdent : Parser<_, unit> = |
View bf.bf
>>>+[[-]>>[-]++>+>+++++++[<++++>>++<-]++>>+>+>+++++[> | |
++>++++++<<-]+>>>,<++[[>[->>]<[>>]<<-]<[<]<+>>[>]>[<+ | |
>-[[<+>-]>]<[[[-]<]++<-[<+++++++++>[<->-]>>]>>]]<<]<] | |
< | |
[[<]>[[>]>>[>>]+[<<]<[<]<+>>-]>[>]+[->>]<<<<[[<<]<[<] | |
+<<[+>+<<-[>-->+<<-[>+<[>>+<<-]]]>[<+>-]<]++>>-->[>]> | |
>[>>]]<<[>>+<[[<]<]>[[<<]<[<]+[-<+>>-[<<+>++>-[<->[<< | |
+>>-]]]<[>+<-]>]>[>]>]>[>>]>>]<<[>>+>>+>>]<<[->>>>>>> | |
>]<<[>.>>>>>>>]<<[>->>>>>]<<[>,>>>]<<[>+>]<<[+<<]<] |
View j.c
typedef char C;typedef long I; | |
typedef struct a{I t,r,d[3],p[2];}*A; | |
#define P printf | |
#define R return | |
#define V1(f) A f(w)A w; | |
#define V2(f) A f(a,w)A a,w; | |
#define DO(n,x) {I i=0,_n=(n);for(;i<_n;++i){x;}} | |
I *ma(n){R(I*)malloc(n*4);}mv(d,s,n)I *d,*s;{DO(n,d[i]=s[i]);} | |
tr(r,d)I *d;{I z=1;DO(r,z=z*d[i]);R z;} | |
A ga(t,r,d)I *d;{A z=(A)ma(5+tr(r,d));z->t=t,z->r=r,mv(z->d,d,r); |
View dfs.fs
open System.Collections.Generic | |
/// Imperative depth-first search | |
let dfs (V, E) = | |
let visited = HashSet(HashIdentity.Structural) | |
let stack = Stack[V] | |
while stack.Count > 0 do | |
let u = stack.Pop() | |
if not(visited.Contains u) then | |
for v in E u do |