in Scala 2, they don't chain 😇, even if we try to give the compiler an assist
can we make them chain in Dotty? 😈
let's try it!
first let's set up sbt:
% cat project/plugins.sbt
| sealed trait Bool | |
| object Bool: | |
| sealed trait True extends Bool | |
| sealed trait False extends Bool | |
| sealed trait Nat | |
| object Nat: | |
| sealed trait _0 extends Nat | |
| sealed trait Succ[N <: Nat] extends Nat |
| Spark session available as 'spark'. | |
| Welcome to | |
| ____ __ | |
| / __/__ ___ _____/ /__ | |
| _\ \/ _ \/ _ `/ __/ '_/ | |
| /___/ .__/\_,_/_/ /_/\_\ version 3.2.0-SNAPSHOT | |
| /_/ | |
| Using Scala version 2.12.10 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_181) | |
| Type in expressions to have them evaluated. |
| import scala.reflect.ClassTag | |
| object Bottom extends App { | |
| class C[T](implicit ev: reflect.ClassTag[T]) { | |
| def ct: reflect.ClassTag[T] = ev | |
| } | |
| class X[U, -T] | |
| object X { |
| {-# LANGUAGE RankNTypes, TypeApplications #-} | |
| -- We give a constructive proof that any natural transformation that uses | |
| -- a type switch in its implementation can also be implemented without the type switch, | |
| -- as long as the domain functor is finitely Traversable (and the argument can easily | |
| -- be modified to drop the finiteness property). | |
| -- We do this by providing a function `opaquify` which takes an n.t. which may do | |
| -- type switches, and returns an equivalent n.t. which does not. |
| import scala.reflect.ClassTag | |
| object DefaultType extends App { | |
| case class AttributeMeasure[T](name: String)(implicit ev: reflect.ClassTag[T]) { | |
| def ct: ClassTag[T] = ev | |
| } | |
| /** This almost works, except for the case: | |
| * {{{ |
in Scala 2, they don't chain 😇, even if we try to give the compiler an assist
can we make them chain in Dotty? 😈
let's try it!
first let's set up sbt:
% cat project/plugins.sbt
This document aims to show and compare three alternatives for achieving polymorphism in Scala.
Additionally, when implementing the typeclass pattern in Scala,
I think I’ve figured out most parts of the cubical type theory papers; I’m going to take a shot to explain it informally in the format of Q&As. I prefer using syntax or terminologies that fit better rather than the more standard ones.
Q: What is cubical type theory?
A: It’s a type theory giving homotopy type theory its computational meaning.
Q: What is homotopy type theory then?
A: It’s traditional type theory (which refers to Martin-Löf type theory in this Q&A) augmented with higher inductive types and the univalence axiom.
| import org.apache.spark.SparkConf | |
| import org.apache.spark.sql.SparkSession | |
| //create a spark session who works with Kryo. | |
| object SparkSessionKryo { | |
| def getSparkSession: SparkSession = { | |
| val spark = SparkSession | |
| .builder | |
| .appName("my spark application name") | |
| .config(getConfig) |
| import scala.language.experimental.macros | |
| import scala.reflect.macros.whitebox.Context | |
| trait HasCompanion[A] { | |
| type Type | |
| def companion: Type | |
| } | |
| object HasCompanion { | |
| type Aux[A,C] = HasCompanion[A] { type Type = C } | |
| def apply[A](implicit hc: HasCompanion[A]): hc.type = hc |