4

I'm trying to use symulacrum's @typeclass to avoid writing Ops/Syntax boilerplate. I have a trait parameterized with effect and a type:

@typeclass trait Close[F[_], T]{
    def close(t: T): F[Unit]
}

With the intention to be used as follows:

trait Stream[F[_], Pipe]{
    def open(): F[Pipe]
    def drain(): F[Unit]
}
object App{
    def runApp[F[_], Pipe: Close[F, ?]](implicit stream: Stream[F, Pipe]) = {
        for{
            pipe <- stream.open()
            _ <- stream.drain(pipe)
            _ <- pipe.close()
        } yield ()
    }
}

The reason I decided to put Close[F[_], T] away was that some Pipes in my application are inherently unclosable so it is kind of wierd to put close method for all Pipes

This is the error I get:

Error:(32, 4) @typeclass may only be applied to types that take a single type parameter
  @typeclass trait Close[F[_], T]

QUESTION: In case of a trait has multiple type parameters (like Close[F[_], T]) do I have to write all the Ops/Syntax boilerplate on my own and symulacrum's @typeclass cannot help here?

St.Antario
  • 26,175
  • 41
  • 130
  • 318
  • I published small library https://github.com/DmytroMitin/AUXify Try annotation `@syntax` from there. https://gist.github.com/DmytroMitin/7fe3e538434155f35a0fe30acb2af5c3 – Dmytro Mitin Jul 21 '19 at 16:17

1 Answers1

4

On your own.

https://github.com/mpilquist/simulacrum#known-limitations

Known Limitations

  • Only type classes that abstract over a proper type or a unary type constructor are currently supported.
Dmytro Mitin
  • 48,194
  • 3
  • 28
  • 66