type Void <: Nothing
type ¬[-A] = A => Void
type ¬¬[+A] = ¬[¬[A]]
type ⋁[+A, +B] = Either[A, B]
type ⋀[+A, +B] = Tuple2[A, B]
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
// This is the traditional encoding, using abstract type members | |
// to encode existentials | |
object AbstractExistentials { | |
trait E { | |
type X | |
val x: X | |
def f(p: X): String | |
} | |
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 retry | |
import scala.concurrent.duration.{Duration, FiniteDuration} | |
import scala.util.Random | |
import scala.concurrent.duration._ | |
object Backoff { | |
val none: Backoff = _ => Duration.Zero |
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 quantified | |
import cats.Monad | |
import scala.language.implicitConversions | |
/** | |
* C[_] constraint applied to type F[_, _] quantified in first parameter, i.e. | |
* | |
* {{{ |
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
import cats.data.Kleisli | |
import cats.effect.{ Concurrent, Sync } | |
import cats.effect.concurrent.MVar | |
import cats.implicits._ | |
import cats.{ Applicative, Functor, Monad } | |
// Let's start with our dsl | |
// First we need to interact with a console | |
trait Console[F[_]] { |
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
object RaceN { | |
import cats.implicits._ | |
import cats.effect._ | |
import cats.effect.concurrent._ | |
import cats.data.NonEmptyList | |
// Use with atleast 3, otherwise you should prefer Concurrent.race | |
def raceN[F[_]: Concurrent, A](x1: F[A], x2: F[A], x3: F[A], xs: F[A]*): F[Either[NonEmptyList[Throwable], A]] = { | |
for { | |
deferred <- Deferred[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
import concurrent.{Future, Await, Promise, ExecutionContext} | |
import java.util.concurrent.{Future => JavaFuture, TimeUnit, Callable, CancellationException, ExecutorService} | |
import concurrent.duration._ | |
import scala.util.Success | |
import scala.util.Failure | |
import scala.util.control.NonFatal | |
import scala.collection.JavaConverters._ | |
import concurrent.duration.TimeUnit | |
import java.{util => jutil} |
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
-- This illustrates (most of) a new(?) encoding of ad-hoc polymorphism using | |
-- dependent types and implicits. | |
-- | |
-- Benefits of this approach: | |
-- • can have multiple “ambiguous” instances without requiring things like | |
-- Haskell’s newtypes to distinguish them; | |
-- • can disambiguate instances with minimal information, rather than having to | |
-- know some arbitrary instance name as you would with a system like Scala’s | |
-- implicits; | |
-- • implementers don’t need to know/provide the full family of instances – they |
OlderNewer