Last active
October 10, 2021 06:51
-
-
Save tpolecat/1227e22e3161b5816e014c00650f3b57 to your computer and use it in GitHub Desktop.
A demonstration in Scala of failed associativity of ListT. Example taken from https://wiki.haskell.org/ListT_done_right
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
// addCompilerPlugin("com.milessabin" % "si2712fix-plugin" % "1.2.0" cross CrossVersion.full) | |
import scalaz._, Scalaz._ | |
implicit def f2k[F[_], A, B](f: A => F[B]) = Kleisli(f) | |
val a: Int => ListT[List, Int] = { | |
case 0 => ListT(List(List(0, 1))) | |
case 1 => ListT(List(List(0), List(1))) | |
} | |
println(((a >=> a) >=> a ).run(0)) | |
println(( a >=> (a >=> a)).run(0)) | |
// ListT(List(List(0, 1, 0, 0, 1), List(0, 1, 1, 0, 1), List(0, 1, 0, 0), List(0, 1, 0, 1), List(0, 1, 1, 0), List(0, 1, 1, 1))) | |
// ListT(List(List(0, 1, 0, 0, 1), List(0, 1, 0, 0), List(0, 1, 0, 1), List(0, 1, 1, 0, 1), List(0, 1, 1, 0), List(0, 1, 1, 1))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment