Created
May 29, 2011 17:33
-
-
Save Talljoe/997976 to your computer and use it in GitHub Desktop.
DSL notes from ALT.NET Seattle
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 -> {} | |
| _ -> {}) | |
// direct DSL | |
// Abstraction breaks when using new methods | |
Route "/" [ | |
GET (fun request -> View "Home") | |
] | |
let GET f = ("GET", f) // i.e tuples | |
// custom operator | |
// Less obvious | |
let (@=) method hander = (method, handler) | |
let GET = "GET" | |
// Route: string -> (string * (request -> async<response>)) list -> ??? | |
Route "/" [ | |
GET @= Object (fun request -> async { | |
let! all = db.All() | |
all | |
}) @? Cache.For(10 minutes) // composition | |
] | |
// records | |
// Less obvious, but has intellisense. | |
// Allows for easier handling of optional values | |
// Route: string -> RouteRecord list -> ??? | |
Route "/" [ | |
{GET with Handler=(fun request -> async {})} | |
{POST with AntiForgeryValidation=true; Handler=(fun ...)} | |
] | |
// function composition | |
// Have to process each entry (no map) | |
// Route: string -> (request -> async<response>) list -> ??? | |
Route "/*" [ | |
"GET" |> Response<User> (fun request -> View "Home") | |
"POST" |> Create (fun request -> async { ... }) | |
] | |
// Maximum composition! | |
Route "/(?'id'\d+)" [ | |
GET @= Require.Authorization | |
@+ getParameter("id") |> db.GetById | |
@+ toResponse | |
@+ Cache.For(10 minutes); | |
POST @= toObject<User> | |
@+ db.Add | |
@+ getIdForUser >> redirectTo | |
] | |
// Issue: handling different types of return values | |
// return object | |
// return object + responsedata (cookies, headers, etc) | |
// return responsedata (cookies, headers, content, etc) | |
// Maybe always return responsdata and have helpers to go from object to responsedata |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment