Type Class instance syntax

29 views
Skip to first unread message

Lars Hupel

unread,
May 18, 2013, 3:30:34 PM5/18/13
to sca...@googlegroups.com
Recently I've been wondering about the instance-specific syntax:

val LM = Monad[List]
import LM.monadSyntax._

Now, one can write:

1.pure

and the compiler can actually figure out what is meant. Without
instance-specific syntax, one would have to write:

1.pure[List]

Does anybody actually use that feature?

I would really like to see that go away, because it seems odd to me: why
would you want to use syntax only for one specific `Monad`/...? (Also,
it introduces redundancy in `FunctorSyntax` and `ApplicativeSyntax`.)

Anyway, I tried removing it, and it's not too much of a hassle. As far
as I can see, only three functions are affected, with the most important
being `pure`/`pointed`. There are a few places in the examples which
won't compile any more – where `0.pure` is used to put a value into a
`State`:

val S = scalaz.StateT.stateMonad[(Int, Int)]
import S.monadSyntax._

0.pure

There are two possible workarounds:

S.pure(0)

and

import scalaz.syntax.applicative._

type IState[α] = State[(Int, Int), α]
0.pure[IState]

I think that is not too bad.

Paul Chiusano

unread,
May 19, 2013, 9:19:47 AM5/19/13
to sca...@googlegroups.com

I use it all the time. I'd like to keep it around.

--
You received this message because you are subscribed to the Google Groups "scalaz" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalaz+un...@googlegroups.com.
To post to this group, send email to sca...@googlegroups.com.
Visit this group at http://groups.google.com/group/scalaz?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Lars Hupel

unread,
May 20, 2013, 9:27:52 AM5/20/13
to sca...@googlegroups.com
> I use it all the time. I'd like to keep it around.

Okay. Do you have any idea how we could get rid of those redundant
definitions, e.g.:
<https://github.com/scalaz/scalaz/blob/436b79a1ca4eab7bc1b8c5d8620e3af18496e53a/core/src/main/scala/scalaz/syntax/ApplySyntax.scala#L44-L115>?
Reply all
Reply to author
Forward
0 new messages