Skip to content

Instantly share code, notes, and snippets.

View DmytroMitin's full-sized avatar
😎
everything is ok

Dmytro Mitin DmytroMitin

😎
everything is ok
View GitHub Profile
@johnhungerford
johnhungerford / TicTacToe.Scala
Last active March 26, 2023 11:13
Type level tic tac toe using match types
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 {
@luqui
luqui / opaque.hs
Last active May 23, 2020 08:09
Natural transformations never need to type switch
{-# 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:
* {{{
@SethTisue
SethTisue / chaining-implicits.md
Last active February 19, 2024 00:56
chaining implicit conversions in Scala 2 and Scala 3

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
@BalmungSan
BalmungSan / Polymorphism.md
Last active September 11, 2024 00:00
Polymorphism in Scala.

Polymorphism in Scala

This document aims to show and compare three alternatives for achieving polymorphism in Scala.

  • Subtyping, common in object-oriented languages like Java.
  • Duck typing, common in dynamically typed languages like Python.
  • Typeclasses, common in functional languages like Haskell.

Additionally, when implementing the typeclass pattern in Scala,

@AndyShiue
AndyShiue / CuTT.md
Last active October 30, 2024 20:12
Cubical type theory for dummies

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.

@claudinei-daitx
claudinei-daitx / SparkSessionKryo.scala
Last active March 22, 2023 15:51
Examples to create a Spark Session with Kryo
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)
@Jasper-M
Jasper-M / HasCompanion.scala
Last active November 2, 2022 02:18
Typeclass that provides evidence that a type has a companion object, and access to the object.
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