Re: [Haskell-cafe] Problem with HXT `when`

2013-09-25 Thread Vlatko Basic

Hi Albert,

thanks for your answer. It helped in some other issues I have.
I did experiment with parenthesis, but obviously not in the right place.


I found the filterA arrow to do the thing I want, like this:

getRowWithHeading caption =
filterA (deep (hasName "th" /> hasText (==caption) )) />
hasName "td" >>>
getChildren


I like to ask you if you might know the answer to the following:

In a structure
   +---XTag "a"
   |   +---XText "A text 1"
   |
   +---XText "Plain text 1"
   |
   +---XTag "a"
   |   +---XText "A text 2"
   |
   +---XText "Plain text 2"
   ...

I must combine "A text 1" with "Plain text 1", etc., but they are in sequence on 
the same level.


Is it possible, in a simple way, to do it in a single arrow flow?
(Or only outside the arrow by pairing the list items?)

Something like:
  hasName "a" /> getText  &&& (getNextItem??? >>> getText)


I assume not, but I'm still new to Haskell and would like to check.


br,

vlatko

 Original Message  
Subject: Re: [Haskell-cafe] Problem with HXT `when`
From: Albert Y. C. Lai 
To: haskell-cafe@haskell.org
Date: 25.09.2013 03:22


On 13-09-21 05:13 AM, Vlatko Basic wrote:

I'd like to extract A texts from row with header "Caption", and have
come up with this

runX $ doc
 >>> (deep (hasName "tr")   --
filter only TRs
>>> withTraceLevel 5 traceTree   --
shows correct TR
`when`
  deep (
 hasName "th" >>>
-- filter THs with specified text
 getChildren >>> hasText (=="Caption")
  ) -- inner deep
  >>> getChildren >>> hasName "td" -- shouldn't here be only
one TR?
  >>> getChildren
   )
  >>> getName &&& (getChildren >>> getText)  -- list has TDs
from all three TRs


Operator precedences:
   >>> infixr 1
   `when` infixl 9 (default)

Therefore, this expression redundantly parenthesized and systematically indented
to ensure that you are on the same page with the computer is:

runX $
 doc
 >>>
 ( deep (hasName "tr")
   >>>
-- begin{conditionally prints but otherwise is arr id}
   ( withTraceLevel 5 traceTree
 `when`
 deep ( hasName "th"
>>>
getChildren
>>>
hasText (=="Caption")
  ) -- inner deep
   )
-- end{conditionally prints but otherwise is arr id}
   >>>
   getChildren
   >>>
   hasName "td"
   >>>
   getChildren
 )
 >>>
 ( getName &&& (getChildren >>> getText) )

The condition on Caption ends up controlling trace messages only; it is
not used to limit real processing.

"when" doesn't help even when used correctly: it doesn't ban data. "guards" and
"containing" ban data, but you have to put them at the right place, i.e.,
parenthesize correctly.

runX $
 doc
 >>>
 ( deep ( hasName "tr"
  `containing`
  deep ( hasName "th"
 >>>
 getChildren
 >>>
 hasText (=="Caption")
   )
)
   >>>
   getChildren
   >>>
   hasName "td"
   >>>
   getChildren
 )
 >>>
 ( getName
   &&&
   (getChildren >>> getText)
 )

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Problem with HXT `when`

2013-09-24 Thread Albert Y. C. Lai

On 13-09-21 05:13 AM, Vlatko Basic wrote:

I'd like to extract A texts from row with header "Caption", and have
come up with this

runX $ doc
 >>> (deep (hasName "tr")   --
filter only TRs
>>> withTraceLevel 5 traceTree   --
shows correct TR
`when`
  deep (
 hasName "th" >>>
-- filter THs with specified text
 getChildren >>> hasText (=="Caption")
  ) -- inner deep
  >>> getChildren >>> hasName "td" -- shouldn't here be only
one TR?
  >>> getChildren
   )
  >>> getName &&& (getChildren >>> getText)  -- list has TDs
from all three TRs


Operator precedences:
  >>> infixr 1
  `when` infixl 9 (default)

Therefore, this expression redundantly parenthesized and systematically 
indented to ensure that you are on the same page with the computer is:


runX $
doc
>>>
( deep (hasName "tr")
  >>>
-- begin{conditionally prints but otherwise is arr id}
  ( withTraceLevel 5 traceTree
`when`
deep ( hasName "th"
   >>>
   getChildren
   >>>
   hasText (=="Caption")
 ) -- inner deep
  )
-- end{conditionally prints but otherwise is arr id}
  >>>
  getChildren
  >>>
  hasName "td"
  >>>
  getChildren
)
>>>
( getName &&& (getChildren >>> getText) )

The condition on Caption ends up controlling trace messages 
only; it is not used to limit real processing.


"when" doesn't help even when used correctly: it doesn't ban data. 
"guards" and "containing" ban data, but you have to put them at the 
right place, i.e., parenthesize correctly.


runX $
doc
>>>
( deep ( hasName "tr"
 `containing`
 deep ( hasName "th"
>>>
getChildren
>>>
hasText (=="Caption")
  )
   )
  >>>
  getChildren
  >>>
  hasName "td"
  >>>
  getChildren
)
>>>
( getName
  &&&
  (getChildren >>> getText)
)

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe