Skip to content

Instantly share code, notes, and snippets.

@bbarker
bbarker / VarianceWildcards.java
Created December 6, 2021 22:59
An Example for the post Existential Types and Variance in Scala
import java.lang.Object;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class MyClass {
//
public class JavaBean<A> {
public JavaBean(A initA) {
this.theA = initA;
@bbarker
bbarker / WildcardsInTapir.md
Created December 4, 2021 15:43
Wildcards In Tapir

With existential wildcard types, we can write a function like this, which will work as desired:

 def apply[Env](
    serverEndpoints: List[ServerEndpoint[_, _, _, AkkaStreams & WebSockets, Future]],
    layer: ULayer[Env],
    serverOptions: Option[AkkaHttpServerOptions],
): Route =  serverOptions
    .fold(ifEmpty = AkkaHttpServerInterpreter())(serverOptions => AkkaHttpServerInterpreter(serverOptions))
    .toRoute(serverEndpoints)
// using scala 3.1.0
// using lib dev.zio::zio::2.0.0-M6-2
/* Interpreter and Transformer-free effect extension */
// Note: may need to occassionally run `scala-cli setup-ide -S 3.1.0`
// Cite: Zionomicon ZManaged chapter (advanced)
// Adam Fraser's ZQuery talk, and ZStreams talk
standard-library==v1.2
@bbarker
bbarker / EducationResources.md
Created June 13, 2021 14:11
V Language Education Projects
@bbarker
bbarker / EffectTut.scala
Created June 2, 2021 01:39
Live session of Effect Tutorial
package progscala3.fp.effects
import progscala3.fp.effects.Program.succeed
import scala.util.*
/*
* Last week we talked about Referential Transparency and said that
* overall an expression is considered referentially transparent if it can be
* replaced by the value it is reduced to once evaluated, without affecting the
@bbarker
bbarker / build.sc
Created April 27, 2021 21:52
cross module with mill
import mill._
import mill.api.Loose
import mill.define.Target
import mill.scalajslib._
import mill.scalalib._
import mill.scalalib.api.CompilationResult
object versions {
val scala = "3.0.0-RC3"
val scalaJS = "1.5.1"

Free monads

John De Goes on Free monads:

@bblfish Well, all the effect systems in Scala have to use a free structure. Final-tagless in Scala doesn't work without a free monad as the base. ZIO achieves higher performance than free monads because there is no "algebra", or rather it's custom and is completely flat, whereas in older free monad schemes, the algebra was a coproduct of many different types, representing composition of different effect types. Jun 01 2019 11:13 ZIO will be slower than procedural code, at the microscopic level. At the macroscopic level, you get efficiency with async computations (never any blocking threads) and cancelled computation. Those can add up. For some designs (not all), ZIO can offer great performance competitive with procedural systems.

Adam Barber likey narrowed down Concur's performance issues to Free monads, and thinks they may be unnecessary.

@bbarker
bbarker / configuration.nix
Created January 14, 2021 15:04
configuration.nix for Dell Latitude 7480 laptop
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).
{ config, pkgs, ... }:
{
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
@bbarker
bbarker / Main.purs
Last active November 20, 2020 20:30
RowToList error in JSON Parsing
module Main where
import Control.Monad.Except (except, runExcept)
import Data.Array.NonEmpty (NonEmptyArray, fromArray)
import Data.Either (Either(..))
import Data.HeytingAlgebra ((&&), (||))
import Data.Lazy (Lazy, force)
import Data.Maybe (Maybe(..))
import Data.Semigroup ((<>))
import Data.String.NonEmpty (NonEmptyString, fromString)