我目前正在尝试解决我的问题HXT: Can an input change with the arrow syntax?,因此希望在ghc编译器去掉Arrow syntax之后看到haskell代码。我怎么能这样做?
我已经尝试了-ddump-ds
但是有了这个标志,我得到了一个可怕的长代码,因为所有类型都被解析了。有没有办法看到代码只用箭头语法desugaring?
答案 0 :(得分:6)
原始arrow project提供了一个名为arrowp
的解析器available on Hackage,并将箭头语法转换为Haskell98:
cabal install arrowp
arrowp --help
arrowp source.hs > desugared.hs
来源取自your other question。
{-# LANGUAGE Arrows #-}
import Text.XML.HXT.Core
data Person = Person { forname :: String, surname :: String } deriving (Show)
parseXml :: IOSArrow XmlTree Person
parseXml = proc x -> do
forname <- x >- this /> this /> hasName "fn" /> getText
surname <- x >- this /> this /> hasName "sn" /> getText
returnA -< Person forname surname
main :: IO ()
main = do
person <- runX (readString [withValidate no]
"<p><fn>John</fn><sn>Smith</sn></p>"
>>> parseXml)
putStrLn $ show person
return ()
arrowp source.hs
{-# LINE 2 "source.hs" #-}
module Main (main) where
{-# LINE 2 "source.hs" #-}
import Text.XML.HXT.Core
{-# LINE 4 "source.hs" #-}
data Person = Person{forname :: String, surname :: String}
deriving Show
{-# LINE 6 "source.hs" #-}
parseXml :: IOSArrow XmlTree Person
{-# LINE 7 "source.hs" #-}
parseXml
= (arr (\ x -> (x, x)) >>>
(first (this /> this /> hasName "fn" /> getText) >>>
arr (\ (forname, x) -> (x, forname)))
>>>
(first (this /> this /> hasName "sn" /> getText) >>>
arr (\ (surname, forname) -> Person forname surname)))
{-# LINE 12 "source.hs" #-}
main :: IO ()
{-# LINE 13 "source.hs" #-}
main
= do person <- runX
(readString [withValidate no] "<p><fn>John</fn><sn>Smith</sn></p>"
>>> parseXml)
putStrLn $ show person
return ()