Skip to content

Instantly share code, notes, and snippets.

View Sintrastes's full-sized avatar

Nathan BeDell Sintrastes

View GitHub Profile
@vivshaw
vivshaw / README.md
Last active May 2, 2022 20:55
🙈🙉🙊 Three Wise Monkeys 🙈🙉🙊
@TOTBWF
TOTBWF / Pullback.hs
Created May 14, 2020 01:08
Pullbacks in (dependent) haskell
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoStarIsType #-}
{-# LANGUAGE GADTs #-}
module Pullbacks where
@PhBastiani
PhBastiani / # ArrowFreePrograms.md
Last active February 5, 2024 02:59
[Arrow-kt] For-Comprehension Free Monads in Kotlin

For-Comprehension Free Monads in Kotlin - Mini Howto

Copyright © 2020, Philippe Bastiani.
License: CC BY-NC-SA 4.0 with this restriction: this GIST could be, all or part, updated, copied, diffused for documentary purposes in the Λrrow project.

This GIST is an attempt to describe a repeatable, and automatable, process for building an embedded Domain Specific Language (DSL) with the help of a Free monad.
As material, i'll use Λrrow, the functional companion to Kotlin's Standard Library.

Disclaimer: This GIST assumes that you are roughly familiar with the concept of Free monad.

#!/usr/bin/env stack
{- stack --resolver lts-12.0 runghc -}
{-# LANGUAGE TypeFamilies, FlexibleInstances #-}
{-# LANGUAGE DataKinds, PolyKinds, KindSignatures, TypeInType #-}
{-# LANGUAGE AllowAmbiguousTypes, TypeApplications, GADTs #-}
import Prelude hiding ((.), id)
import qualified Prelude
import Data.Kind
@573
573 / readme.md
Last active January 20, 2024 21:02
nix complains "error: cannot auto-call a function that has an argument without a default value ('stdenv')"?

Add on top of default.nix: with import {}; or simply run as nix-build '' (i. e. for nix-build complaining) or rather nix-build -E 'with import {}; callPackage ./default.nix {}' (or even import)

@wigahluk
wigahluk / Optics References.md
Last active October 29, 2021 13:26
Optics References

Optics, Lenses, Profunctors and related beasts

I got interested in lenses because I was looking for a better way to handle state in front end applications (ELM Architecture and Redux were nice ideas but using Elm or PureScript face some management obstacles and Redux lacks types and more explicit composition). Studying them I found profunctors and the more I knew about them both the more interested I was. Now I look at optics as profunctor transformations that can be applied to a much wider menu of use cases than data accessors for nested structures.

This Gist is my collection of shortcuts to several resources here and there that either I consult frequently or I recommend frequently.

Profunctor presentation

Optics as profunctor transformations are in correspondence with the profunctorial restrictions and have the following

@davibe
davibe / architecture-with-type-intersection-based-DI.swift
Last active July 16, 2022 18:39
Using protocol composition (intersection types) as simple DI in Swift
// Providers
class Provider1 { }
protocol HasProvider1 { var provider1: Provider1 { get } }
class Provider2 { }
protocol HasProvider2 { var provider2: Provider2 { get } }
// a Provider that depends on the other two needs to be configured
protocol Configurable {
func configure(providerBag: HasProviders)
@gvolpe
gvolpe / di-in-fp.md
Last active April 24, 2024 20:51
Dependency Injection in Functional Programming

Dependency Injection in Functional Programming

There exist several DI frameworks / libraries in the Scala ecosystem. But the more functional code you write the more you'll realize there's no need to use any of them.

A few of the most claimed benefits are the following:

  • Dependency Injection.
  • Life cycle management.
  • Dependency graph rewriting.
@nicball
nicball / Cont.java
Created February 26, 2017 06:33
Continuation monad in Java
import java.util.function.Function;
import java.util.function.Consumer;
public class Cont<R, T> {
private final Function<Function<T, R>, R> cont;
public Cont(Function<Function<T, R>, R> k) {
cont = k;
}
@egonSchiele
egonSchiele / reader.hs
Created June 10, 2013 20:51
Reader monad example
import Control.Monad.Reader
hello :: Reader String String
hello = do
name <- ask
return ("hello, " ++ name ++ "!")
bye :: Reader String String
bye = do
name <- ask