Skip to content

Error "Macro has not been expanded" when using monadic Nothing #41

@dominique-unruh

Description

@dominique-unruh

In monadic[F] { ... }, if each is applied to a monad of type F[Nothing], a compilation error "Macro has not been expanded" occurs.

F[Nothing] is a natural type for a fail operation (e.g., Nil, None) in a monad, since the return value can be upcast to anything (e.g., val x = if (x >= 0) sqrt(x) else None.each would be a use case).

Example code:

object MonadicNeedsCast {
  def main(args: Array[String]): Unit = {
    val monad = monadic[Option] {
      None.each // Normally, this would be inside an if and represent a failure of the computation
//      (None:Option[Unit]).each // This one works
      55
    }
    println(monad) // Should be None
  }
}

The error also appears with monadic[List] or with custom monads. It also appears when using fail.each where fail has type [T]fail( => T).

I am using Scala 2.11.8 and Each 2.0.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions