Skip to content

Instantly share code, notes, and snippets.

@wokalski
wokalski / Ppx_driver_with_bucklescript.md
Created August 26, 2019 07:38
How to run a driver based ppx with bucklescript
  1. Create a dune file:
(library
 (public_name aggregate_ppx_name)
 (kind ppx_rewriter)
 (libraries ppx_deriving_protobuf other_ppx another_ppx))
  1. Build:
dune build --profile release
module State: {
type t('a);
let createSlot: (t('a) => 'b) => 'b;
let useHook: ('a, t('a)) => ('a, 'a => unit);
} = {
type t('a) = ref(option('a));
let createSlot = cont => cont(ref(None));
let useHook = (initial: 'a, slot: t('a)) => {
let state =
switch (slot^) {
@lpalmes
lpalmes / react.md
Last active May 7, 2021 17:59
React and Reconcilers in Reason

React

This is the base of all projects and it will include the foundation for all potential react-based projects in Reason.

This base package should include a ReasonReact api to promote collaboration and familiarity with people using a ReasonReact, and for the modern world of React this should also include a Hooks api that currently revery uses.

React module

All blocks in Jsx are of type React.reactElement. This reactElement should represent:

module Store = {
type action =
| Increase
| Decrease
| SetUsername(string);
type state = {
count: int,
username: string,
};
type storeBag = {
@busypeoples
busypeoples / Game.re
Last active January 7, 2018 22:08
ReasonML Game
type field =
| O
| X;
type position = (field, field, field, field);
type unit = (position, position, position, position);
type units = list(unit);
@Zerim
Zerim / SignupForm.re
Last active February 19, 2018 23:25
A simple SignupForm written in ReasonML
/* `action` and `state` types must be defined before the `let component` statement for type inference to work */
type action =
| UpdateEmail string
| UpdatePassword string;
type state = {
email: string,
password: string
};
@lilactown
lilactown / promises.re
Last active August 20, 2022 07:56
Notes on using JavaScript Promises in ReasonML/BuckleScript
/**
* Making promises
*/
let okPromise = Js.Promise.make((~resolve, ~reject as _) => [@bs] resolve("ok"));
/* Simpler promise creation for static values */
Js.Promise.resolve("easy");
Js.Promise.reject(Invalid_argument("too easy"));
@derBingle
derBingle / recp.zsh
Created September 8, 2017 17:41
Convert an OCaml file or the clipboard to Reason, and copy the result to the clipboard.
function recp () {
if [ $# -ge 1 -a -f "$1" ]
then
refmt --parse ml --print re "$@" | pbcopy;
else
pbpaste | refmt --parse ml --print re | pbcopy
fi
}
@busypeoples
busypeoples / PhantomTypeReasonML.md
Last active February 6, 2024 21:29
Phantom types in ReasonML

Phantom types in ReasonML

Introduction

"A phantom type is a parametrised type whose parameters do not all appear on the right-hand side of its definition..." Haskell Wiki, PhantomType

The following write-up is intended as an introduction into using phantom types in ReasonML.

Taking a look at the above definition from the Haskell wiki, it states that phantom types are parametrised types where not all parameters appear on the right-hand side. Let's try to see if we can implement a similar example as in said wiki.

@danharper
danharper / gulpfile.js
Last active September 25, 2024 09:04
New ES6 project with Babel, Browserify & Gulp
var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var browserify = require('browserify');
var watchify = require('watchify');
var babel = require('babelify');
function compile(watch) {
var bundler = watchify(browserify('./src/index.js', { debug: true }).transform(babel));