[Haskell-beginners] Scoping within arrow notation (using HXT)?
Michael Alan Dorman
mdorman at ironicdesign.com
Fri Jun 8 17:48:23 CEST 2012
Hey, Haskellers,
I'm trying to use state threaded through an arrow in some HXT code to
avoid passing explicit parameters through several layers of functions,
but I think I'm not understanding quite what the arrow notation is
doing, because when I try to use a value I'm extracting from the state,
I'm getting a scope error.
I had many ways I was prepared for the code to be wrong, but that one
has me baffled. Any suggestions?
Mike.
{-# LANGUAGE Arrows, NoMonomorphismRestriction #-}
module HXTTest () where
import Text.XML.HXT.Core
data Info = Info {
value :: String
} deriving (Show)
info = Info { value = "foo" }
html = "<html><head></head><body><div class='foo'>llama</div></body>";
-- print (runSLA (getState >>> arr value) info html)
-- Div class is static, no reference to state
findFoo =
proc content -> do
(deep (isElem >>>
hasName "div" >>>
hasAttrValue "class" (== "foo"))) -< content
-- print (runSLA (hread >>> findFoo) info html)
-- Extract class from state, but don't use it
findFoo' =
proc content -> do
divName <- (getState >>> arr value) -< content
content >- (deep (isElem >>>
hasName "div" >>>
hasAttrValue "class" (== "foo")))
-- print (runSLA (hread >>> findFoo') info html)
-- Extract class from state, try to use it: "Not in scope: `divName'"
-- findFoo'' =
-- proc content -> do
-- divName <- (getState >>> arr value) -< content
-- content >- (deep (isElem >>>
-- hasName "div" >>>
-- hasAttrValue "class" (== divName)))
More information about the Beginners
mailing list