Skip to content

Instantly share code, notes, and snippets.

View kl0tl's full-sized avatar

Cyril Sobierajewicz kl0tl

View GitHub Profile
@kl0tl
kl0tl / Main.purs
Last active September 8, 2020 09:29 — forked from JordanMartinez/Main.purs
ArrayZipper's smallest Extend implementation
module Main where
import Prelude
import Control.Comonad (class Comonad)
import Control.Extend (class Extend)
import Control.Monad.Gen (chooseInt)
import Data.Array (length, mapWithIndex, unsafeIndex)
import Data.Array.NonEmpty (toArray)
import Effect (Effect)

Keybase proof

I hereby claim:

  • I am kl0tl on github.
  • I am kl0tl (https://keybase.io/kl0tl) on keybase.
  • I have a public key ASDgd_rSzGBvU0Y-hvA3h4npKodTW9vVhWQxlrs0KnopYQo

To claim this, I am signing this object:

@kl0tl
kl0tl / gist:04eb7640c5ba84d201bd19307b45354a
Last active January 11, 2018 10:23
Stores, Pretexts and Bazaars!
{-# LANGUAGE DeriveFunctor, RankNTypes #-}
data Const r a = Const { getConst :: r }
deriving Functor
instance Monoid r => Applicative (Const r) where
pure _ = Const mempty
(Const a) <*> (Const b) = Const (a `mappend` b)
foldMapDefault f = getConst . traverse (Const . f)
data Compose f g a = Compose { decompose :: f (g a) }
@kl0tl
kl0tl / .ghci
Last active August 15, 2017 11:51
Kan Extensions!
:set -i.
@kl0tl
kl0tl / .ghci
Last active July 23, 2017 19:28
Lenses!
:set -i.
@kl0tl
kl0tl / Maybe.hs
Last active May 17, 2017 16:56
`Semigroup`(s), `Monoid`(s) and `Alt`(s) instances
{-# LANGUAGE NoImplicitPrelude, GeneralizedNewtypeDeriving #-}
class Semigroup a where
(<>) :: a -> a -> a
class (Semigroup a) => Monoid a where
mempty :: a
class Functor f where
fmap :: (a -> b) -> f a -> f b
class (Functor f) => Alt f where
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, ScopedTypeVariables #-}
class (Monoid a) => Additive a
class (Monoid a) => Multiplicative a
class Iso a b where
from :: b -> a
to :: a -> b
class (Iso a b, Iso a c, Additive b, Multiplicative c) => Ring a b c | a -> b, a -> c where
@kl0tl
kl0tl / Adjunctions.hs
Last active July 30, 2017 15:29
(Co)Monads from adjunctions
{-# LANGUAGE TypeOperators, MultiParamTypeClasses, DeriveFunctor, NoImplicitPrelude #-}
import Prelude hiding (Monad)
class (Functor l, Functor r) => l ⊣ r where
unit :: a -> r (l a)
unit = leftAdjunct id
counit :: l (r a) -> a
counit = rightAdjunct id
leftAdjunct :: (l a -> b) -> a -> r b
@kl0tl
kl0tl / .ghci
Last active August 14, 2017 22:44
Yoneda!
:set -i.
@kl0tl
kl0tl / raven.js
Created December 15, 2016 13:39
Load Raven async
(function (global, document, url) {
var calls = [];
var spy = {};
var methods = ['config', 'install', 'setUserContext', 'captureException'];
for (var i = 0, method; method = methods[i]; i += 1) {
spy[method] = (function (name) {
return function () {
calls.push([name, arguments]);
return this;