scala - When to use monads from scalaz? -


i'd create simple wrapper computations. built-in scala monads (traversablelike) seems sufficient me. , have syntax sugar. point of view scala collection traits accidental monads. , there intended monads provided scalaz library.

what uses cases benefit complex type classed monads of scalaz? functionality unfeasible built-in monads , indicate need scalaz?


some clarification.

this question not holy war inheritance vs type classes. question infrastructure provides scalaz. not library type classes approach, mentioned library. complicates things. have bunch of utility classes have no matches in scala collection library. because collection library, not monadic. question additional functionality provided scalaz. in cases matter?

first point terminology: it's useful shorthand things "option monad", "option has monad instance" or "option monadic" clearer. it's potentially little confusing scalaz provides bunch of monads—what provides monad type class , instances of type class number of types, including of own (e.g. \/, task, etc.) , standard library (list, option, etc.).

so i'm going answer question similar question: what's value of explicit monad type class on monadic syntactic sugar provided standard library?

one place having explicit monad representation useful when want define own generic combinators or operations. suppose want write method addm takes 2 monadic m[int] values , adds them in monad. it's easy write option:

def addm(oa: option[int], ob: option[int]): option[int] = {   <- oa   b <- ob } yield + b 

or lists:

def addm(oa: list[int], ob: list[int]): list[int] = {   <- oa   b <- ob } yield + b 

these 2 implementations have lot in common, , it'd nice able write single generic implementation work in both cases—and other monadic type well. hard if have standard library's hand-wavy monadic syntax, , easy if have monad type class.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -