Skip to content

Instantly share code, notes, and snippets.

@panesofglass
panesofglass / OwinDraft2.fs
Created December 28, 2010 04:50 — forked from bvanderveen/OwinDraft2.cs
An alternate definition of the OWIN specification based on RFC3875
namespace Owin
open System
open System.Collections.Generic
open System.Threading.Tasks
type Request = IDictionary<string, obj>
type Response = string * IDictionary<string, seq<string>> * seq<obj>
type Application = Func<Request, Task<Response>>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
namespace FuncGist {
// signature exposed by middleware and app
@loudej
loudej / ObservableExtensions.cs
Created December 28, 2010 07:59
observable + task
using System;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
namespace FuncGist {
public static class ObservableExtensions {
public static Task Subscribe<T>(this IObservable<T> observable, Action<T> next) {
@panesofglass
panesofglass / TcpServer.fsx
Created January 4, 2011 17:43
Asynchronous TCP server in F#
// [snippet: Async socket server using F# async computations.]
open System
open System.IO
open System.Net
open System.Net.Sockets
open System.Threading
type Socket with
member socket.AsyncAccept() = Async.FromBeginEnd(socket.BeginAccept, socket.EndAccept)
@panesofglass
panesofglass / Parser.fs
Created January 12, 2011 07:04
Parser monad using Async computations
type Parser<'r, 's> = 's -> Async<('r * 's) option>
let returnF v : Parser<'r,'s> = fun input -> async { return Some(v, input) }
let bind (p: Parser<'a,'s>) (f: 'a -> Parser<'b,'s>) : Parser<'b,'s> =
fun input -> async {
let! comp = p input
return! match comp with
| Some(value, input) -> f value input
| None -> async { return None } }
@panesofglass
panesofglass / FSharpServer.fs
Created January 24, 2011 16:24
A functional wrapper around the WCF Web APIs (http://wcf.codeplex.com/)
module Main
open System
open System.Collections.Generic
open System.Net
open System.Net.Http
open Microsoft.ServiceModel.Http
open FSharp.Http
[<EntryPoint>]
let main(args) =
module My.Blogs
open System
open System.Collections.Generic
open System.Web
open IntelliFactory.WebSharper.Sitelets
type Id = int
type Html = string
@bvanderveen
bvanderveen / Http.cs
Created February 19, 2011 21:52
Upcoming Kayak interface
using System;
using System.Collections.Generic;
namespace Kayak.Http
{
public class HttpRequestEventArgs : EventArgs
{
public IHttpServerRequest Request { get; internal set; }
public IHttpServerResponse Response { get; internal set; }
}
@panesofglass
panesofglass / frank-routing-explicit-params.fs
Created February 24, 2011 23:14
Options for Frank routing
let myApp = function
| GET "/" _ -> render "Hello world!"
| POST "/order" p -> frank {
createThingFromParams p
do! redirectTo "/" }
anonymous
anonymous / gist:848035
Created February 28, 2011 21:04
type O<'T>(v : 'T, isSet : bool) =
struct
static member op_Implicit(value) : O<'T> = O(value, true)
member this.ValueOrDefault(defaultValue) = if isSet then v else defaultValue
end
module O =
let get (o : O<_>) v = o.ValueOrDefault v
type Optional = System.Runtime.InteropServices.OptionalAttribute