Skip to content

Instantly share code, notes, and snippets.

View debasishg's full-sized avatar
🏠
Working from home

Debasish Ghosh debasishg

🏠
Working from home
View GitHub Profile
@danclien
danclien / scalaz_console_io_free_monad.scala
Last active August 29, 2015 13:57
Attempt to write a monad for console IO using scalaz's Free monad
:paste
import scalaz._, Scalaz._, scalaz.Free.{Suspend, Return}
// Console grammar
sealed trait ConsoleF[+A]
object Console {
case class WriteLine[A](msg: String, o: A) extends ConsoleF[A]
case class ReadLine[A](o: String => A) extends ConsoleF[A]
}
@pchiusano
pchiusano / buffer.scala
Created August 6, 2014 01:21
Buffer type with purely functional API, using a mutable buffer and cheap copy-on-write scheme
import java.util.concurrent.atomic._
import collection.mutable.ArrayBuffer
/**
* Buffer type with purely functional API, using mutable
* `ArrayBuffer` and cheap copy-on-write scheme.
* Idea described by Bryan O'Sullivan in http://www.serpentine.com/blog/2014/05/31/attoparsec/
*/
class Buffer[A](id: AtomicLong, stamp: Long, values: ArrayBuffer[A], size: Int) {
@johnmyleswhite
johnmyleswhite / gist:14dbd928019669faef82
Last active August 29, 2015 14:06
Benchmarking Resources
// in comments, the syntax:
// [A](B => C)
// represents a quantified function literal parameterized by type A
object Z
{
// The main type, a quantified function object
trait Q[M[_], N[_]] { def apply[C](m: M[C]): N[C] }
// Helper Types
@remeniuk
remeniuk / Aggregator.scala
Created May 12, 2011 11:48
Scatter-Gather with Akka Dataflow
class Aggregator(recipients: Iterable[ActorRef]) extends Actor{
def receive = {
case msg @ Message(text) =>
println("Started processing message `%s`" format(text))
val result = Promise[String]()
val promises = List.fill(recipients.size)(Promise[String]())
recipients.zip(promises).map{case (recipient, promise) =>
@milessabin
milessabin / conversions.scala
Created June 15, 2011 14:29
Code from my talk on representing polymorphic function values using type classes at the Scala eXchange ... full blog post to follow on http://www.chuusai.com/blog.
object Tuples {
import HLists._
implicit def tuple1ToHList[A](t : Product1[A]) = new { def hlisted : A :: HNil = t._1 :: HNil }
implicit def tuple2ToHList[A, B](t : Product2[A, B]) = new { def hlisted : A :: B :: HNil = t._1 :: t._2 :: HNil }
implicit def tuple3ToHList[A, B, C](t : Product3[A, B, C]) = new { def hlisted : A :: B :: C :: HNil = t._1 :: t._2 :: t._3 :: HNil }
implicit def hListToTuple1[A](h : A :: HNil) = new { def tupled : Tuple1[A] = Tuple1(h.head) }
implicit def hListToTuple2[A, B](h : A :: B :: HNil) = new { def tupled : (A, B) = (h.head, h.tail.head) }
implicit def hListToTuple3[A, B, C](h : A :: B :: C :: HNil) = new { def tupled : (A, B, C) = (h.head, h.tail.head, h.tail.tail.head) }
@gkossakowski
gkossakowski / FactoryManifests.scala
Created August 11, 2011 11:19
Scala Manifests without reflection.
package scala.tools.nsc
package backend.jribble
import scala.collection.mutable
import scala.tools.nsc.transform.{Transform, TypingTransformers}
/**
* Implements 'factorymanifests' compiler phase that provides alternative implementation of
* Manifests that use static factories for Array creation.
*
* Canonical Manifest implementation in Scala uses reflection for generic Array creation.
@runarorama
runarorama / gist:1140578
Created August 11, 2011 19:51
ADTs in Scala
trait Maybe[A] {
def apply[B](just: (=> A) => B, nothing: => B): B
}
object Just {
def apply[A](a: => A): Maybe[A] = new Maybe[A] {
def apply[B](just: (=> A) => B, nothing: => B) = just(a)
}
def unapply[A](a: Maybe[A]): Option[A] = a(Some(_), None)
}
@beastaugh
beastaugh / installing-ghc7.2-osx10.7.md
Created August 24, 2011 21:41
Installing GHC 7.2 on Mac OS X 10.7 Lion

Installing GHC 7.2 on Mac OS X

This is a brief and bare-bones guide to getting GHC 7.2 and the cabal-install tool (the two basic things you'll need to do Haskell development) up and running on a new Mac OS X 10.7 install.

The instructions given here worked for me, but YMMV.

@corruptmemory
corruptmemory / DBSkeisli.scala
Created October 17, 2011 02:43
Silly example of Kleisli composition of DB operations
/**
* A silly example using Kleisli composition of DB operations
* Based on an idea from Runar Bjarnason found here:
* https://groups.google.com/d/msg/scala-debate/xYlUlQAnkmE/FteqYKgo2zUJ
*
* Uses Scalaz7
*
* @author <a href="mailto:jim@corruptmemory.com">Jim Powers</a>
*/
object Monadic {