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
case class Box[A](a:A) { | |
def len1(implicit ev: A <:< Seq[_]) = a.length | |
def len2(implicit ev: A => Seq[_]) = a.length | |
} | |
Box(List(1,2,3)).len1 // ok | |
Box(List(1,2,3)).len2 // ok | |
Box("foo").len1 // doesn't compile |
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
package util | |
import shapeless._ | |
import shapeless.TypeOperators._ | |
import shapeless.Nat._ | |
import shapeless.LTEq._ | |
import scala.annotation.implicitNotFound | |
@implicitNotFound("Cannot prove that ${A} is evenly divisble by ${B}") | |
trait Div[A <: Nat, B <: Nat] |
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 Alg { | |
sealed trait Num { def toInt: Int } | |
sealed trait Big extends Num | |
sealed trait Small extends Num | |
object Big { | |
def fromInt(n:Int): Option[Big] = | |
if (n >= 5) Some(new Big { def toInt = n }) else None |
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 2.10.2 and Shapeless 2.0.0-SNAPSHOT | |
import shapeless._ | |
import shapeless.nat._ | |
sealed trait Month { | |
type ND <: Nat | |
def apply(n: Nat)(implicit ev: LTEq[n.N, ND]) = "foo" | |
} |
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
> console | |
[info] Starting scala interpreter... | |
[info] | |
Welcome to Scala version 2.10.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_13). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> import shapeless._ | |
import shapeless._ |
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
package time.calendar | |
import scalaz.Enum | |
import scalaz.Ordering | |
import shapeless._ | |
import shapeless.Nat._ | |
import shapeless._ | |
import shapeless.Nat._ | |
import shapeless.LTEq._ |
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 TPayne extends App { | |
val m = Map( | |
"2" -> List(List("1")), | |
"3" -> List(List("9"), List("5", "6", "7", "8")), | |
"1" -> List(List("8", "9"), List("2"), List("2", "3"))) | |
def combos[A, B](xs: Map[A, List[B]]): List[Map[A, B]] = |
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> trait X { type A } | |
defined trait X | |
scala> implicit def convert(a:X)(implicit ev: a.A =:= String): Int = 42 | |
convert: (a: X)(implicit ev: =:=[a.A,String])Int | |
scala> (new X {}) : Int | |
<console>:10: error: Cannot prove that a.A =:= String. | |
(new X {}) : Int | |
^ |
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> trait X { type A } | |
defined trait X | |
scala> implicit def convert(a:X)(implicit ev: a.A =:= String): Int = 42 | |
convert: (a: X)(implicit ev: =:=[a.A,String])Int | |
scala> (new X {}) : Int | |
<console>:10: error: Cannot prove that a.A =:= String. | |
(new X {}) : Int | |
^ |
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
package angles | |
import spire.algebra._ | |
import scala.math.Pi | |
object Angle { | |
def apply(n: Double): Angle = | |
if (n < 0.0) new Angle(n % 360.0 + 360.0) else new Angle(n % 360.0) | |
def fromRadians(n: Double): Angle = | |
Angle(n * 360.0 / (2.0 * Pi)) |