Skip to content

Instantly share code, notes, and snippets.

View joshburgess's full-sized avatar
💭
🤔

Josh Burgess joshburgess

💭
🤔
View GitHub Profile
@joshburgess
joshburgess / FreeAp.md
Created September 17, 2019 21:08 — forked from paf31/FreeAp.md
FreeAp f is a Comonad

FreeAp f is a Comonad

While thinking about comonads as spaces and Day convolution, I realized an interesting thing. The free applicative functor generated by a comonad f is also a comonad.

The free applicative can be defined in a few different ways, but I like to define it like this:

data FreeApplicative f a = Pure a | Free (Day f (FreeApplicative f) a)
@joshburgess
joshburgess / Data.hs
Created September 2, 2019 14:38 — forked from jproyo/Data.hs
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
@joshburgess
joshburgess / Algebra.purs
Created September 2, 2019 14:24 — forked from LukaJCB/Algebra.purs
Alternative Tagless Final encoding in PureScript
module Algebra where
import Prelude
import Control.Monad.Eff (Eff)
import Data.Maybe (Maybe(..))
newtype ConsoleAlg f = ConsoleAlg
{ printLn :: String -> f Unit
, readLn :: f String
@joshburgess
joshburgess / MonadState.hs
Created September 2, 2019 13:12 — forked from cgibbard/MonadState.hs
How MonadState could potentially look, using DefaultSignatures and type equality constraints.
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
import Control.Monad.Trans.Class
import qualified Control.Monad.Trans.State as State
import Control.Monad.Trans.Identity (IdentityT)
import Control.Monad.Trans.Reader (ReaderT)
@joshburgess
joshburgess / package.dhall
Created August 21, 2019 11:27 — forked from Gabriella439/package.dhall
The Cabal file format encoded as a Dhall type
let Version = ∀(Version : Type) → ∀(v : Text → Version) → Version
in let VersionRange =
∀(VersionRange : Type)
→ ∀(anyVersion : VersionRange)
→ ∀(noVersion : VersionRange)
→ ∀(thisVersion : Version → VersionRange)
→ ∀(notThisVersion : Version → VersionRange)
→ ∀(laterVersion : Version → VersionRange)
→ ∀(earlierVersion : Version → VersionRange)
@joshburgess
joshburgess / freer.ml
Created August 15, 2019 06:26 — forked from leque/freer.ml
Freer monad in OCaml
(*
Requirement: higher, ppx_deriving.show
*)
(*
Lightweight higher-kinded polymorphism
https://ocamllabs.github.io/higher/lightweight-higher-kinded-polymorphism.pdf
*)
open Higher
@joshburgess
joshburgess / stack-ghcid.sh
Created May 16, 2019 14:43 — forked from eborden/stack-ghcid.sh
Run ghcid in a monorepo via stack
project=$(basename "$(pwd)")
# build dependencies
build_deps="stack build $project --fast --pedantic --dependencies-only --interleaved-output"
# restart on changes in other packages
restarts=$(find ../. -maxdepth 1 -type d \
-not -name "$project" \
-not -name .stack-work \
-not -name . \
@joshburgess
joshburgess / ToPursTyConPoly.hs
Created May 14, 2019 18:33 — forked from paf31/ToPursTyConPoly.hs
ToPursTyConPoly
{-# language TypeInType #-}
-- | Types which have PureScript equivalents
class ToPursTyCon a where
toPursTyCon :: Tagged a PursTypeConstructor
-- | The default instance uses 'G.Generic' and pattern matches on the
-- type's representation to create a PureScript type.
default toPursTyCon :: (G.Generic a, GenericToPursTyCon (G.Rep a)) => Tagged a PursTypeConstructor
toPursTyCon = retag $ genericToPursTyConWith @(G.Rep a) defaultPursTypeOptions
@joshburgess
joshburgess / fx.ts
Created February 27, 2019 19:45 — forked from briancavalier/fx.ts
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)
@joshburgess
joshburgess / LensLabels.hs
Created February 12, 2019 14:38 — forked from carymrobbins/LensLabels.hs
Using labels as lenses with GHC 8
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE DeriveGeneric #-}
module LensLabels where
import Prelude
import Control.Lens
import Data.Generics.Labels
import GHC.Generics