This file contains 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 Demo { | |
// A couple of type classes with type members ... | |
trait Foo[T] { | |
type A | |
} | |
object Foo { | |
implicit val fooIS = new Foo[Int] { type A = String } | |
} |
This file contains 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
/* | |
* Copyright (c) 2019 Miles Sabin | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |
This file contains 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
def tupleType(tpes: List[Type]): Type = { | |
val PairType = typeOf[_ *: _] match { | |
case Type.IsAppliedType(tp) => tp.tycon | |
} | |
@tailrec | |
def nestedPairs(tpes: List[Type], acc: Type): Type = tpes match { | |
case Nil => acc | |
case hd :: tail => nestedPairs(tail, Type.AppliedType(PairType, List(hd, acc))) | |
} |
This file contains 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 Utils { | |
type Id[t] = t | |
type Const[c] = [t] => c | |
} | |
import Utils._ | |
class Instances[F[_[_]], T[_]] | |
trait Functor[F[_]] |
This file contains 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
// Universal quantification is encoded in terms of quantifier-free | |
// assertions about an "abitrary" type (cp. "all swans are white" vs. | |
// "the arbitrary swan is white". Inspired by Kit Fine's 1985 "Reasoning | |
// with Arbitrary Objects", http://philosophy.fas.nyu.edu/object/kitfine. | |
// | |
// Possibly also related to Oleg Kiselyov's "Interpreting types as | |
// abstract values", http://okmij.org/ftp/Computation/index.html#teval. | |
// What I wouldn't give for kind-polymorphism here ... | |
This file contains 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
scala> import shapeless._, record._ | |
import shapeless._ | |
import record._ | |
scala> case class Person(name: String, address: String, age: Int) | |
defined class Person | |
scala> val joe = Person("Joe", "Brighton", 33) | |
joe: Person = Person(Joe,Brighton,33) |
This file contains 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
// local/localtests/test/localtests/LocalTests.scala | |
package localtests | |
import java.nio.file._ | |
import java.util.stream.{ Stream => JStream } | |
import org.junit.{ AfterClass, Test } | |
import scala.collection.JavaConverters._ | |
import scala.concurrent.duration._ |
This file contains 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 scala.language.higherKinds | |
// Whitebox ... | |
trait Schema[T, R] { | |
def conv(t: T): R | |
} | |
object Schema { | |
// Whitebox macro: R is computed from T | |
implicit def mkSchema[T, R]: Schema[T, R] = ??? // macro ... |