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
Welcome to Scala version 2.9.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_05). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> import scalaz._ | |
import scalaz._ | |
scala> val (foo, bar, baz) = (Need({println("foo") ; "foo"}), Need({ println("bar") ; "bar"}), Need({ println("baz") ; "baz"})) | |
foo: scalaz.Need[java.lang.String] = scalaz.Need$$anon$4@1d90d034 | |
bar: scalaz.Need[java.lang.String] = scalaz.Need$$anon$4@e551516 |
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._ | |
// fogus wanted this: | |
// [a] -> [b] -> [a b a b ...] | |
// Follow up question: "Do you know a dependent language with my interleave?" | |
// Yes. Scala and shapeless even make it a single line! | |
trait AB[-L <: HList, 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
// With -Ydependent-method-types | |
// Compiles with 2.10.x | |
scala> trait Algebra[F[_]] { trait Expr[A] } | |
defined trait Algebra | |
scala> trait ClosedExpr { def apply[F[_], A](algebra: Algebra[F]): algebra.Expr[A] } | |
defined trait ClosedExpr | |
scala> new ClosedExpr { def apply[F[_], A](algebra: Algebra[F]): algebra.Expr[A] = new algebra.Expr[A] {} } |
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 shapeless.examples | |
import shapeless.test.illTyped | |
object PantsOnFire { | |
//illTyped { 1+1 } // Does not compile | |
illTyped { illTyped { 1+1 } } // Compiles | |
val liar = illTyped { liar } // ??? | |
} |
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) 2013 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
scala> trait Foo ; trait Bar <: Foo | |
defined trait Foo | |
defined trait Bar | |
scala> implicitly[Bar <:< Foo] | |
res2: <:<[Bar,Foo] = <function1> |
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._ | |
trait Name | |
case class VarName(nme: String) extends Name | |
case class ParamName(nme: String) extends Name | |
def lookup(nme: String): Option[Name] :: Option[Name] :: HNil = { | |
object get extends Poly1 { | |
implicit def default[T <: Name] = at[Map[String, T]](_.get(nme)) | |
} |
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] Starting scala interpreter... | |
[info] | |
Welcome to Scala version 2.10.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_21). | |
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
scala> import shapeless._ | |
import shapeless._ | |
scala> import SingletonTypes._ | |
import SingletonTypes._ | |
scala> :paste | |
// Entering paste mode (ctrl-D to finish) | |
trait Show[T] { |
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
Welcome to Scala version 2.10.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_21). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> import shapeless._ | |
import shapeless._ | |
scala> import syntax.tuple._ | |
import syntax.tuple._ |