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
| static class X | |
| { | |
| public static X<T> Create<T>(T t) { return new X<T>(t); } | |
| } | |
| class X<T> | |
| { | |
| T MyT { get; } | |
| public X(T t) | |
| { |
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
| newtype Visitor e r = Visitor { visit :: e -> r } | |
| data Employee = PermanentEmployee | Contractor | |
| xmlvisitor :: Visitor Employee String | |
| xmlvisitor = Visitor { visit = visitEmp } | |
| where visitEmp PermanentEmployee = "<employee />" | |
| visitEmp Contractor = "<contractor />" | |
| class Visitee e 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
| newtype EmployeeVisitor r = EmployeeVisitor { visit :: Employee -> r } | |
| data Employee = PermanentEmployee | Contractor | |
| xmlvisitor :: EmployeeVisitor String | |
| xmlvisitor = EmployeeVisitor { visit = visitEmp } | |
| where visitEmp PermanentEmployee = "<employee />" | |
| visitEmp Contractor = "<contractor />" | |
| class VisitableEmployee e where | |
| accept :: e -> EmployeeVisitor r -> r |
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 { sc } from './sc' | |
| import { h } from 'snabbdom' | |
| // ...snabbdom imports | |
| export const helloWorldCmp = cmp(({ state, setState }) => | |
| h('div', [ | |
| h('div', ['Hello ', state]), | |
| h('input', { on: { input: e => setState(e.target.value) } }) | |
| ])) |
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 _ = require("lodash") | |
| // Utilities | |
| const range = n => [...Array(n).keys()] | |
| const cart = (l, r) => _.flatMap(l, li => r.map(ri => [li, ri])) | |
| const partitions = arr => { | |
| const n = arr.length | |
| const masks = range(Math.pow(2, n) - 1) | |
| return masks.map(m => { | |
| let i = 0 |
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 Tone = require("tone"); | |
| const input = ` | |
| h x x x x x x x x | |
| s - - x - - - x - | |
| b x - - - x - - - | |
| `; | |
| const parse = input => { | |
| const lines = input.trim().split("\n"); |
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
| // Functor | |
| export const map = f => s => x0 => { | |
| const [v, x1] = s(x0); | |
| return [f(v), x1]; | |
| }; | |
| // Applicative | |
| export const pure = a => x => [a, x]; | |
| export const ap = stf => stv => x0 => { | |
| const [f, x1] = stf(x0); |
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 { match } = require("natch"); | |
| const compose = f => g => x => f(g(x)); | |
| const kleisli = bind => fk => gk => compose(bind(fk))(gk); | |
| // The reader module | |
| const Reader = (() => { | |
| // Constructors | |
| const Pure = v => ({ t: "pure", v }); | |
| const Get = v => ({ t: "get", v }); |
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 GenericEither = ({ Left, Right, match }) => { | |
| const map = f => match({ Left, Right: x => Right(f(x)) }); | |
| const of = Right; | |
| const chain = f => match({ Left, Right: f }); | |
| return { map, of, chain }; | |
| }; | |
| // A concrete representation of an Either | |
| const MyEither = { |
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
| // Instances | |
| const Arr = (() => { | |
| // Monoid instance (forall a, [a] is a Monoid) | |
| // :: [a] | |
| const empty = [] | |
| // :: [a] -> [a] -> [a] | |
| const concat = a => b => a.concat(b) | |
| // Traversable instance (we have no typeclass system, so we need to accept the applicative instance dictionary explicitly) | |
| // :: { "of" :: a -> f a, "lift2": (a -> b -> c) -> f a -> f b -> fc } |