I currently try to solve my problem HXT: Can an input change with the arrow syntax? and therefore and want to see the haskell code after the ghc compiler desugars the Arrow syntax. How can I do this?
I already tried -ddump-ds
but with this flag I get a horrible long code because also all types are resolved. Is there a way to see the code with just arrow syntax desugaring?
The original arrow project provided a parser, called arrowp
, which is available on Hackage and translates the arrow syntax to Haskell98:
cabal install arrowp
arrowp --help
arrowp source.hs > desugared.hs
Source has been taken from 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 ()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With