Skip to content

Instantly share code, notes, and snippets.

View joshburgess's full-sized avatar
💭
🤔

Josh Burgess joshburgess

💭
🤔
View GitHub Profile
// getEmptyPlate :: IxBurgerBuilder Ready EmptyPlate BurgerSpec
// getEmptyPlate = IxBurgerBuilder mempty
const getEmptyPlate = new IxBurgerBuilder<Ready, EmptyPlate, BurgerSpec>([]);
// addIngredient :: forall i o. String -> BurgerSpec -> IxBurgerBuilder i o (BurgerSpec)
// addIngredient x xs = IxBurgerBuilder $ Ingredient x : xs
const addIngredient = <I, O>(s: string) => (spec: BurgerSpec) => new IxBurgerBuilder<I ,O, BurgerSpec>(spec.concat([s]));
// -- ADDING THE BUN
// placeEmptyBun :: BurgerSpec -> IxBurgerBuilder EmptyPlate BottomBunOn BurgerSpec
import { Functor3 } from 'fp-ts/lib/Functor'
import { IxMonad3 } from 'fp-ts/lib/IxMonad';
declare module 'fp-ts/lib/HKT' {
// IxBurgerBuilder :: * -> * -> * -> *
interface URI2HKT3<U, L, A> {
IxBurgerBuilder: IxBurgerBuilder<U, L, A>
}
}
// data Ready
// data EmptyPlate
// data BottomBunOn
// data PattyOn
// data CheeseOn
// data OnionOn
// data LettuceOn
// data TomatoOn
// data PicklesOn
// data TopBunOn
@gcanti
gcanti / fp-ts-to-the-max-II.ts
Last active January 16, 2024 12:58
TypeScript port of the second half of John De Goes "FP to the max" (https://www.youtube.com/watch?v=sxudIMiOo68)
import { log } from 'fp-ts/lib/Console'
import { Type, URIS } from 'fp-ts/lib/HKT'
import { none, Option, some } from 'fp-ts/lib/Option'
import { randomInt } from 'fp-ts/lib/Random'
import { fromIO, Task, task, URI as TaskURI } from 'fp-ts/lib/Task'
import { createInterface } from 'readline'
//
// helpers
//
@gcanti
gcanti / fp-ts-to-the-max-I.ts
Created August 8, 2018 14:11
TypeScript port of the first half of John De Goes "FP to the max" (https://www.youtube.com/watch?v=sxudIMiOo68)
import { log } from 'fp-ts/lib/Console'
import { none, Option, some } from 'fp-ts/lib/Option'
import { randomInt } from 'fp-ts/lib/Random'
import { fromIO, Task, task } from 'fp-ts/lib/Task'
import { createInterface } from 'readline'
//
// helpers
//
@SimonAlling
SimonAlling / algebraic.ts
Last active October 24, 2023 21:00
Algebraic Data Types in TypeScript
// Types:
type Just<T> = { Just: T }
type Nothing = {}
type Maybe<T> = Just<T> | Nothing
type Left<L> = { Left: L }
type Right<R> = { Right: R }
type Either<L, R> = Left<L> | Right<R>
// For convenience:
@gelisam
gelisam / bidirectional-structural.ts
Created July 25, 2018 13:13
bidirectional type-checker in TypeScript
// in response to https://twitter.com/arntzenius/status/1022076441603829760
// types A,B ∷= base | A → B
// terms M ∷= E | λx.M
// exprs E ∷= x | E M | (M : A)
type Type = "Base" | {lhs: Type, tag: "->", rhs: Type};
type Var = string;
type Term = Expr | {tag: "Lam", varname: Var, body: Term};
type Expr = Var | {tag: "App", fn: Expr, arg: Term} | {term: Term, tag: ":", tp: Type};
const Day = ({ get, left, right }) => {
const map = f => Day ({
get: f (extract()),
left, right
})
const extend = f =>
Day ({
get: (left, right) => f (Day ({ get, left, right })),
@carymrobbins
carymrobbins / Subtypes.hs
Created July 18, 2018 17:51
Zero cost dirty subtypes for Haskell
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Main where
import Unsafe.Coerce
@konn
konn / Data.Aeson.Generic.DerivingVia.hs
Last active December 7, 2020 21:06
Type-driven safe derivation of ToJSON and FromJSON, using DerivingVia in GHC 8.6 and some type-level hacks
{-# LANGUAGE ConstraintKinds, DataKinds, DeriveGeneric, DerivingVia #-}
{-# LANGUAGE ExplicitNamespaces, FlexibleContexts, FlexibleInstances #-}
{-# LANGUAGE GADTs, GeneralizedNewtypeDeriving, MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds, ScopedTypeVariables, StandaloneDeriving #-}
{-# LANGUAGE TypeApplications, TypeFamilies, TypeInType, TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wall #-}
module Data.Aeson.Generic.DerivingVia
( StrFun(..), Setting(..), SumEncoding'(..), DefaultOptions, WithOptions(..)
, -- Utility type synonyms to save ticks (') before promoted data constructors