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

Daniel Schoepe daniel.schoepe at googlemail.com
Tue Nov 2 17:52:36 EDT 2010

Excerpts from Michael Litchard's message of Tue Nov 02 22:40:27 +0100 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.

In the code sample, the first argument is "Id", in which case the
concrete type for the type variable str is String, and the second
argument are the tags returned by the call to filter, which have type
Tag String.

The second parameter is not a str of type Tag, but Tag (which is a
type constructor) applied to
the same concrete type for str its first argument has.

So in your case, calling
> fromAttrib "href" (TagOpen ...)

Would give you
"/launchWebForward.do?resourceId=4&policy=0&returnTo=%2FshowWebForwards.do". To
get the resourceId you want, you'd have to dissect this string further.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20101102/efcc06df/signature.bin

More information about the Haskell-Cafe mailing list