A law is a group of two or more expressions which are required to be the same. The expressions will usually involve one or more typed holes ("inputs") which vary.
Some examples:
x.map(id) === x
/** | |
* In this version of `Traverse`, sequencing always goes through `List` (or some other canonical sequence type), | |
* which can be done in a stack-safe manner using a balanced fold as in https://gist.github.com/pchiusano/7667597. | |
* It's quite nice that `sequence` and `traverse` are now derived functions. | |
*/ | |
trait Traverse[F[_]] extends Functor[F] { | |
/** Inefficient but correct implementation of `toList` in terms of `mapAccumulate`. */ | |
def toList[A](f: F[A]): List[A] = mapAccumulate(f, List())((a, rbuf) => (a, a :: rbuf))._2.reverse | |
/** The only function that must be implemented. Must be consistent with `map`. */ |
{-# LANGUAGE TemplateHaskell #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
{-# LANGUAGE DeriveFunctor #-} | |
import Control.Lens | |
import Prelude hiding (readFile, writeFile, print) | |
import qualified Prelude as Prelude(readFile, writeFile, print) |
with builtins; | |
rec { | |
pkgs = import <nixpkgs> {}; | |
testGHC = pkgs.haskellPackages.ghcWithPackages (p: with p; [ | |
base base-orphans bifunctors comonad contravariant distributive | |
tagged transformers | |
]); |
Balaji Sivaraman @balajisivaraman_twitter
Hi all, I need some help understanding a piece of Doobie code from the examples. It is the StreamingCopy one: (https://github.com/tpolecat/doobie/blob/series/0.4.x/yax/example/src/main/scala/example/StreamingCopy.scala). I am using a modified version of the fuseMap2 example from that file. Here’s how I’ve modified it for my requirements:
def fuseMap[F[_]: Catchable: Monad, A, B](
source: Process[ConnectionIO, A],
sink: Vector[A] => ConnectionIO[B],
delete: ConnectionIO[Unit]
)(
sourceXA: Transactor[F],
package scalaworld.interpreters | |
/* | |
This file shows a simple language, an interpreter, and two | |
partial evaluators for that language, along with a profiling suite. | |
*/ | |
trait Expr // denotes a Vector[Double] => Vector[Double] | |
object Expr { |