Skip to content

Instantly share code, notes, and snippets.

View argumatronic's full-sized avatar
🏠
Working from home

Julie Moronuki argumatronic

🏠
Working from home
View GitHub Profile
@friedbrice
friedbrice / lenses-introduction.js
Last active April 4, 2024 16:02
Javascript has lenses?
var danielsLensTalk = {
recordId: 0,
creation: {
user: 'danielbrice@gmail.com',
moment: {
date: {
year: 2019,
month: 5,
day: 29
},
@jaspervdj
jaspervdj / list-vs-non-empty.hs
Created April 3, 2019 07:37
Is List or NonEmpty "simpler"? Neither.
--------------------------------------------------------------------------------
-- Is List or NonEmpty "simpler"? Neither:
type NonEmpty a = Fix (Compose ((,) a) Maybe)
type List a = Fix (Compose Maybe ((,) a))
--------------------------------------------------------------------------------
newtype Fix f = Fix {unFix :: f (Fix f)}
@bradparker
bradparker / Main.hs
Last active November 21, 2018 22:10
Essence of the iterator pattern word count
module Main where
import Data.Bool (bool)
import Control.Monad ((<=<))
import Control.Monad.State (State, evalState, get, put)
import Data.Char (isSpace)
import Data.Foldable (traverse_)
import Data.Functor.Compose (Compose(Compose, getCompose))
import Data.Functor.Const (Const(Const, getConst))
import Data.Functor.Product (Product(Pair))

Writing a paper, according to SPJ

Source: https://www.cis.upenn.edu/~sweirich/icfp-plmw15/slides/peyton-jones.pdf

  1. Abstract (4 sentences, write last; used by program committee members to decide which papers to read)
    1. State the problem
    2. Say why it’s an interesting problem
    3. Say what your solution achieves
    4. Say what follows from your solution
  2. Introduction (1 page)
@marcosh
marcosh / Application.hs
Created June 14, 2018 13:20
Web applications as profunctors
module Application where
import Data.Profunctor
newtype Application request response = Application {unApplication :: request -> IO response}
instance Profunctor Application where
dimap actOnRequest actOnResponse application = Application $ (fmap actOnResponse) . (unApplication application) . actOnRequest
@beesandbombs
beesandbombs / dancinDots.pde
Created April 5, 2018 19:26
dancin’ dots
int[][] result;
float t, c;
float ease(float p) {
return 3*p*p - 2*p*p*p;
}
float ease(float p, float g) {
if (p < 0.5)
return 0.5 * pow(2*p, g);
{-# LANGUAGE DeriveFunctor #-}
import Control.Arrow ((&&&))
import Data.Bifunctor
-- Recursion Schemes for Dynamic Programming
-- Kabanov and Vene, Mathematics for Program Construction 2006
-- Basic stuff
newtype Mu f = In { out :: f (Mu f) }
@Gabriella439
Gabriella439 / fibonacci.hs
Created March 25, 2018 00:52
Efficient fibonacci numbers using infinite precision integer arithmetic
import Numeric.Natural (Natural)
import qualified Data.Semigroup
-- | @fibonacci n@ computes the @nth@ fibonacci number efficiently using infinite
-- precision integer arithmetic
--
-- Try @fibonacci 1000000@
fibonacci :: Natural -> Natural
fibonacci n = x01 (Data.Semigroup.mtimesDefault n m)
@cocreature
cocreature / Derangement.hs
Created January 10, 2018 18:32
An explanation for the benchmark results in https://github.com/vmchale/ats-benchmarks
-- This gist provides an explanation for why Haskell is significantly
-- faster than ATS and Rust in [vmchale’s great
-- benchmarks](https://github.com/vmchale/ats-benchmarks). What’s
-- happening is that the `derangements` list gets memoized so the
-- benchmark only checks the performance of (!!). `derangements'`
-- prevents GHC from memoizing the list and results in a significant
-- loss of performance. Criterion does try to prevent memoization but
-- it only prevents memoization of the function application (that’s
-- why the function and the argument need to be passed separately to
-- `nf`). It cannot prevent the memoization of the `derangements`
@chris-martin
chris-martin / lazy.md
Last active September 16, 2017 20:16

Let's say we want to test whether the list [1,2,3,4,5] contains 2.

We could do this by turning the list of integers [1,2,3,4,5] into a list of Booleans [False, True, False, False, False] indicating, for each element in the original list, whether it is equal to 2.

λ> x = map (== 2) [1..5]