This document is about Task
, an alternative for Scalaz's Task
or Scala's Future
.
Note this is work in progress and this document suffered multiple modifications already:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> null.asInstanceOf[Int] | |
res0: Int = 0 | |
scala> 0.asInstanceOf[String] | |
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String | |
... 33 elided | |
scala> null.asInstanceOf[Int].asInstanceOf[String] | |
res2: String = null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;; Freer monad in Scheme | |
;;;; See also | |
;;;; * "Freer monads, more extensible effects" | |
;;;; http://dl.acm.org/citation.cfm?doid=2804302.2804319 | |
;;;; * Free monad in Scheme https://gist.github.com/wasabiz/951b2f0b22643a59aeb2 | |
(use gauche.record) | |
(use util.match) | |
;;; data Freer f a where | |
;;; Pure :: a -> Freer f a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Given the following ADT: | |
sealed trait Status | |
case object One extends Status | |
case object Two extends Status | |
case object Three extends Status | |
// They represent states. The natural progression, for this | |
// example, is : One -> Two -> Three |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE Rank2Types, ScopedTypeVariables #-} | |
import Prelude hiding ((<*>), abs) | |
import qualified Control.Applicative as A | |
import Control.Monad | |
import Test.QuickCheck | |
class NearSemiring m where | |
(<+>) :: m a -> m a -> m a | |
zero :: m a | |
(<*>) :: m a -> m a -> m a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package streams | |
trait Free[+F[_],+A] { | |
import Free._ | |
def flatMap[F2[x]>:F[x],B](f: A => Free[F2,B]): Free[F2,B] = Bind(this, f) | |
def map[B](f: A => B): Free[F,B] = Bind(this, f andThen (Free.Pure(_))) | |
} | |
object Free { | |
case class Pure[A](a: A) extends Free[Nothing,A] | |
case class Eval[F[_],A](fa: F[A]) extends Free[F,A] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Applicative[F[_]] { | |
def pure[A](a: A): F[A] | |
def apply[A, B](f: F[A => B], a: F[A]): F[B] | |
} | |
trait Traversable[T[_], F[_]] { | |
def traverse[A, B](f: A => F[B], a: T[A]): F[T[B]] | |
} | |
trait Monoid[A] { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> :paste | |
// Entering paste mode (ctrl-D to finish) | |
def impl[T: c.WeakTypeTag](c: Context): c.Tree = { | |
import c.universe._ | |
def subs = weakTypeOf[T].typeSymbol.asClass.knownDirectSubclasses | |
val subs1 = subs | |
println(subs1) | |
val global = c.universe.asInstanceOf[tools.nsc.Global] | |
def checkSubsPostTyper = if (subs1 != subs) |