Skip to content

Instantly share code, notes, and snippets.

View jto's full-sized avatar
🏠
Working from home

Julien Tournay jto

🏠
Working from home
View GitHub Profile
object Unpack:
import scala.quoted._
import scala.compiletime._
private def tupleType(s: String)(using q: Quotes): q.reflect.TypeRepr =
import q.reflect._
val typeParams =
s.map{ c =>
TypeRepr.of(using ConstantType(CharConstant(c)).asType)
}.toList
package modules {
// Modules examples taken from
// see https://www.cs.cmu.edu/~rwh/introsml/modules/sigstruct.htm
// structure IntLT = struct
// type t = int
// val lt = (op <)
// val eq = (op =)
// end
import shapeless.LowPriority
trait Dec[T] { type V }
object Dec {
type ItIsYes
type ItIsNo
implicit def itIsNo[T](implicit l: LowPriority): No[T] = new Dec[T] { type V = ItIsNo }
implicit def itIsYes[T](implicit t: T): Yes[T] = new Dec[T] { type V = ItIsYes }
{-
See: http://lpaste.net/104020
and https://github.com/gonzaw/extensible-records
-}
module Record
import Data.List
%default total
@jto
jto / 1 - record.idr
Last active May 15, 2018 20:54
Ooopps
module Record
import Data.List
%default total
data IsSet : List t -> Type where
IsSetNil : IsSet []
IsSetCons : Not (Elem x xs) -> IsSet xs -> IsSet (x :: xs)
@jto
jto / VecHlist.scala
Last active April 16, 2018 19:14
VecHlist.scala
final object F {
type HList //<: Product with Serializable
type HNil <: HList
type #:[+H, +T <: HList] <: HList
implicit class HListBuilder[T <: HList](h: T) {
def #:[H](a: H): H #: T = F.#:(a, h)
}
object #: {
val xs = List("1", "2", "3", "foo", "bar", "4")
def isAnInt(s: String): Boolean = s.matches("""-?\d+""")
def toInts(is: List[String]): List[Int] = {
???
}
val out = List(1, 2, 3, 4)
trait TC[F[_]]
trait Foo {
type I[_]
implicit def tc: TC[I]
}
def test(g: Foo): Int = {
import g._
implicitly[TC[I]](tc) // compiles
StringOrInt : Bool -> Type
StringOrInt False = String
StringOrInt True = Int
trait Foo[A]
type Alias[A] = List[Foo[A]]
trait Test1[C[_]]
implicit def test1[C[_]]: Test1[C] = new Test1[C]{}
implicitly[Test1[Alias]] // Compiles fine
implicitly[Test1[λ[α => List[Foo[α]]]]] // Does not compile: could not find implicit value for parameter e: Test1[[α]List[Foo[α]]]