This file contains hidden or 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
| (* | |
| See the Haskell source: https://gist.github.com/1082416 | |
| There exist a few problems: | |
| (0) How correct is this? Non-termination, stack overflows? The kind | |
| of grammars that are recognized here are obviously not simply | |
| regular expressions, because of the fixpoints. Try for instance: |
This file contains hidden or 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
| module Serialization.Binary | |
| exception EncodingError | |
| exception NoEncoding of System.Type with | |
| override this.ToString() = | |
| sprintf "Failed to derive a binary encoding for type: %O" this.Data0 | |
| type E = (string -> int) -> System.IO.BinaryWriter -> obj -> unit | |
| type D = (int -> string) -> System.IO.BinaryReader -> obj |
This file contains hidden or 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 -XGADTs #-} | |
| -- This is an excercise in constructing a combinator-based regular | |
| -- expression matcher for self-education. | |
| -- | |
| -- Special thanks to Roman Cheplyaka (@shebang) for pointing out to me | |
| -- the need for state reduction to eliminate exponential complexity on | |
| -- certain benchmarks. | |
| module Regex (Regex, SM, token, compile, run, char, string) where |
This file contains hidden or 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 hidden or 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 hidden or 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
| function merge(a, b) { | |
| if (typeof b == "object") { | |
| for (var p in b) { | |
| a[p] = b[p]; | |
| } | |
| return a; | |
| } else { | |
| return b; | |
| } | |
| } |
This file contains hidden or 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 -XExistentialQuantification -XMultiParamTypeClasses #-} | |
| -- Serialization requires being able to marshall and unmarshall. | |
| class Serializable a where | |
| serialize :: a -> String | |
| deserialize :: String -> (a, String) | |
| -- Static assertion that `a` encodes `b -> c`. | |
| class Encoding a b c where | |
| decode :: a -> b -> c |
This file contains hidden or 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 R = | |
| { | |
| A : int | |
| B : int | |
| C : int | |
| } | |
| let Test = | |
| { | |
| A = (printf "A"; 1) |
This file contains hidden or 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
| % ``\Listing{...}'' command typesets its argument as a code block - | |
| % with monospace font and whitespace preserved. It is an | |
| % environment-like command accepting multiple paragraphs. | |
| \def\Listing{\bigskip\begingroup% | |
| \setlength{\parskip}{0pc}\addtolength{\parindent}{1pc}% | |
| \tt\scriptsize\obeylines\obeyspaces\PreserveWhitespace\ListingBody} | |
| % ``\ListingBody'' is an auxillary command need to make Listing work. | |
| % It inserts the argument and closes the group opened by Listing. | |
| \long\def\ListingBody#1{#1\endgroup\smallskip} |
This file contains hidden or 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
| @parser::members { | |
| private bool CanInsertSemicolon { | |
| get { | |
| var i = input.LA(1); | |
| return (i == RCURL | |
| || i == EOF | |
| || input.LT(1).Line > input.LT(-1).Line); | |
| } | |
| } |