Benchmarking seems not to be a main focus of any specific academic field, although the problem has been addressed by many different groups in CS.
Some papers I found interesting:
| :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] | |
| } |
| 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) { | |
Benchmarking seems not to be a main focus of any specific academic field, although the problem has been addressed by many different groups in CS.
Some papers I found interesting:
| // 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 |
| 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) => |
| 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) } |
| 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. |
| 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) | |
| } |
| /** | |
| * 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 { |