Skip to content

Instantly share code, notes, and snippets.

@i-am-tom
i-am-tom / Main.purs
Created May 11, 2018 23:16
Super Circles
module Main where
import Color (rotateHue)
import Color as Color
import Color.Scheme.MaterialDesign (red)
import Control.Apply (lift3)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (logShow)
import Data.Maybe (Maybe(..))
import Data.Monoid (mempty)
@i-am-tom
i-am-tom / Bag.purs
Last active May 3, 2018 10:06
PureScript port of Will Jones' type-indexed config "bag".
module Main where
import Control.Alternative ((<|>))
import Control.Apply (lift2)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, logShow)
import Data.Argonaut.Core (Json)
import Data.Argonaut.Decode (class DecodeJson, decodeJson)
import Data.Argonaut.Encode (class EncodeJson, encodeJson)
import Data.Either (hush)
@i-am-tom
i-am-tom / .vimrc
Last active May 19, 2020 19:27
Neovim config :)
call plug#begin('~/.vim/plugged')
Plug 'godlygeek/tabular'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'kcsongor/vim-monochrome'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-unimpaired'
call plug#end()
colorscheme monochrome
@i-am-tom
i-am-tom / Main.purs
Created December 14, 2017 21:59
Generating unique identifiers with a purely functional approach.
module Main where
-- Often in applications, we want to generate unique IDs. In imperative
-- programming, we might be tempted to define, albeit with obfuscation,
-- a global integer that we increment every time we want a new value.
-- In this gist, we'll look at how to achieve the same thing using the
-- state type to keep things good and pure.
import Control.Apply (lift2)
import Control.Monad.Eff (Eff)
@i-am-tom
i-am-tom / Main.purs
Last active February 27, 2019 14:18
Church/Scott encoding of a couple familiar ADTs.
module Main where
import Control.Monad ((<=<))
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (log)
import TryPureScript (withConsole, render)
import Prelude ((#), (+), ($), bind, discard, show, Unit)
-- | Encoding data types with universal quantification!
@i-am-tom
i-am-tom / ReaderTFuture.js
Created November 21, 2017 12:12
Config-dependent Future.
const Future = require('fluture')
// I can't guarantee this will work out of the box - it's quite old... but
// you should hopefully be able to see how this fits together!
const { ReaderT } = require('fantasy-readers')
// First of all, you're going to need to "lift" all your `Future` operations
// to work within ReaderT. Basically, you just need to call `ReaderT.lift` on
// any `Future` values.
const doAjaxThing_ = x => ReaderT.lift(doAjaxThing(x))
@i-am-tom
i-am-tom / Base.Nat.hs
Last active January 8, 2018 13:09
Primitive recursion schemes and combinators specialised to Nat.
-- Folding
project :: Nat -> Maybe Nat
cata :: (Maybe a -> a) -> Nat -> a
gcata :: Comonad w => Distributive w => (Maybe (w a) -> a) -> Nat -> a
para :: (Maybe (Nat, a) -> a) -> Nat -> a
gpara :: Comonad w => Distributive w => (Maybe (Nat, w a) -> a) -> Nat -> a
@i-am-tom
i-am-tom / RowToTuple.hs
Last active September 12, 2017 21:34
Discarding row labels to reduce records to "HLists" (nested tuple chains)
module Main where
import Prelude (Unit, ($), discard)
import Type.Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, logShow)
import Data.Record (get)
import Data.Tuple (Tuple)
import Data.Tuple.Nested ((/\))
@i-am-tom
i-am-tom / working.md
Created September 10, 2017 08:51
Lambda Calculus evaluation of `compose flip flip id`
((\f.\g.\x.f(gx))(\f.\x.\y.fyx)(\f.\x.\y.fyx))(\x.x)

Renaming things for clarity...

((\f.\g.\x.f(gx))(\f2.\x2.\y2.f2 y2 x2)(\f3.\x3.\y3.f3 y3 x3))(\x4.x4)
@i-am-tom
i-am-tom / ZipDisjointRecord.purs
Created September 1, 2017 20:32
Zipping records with mismatched keys.
module Main (main, zip, zipRecord, class ZipRowList) where
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)
import Data.Record (get, insert)
import Data.Symbol (class IsSymbol, SProxy(..))
import Data.These (These(..))
import Global.Unsafe (unsafeStringify)
import Prelude (Unit, discard)
import Type.Row