This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {- | |
| See: http://lpaste.net/104020 | |
| and https://github.com/gonzaw/extensible-records | |
| -} | |
| module Record | |
| import Data.List | |
| %default total |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 #: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| trait TC[F[_]] | |
| trait Foo { | |
| type I[_] | |
| implicit def tc: TC[I] | |
| } | |
| def test(g: Foo): Int = { | |
| import g._ | |
| implicitly[TC[I]](tc) // compiles |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| StringOrInt : Bool -> Type | |
| StringOrInt False = String | |
| StringOrInt True = Int |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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[α]]] |
NewerOlder