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
trait FoldRight[-M[_]] | |
{ | |
implicit val StreamFoldRight: FoldRight[Stream] = new FoldRight[Stream] {} | |
implicit val IterableFoldRight: FoldRight[Iterable] = new FoldRight[Iterable] {} | |
assert(implicitly[FoldRight[Stream]] eq IterableFoldRight) // want StreamFoldRight | |
} | |
{ |
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
trait A | |
trait B extends A | |
trait C extends B | |
{ | |
trait Covariant[+X] | |
type Expected = Covariant[A] | |
type CandidateB = Covariant[B] | |
type CandidateC = Covariant[C] | |
implicitly[CandidateB <:< Expected] |
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
// for 2.7.x compatibility | |
def locally[T](x: T): T = x | |
def implicitly[T](implicit e: T) = e | |
object A { | |
implicit val one = 1 | |
} | |
object Test { | |
locally { |
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 collection.immutable.List | |
import java.io.{OutputStreamWriter, FileWriter, FileOutputStream, File} | |
import scala.io.{Source, Codec} | |
import scalaz._ | |
import Scalaz._ | |
val base = new File("""E:\code\raptor""") | |
val tree: Tree[Stream[File]] = base.unfoldTree[Stream[File]] {(f: File) => | |
val (files, dirs) = f.listFiles.toStream.partition(_.isFile) |
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 util.NameTransformer | |
def unfold[A](a: A, f: A => Option[A]): Stream[A] = { | |
Stream.cons(a, f(a).map(unfold(_, f)).getOrElse(Stream.empty)) | |
} | |
def get[T](f: java.lang.reflect.Field, a: AnyRef): T = { | |
f.setAccessible(true) | |
f.get(a).asInstanceOf[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
import util.NameTransformer | |
def unfold[A](a: A, f: A => Option[A]): Stream[A] = { | |
Stream.cons(a, f(a).map(unfold(_, f)).getOrElse(Stream.empty)) | |
} | |
def get[T](f: java.lang.reflect.Field, a: AnyRef): T = { | |
f.setAccessible(true) | |
f.get(a).asInstanceOf[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
> | |
> compile | |
[info] | |
[info] == scalaz-core / compile == | |
[info] Source analysis: 118 new/modified, 0 indirectly invalidated, 0 removed. | |
[info] Compiling main sources... | |
[Classpath = merged classpath (directory classpath: /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/classes.jar | |
directory classpath: /System/Library/Frameworks/JavaVM.framework/Frameworks/JavaRuntimeSupport.framework/Resources/Java/JavaRuntimeSupport.jar | |
directory classpath: /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/ui.jar | |
directory classpath: /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/laf.jar |
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 scalaz._ | |
import Scalaz._ | |
val o1 = some(1) | |
val o2 = some(2) | |
val v1 = o1.<⊛>(o2, (_: Int) + (_: Int)) | |
println(v1) | |
val v2 = for { |
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
trait PartialApply1Of2[T[_, _], A] { | |
type Apply[B] = T[A, B] | |
} | |
trait Foo[M[_]] | |
def foo[M[_]]: Foo[M] = null | |
// Why can't the type parameter be inferred 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
trait T | |
trait U extends U | |
implicitly[T =:= T] | |
// compile error | |
// implicitly[T =:= U] | |
def typesEqual[A, B](implicit ev: A =:= B = null) = ev ne null | |
assert(typesEqual[T, T] == true) | |
assert(typesEqual[T, U] == false) |