Skip to content

Instantly share code, notes, and snippets.

View gcanti's full-sized avatar

Giulio Canti gcanti

View GitHub Profile
@gcanti
gcanti / purescript-dependency-graph.md
Last active April 16, 2016 16:46
Dependency graph of some purescript packages

Source

Format: module -> import -> dependency

{
  "purescript-arrays": {
    "Prelude": "purescript-prelude",
    "Control.Alt": "purescript-control",
    "Control.Alternative": "purescript-control",
@gcanti
gcanti / proof_in_functions.js
Created July 3, 2016 08:56
"Proof in functions" by @mbrandonw implemented in JavaScript and using Flow as a static type checker
// @flow
/*
"Proof in functions" by @mbrandonw
implemented in JavaScript and using Flow as a static type checker
Original post:
http://www.fewbutripe.com/swift/math/2015/01/06/proof-in-functions.html
@gcanti
gcanti / beginnerProgram.js
Created July 3, 2016 10:13
Elm architecture with Flow + react + redux
// @flow
import ReactDOM from 'react-dom'
import React from 'react'
import type { Component, Element } from 'react'
import { createStore } from 'redux'
type ReduxInitAction = { type: '@@redux/INIT' };
type MsgShape = { type: any };
function updateObj<T: Object>(obj: T, fields: $Shape<T>) : T {
  return Object.assign({}, obj, fields)
}

const person1 = { name: 'Giulio', age: 42 }
// I guess here Flow infers that person1 is of type { name: string, age: number }

const person2 = updateObj(person1, { age: 43 } ) // ok
const person2 = updateObj(person1, { a: 1 } ) // error: property `a` of object literal. Property not found
export default class Eff<EA: Object, A> {
run: () => A;
constructor(run: () => A) {
this.run = run
}
map<B>(f: (_: A) => B): Eff<EA, B> {
return new Eff(() => f(this.run()))
}
chain<EB: Object, B>(f: (_: A) => Eff<EB, B>): Eff<EA & EB, B> {
return Eff.join(this.map(f))
@gcanti
gcanti / HKT.js
Last active September 6, 2016 12:01
// @flow
import { HKT } from '../HKT'
import type { Functor } from '../Functor'
class IsList {}
class Cons<A> {
head: A;
tail: ListV<A>;
@gcanti
gcanti / HOC.js
Created September 14, 2016 09:24
/* @flow */
import React from 'react'
import ReactDOM from 'react-dom'
type FunctionComponent<A> = (props: A) => ?React$Element<any>;
type ClassComponent<D, A, S> = Class<React$Component<D, A, S>>;
type Component<A> = FunctionComponent<A> | ClassComponent<any, A, any>;
@gcanti
gcanti / TDD.md
Last active October 10, 2016 09:51

Type driven development with Flow

Written by @alpacaaa and @GiulioCanti

"Type driven development" is a technique used to split a problem into a set of smaller problems, letting the type checker suggest the concrete implementation, or at least helping us getting there. Here's a practical example

The Problem

Say for instance that we like to reimplement the function Promise.all, we'll name it sequence. Let's start with its signature

// @flow
declare type Reducer<S, A> = (state: S, action: A) => S;
type ExtractState = <S>(r: Reducer<S, *>) => S;
declare function combineReducers<O, A>(reducers: O): Reducer<$ObjMap<O, ExtractState>, A>;
type State = {
name: string,
age: number
};
@gcanti
gcanti / flow_tlp1.md
Last active April 6, 2018 19:34
Type level programming with Flow, encoding a finite state machine
// @flow

// based on State Machines All The Way Down
// An Architecture for Dependently Typed Applications
// https://eb.host.cs.st-andrews.ac.uk/drafts/states-all-the-way.pdf
// by Edwin Brady

//
// finite state machine