Skip to content

Instantly share code, notes, and snippets.

View masaeedu's full-sized avatar

Asad Saeeduddin masaeedu

  • Montreal, QC, Canada
View GitHub Profile
@masaeedu
masaeedu / traversing_state.js
Created March 27, 2019 00:43
Refactoring to discover Arr.traverse and the State applicative
// This gist shows how to factor a concrete stateful fold in vanilla JS
// into a number of general purpose utilities that can be combined to recover
// the original behavior
// We're going to start from a particular code snippet and iteratively make
// small changes to it to get a finished product
// While reading this post, it is useful to have a diff tool at hand that allows
// you to compare snippets side by side and see what changed in each iteration
@masaeedu
masaeedu / cpsfreer.js
Last active April 5, 2019 20:17
The CPS-ed freer monad
const { adt, match, otherwise } = require("@masaeedu/adt");
const {
Obj,
Fn,
Arr,
Cont,
implement,
Functor,
Apply,
Chain,
@masaeedu
masaeedu / example1.dts
Last active April 11, 2019 00:45
Dream type system
:: :: morphism c = c -> c -> *
:: :: morphism c -> *
:: category p =
:: { id: p a a, compose: p b c -> p a b -> p a c }
:: :: (c -> d) -> morphism c -> morphism d -> *
:: functor f i o =
:: { map: i a b -> o (f a) (f b) }
@masaeedu
masaeedu / reservoir_sampling.hs
Last active April 25, 2019 13:16
Reservoir sampling in Haskell
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Main where
import Prelude as P
@masaeedu
masaeedu / monoidal.hs
Created June 8, 2019 07:47
Various monoidal categories, monoidal functors, and monoid objects
{-# LANGUAGE
RankNTypes,
TypeApplications,
TypeOperators,
KindSignatures,
TypeFamilies,
TypeInType,
MultiParamTypeClasses,
FunctionalDependencies,
FlexibleInstances,
@masaeedu
masaeedu / Main.hs
Last active June 28, 2019 03:20
Questionnaire thing
{-# LANGUAGE
KindSignatures
, DataKinds
, RankNTypes
, GADTs
, TypeFamilies
, TypeFamilyDependencies
, ScopedTypeVariables
, TypeApplications
, ViewPatterns
@masaeedu
masaeedu / Test.purs
Created June 30, 2019 05:09
Lensing into cases that may not be there
module Test where
import Prelude
import Data.Lens (Lens, _Just, lens, (.~))
import Data.Maybe (Maybe(..))
import Effect.Exception.Unsafe (unsafeThrow)
data CRUD a
= Create
@masaeedu
masaeedu / ComonadKleisli.hs
Last active July 4, 2019 18:52
Comonad on a Kleisli category
module ComonadKleisli where
import Data.Maybe
import Data.List
import Control.Monad
fmapM :: (a -> Maybe b) -> [a] -> Maybe [b]
fmapM f = Just . catMaybes . fmap f
duplicateM :: [a] -> Maybe [[a]]
@masaeedu
masaeedu / init-haskell.sh
Last active May 20, 2021 15:24
Basic nix haskell setup
#!/usr/bin/env bash
set -Eeuxo pipefail
# Set up git
git init
gitignore haskell
echo '*.cabal' >> .gitignore
# Set up niv
niv init
@masaeedu
masaeedu / Test.hs
Created July 5, 2019 18:44
Comonad as comonoid on hask with composition and identity as monoidal structure
{-# LANGUAGE
TypeOperators
, RankNTypes
, MultiParamTypeClasses
, ConstraintKinds
, QuantifiedConstraints
, KindSignatures
#-}
module Main where