This file contains hidden or 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 Microsoft.FSharp.Quotations | |
| // <@ fun x -> (% <@ x @> ) @> ~ lambda (fun x -> x) | |
| let lambda (f : Expr<'T> -> Expr<'R>) : Expr<'T -> 'R> = | |
| let var = new Var("__temp__", typeof<'T>) | |
| Expr.Cast<_>(Expr.Lambda(var, f (Expr.Cast<_>(Expr.Var var)))) | |
| // Staged fixed-point combinator |
This file contains hidden or 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
| // http://www.cs.princeton.edu/courses/archive/spr09/cos333/beautiful.html | |
| // http://scala-lms.github.io/tutorials/regex.html | |
| #r "../packages/FSharp.Compiler.Service.1.3.1.0/lib/net45/FSharp.Compiler.Service.dll" | |
| #r "../packages/QuotationCompiler.0.0.7-alpha/lib/net45/QuotationCompiler.dll" | |
| open QuotationCompiler |
This file contains hidden or 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
| type Stream<'T> // abstract type | |
| module Stream = | |
| // general combinators | |
| val map : (Expr<'A> -> Expr<'B>) -> Stream<'A> -> Stream<'B> | |
| val collect : (Expr<'A> -> Stream<'B>) -> Stream<'A> -> Stream<'B> | |
| val filter : (Expr<'A> -> Expr<bool>) -> Stream<'A> -> Stream<'A> | |
| val take : Expr<int> -> Stream<'A> -> Stream<'A> | |
| val zipWith : (Expr<'A> -> Expr<'B> -> Expr<'C>) -> Stream<'A> -> Stream<'B> -> Stream<'C> | |
| // ... |
This file contains hidden or 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
| (require '[clojure.core.match :refer [match]]) | |
| (defn extend [k v l] | |
| (fn [k'] | |
| (if (= k k') v (l k')))) | |
| (def empty (fn [k'] (throw (Exception. "oups")))) | |
| (defn eval [e env] |
This file contains hidden or 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
| extern crate time; | |
| use std::io; | |
| use time::PreciseTime; | |
| fn main() { | |
| let mut guess: String = String::new(); | |
| io::stdin().read_line(&mut guess).expect("failed to read line"); | |
| let n: i64 = guess.trim().parse().expect("Please type a number!"); |
This file contains hidden or 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 test where | |
| import prelude | |
| import univalence | |
| data list (A : U) = nil | cons (x : A) (xs : list A) | |
| data bool = false | true | |
| data nat = zero | suc (n : nat) | |
| one : nat = suc zero |
This file contains hidden or 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
| #time | |
| [<Struct>] | |
| type ResultStruct<'T, 'TError> = | |
| | OkS of ok : 'T | |
| | ErrorS of error : 'TError | |
| type ResultClass<'T, 'TError> = | |
| | OkC of ok : 'T | |
| | ErrorC of error : 'TError |
This file contains hidden or 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; | |
| public class C { | |
| public void M() { | |
| Func<Func<dynamic, dynamic>, dynamic> fd = x => x; | |
| dynamic Y = fd(f => fd(x => f(fd(y => x(x)(y))))(fd(x => f(fd(y => x(x)(y)))))); | |
| Y(fd(f => fd(x => f(x))))(42); | |
| } | |
| } |
This file contains hidden or 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 Program | |
| { | |
| class Node | |
| { | |
| public int Id; | |
| public Node Parent; | |
| } | |
| class TreeNode | |
| { |
This file contains hidden or 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
| public class Subs : ExpressionVisitor | |
| { | |
| private Dictionary<ParameterExpression, Expression> env; | |
| public Subs(Dictionary<ParameterExpression, Expression> env) | |
| { | |
| this.env = env; | |
| } | |
| protected override Expression VisitParameter(ParameterExpression node) | |
| { |