scala - Scalaz minimal imports required to inject right and left use -
simple question, have looked @ 1 already: managing imports in scalaz7, can't figure out how minimally inject right
, left
methods objects construct instances of \/
.
i did try:
import syntax.todataops
, other variations of to...
such syntax.toidops
suggested in http://eed3si9n.com/learning-scalaz-day13.
simple example:
import scalaz.{\/, syntax} import // goes here class test { def returneithert(h: int): string \/ int = { h right } }
thanks, jason.
===========
i solved using import syntax.id._
i'm unsure why worked.
syntax.id
contains syntax "plain" values, i.e. places no constraints on type of value.
in general, when import syntax expression of form x.op
, place import syntax depends on type of x
, because op
needs valid operation on type.
because \/[a, b]
universally quantified , b, using syntax x.left
, x.right
places no constraints on type of x
. hence, belongs in syntax.id
.
for working understanding of syntax available where, worth looking @ source of of modules make syntax
packages. example, contrast idops[a]
, has syntax a
, functorops[f[_],a]
, has requirement f
functor
.
i not sure name id
comes exactly; perhaps related identity functor id
, can defined type id[a] = a
. if had choose type constraint values usable syntax.id
, in id
. being universally quantified in a
, operations can't know structure of value of a
, hence can't structure-altering operations on a
.