튜토리얼 https://hackage.haskell.org/package/pipes-attoparsec-0.1.0.1/docs/Control-Proxy-Attoparsec-Tutorial.html을 따라 attoparsec과 함께 파이프를 사용하는 방법을 배우려고합니다. 하지만 Control.Proxy.Trans.Either를 가져올 수 없습니다. lib에이 모듈이 있습니까?Control.Proxy.Trans.Either를 가져올 수 없습니다
1
A
답변
1
pipes
의 이전 버전 인 pipes-attoparsec
의 이전 버전을 누르십시오. 최근 버전에서는 첫 번째 예제와 같은 것이 파이프없이 작성됩니다. 우리는 parsed
함수를 사용할 것입니다.이 함수는 파서가 실패 할 때까지 반복적으로 파서를 적용하여 좋은 파서를 스트리밍합니다.
{-# LANGUAGE OverloadedStrings #-}
import Pipes
import qualified Pipes.Prelude as P
import Pipes.Attoparsec
import Data.Attoparsec.Text
import Data.Text (Text)
data Name = Name Text deriving (Show)
hello :: Parser Name
hello = fmap Name $ "Hello " *> takeWhile1 (/='.') <* "."
helloparses :: Monad m => Producer Text m r -> Producer Name m (Either (ParsingError, Producer Text m r) r)
helloparses = parsed hello
process txt = do
e <- runEffect $ helloparses txt >-> P.print
case e of
Left (err,rest) -> print err >> runEffect (rest >-> P.print)
Right() -> return()
input1, input2 :: Monad m => Producer Text m()
input1 = each
[ "Hello Kate."
, "Hello Mary.Hello Jef"
, "f."
, "Hel"
, "lo Tom."
]
input2 = input1 >> yield "garbage"
그런 다음 우리는
-- >>> process input1
-- Name "Kate"
-- Name "Mary"
-- Name "Jeff"
-- Name "Tom"
-- >>> process input2
-- Name "Kate"
-- Name "Mary"
-- Name "Jeff"
-- Name "Tom"
-- ParsingError {peContexts = [], peMessage = "string"}
-- "garbage"
정의 된 다른 원리 기능 pipes-attoparsec
그냥 parse
입니다 참조하십시오. 이것은 attoparsec 구문 분석기를 파이프 StateT
파서로 변환하여 파서와 일치하는 제작자의 초기 세그먼트를 구문 분석합니다. 당신은 그들에 대해 여기서 읽을 수 있습니다 http://www.haskellforall.com/2014/02/pipes-parse-30-lens-based-parsing.html
내 질문에 대답 해 주셔서 감사합니다. 파이프 attoparsec가 최근에 극적인 변화를 본 것처럼 보입니다. 내가 심판 한 튜토리얼은 완전히 쓸모없고 혼란 스럽다. – user2812201