Here's an ADT which is not a GADT, in Haskell:
data Expr = IntExpr Int | BoolExpr Bool
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} |
val n = 9 | |
val s = Math.sqrt(n).toInt | |
type Board = IndexedSeq[IndexedSeq[Int]] | |
def solve(board: Board, cell: Int = 0): Option[Board] = (cell%n, cell/n) match { | |
case (r, `n`) => Some(board) | |
case (r, c) if board(r)(c) > 0 => solve(board, cell + 1) | |
case (r, c) => | |
def guess(x: Int) = solve(board.updated(r, board(r).updated(c, x)), cell + 1) | |
val used = board.indices.flatMap(i => Seq(board(r)(i), board(i)(c), board(s*(r/s) + i/s)(s*(c/s) + i%s))) |
Tageless Final interpreters are an alternative to the traditional Algebraic Data Type (and generalized ADT) based implementation of the interpreter pattern. This document presents the Tageless Final approach with Scala, and shows how Dotty with it's recently added implicits functions makes the approach even more appealing. All examples are direct translations of their Haskell version presented in the Typed Tagless Final Interpreters: Lecture Notes (section 2).
The interpreter pattern has recently received a lot of attention in the Scala community. A lot of efforts have been invested in trying to address the biggest shortcomings of ADT/GADT based solutions: extensibility. One can first look at cats' Inject
typeclass for an implementation of [Data Type à la Carte](http://www.cs.ru.nl/~W.Swierstra/Publications/DataTypesA
package retry | |
import scala.concurrent.duration.{Duration, FiniteDuration} | |
import scala.util.Random | |
import scala.concurrent.duration._ | |
object Backoff { | |
val none: Backoff = _ => Duration.Zero |
I have some data which has adjacent entries that I want to group together and perform actions on.
I know roughly that fs2.Pull
can be used to "step" through a stream and do more complicated
logic than the built in combinators allow. I don't know how to write one though!
In the end we should have something like
def combineAdjacent[F[_], A](
shouldCombine: (A, A) => Boolean,