[Haskell-cafe] trying to use Tag Soup - fromAttrib
Neil Mitchell
ndmitchell at gmail.com
Tue Nov 2 18:47:03 EDT 2010
Hi Michael,
If you just replace all 'str' with 'String' when reading the signature
then that will almost certainly be sufficient for your purposes. So
read it as:
fromAttrib :: String -> Tag String -> String
Where "Tag String" can be thought of as just "Tag". If you try to
parse HTML with regular expressions you'll probably find it much
harder than using tagsoup.
As one of the previous commenter's guessed, Show is indeed required
only for nice error messages. I think it's also probably redundant,
since StringLike has a toString style method on it anyway.
Thanks, Neil
On Tue, Nov 2, 2010 at 10:04 PM, Michael Litchard <michael at schmong.org> wrote:
> Ah thank you. I can go ahead and figure out how to parse that string.
> Using a regex is tempting but I have a feeling I can get something
> more maintainable if I use another approach.
>
> On Tue, Nov 2, 2010 at 2:52 PM, Daniel Schoepe
> <daniel.schoepe at googlemail.com> wrote:
>> 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.
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
More information about the Haskell-Cafe
mailing list