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 Main where | |
import Prelude | |
import Control.Monad.Eff.Console (logShow) | |
import TryPureScript (render, withConsole) | |
-- Declare the recursive type. | |
data Peano = Z | S Peano | |
-- This allows us to print the type. |
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
const counterReducer = (state = 0, {type}) => { | |
switch(type) { | |
case 'INC': return state + 1 | |
case 'DEC': return state - 1 | |
default: return state | |
} | |
} | |
const todoReducer = (state = 0, {type, text}) => { | |
switch(type) { |
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
const createSelector = (...fns) => R.memoize(R.converge(R.last(fns), R.init(fns))) | |
// test case | |
const selector = createSelector( | |
state => state.a, | |
state => state.b, | |
(a, b) => console.log('Called!') || ({ | |
c: a * 2, | |
d: b * 3 |
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
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
{-# LANGUAGE RankNTypes #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE TypeOperators #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
module CCCs 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
// Typescript can handle monomoprhic functions | |
const flip = <A, B, C>(f: (a: A) => (b: B) => C): ((b: B) => (a: A) => C) => b => a => f(a)(b) | |
const foo = (a: string) => (b: number) => a.length - b | |
// fooFlipped: (b: number) => (a: string) => number | |
const fooFlipped = flip(foo) | |
// But can't handle polymorphic functions | |
const concat = <A>(xs: Array<A>) => (a: A): Array<A> => xs.concat([a]) |
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 Tac Toe: Advanced Type Safety | |
================================== | |
Adapted from http://chrispenner.ca/posts/type-tac-toe | |
*/ | |
/** Either X, O, or Nothing */ | |
type Piece = 'X' | 'O' | 'N' | |
/** coordinates */ |
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
/* Slaying a UI Anti Pattern in Reason */ | |
type remoteData 'e 'a = | |
| Nothing | |
| Loading | |
| Failure 'e | |
| Success 'a; | |
type item = { | |
userId: int, |
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
// | |
// product types | |
// | |
/* | |
// A coordinate in 3D space | |
export type Coord = { | |
readonly x: number | |
readonly y: number | |
readonly z: number |
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
import React from "react"; | |
import { render } from "react-dom"; | |
import R from "ramda"; | |
const users = [ | |
{ id: 1, name: "foo", points: 45 }, | |
{ id: 2, name: "bar", points: 22 }, | |
{ id: 3, name: "baz", points: 79 }, | |
{ id: 4, name: "bla", points: 54 } | |
]; |