Skip to content

Instantly share code, notes, and snippets.

View Mzk-Levi's full-sized avatar

Melchizedek Mzk-Levi

View GitHub Profile
@raichoo
raichoo / gist:1163522
Created August 22, 2011 20:56
Scala NList
package nlist
sealed trait Nat
sealed trait Z extends Nat
sealed trait S[A <: Nat] extends Nat
sealed trait NList[A <: Nat, +B] {
type Length = A
def zap[C](l: NList[Length, B => C]): NList[Length, C]
@HeinrichApfelmus
HeinrichApfelmus / gist:2187593
Created March 24, 2012 20:42
BIjection between Twan van Laarhoven's Pipe and the data types from Conduit
-- http://www.reddit.com/r/haskell/comments/rbgvz/conduits_vs_pipes_using_void_as_an_input_or/
import Control.Monad
data Pipe m i o r =
NeedInput (i -> Pipe m i o r) (Pipe m () o r)
| HaveOutput (Pipe m i o r) (m ()) o
| Finished (Maybe i) r
| PipeM (m (Pipe m i o r)) (m r)
@hellerbarde
hellerbarde / latency.markdown
Created May 31, 2012 13:16 — forked from jboner/latency.txt
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@23Skidoo
23Skidoo / Applicative.hs
Created August 16, 2012 20:42
Fun with Applicative, Monad and Monoidal
-- See http://blog.ezyang.com/2012/08/applicative-functors/
module Main
where
import Prelude hiding ((**))
import Control.Monad
bind :: Monad m => m a -> (a -> m b) -> m b
bind = (>>=)
@ymasory
ymasory / scala-irc
Last active August 30, 2017 21:16
List of all Scala-related IRC channels.
Please help compile a list of all Scala-related IRC rooms.
All of these channels are on Freenode.
#akka | concurrency & distribution framework
#argonaut | json library
#fp-in-scala | the book Functional Programming in Scala
#geotrellis | geoprocessing library
#indyscala | regional scala group
#json4s | json library
@jdegoes
jdegoes / DataScienceInScala.scala
Created February 8, 2013 15:11
Example code for the Creating a Data Science Platform in Scala talk.
object BenchmarkCommon {
import scala.util.Random
val DatasetSize = 10000
val Iterations = 10000
val ArrayPoolSize = 1000
val ArrayPool = {
def randomArray(): Array[Int] = {
val array = new Array[Int](DatasetSize)
import scalaz._, Scalaz._, NonEmptyList._
sealed trait Interval[+A] {
val min: A
val max: A
def map[B: Order](f: A => B): Interval[B] =
Interval(f(min), f(max))
def merge[AA >: A](i: Interval[AA])(implicit E: Enum[AA]): Option[Interval[AA]] =
@raichoo
raichoo / gist:5371927
Last active May 12, 2016 18:43
Playing with propositional equality in Scala (+inductive proof)
import scala.language.higherKinds
/*
* The usual peano numbers with addtion and multiplication
*/
sealed trait Nat {
type Plus[N <: Nat] <: Nat
type Mult[N <: Nat] <: Nat
}
@halcat0x15a
halcat0x15a / gist:5376994
Created April 13, 2013 04:57
Maybe Monad with Church Encoding in Scala
import scala.language.higherKinds
import scala.language.implicitConversions
import scala.language.reflectiveCalls
trait Forall[M[_]] {
def apply[A]: M[A]
}
object Maybe {
@zvozin
zvozin / BufferActor.scala
Last active December 17, 2015 09:19
Time-and-space bounded Scalaz-based actor. Buffers elements of type A until either buffer size has been reached, or the time bound has elapsed.
import scalaz.concurrent.Actor
import collection.mutable.ArrayBuffer
import java.util.Timer
/**
* Usage:
*
* <code>
* val buffer = BufferActor[String](onFlush = _ foreach (println(_), onError = println(_))
* buffer ! "Now we're talking!"