Skip to content

Instantly share code, notes, and snippets.

@shajra
shajra / FreeList.scala
Created July 31, 2013 01:54
making Free and then a list with it
package learning
trait Functor[F[_]] {
def map[A,B](a: F[A])(f: A => B): F[B]
}
trait Monad[M[_]] extends Functor[M] {
def point[A](a: A): M[A]
@shajra
shajra / implicits.scala
Created August 18, 2013 03:46
this compiles; didn't realize package b would see implicit from package a without an explicit import
package implicits {
package a {
case class Foo(i: Int)
object FooApp extends App {
Foo(1).rich
}
@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

@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]
@shajra
shajra / existential_name_collision.scala
Created August 28, 2013 20:18
Is there a way to avoid this kind of name collision?
def newExistential[S]
(producer: Inputs => S, consumer: S => Output)
: Existential = {
type SS = S
val producer_ = producer
val consumer_ = consumer
new Existential {
type S = SS
def producer(is: Inputs) = producer_(is)
def consumer(s: S) = consumer_(s)
@shajra
shajra / scala_in_2018_questions.md
Last active December 22, 2015 08:38
Questions we'd all love Rod Johnson to answer
@shajra
shajra / CallStrategy.scala
Created September 13, 2013 00:05
Anyone got ideas for refactoring this? The nested EitherTs don't seem finished to me, although they're compact.
trait CallStrategy[C, E] {
type State[_]
def call
(desc: CallDesc[C],
state: State[C],
pool: ExecutionContextExecutorService)
: Task[E \/ Media]
import scalaz._
import Scalaz._
import Free._
/** "Pure" interactions with a console. */
sealed trait Console[+A]
case class GetLine[A](k: String => A) extends Console[A]
case class PutLine[A](s: String, a: A) extends Console[A]
object Console {
@shajra
shajra / erasure.md
Last active August 29, 2015 13:56
Erased generics are good

Type Erasure Is Good

let's stick the the facts

A lot of the answers thus far are overly concerned with the Twitter user. It's helpful to keep focused on the messages and not the messenger. There is a fairly consistent message with the even just the excerpts mentioned thus far:

It's funny when Java users complain about type erasure, which is the only thing Java got right, while ignoring all the things it got wrong.

I get huge benefits (e.g. parametricity) and nil cost (alleged cost is a limit of imagination).

@shajra
shajra / foo.cabal
Created March 24, 2014 18:26
impressed by cabal init's template comments
-- The package version. See the Haskell package versioning policy (PVP)
-- for standards guiding when and how versions should be incremented.
-- http://www.haskell.org/haskellwiki/Package_versioning_policy
-- PVP summary: +-+------- breaking API changes
-- | | +----- non-breaking API additions
-- | | | +--- code changes with no API change
version: 0.1.0.0