Skip to content

Instantly share code, notes, and snippets.

View timbuckley's full-sized avatar

Tim Buckley timbuckley

  • Aline
  • NYC
View GitHub Profile
@cscalfani
cscalfani / ThinkAboutMonads.md
Last active December 4, 2022 20:58
How to think about monads

How to think about Monads

UPDATE 2021: I wrote this long before I wrote my book Functional Programming Made Easier: A Step-by-step Guide. For a much more in depth discussion on Monads see Chapter 18.

Initially, Monads are the biggest, scariest thing about Functional Programming and especially Haskell. I've used monads for quite some time now, but I didn't have a very good model for what they really are. I read Philip Wadler's paper Monads for functional programming and I still didnt quite see the pattern.

It wasn't until I read the blog post You Could Have Invented Monads! (And Maybe You Already Have.) that I started to see things more clearly.

This is a distillation of those works and most likely an oversimplification in an attempt to make things easier to understand. Nuance can come later. What we need when first le

@hrb90
hrb90 / monadic-fizzbuzz.js
Last active November 28, 2017 01:31
FizzBuzz with monads!
/***
You've probably seen FizzBuzz before. If you need a reminder, the problem is
this: Print out a list of numbers from 1 to 100, except that if a number's
divisible by 3, replace it with "Fizz", and if it's divisible by 5, replace it
with "Buzz". If it's divisible by 3 and 5, replace it with "FizzBuzz".
This is pretty straightforward to do in JavaScript with a for loop and some
if-then blocks, but it quickly gets more complicated. What if we want to add
"Quux" at the end of every number divisible by 7? And also add "Prime" at the
@Rich-Harris
Rich-Harris / footgun.md
Last active May 6, 2024 10:24
Top-level `await` is a footgun

Edit — February 2019

This gist had a far larger impact than I imagined it would, and apparently people are still finding it, so a quick update:

  • TC39 is currently moving forward with a slightly different version of TLA, referred to as 'variant B', in which a module with TLA doesn't block sibling execution. This vastly reduces the danger of parallelizable work happening in serial and thereby delaying startup, which was the concern that motivated me to write this gist
  • In the wild, we're seeing (async main(){...}()) as a substitute for TLA. This completely eliminates the blocking problem (yay!) but it's less powerful, and harder to statically analyse (boo). In other words the lack of TLA is causing real problems
  • Therefore, a version of TLA that solves the original issue is a valuable addition to the language, and I'm in full support of the current proposal, which you can read here.

I'll leave the rest of this document unedited, for archaeological

@ricardojmendez
ricardojmendez / circles.cljs
Created January 13, 2015 07:19
Quil/ClojureScript sketch showing the intersection of wandering circles
(ns quil-js.circles
(:require [quil.core :as q :include-macros true]
[quil.middleware :as m]))
(deftype Circle [x y radius x-move y-move line-color fill-color alpha])
(defn draw-circle [circle]
; (.log js/console (str "Drawing " x "," y " with " overlap))
@ricardojmendez
ricardojmendez / circles.coffee
Last active December 17, 2015 15:35
P5.js sketch showing the intersection of wandering circles
class Circle
constructor: (@x, @y, @radius, @x_move, @y_move) ->
class Overlap
constructor: (@x = 0, @y = 0, @amount = 0) ->
mysketch = (sketch) ->
circles = []
@staltz
staltz / introrx.md
Last active May 10, 2024 12:08
The introduction to Reactive Programming you've been missing
@gatlin
gatlin / imperative.lhs
Last active April 20, 2023 00:51
Imperative Programming in Haskell
How to add imperative programming to a pure functional language
===
Many people bemoan languages such as Haskell for not supporting imperative
programming; they decry the need for math in their computer science.
![Math? In my computer? Yeah right.](http://i.imgur.com/YDIaEPB.jpg)
I'm here to tell you that not only does Haskell make imperative programming a
cinch, but safe and correct as well. Follow along! This post is written in