Skip to content

Instantly share code, notes, and snippets.

View vmarquez's full-sized avatar

Vincent Marquez vmarquez

  • Irvine, CA
View GitHub Profile
@bitemyapp
bitemyapp / gist:8739525
Last active May 7, 2021 23:22
Learning Haskell
@shajra
shajra / Task.scala
Created August 23, 2013 03:34
integration code between Scalaz and Scala standard concurrency libraries.
import concurrent.{ExecutionContext, Future => SFuture, Promise}
import util.Try
import _root_.scalaz.\/
import _root_.scalaz.concurrent.{Task => ZTask}
object Task {
def fromScala[A]
@vmarquez
vmarquez / ReaderMonad.cs
Last active February 20, 2020 20:30
This is an example of using the Reader Monad for Dependency Injection using LINQ in C#. I learned about this from Tony Morris and Rúnar Bjarnason's video here: http://www.youtube.com/watch?v=ECPGTUa1WAI To figure out the (slightly weird) SelectMany peculiarities I found http://mikehadlow.blogspot.com/2011/01/monads-in-c-4-linq-loves-monads.html
//Reader Monad and its extension class to give it SelectMany(bind/flatMap) capabilities for use in LINQ queries
public static class ReaderMonadExt
{
public static ReaderMonad<T, C> SelectMany<T, A, B, C>(this ReaderMonad<T, A> rm, Func<A, ReaderMonad<T, B>> bindf, Func<A, B, C> select)
{
return new ReaderMonad<T, C>(t =>
{
var a = rm.Run(t);
return select(a, bindf(a).Run(t));
});
@vpatryshev
vpatryshev / ZFC in Java
Created November 29, 2013 20:52
Wrote this code in July 2008, implementing ZFC set theory in Java. Kind of funny; it worked.
import java.util.List;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Arrays;
import java.util.Map;
import java.util.IdentityHashMap;
import java.util.LinkedList;
import java.util.SortedSet;
import java.util.TreeSet;
@runarorama
runarorama / Adjunctions.scala
Last active December 2, 2019 19:58
Free/forgetful adjunctions
import scalaz._, Scalaz._
// Adjunction between `F` and `G` means there is an
// isomorphism between `A => G[B]` and `F[A] => B`.
trait Adjunction[F[_],G[_]] {
def leftAdjunct[A, B](a: A)(f: F[A] => B): G[B]
def rightAdjunct[A, B](a: F[A])(f: A => G[B]): B
}
// Adjunction between free and forgetful functor.
@aloiscochard
aloiscochard / qsbt.sh
Last active March 5, 2018 21:34
QuickSBT - Launch SBT with support for generating /tmp/sbt.quickfix file for Vim
#!/usr/bin/env bash
############
# QuickSBT #
############
# Launch SBT with support for generating /tmp/sbt.quickfix file for Vim
# http://github.com/aloiscochard / https://gist.github.com/4698501
# Error format for SBT, and shortcut to open SBT quickfix file :
@shajra
shajra / try_task_and_rt.md
Last active July 16, 2017 18:19
my thoughts on scala.util.Try, scalaz.concurrent.Task, and referential transparency

When scala.util.Try first came out, there was a lot of discussions about the validity of it's implementation. Some discussions got distracted with issues beyond the facts. Ultimately, the issue came down to the following:

  1. Is Try a monad?

  2. Does referential transparency (RT) apply in the presence of possible non-terminating or errant functions -- those returning ⊥?

Not requiring Try to be a monad is an easy solution to the whole problem. If

@dscleaver
dscleaver / Fib.scala
Created February 27, 2013 14:45
Port of http://t.co/KvoY7PDGSg. Created in a Scala IDE worksheet.
import scalaz._
import Scalaz._
object monads {
def fix[A](f: (=> A) => A): A = f(fix(f)) //> fix: [A](f: => A => A)A
type Gen[A] = (=> A) => A
def gFib: Gen[Int => Int] = (self) => n =>
@paulp
paulp / universal.scala
Created May 6, 2015 16:21
existentials are inverted universals
// [info] Running p.Run
// List(Fish(Bob, Esq.,12), Kitty(Thor, Esq.,java.awt.Color[r=255,g=200,b=0]))
import java.awt.Color
package p {
trait Pet[A] {
def name(a: A): String
def renamed(a: A, newName: String): A
}
import scalaz.{LensFamily, Lens}
import Lens.{lensg, lensFamilyg}
object LensFns {
/**
* A lens that requires a key be provided to extract B from A.
*
* @tparam A The record type.
* @tparam K The field key type.