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
type Async<'T> = ('T -> unit) -> unit | |
[<Sealed>] | |
type Async() = | |
static let self = Async() | |
member inline this.Return(x: 'T) : Async<'T> = | |
fun f -> f x | |
member inline this.ReturnFrom(x: Async<'T>) = x | |
member inline this.Bind |
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
(* Consider lists indexed by length. *) | |
Inductive List (t : Type) : nat -> Type := | |
| Nil : List t 0 | |
| Cons : forall n, t -> List t n -> List t (S n). | |
(* Every non-empty list has a head element. *) | |
Definition Head : forall t n, List t (S n) -> t. | |
intros t n list. inversion list. assumption. Defined. |
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
type IList<'T> = | |
abstract member Tail : #IListConsumer<'T,'R> -> 'R | |
abstract member Head : 'T | |
abstract member IsEmpty : bool | |
and IListConsumer<'T,'R> = | |
abstract member Consume : #IList<'T> -> 'R | |
[<Struct>] | |
type Nil<'T> = |
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
let rec loop : Async<unit> = | |
async { | |
let! req = HttpRequestParser.Parse buf read | |
let! resp = app.Handle req | |
let kA = isKeepAlive req | |
do! respond socket buf (setKeepAlive kA resp) | |
if isKeepAlive req then | |
return! loop | |
else | |
return () |
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
var http = require('http'); | |
http.createServer(function (req, res) { | |
res.writeHead(200, {'Content-Type': 'text/plain', | |
'Connection': 'keep-alive'}); | |
res.end('Hello World\n'); | |
}).listen(8080, "192.168.56.1"); | |
console.log('Server running'); |
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.Net.Sockets | |
type A = System.Net.Sockets.SocketAsyncEventArgs | |
type B = System.ArraySegment<byte> | |
exception SocketIssue of SocketError with | |
override this.ToString() = | |
string this.Data0 | |
/// Wraps the Socket.xxxAsync logic into F# async logic. |
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
(* | |
We start designing a representation for some functional language. | |
Keeping it simple, we use strings to represent identifiers (to be | |
changed later by something more fancy), define a few primitives, | |
constants, and finally expressions. | |
*) | |
type Id = string |
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
[<JavaScript>] | |
let Factorial (n: int) = | |
let rec fac n acc = | |
match n with | |
| 0 | 1 -> acc | |
| n -> fac (n - 1) (acc * n) | |
fac n 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
/// generated JavaScript for k=16 | |
function bind(x,f) {return f(x)} | |
function test(x0) { | |
var k0; | |
k0 = function (x1) { | |
var k1; | |
k1 = function (x2) { | |
var k2; | |
k2 = function (x3) { |
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
{-# OPTIONS -XDoRec -XDeriveDataTypeable #-} | |
module Example where | |
import Text.Earley | |
import Data.Dynamic | |
import Control.Applicative | |
data E = Nat Int | |
| Add E E deriving (Show, Typeable) |