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 MonoidHomomorphism extends App { | |
import scalaz._ | |
import Scalaz._ | |
/** | |
* Turn any null into the Zero value for its type | |
*/ | |
def nullAsZero[T: Monoid : Equal](a: T) = if (a == null) implicitly[Monoid[T]].zero else 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
case class Foo[T](x: T) { | |
def map[B](f: T => B) = Foo(f(x)) | |
} | |
object OldWay { | |
def combineLatest[T1, T2](e1: Foo[T1], e2: Foo[T2]): Foo[(T1, T2)] = Foo((e1.x, e2.x)) | |
def combineLatest[T1, T2, T3](e1: Foo[T1], e2: Foo[T2], e3: Foo[T3]): Foo[(T1, T2, T3)] = | |
combineLatest(combineLatest(e1, e2), e3) map { |
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._ | |
object LensFu extends App { | |
case class FieldValue[T](name: String, v: T) | |
case class Field[T, F](name: String, lens: Lens[T, F]) { | |
def >=>[G](field: Field[F, G]): Field[T, G] = Field(name + "." + field.name, lens >=> field.lens) | |
def get(v: T): FieldValue[F] = FieldValue(name, lens.get(v)) | |
def set(a: T, b: F): T = lens.set(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
module Main | |
rev : Vect n a -> Vect n a | |
rev Nil = Nil | |
rev (x :: xs) = (rev xs) ++ (x :: Nil) | |
main : IO () | |
main = putStrLn $ show $ rev [1,2,3] | |
fails to compile with |
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
21:15:22.745 ERROR akka://ENSIME/user/$b o.e.s.SocketHandler - Error in socket reader: | |
java.lang.NumberFormatException: For input string: "new Wo" | |
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[na:1.8.0_31] | |
at java.lang.Integer.parseInt(Integer.java:580) ~[na:1.8.0_31] | |
at java.lang.Integer.valueOf(Integer.java:740) ~[na:1.8.0_31] | |
at org.ensime.server.FramedStringProtocol$class.readString(FramedStringProtocol.scala:39) ~[server_2.11-0.9.10-SNAPSHOT.jar:0.9.10-SNAPSHOT] | |
at org.ensime.server.SwankProtocol.readString(SwankProtocol.scala:10) ~[server_2.11-0.9.10-SNAPSHOT.jar:0.9.10-SNAPSHOT] | |
at org.ensime.server.S≈wankProtocol.read(SwankProtocol.scala:15) ~[server_2.11-0.9.10-SNAPSHOT.jar:0.9.10-SNAPSHOT] | |
at org.ensime.server.SocketHandler$$anon$1.run(SocketHandler.scala:43) ~[server_2.11-0.9.10-SNAPSHOT.jar:0.9.10-SNAPSHOT] |
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._ | |
import scalaz.effects._ | |
import java.io._ | |
/** | |
* Background reading: | |
* http://www.stackmob.com/2011/12/scalaz-post-part-2/ | |
* http://blog.sigfpe.com/2007/11/io-monad-for-people-who-simply-dont.html |
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 Generics { | |
import shapeless.HList | |
import shapeless.Nat | |
import shapeless.Nat._ | |
import shapeless._ | |
trait <[A <: Nat, B <: Nat] | |
implicit def lt1[B <: Nat] = new <[_0, Succ[B]] {} | |
implicit def lt2[A <: Nat, B <: Nat](implicit lt: A < B) = new <[Succ[A], Succ[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
object KleisliValidation extends App { | |
import scalaz._ | |
import Scalaz._ | |
import scala.util.control.Exception._ | |
type EValidation[+T] = Validation[String, T] | |
implicit val binding = new Bind[EValidation] { | |
def map[A, B](fa: EValidation[A])(f: A => B): EValidation[B] = fa.map(f) | |
def bind[A, B](fa: EValidation[A])(f: A => EValidation[B]): EValidation[B] = fa.flatMap(f) | |
} |
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 KleisliValidation extends App { | |
import scalaz._ | |
import Scalaz._ | |
import scala.util.control.Exception._ | |
implicit def vm = Validation.validationMonad[String] | |
type EValidation[+T] = Validation[String, T] | |
def toDouble(s: String): EValidation[Double] = allCatch.either(s.toDouble).fold(_.toString.fail, _.success) |
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
@channingwalton Recently read »I, Robot« from Asimov. The short stories are entertaining and very thoughtful. | |
@channingwalton I would like a wizard where I tell it I like Asimov (especially Daneel and Giskard) and Clarke, and it recommends others. | |
@channingwalton pretty much anything by Alastair Reynolds. House of Suns is particularly great. | |
@channingwalton I’ve enjoyed the Laundry novels by Charles Stross. | |
@channingwalton "Wool" series by Hugh Howey. |
OlderNewer