[Haskell-cafe] trying to use Tag Soup - fromAttrib

Michael Litchard michael at schmong.org
Tue Nov 2 17:40:27 EDT 2010


Daniel,
           Thank you for your reply. I'm still confused.
When I see a code sample like this
main = do
  posts <- liftM parseTags (readFile "posts.xml")
  print $ head $ map (fromAttrib "Id") $
                 filter (~== ("<row OwnerUserId=" ++ userid ++ ">"))
                 posts

I have no idea how to match that up with what you said. The usage of
fromAttrib here doesn't match up with what I htink the type signature
is saying.

fromAttrib :: (Show str, Eq str, StringLike str) => str -> Tag str -> str

seems to say "fromAttrib takes two parameters (I know it doesn't
literally take two), one str (with the constraints in parenthesis to
the left) and one str of type Tag, giving back a str. Then I look at
the above code sample and can't match the two up.

On Tue, Nov 2, 2010 at 2:23 PM, Daniel Fischer <daniel.is.fischer at web.de> wrote:
> On Tuesday 02 November 2010 22:17:48, Michael Litchard wrote:
>> I have the following TagOpen
>> [TagOpen "a"
>> [("href","/launchWebForward.do?resourceId=4&policy=0&returnTo=%2FshowWeb
>>Forwards.do")]]
>>
>> I would like to get the attribute resourceId=4 from that. My
>> understanding is that fromAttrib is the right thing to use. But
>> I'm having difficulty understanding the type signature
>> fromAttrib :: (Show str, Eq str, StringLike str) => str -> Tag str ->
>> str
>>
>> I'm sure if I did, the way to use it would be clear. Could someone
>> help me make sense of this?
>
> In most uses, str will be one of
>
> - String
> - ByteString
> - Text
>
> substitute the one you're using for str.
>
> I've no idea why there's a Show constraint (except perhaps it's needed for
> a failure message).
>
>


More information about the Haskell-Cafe mailing list