Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Future Effect example does not work since it requires an ExecutionContext, could you rework the example #4

Closed
pavlosgi opened this issue Apr 18, 2016 · 11 comments

Comments

@pavlosgi
Copy link
Contributor

No description provided.

@etorreborre
Copy link
Member

I added the import to the example. Thanks.

@pavlosgi
Copy link
Contributor Author

Thank you for that, it doesn't seem to compile though.

@etorreborre
Copy link
Member

What is your compilation error? My example is compiling because the doc is generated from valid Scala code here.

@pavlosgi
Copy link
Contributor Author

pavlosgi commented Apr 19, 2016

[error] /Users/pavlos/Workspace/habito-deployment/slib/habito-effects/src/main/scala/habito/effects/Effects.scala:5: not found: object all
[error] import org.atnos.eff., all.
[error] ^
[error] /Users/pavlos/Workspace/habito-deployment/slib/habito-effects/src/main/scala/habito/effects/Effects.scala:6: object interpret is not a member of package org.atnos.eff
[error] import org.atnos.eff.interpret._
[error] ^
[error] /Users/pavlos/Workspace/habito-deployment/slib/habito-effects/src/main/scala/habito/effects/Effects.scala:18: not found: type <=
[error] def future[R, A](a: => A)(implicit m: Fut <= R): Eff[R, A] =
[error] ^
[error] /Users/pavlos/Workspace/habito-deployment/slib/habito-effects/src/main/scala/habito/effects/Effects.scala:19: not found: value send
[error] send[Fut, R, A](Future%28%28%29 => a%29)
[error] ^
[error] /Users/pavlos/Workspace/habito-deployment/slib/habito-effects/src/main/scala/habito/effects/Effects.scala:24: not found: type Recurse
[error] val recurse = new Recurse[Fut, U, A] {
[error] ^
[error] /Users/pavlos/Workspace/habito-deployment/slib/habito-effects/src/main/scala/habito/effects/Effects.scala:28: not found: value interpret1
[error] interpret1((a: A) => a)(recurse)(effects)(m)
[error] ^
[error] 6 errors found
error Compilation failed
[error] Total time: 0 s, completed 19-Apr-2016 20:04:38
4. Waiting for source changes... (press enter to interrupt)
[info] Compiling 2 Scala sources to /Users/pavlos/Workspace/habito-deployment/slib/habito-effects/target/scala-2.11/classes...
[error] /Users/pavlos/Workspace/habito-deployment/slib/habito-effects/src/main/scala/habito/effects.scala:3: not found: type Effects
[error] package object effects extends Effects
[error] ^
[error] one error found
error Compilation failed
[error] Total time: 0 s, completed 19-Apr-2016 20:05:10
5. Waiting for source changes... (press enter to interrupt)

@pavlosgi
Copy link
Contributor Author

These are the errors if I copy and paste the snippet as it is

@pavlosgi
Copy link
Contributor Author

pavlosgi commented Apr 19, 2016

Now my code is like this

import scala.concurrent.{Await, ExecutionContext, Future}
import cats.data.Xor
import org.atnos.eff._
import Eff._
import Member._
import Interpret._

import scala.concurrent.duration.Duration

trait Effects {

  object FutureEffect {
    type Fut[A] = Future[() => A]

    def future[R, A](a: => A)(implicit m: Fut <= R, ec: ExecutionContext): Eff[R, A] =
      send[Fut, R, A](Future(() => a))

    def runFuture[R <: Effects, U <: Effects, A]
    (
      atMost: Duration
    )
    (
      effects: Eff[R, A]
    )(
      implicit m: Member.Aux[Fut, R, U],
      ec: ExecutionContext

    ): Eff[U, A] = {

      val recurse = new Recurse[Fut, U, A] {
        override def apply[X](m: Fut[X]): Xor[X, Eff[U, A]] =
          Xor.left(Await.result(m.map(_ ()), atMost))
      }

      interpret1[R, U, Fut, A, A]((a: A) => a)(recurse: Recurse[Fut, U, A])(effects)(m)
    }
  }

}

@pavlosgi
Copy link
Contributor Author

The error here is
type arguments [R,U,habito.effects.Effects.FutureEffect.Fut,A,A] do not conform to method interpret1's type parameter bounds [R <: org.atnos.eff.Effects,U <: org.atnos.eff.Effects,M[_],A,B]
[error] interpret1[R, U, Fut, A, A](%28a: A%29 => a)(recurse: Recurse[Fut, U, A])(effects)(m)
[error] ^
[error] one error found

@etorreborre
Copy link
Member

Is this a public project I could have a look at?

@pavlosgi
Copy link
Contributor Author

Sorry it's not, but the snippet I pasted should be enough, is it not?

Thank you
On 19 Apr 2016 21:20, "Eric Torreborre" notifications@github.com wrote:

Is this a public project I could have a look at?


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#4 (comment)

@etorreborre
Copy link
Member

Those errors seem to correspond to the latest code which was not yet published. Please try version 1.4 which I just published now.

@pavlosgi
Copy link
Contributor Author

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants