Skip to content

Instantly share code, notes, and snippets.

View masaeedu's full-sized avatar

Asad Saeeduddin masaeedu

  • Montreal, QC, Canada
View GitHub Profile
{-# LANGUAGE RankNTypes, TypeOperators, KindSignatures, DataKinds, PolyKinds, TypeApplications, DuplicateRecordFields, FlexibleContexts, ScopedTypeVariables #-}
module Main where
import Data.IORef
import Control.Monad.Reader
import Control.Monad.State
type (~>) f g = forall x. f x -> g x
newtype Product f g a = Product { runProduct :: (f a, g a) }
@masaeedu
masaeedu / Rig.hs
Created September 10, 2019 22:30
Free monoids in rig categories
{-# LANGUAGE RankNTypes, DataKinds, KindSignatures, PolyKinds, TypeOperators, MultiParamTypeClasses, GADTs, FlexibleContexts, AllowAmbiguousTypes #-}
module Rig where
type Hom c = c -> c -> *
-- A (small) category
class GCategory (p :: Hom c)
where
gidentity :: forall a. p a a
@masaeedu
masaeedu / Coproducts.hs
Last active September 14, 2019 04:51
Obtaining functor instances via coproducts of functors
{-# LANGUAGE
DataKinds
, KindSignatures
, PolyKinds
, ConstraintKinds
, GADTs
, TypeFamilies
, MultiParamTypeClasses
@masaeedu
masaeedu / absolutenonsense.hs
Last active August 25, 2019 06:37
failing at contramapping entailment
type Whatever
(c :: k -> Constraint)
(f :: k -> *)
(v :: k)
= forall x. (c v => f v -> x) -> x
class Everything (a :: k)
instance Everything a
foo :: (forall x. (cb b => x) -> (ca a => x), f b -> f a) -> (ca a => f a) -> (cb b => f b)
@masaeedu
masaeedu / SquishyAppend.purs
Created August 18, 2019 23:49
A record append operation that smushes together duplicate fields using a monoid instance
module SquishyAppend where
import Prelude
import Data.Functor.Variant (SProxy(..))
import Data.Monoid (class Monoid, class Semigroup, mempty, (<>))
import Data.Tuple (Tuple(..))
import Prim.RowList (Cons, Nil, kind RowList)
import Record as Record
import Type.Data.Boolean (True, False, kind Boolean)
module Data.Record.Operations where
import Data.Functor.Variant (SProxy(..))
import Data.Monoid (class Monoid)
import Prim.RowList (Cons, Nil, kind RowList)
import Type.Data.Boolean (True, False, kind Boolean)
import Type.Data.Symbol (class Equals)
import Type.Prelude (class ListToRow, class RowToList)
import Unsafe.Coerce (unsafeCoerce)
const { cata } = require("@masaeedu/fp")
const { adt, match } = require("@masaeedu/adt")
// All of these are common, reusable utilities you could get from a library
const classes = (() => {
const foldable = ({ foldMap }) => {
const fold = fn.flip(foldMap)(fn.identity)
return { fold }
}
const bifoldable = ({ bifoldMap }) => {
@masaeedu
masaeedu / co-monad.md
Last active September 16, 2019 09:02
- an adjunction `F -| G`
 - is read "F is left adjoint to G"
 - consist of functors `F : D -> C` and `G : C -> D`
 - gives rise to a monad `GF : D -> D` and a comonad `FG : C -> C`

- adjunctions can be composed
 - consider two adjunctions:
   - `F' -| (G' : D -> E)`
   - `F  -| (G  : C -> D)`
@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
@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