Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get haskell code after desugaring arrow syntax?

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?

like image 363
Stephan Kulla Avatar asked Mar 28 '14 09:03

Stephan Kulla


1 Answers

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

Example

Source has been taken from your other question.

source.hs

{-# 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 ()
like image 140
Zeta Avatar answered Oct 27 '22 01:10

Zeta