I have a monadic type I have heard about Moned Transformer, but still is scared of Scalaz 7's wierd import system. Can anyone answer that "Weird" import system for the first easy part: all this will always work (except for the name collision, but this is a possibility with any library And it's easy to solve), and no one is paying attention to you not to use the new la carte import, which is mainly about documentation. The basic pattern for the mondad transformer is that you have a In this case it seems that you want to end with a See some discussion about why It works like this: Note that < Code> oddNumber run gives us a We are not actually going to call The syntax here is ugly, we lose the good exp and I want to create such parser which Parsing in the value of The following code works, but can I do some cool / cooler?
def grid (x: int, y: int): problem = ??? Def expInt: parser [EXP [int]] = ??? Def Grid: Parser [Excl. [Problem]] = For {ex ~ _ ~ ey & lt; - "Grid (" ~> expInt ~ "," ~ expInt <~ ")"} {x
exp Monaad
import scales ._, scales._
whatevert [f [_], ...] type class whose name is
runWhateverT (Or just
play ) which
f [whichever [...]] returns .
parser [XP] , which tells you that you have your own
expT [f [ _]] needs transformers. I will not start with details about how to implement it (which will definitely depend on the words of your mona), but
OptionT :
Import scala.util.parsing.combinator._ import scalaz._, Scalaz._ Object Expands MyParser RegexParsers {Inherent Val Monad = Parser Monad (this) Def Aud Number: OptionT [Parser, Int] = OptionT.optionT ( "\ D +". ^ ^ (_.toInt) ^ ^ (i = & gt; (i% 2! = 0) option i) def pairop objects: OptionT [parser, (int, int)] = {_ & Lt; LiftM [Option]] - Lifel ("("). LiftM [Option +] X & Lt; - Strange Number _ - Literal (","). LiftM [Option +] Y & lt; - Strange Number _ & Lt - Literal (")"). LiftM [OptionT]} yield (X, Y) DEF applied (S: string) = purse (pairOfOdds.run, s)}
Implicit Val monad = ... line.
scala> MyParser ("(13, 43)") res0: MyParser.ParseResult [option ([int, int]] = [1.9] Parsed: some ((13,43)) scale & gt; MyParser (", 13, 42)") res1: MyParser.ParseResult [option [(int, int)] [[1.8] parsed: Any
parser [option [int]] which will parse the number of a string and return either
some (i) ( If they are weird numbers) or
none (if they are also).
oddNumber.run , however, the fact is that the fact that we are using a moned transformer means that We raised
oddNumber to
parser verb (
literal (...) to understand a
here ).
~ combination and for example,
string to
parser [string] Built-in conversion, but if we want we can easily write the version of those things.
No comments:
Post a Comment