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
using System; | |
using System.IO; | |
using System.Net; | |
using System.Reactive.Concurrency; | |
using System.Reactive.Disposables; | |
using System.Reactive.Linq; | |
namespace NodeSharp | |
{ | |
class Program |
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Reactive.Subjects; | |
using System.Reactive.Linq; | |
namespace FpCs | |
{ | |
class Program |
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 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)) |
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
(* 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. *) |
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
/// 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, |
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
// 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 -> {} |
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using FluentValidation; | |
using System.Collections.Specialized; | |
namespace HtmlFormHelpers | |
{ |
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'); | |
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'}); |
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 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 | |
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 myApp = function | |
| GET "/" _ -> render "Hello world!" | |
| POST "/order" p -> frank { | |
createThingFromParams p | |
do! redirectTo "/" } |