Skip to content

Instantly share code, notes, and snippets.

declare module 'circular-buffer' {
class CircularBuffer<T> {
constructor(capacity: number);
size(): number;
capacity(): number;
enq(value: T): void;
deq(): T;
get(idx: number): T;
get(start, end): T[];
toarray(): T[];
let compiler = newCompiler(result => {
match result {
Ok(res) => {
outputTextArea.classList.remove("has-errors")
outputTextArea.value = res
}
Err(err) => {
outputTextArea.classList.add("has-errors")
outputTextArea.value = err
}
$ java -jar compiler.jar --help
--angular_pass : Generate $inject properties for
AngularJS for functions annotated
with @ngInject
--assume_function_wrapper : Enable additional optimizations based
on the assumption that the output
will be wrapped with a function
wrapper. This flag is used to
indicate that "global" declarations
will not actually be global but
type ModuleLoader = AST.ModuleName -> IO (Either Error.Error AST.ParsedModule)
newChainedModuleLoader :: [ModuleLoader] -> ModuleLoader
newChainedModuleLoader [] moduleName = return $ Left $ Error.ModuleNotFound moduleName
newChainedModuleLoader (loader:rest) moduleName = do
loader moduleName >>= \case
Left (Error.ModuleNotFound _) -> newChainedModuleLoader rest moduleName
Left e -> return $ Left e
Right m -> return $ Right m
export default class RingBuffer<T> {
_max_length: number;
_buffer: T[];
_write_head: number;
_length: number;
constructor(max_length: number) {
this._max_length = max_length;
this._buffer = new Array(max_length);
this._write_head = 0;
{-# LANGUAGE ExistentialQuantification, LambdaCase #-}
import Data.IORef
import Control.Monad
data Mover = forall a. Mover (IORef [a]) (IORef [a])
doMove :: Mover -> IO ()
doMove (Mover left right) = do
readIORef left >>= \case
/Users/ca/projects/datagraph/src/Main.hs:168:3:
Couldn't match type ‘HashMap k0 v0’
with ‘GenHaxl () (HashMap Text ResponseValue)’
Expected type: (AST.Selection
-> GenHaxl () (AST.Name, ResponseValue))
-> TheMonad (HashMap Text ResponseValue)
Actual type: (AST.Selection -> [b0]) -> HashMap k0 v0
The first argument of ($) takes one argument,
its type is ‘f0 b1’,
it is specialized to ‘(AST.Selection -> [b0]) -> HashMap k0 v0’
data Scalar
= SInt Int32
| SFloat Float
| SBoolean Bool
| SString Text
| SEnum Text -- unquoted on parse
data InputValue
= IVar Text
| IScalar Scalar
run :: HashMap ModuleName LoadedModule -> Module UnresolvedReference Pos -> IO (Either Error.Error LoadedModule)
run loadedModules modul = runEitherT $ do
env <- EitherT $ (try $ buildTypeEnvironment loadedModules modul) >>= \case
Left err -> return $ Left $ Error.TypeError err
Right result -> return result
decls <- forM (mDecls modul) $ \decl -> do
(lift $ try $ checkDecl env decl) >>= \case
Left err -> left $ Error.TypeError err
Right d -> return d
lift $ freezeModule modul
foo(function() {
// ...
}, function() {
// ...
})