English 中文(简体)
Underlying Parsec Monad
原标题:Underlying Parsec Monad
最佳回答

Parser的定义是Parsec,而不是ParsecT。 而安全则被定义为

type Parsec s u = ParsecT s u Identity

因此,答案是,在使用CharParser时, under子是身份证明。

问题回答

在您的情形下,lying系Identity。 但是,ParsecT与大多数mon变器不同,因为即使其类型参数为m ,它还是<代码>的一个实例。 如果你看看源代码,你将注意到在示范声明中没有“(Monad m)=>

因此,你要求 yourself,“如果我要有一个非部落的mon,那么会在哪里使用?”

这个问题有三个答案:

  1. 用于<代码>uncons a. 下一层:

     class (Monad m) => Stream s m t | s -> t where
         uncons :: s -> m (Maybe (t,s))
    

    通知<代码>uncons 采用<条码><>(条码/代码>(条形码<>t)并将之结果填入门。 这使得人们能够做一些有趣的事情,甚至是在下台时。

  2. 它是用于每一层的产物。 这意味着,你可以创造不触及投入的教区,但在mon子里采取行动,并利用合并者把他们约束在正规教区。 换言之,<条码>升值(x a) 治安 T s u m a。

  3. 最后,RunParsecT和朋友(直到您建立为止,mIdentity所取代)的结局将在本mon中总结的成果退回。

The monad and the one from Monadic Parsing in Haskell 。 在该案中,胡顿和梅伊杰尔提到“ParsecT”一案。 在Parsec-3.0.0和ParsecT以外地区已成为mon变者这一事实与该文件无关。

然而,我认为,你所期待的是可能的成果清单。 在胡顿和梅伊杰尔,教区归还了一份所有可能结果的清单,而Parsec则顽固地返回只有一个。 我认为,你正在研究<代码>m,并想到,结果清单必须存放在其他地方。 不是。

出于效率原因,Parsec选择了选择,选择了第一个相应的结果,即胡顿和梅伊杰尔结果清单。 让我们把胡顿和梅伊杰尔名单的尾声中未使用的结果,也从心灵中抹掉,因为我们永远不会倒退。 In parsec, given the joint parser a < ; ba 消费任何投入的<代码>b永远不会得到评估。 <代码>try,将国家重新编号为a,然后评价<代码>b。

You asked in the comments if this was done using Maybe or Either. The answer is "almost but not quite." If you look at the low lever run* functions you see that they return an Algebraic type which tell weather input was consumed then a second which give either the result or an error message. These types work kind of like Either, but even they are not used directly. Rather then stretch this out further, I ll refer you to the post by Antoine Latter that explains how this works and why it is done this way.





相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

How to get instance from string in C#?

Is it possible to get the property of a class from string and then set a value? Example: string s = "label1.text"; string value = "new value"; label1.text = value; <--and some code that makes ...

XML DOM parsing br tag

I need to parse a xml string to obtain the xml DOM, the problem I m facing is with the self closing html tag like <br /> giving me the error of Tag mismatch expected </br>. I m aware this ...

Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

Locating specific string and capturing data following it

I built a site a long time ago and now I want to place the data into a database without copying and pasting the 400+ pages that it has grown to so that I can make the site database driven. My site ...

热门标签