I have the following types and declarations:
import scalaz._, Scalaz._
trait Container[T]
type FreeContainer[A] = Free[Container, A]
type FreeFreeContainer[A] = Free[FreeContainer, A]
val fc: FreeContainer[Int]
val ffc: FreeFreeContainer[Int]
val t: Container ~> Id
val tranformed: Int = fc.foldMap(t) //ok
val tranformed2: Int = ffc.foldMap(t) //error
Is it possible to lift Container ~> Id to FreeContainer ~> Id?
Yes, via
foldMap:Using the polymorphic lambda syntax of kind-projector, this can be simplified to
So you can do
Alternatively, you can just do two consecutive
foldMaps, the first one with the identity natural transformation: