Skip to content

Instantly share code, notes, and snippets.

View joshburgess's full-sized avatar
💭
🤔

Josh Burgess joshburgess

💭
🤔
View GitHub Profile
@i-am-tom
i-am-tom / Commit.hs
Created March 22, 2019 21:55
Apply your function parameters in any order, for no reason other than that you can.
{-# lAnGuAgE DataKinds #-}
{-# LaNgUaGe FlexibleInstances #-}
{-# lAnGuAgE FunctionalDependencies #-}
{-# LaNgUaGe KindSignatures #-}
{-# lAnGuAgE TypeFamilies #-}
{-# LaNgUaGe TypeOperators #-}
{-# lAnGuAgE UndecidableInstances #-}
module Commit where
import Data.Kind (Constraint, Type)
@jproyo
jproyo / Data.hs
Last active May 19, 2022 16:04
Tagless Final Encoding in Haskell Example
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
module Data where
type UserName = String
data DataResult = DataResult String
deriving (Eq, Show)
class Monad m => Cache m where
find ~/Work -name stack.yaml | xargs grep -o '^resolver: \([^#]*\)'
@briancavalier
briancavalier / fx.ts
Last active March 17, 2019 23:55
Small encoding of algebraic effects in Typescript (probably works in Flow, too, with syntax tweaks) used in helicopter: https://github.com/briancavalier/helicopter/blob/master/packages/core/src/fx.ts
export type Cancel = void | ((k: (r: void) => void) => void)
export const runCancel = (c: Cancel, k: (r: void) => void): void =>
c ? c(k) : k()
export type Fx<H, A> = (handler: H, k: (a: A) => void) => Cancel
export type Pure<A> = Fx<{}, A>
export const handle = <H0, H1, A>(fx: Fx<H0 & H1, A>, h1: H1): Fx<H0, A> =>
(h0, k) => fx({ ...h0, ...h1 } as H0 & H1, k)
@gelisam
gelisam / EIO.hs
Last active February 10, 2022 05:21
Keeping track of which exceptions have and haven't been handled
-- a continuation of https://gist.github.com/gelisam/137effb33d2777328d366dcb563d8d13
{-# LANGUAGE FlexibleContexts, FlexibleInstances, GeneralizedNewtypeDeriving, LambdaCase, MultiParamTypeClasses #-}
module EIO where
import Control.Monad
import Data.Void
import Test.DocTest
import qualified Control.Exception as E
@rust-play
rust-play / playground.rs
Created October 26, 2018 21:29
Code shared from the Rust Playground
#![feature(cell_update)]
use std::fmt::Display;
use std::cell::Cell;
pub trait IO: Sized {
type Output;
fn exec(self) -> Self::Output;
}
pub trait IOExt : IO {
// funciona somente com v3.1.6, essa estrategia de end/continue
// era um backdoor para fazer recursao em types, recursao funcionava somente com interfaces
// antigamente pela resolucao de tipos ser lazyness e nao acabar fazendo o compiler cair
// potencialmente em um looping infinito na resolucao do tipo, por causa disto tem validacao
// no compiler agora e codigos nesse estilo sao barrados pelo compiler
type Init<T extends any[], TTail extends any[] = TailArray<T>> = CastArray<{
[K in keyof TTail]: T[keyof T & K];
}>
@OliverJAsh
OliverJAsh / README.md
Last active September 14, 2018 06:45
FP list combinators demo with fp-ts
tsc && node main.js
// -- EXAMPLE THAT WOULD BE WRONG
// -- wrongBurgerSpec :: IxBurgerBuilder Ready TopBunOn BurgerSpec
// -- wrongBurgerSpec = getEmptyPlate
// -- :>>= placeEmptyBun
// -- :>>= addKetchup
// -- :>>= addCheese -- Can't match PattyOn with BottomBunOn, since we haven't put on the patty, the most important part!!!
// -- :>>= addOnions
// -- :>>= noLettuce
// -- :>>= addTomato
// -- :>>= addTopBun
// -- OUR AMAZING INDEXED BURGER SPEC FROM READY TO TOP BUN ON
// burgerSpec :: IxBurgerBuilder Ready TopBunOn BurgerSpec
// burgerSpec = getEmptyPlate
// :>>= placeEmptyBun
// :>>= addKetchup
// :>>= addPatty
// :>>= addCheese
// :>>= addOnions
// :>>= noLettuce
// :>>= addTomato