Skip to content

Instantly share code, notes, and snippets.

View samwgoldman's full-sized avatar

Sam Goldman samwgoldman

View GitHub Profile
type variance = Bi | Co | Cn | Inv
type ty =
| Unit
| Tvar of int
| Arrow of ty * ty
| TyApp of int * ty array
type injectivity = bool
index 3ef907960..5de2e0e85 100644
--- a/runtime/compare.c
+++ b/runtime/compare.c
@@ -133,7 +133,8 @@ static intnat do_compare_val(struct compare_stack* stk,
return Long_val(v1) - Long_val(v2);
/* Subtraction above cannot overflow and cannot result in UNORDERED */
#ifndef NO_NAKED_POINTERS
- if (Is_in_value_area(v2)) {
+ if (!Is_in_value_area(v2))
+ return LESS;
@samwgoldman
samwgoldman / jsverify.js
Created November 14, 2015 00:38
First pass at Flow interface file for jsverify
declare module "jsverify" {
// Either
declare interface Either<A,B> {
either<T>(l: (a: A) => T, r: (b: B) => T): T;
isEqual(other: Either<A,B>): boolean;
bimap<C,D>(f: (a: A) => C, g: (b: B) => D): Either<C,D>;
first<C>(f: (a: A) => C): Either<C,B>;
second<D>(g: (b: B) => D): Either<A,D>;
/* @flow */
type Maybe2<T,U> = (pattern: {
some: (x: T) => U,
none: () => U
}) => U;
type Maybe<T> = Maybe2<T, *>;
// Constructors
var foo = {}
Object.defineProperty(foo, "bar", {
enumerable: true,
get: function() {
return bar;
}
})
var bar = { foo: foo }
foo.bar.foo === foo // true
@samwgoldman
samwgoldman / example.js
Last active April 3, 2021 22:20
Pure, stateless, type-checked React components with Immutable.js and Flow
/* @flow */
var React = require("react")
var Immutable = require("immutable")
// In order to use any type as props, including Immutable objects, we
// wrap our prop type as the sole "data" key passed as props.
type Component<P> = ReactClass<{},{ data: P },{}>
type Element = ReactElement<any, any, any>
@samwgoldman
samwgoldman / result.rb
Last active August 29, 2015 14:16
success/failure result object
module Result
class << self
def success(value)
Success.new(value)
end
def failure(error)
Failure.new(error)
end
end
@samwgoldman
samwgoldman / gist:1fcceea36206e1544414
Last active February 18, 2017 16:07
Maybe type in JS/Flow
/* @flow */
type Maybe<T,U> = (pattern: {
some(x: T): U;
none(): U;
}) => U;
function map<A,B,C>(maybe: Maybe<A,C>, f: (a: A) => B): Maybe<B,C> {
return function(pattern) {
return maybe({
@samwgoldman
samwgoldman / main.rb
Last active August 29, 2015 14:11
TorqueBox testing issue
require "capybara"
require "capybara/poltergeist"
require "torquebox-web"
require "torquebox-messaging"
page = DATA.read
app = proc do
headers = {
"Content-Type" => "text/html",
"Content-Length" => page.length.to_s
module Result
class << self
def not_nil(value)
if value.nil?
None
else
Some.new(value)
end
end