Skip to content

Instantly share code, notes, and snippets.

@LukaJCB
LukaJCB / Rank-N-Bifunctors.md
Created September 8, 2019 19:11
Bifunctor extensions

Uniting the bifunctor and monofunctor hierarchies

With the rise of so-called bifunctor IO types, such as ZIO, questions have naturally arisen of how one could leverage the cats-effect type classes to make use of this new power. So far suggestions have mostly focused on duplicating the existing hierarchy into two distinct branches, one parameterized over F[_] and another parameterized over F[_, _]. To me this is not a great situation, as now library maintainers would have to write code for both of these hierarchies or choose one and leave the other one in the dust.

Instead we should find a way to unite the two shapes under a single hierarchy. This is a draft on how to enable this unification using polymorphic function types in Dotty.

@ShaneDelmore
ShaneDelmore / foo.scala
Created June 19, 2018 22:58
Disable good code red in intellij (keywords: squigglies, squiggley, squiggle, disable, suppress)
/*_*/
val 1 = "Hello"
/*_*/
@jastice
jastice / integrations-bsp-intellij-bloop.md
Last active June 28, 2019 11:48 — forked from jvican/integrations-bsp-intellij-bloop.md
Instructions to try the BSP IntelliJ-Bloop integration out.

Installation instructions

  1. Install bloop 1.0.0-M11 by following the Bloop installation instructions. Then, make sure you start up the bloop server on the background and to generate the configuration files by running bloopInstall in your build tool.
  2. Install IntelliJ 2018.2 EAP and then enable the nightly version of the Scala Plugin by opening Preferences | Languages & Frameworks | Scala | Updates tab and selecting the Nightly plugin update channel: intellij-eap
  3. check for updates and download the Scala plugin Nightly release.
  4. Reboot IntelliJ. The Scala plugin should now have version 2018.2.277 or higher (check in Preferences | Plugins)
  5. Open the "Find Action" search box (usual hotkey Shift+Ctrl+A or shift+cmd+A) and search for "bsp". The search box will show the full action name: "Enable experime
@johnynek
johnynek / flatMapFromTailRec.scala
Created October 7, 2017 01:55
I hadn't realized (maybe the original paper mentioned) but tailRecM + map is enough to do flatMap (and of course logically flatMap + pure are enough to do tailRecM).
object Monad {
trait Monad[F[_]] {
def pure[A](a: A): F[A]
/**
* We can have a default implementation in terms of tailRecM
* and map
*/
def flatMap[A, B](fa: F[A])(fn: A => F[B]): F[B] = {
def step(first: Option[A]): F[Either[Option[A], B]] =
sealed trait Decidable[+Proof]
final case class Yes[Proof](proof: Proof) extends Decidable[Proof]
final case object No extends Decidable[Nothing]
sealed trait List[+A] {
def nonEmpty: Decidable[this.type <:< ::[A]]
def ::[AA >: A](value: AA): ::[AA] = new ::[AA](value, this)
}
final case object Nil extends List[Nothing] {
def nonEmpty: Decidable[this.type <:< ::[Nothing]] = No
@lamdor
lamdor / build.sbt
Last active May 26, 2021 21:27
Playing around with tagless final style and Eff (from https://github.com/edmundnoble/final-tagless-typelevel-summit)
scalaVersion := "2.11.8"
scalaOrganization := "org.typelevel"
libraryDependencies ++= Seq(
"org.typelevel" %% "cats" % "0.9.0",
"org.atnos" %% "eff" % "4.0.0"
)
addCompilerPlugin("org.spire-math" %% "kind-projector" % "0.9.3")

Revisiting Tagless Final Interpreters

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

@Fristi
Fristi / Data.scala
Last active July 26, 2017 09:21
Types are data and data are types
package data
import cats.Cartesian
import cats.data.{NonEmptyList, State, StateT, Validated}
import cats.functor.Invariant
import cats.implicits._
import eu.timepit.refined._
import eu.timepit.refined.api.{Refined, Validate}
import eu.timepit.refined.boolean._
import eu.timepit.refined.collection._
@paulp
paulp / global.sbt
Last active October 16, 2018 19:09
continuous compilation of the sbt build
// These lines go in ~/.sbt/0.13/global.sbt
watchSources ++= (
(baseDirectory.value * "*.sbt").get
++ (baseDirectory.value / "project" * "*.scala").get
++ (baseDirectory.value / "project" * "*.sbt").get
)
addCommandAlias("rtu", "; reload ; test:update")
addCommandAlias("rtc", "; reload ; test:compile")
addCommandAlias("ru", "; reload ; update")