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> class Foo { self: Singleton => } | |
defined class Foo | |
scala> class Bar extends Foo | |
<console>:12: error: illegal inheritance; | |
self-type Bar does not conform to Foo's selftype Foo with Singleton | |
class Bar extends Foo | |
^ | |
scala> object Bar extends 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
import scala.language.higherKinds | |
object cats { | |
trait Show[A] { | |
def apply(x: A): String | |
} | |
object Show { | |
implicit def stringShow: Show[String] = new Show[String] { | |
def apply(x: String): String = x |
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 Label[T] { val value: Boolean } | |
defined trait Label | |
scala> def mkInstance(s: String, v: Boolean): Label[s.type] = new Label[s.type] { val value = v } | |
mkInstance: (s: String, v: Boolean)Label[s.type] | |
scala> implicit def lTrue = mkInstance("True", true) | |
lTrue: Label[String("True")] | |
scala> implicit def lFalse = mkInstance("False", false) |
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
miles@frege:~$ ./shapeless.sh | |
Loading... | |
Welcome to the Ammonite Repl 0.5.2 | |
(Scala 2.11.7 Java 1.8.0_51) | |
@ val l = 23 :: "foo" :: true :: HNil | |
l: Int :: String :: Boolean :: HNil = ::(23, ::("foo", ::(true, HNil))) | |
@ |
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
sealed trait Dec[+T] | |
final case class Yes[T](t: T) extends Dec[T] | |
final case object No extends Dec[Nothing] | |
object Dec extends Dec0 { | |
implicit def yes[T](implicit t: T): Dec[T] = Yes(t) | |
} | |
trait Dec0 { | |
implicit def no[T]: Dec[T] = No |
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 | |
object Foo { | |
bar | |
} | |
``` |
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
[info] published shapeless_sjs0.6_2.12.0-M3 to https://oss.sonatype.org/service/local/staging/deploy/maven2/com/chuusai/shapeless_sjs0.6_2.12.0-M3/2.3.0-RC4/shapeless_sjs0.6_2.12.0-M3-2.3.0-RC4.jar | |
[success] Total time: 106 s, completed 23-Feb-2016 16:54:42 | |
[info] Setting scala version to 2.11.7 | |
[info] Set current project to root (in build file:/home/miles/projects/shapeless/) | |
[info] Setting version to '2.3.0-SNAPSHOT'. | |
[info] Reapplying settings... | |
[info] Set current project to root (in build file:/home/miles/projects/shapeless/) | |
[info] [master f0e0f6c] Setting version to 2.3.0-SNAPSHOT | |
[info] 1 file changed, 1 insertion(+), 1 deletion(-) | |
Push changes to the remote repository (y/n)? [y] y |
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 shapeless._ | |
import ops.hlist.Tupler | |
trait TupleGeneric[C <: Product] extends Serializable { | |
type Repr <: Product | |
def to(t : C) : Repr | |
def from(r : Repr) : C | |
} |
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 shapeless._ | |
import ops._ | |
import coproduct._ | |
object coproducttest { | |
type U = Int :+: String :+: CNil | |
type V = Double :+: List[Int] :+: CNil |
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 shapeless._, ops.function._, ops.hlist._ | |
trait Bar { | |
trait Wrapper { type T } | |
case class A[U]() extends Wrapper { type T = U } | |
trait Unwrapper { | |
type Args <: HList | |
type F[R] = Args => R |