I've started the friendly tutorial tutorial on HXT to parse XML file with haskell.
In the first page of the tutorial we try to retrieve guest from a xml file. And there is the following function for that.
data Guest = Guest {firstName, lastName :: String}
deriving (Show, Eq)
getGuest = deep (isElem >>> hasName "guest") >>>
proc x -> do
fname <- getText <<< getChildren <<< deep (hasName "fname") -< x
lname <- getText <<< getChildren <<< deep (hasName "lname") -< x
returnA -< Guest {firstName = fname, lastName = lname}
but when I tried to load the file in the interpreter ghci
. I still get this error :
Prelude> :l hxt_tuto.hs
hxt_tuto.hs:15:37: parse error on input `->'
Failed, modules loaded: none.
pointing the fact that operator -> in the expression proc x -> do
has a parse error,
I've try many modification without help. like writing all this in a single line
getGuest2 = deep (isElem >>> hasName "guest") >>> proc x -> do { fname <- getText <<< getChildren <<< deep (hasName "fname") -< x; lname <- getText <<< getChildren <<< deep (hasName "lname") -< x; returnA -< Guest {firstName = fname, lastName = lname }}
Can anybody Help me understand what I've missed ?
thanks for any reply!
Did you remember to put
{-# LANGUAGE Arrows, NoMonomorphismRestriction #-}
import Text.XML.HXT.Core
at the top of your file?