Skip to content

Instantly share code, notes, and snippets.

using System;
using System.IO;
using System.Net;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Reactive.Linq;
namespace NodeSharp
{
class Program
@hodzanassredin
hodzanassredin / reactive.cs
Created July 7, 2011 11:20
Using RX for object level CQRS, method proxy and logging.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reactive.Subjects;
using System.Reactive.Linq;
namespace FpCs
{
class Program
type OptionMonad = | OptionMonad with
static member ret x = Some x
static member bind (x, f) = Option.bind f x
type ListMonad = | ListMonad with
static member ret x = [x]
static member bind (x, f) = List.collect f x
let inline ret (monad : ^M) (x : 'a) : 'b =
(^M : (static member ret : 'a -> 'b) (x))
@t0yv0
t0yv0 / MonadExamples.fs
Created July 2, 2011 23:29
Emulating higher kinds with F# inline functions.
(* F# lacks proper support for higher-kinded abstraction such as ML
functors or Haskell typeclasses. In particular it makes it seemingly
impossible to define functions that work for every type constructor.
The code below demonstrates that this functionality can be partially
recovered by using inline functions with static member constraints.
The approach requires explicitly passing typeclass instance values.
Error messages and derived types are horrible. Nonetheless, there is
some type safety - if the typeclass instances have been defined right,
type-unsafe code will be rejected by the typechecker, albeit with a
hairy message. Another disadvantage is the need to invent operators. *)
@t0yv0
t0yv0 / FSCGI.Structural.Converter.fs
Created June 30, 2011 01:07
An attempt to improve on OWIN<http://owin.org> in F#.
/// Converts structural encodings to proper FSCGI.* types.
module FSCGI.Structural.Converter
type private Encodings<'R,'W> =
('W -> Writer<'W>) *
('R -> Response<'R,'W>)
let private ConvertRequest (r : FSCGI.Request) : Request =
(
r.Headers,
@Talljoe
Talljoe / frankdsl.fs
Created May 29, 2011 17:33
DSL notes from ALT.NET Seattle
// Possible DSLs for Frank
// Pattern matching of some sort
// Can't short-circuit the match when a method isn't supported
// Must have a default handler
// Hard to make sensible DSL
"/users/{id}" Resource<User> (fun method ->
match method with
| GET id -> {}
| POST user -> {}
@joeriks
joeriks / HtmlFormHelpers.cs
Created April 7, 2011 13:14
Using a generic html form builder with client side and server side validation (Fluent Validation)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FluentValidation;
using System.Collections.Specialized;
namespace HtmlFormHelpers
{
@mattpodwysocki
mattpodwysocki / tweet-sentiment-rxjs.js
Created March 5, 2011 18:25
Using Tweet Sentiments with the Reactive Extensions for JavaScript
var http = require('http');
require('./rx-node/rx');
require('./rx-node/rx.aggregates');
require('./rx-node/rx_events');
var client = http.createClient(8080, 'data.tweetsentiments.com');
function getSentimentData(topic) {
var request = client.request('GET', '/api/search.json?topic=' + topic, {'host': 'data.tweetsentiments.com'});
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
@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 "/" }