This file contains hidden or 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 Foo[L,R] { | |
| def doLeft(l:L):L | |
| } | |
| object RightOnly extends Foo[Nothing, Int] { | |
| def doLeft(l:Nothing) = sys.error("Not possible") | |
| } | |
| // > scalac -Ywarn-dead-code Nothing.scala | |
| // Nothing.scala:4: warning: dead code following this construct |
This file contains hidden or 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.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_15). | |
| Type in expressions to have them evaluated. | |
| Type :help for more information. | |
| scala> import scalaz._,Scalaz._ | |
| import scalaz._ | |
| import Scalaz._ | |
| scala> List(1,2,3).map(i => Some( WriterT(("Hello world", i)))) | |
| res0: List[Some[scalaz.WriterT[Any,Nothing,Nothing]]] = List(Some(scalaz.WriterTFunctions$$anon$23@5c41c446), Some(scalaz.WriterTFunctions$$anon$23@61bcfefb), Some(scalaz.WriterTFunctions$$anon$23@3f0842de)) |
This file contains hidden or 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
| /tmp/return> scalac -version | |
| Scala compiler version 2.10.2 -- Copyright 2002-2013, LAMP/EPFL | |
| /tmp/return> java -version | |
| java version "1.7.0_15" | |
| Java(TM) SE Runtime Environment (build 1.7.0_15-b03) | |
| Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode) | |
| /tmp/return> echo "object Return { def test(oi:Option[Int]):Option[String] = oi.map(i => return Some(i.toString)) }" > return.scala | |
| /tmp/return> scalac return.scala | |
| /tmp/return> scalac -optimize return.scala | |
| error: could not find init in: Return.test |
This file contains hidden or 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
| /tmp/return> scalac -version | |
| Scala compiler version 2.10.2 -- Copyright 2002-2013, LAMP/EPFL | |
| /tmp/return> java -version | |
| java version "1.7.0_15" | |
| Java(TM) SE Runtime Environment (build 1.7.0_15-b03) | |
| Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode) | |
| /tmp/return> echo "object Return { def test(oi:Option[Int]):Option[String] = oi.map(i => return Some(i.toString)) }" > return.scala | |
| /tmp/return> scalac return.scala | |
| /tmp/return> scalac -optimize return.scala | |
| error: could not find init in: Return.test |
This file contains hidden or 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 Test { | |
| import shapeless._ | |
| object head extends (List ~> Option) { | |
| def apply[T](l : List[T]) = l.headOption | |
| } | |
| class get(i:Int) extends (List ~> Option) { | |
| def apply[T](l : List[T]) = if (l.isDefinedAt(i)) Some(l(i)) else None | |
| } | |
| type LILS = List[Int] :: List[String] :: HNil |
This file contains hidden or 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 ranges(s:Seq[Int]) = | |
| s.sorted.foldLeft(Seq[(Int,Int)]()){ | |
| case (Seq(),i) => Seq((i,i)) | |
| case (h::t,i) => if (i > h._2 + 1) (i,i) :: h :: t else (h._1,i) :: t | |
| }.reverse |
This file contains hidden or 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._ | |
| case class Person(name:String, age:Int) | |
| val nameLens:Lens[Person,String] = Lens(_.name, (p,n) => p.copy(name = n)) | |
| val ageLens:Lens[Person,Int] = Lens(_.age, (p,a) => p.copy(age = a)) | |
| case class Update[A,V](lens:Lens[A,V], value:V) |
This file contains hidden or 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._ | |
| case class Identifier(i:Long) | |
| case class Thing(id:Identifier) | |
| object Thing extends Equals { | |
| implicit def IdentifierEqual:Equal[Identifier] = equalA | |
| implicit def ThingEqual:Equal[Thing] = equalBy(_.id) | |
| } |
This file contains hidden or 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 TypesProblem { | |
| sealed trait Vice | |
| case class Beer(style:String) extends Vice | |
| case class Cigarette(brand:String) extends Vice | |
| sealed trait Person[Vice] { def name:String; def vice:Vice } | |
| case class Man[V](name:String, vice:V) extends Person[V] | |
| case class Woman[V](name:String, vice:V) extends Person[V] | |
| case class People[P[_]<:Person[_]](drinkers:List[P[Beer]] = List(), smokers:List[P[Cigarette]] = List()) |