0

I'm new to haskell and can't seem to figure this out. I've been using the scalpel web scraping tool and want to concatenate a bunch of URL extensions with a URL.

For example, lets say we have scraped some URL extensions into a list of strings

result =["/contact","/content"] 

and we have let

websiteURL = "www.website.com"

how do I arrive at the list ?

["www.website.com/contact", "www.website.com/content"]

2 Answers 2

2
map ("aaa"++) ["bbb", "ccc"]
==> [ "aaabbb", "aaaccc" ]
Sign up to request clarification or add additional context in comments.

1 Comment

This makes me feel a bit better. I was on the right lines, but had the syntax incorrect.
0

You want to traverse your list of extensions and apply a function to each, so some kind of map is required.

The function you want to apply is to append the websiteURL string, so the answer is:

map (mappend websiteURL) result

If you didn't know the mappend function, you could find it by searching hoogle for Monoid a => a -> a -> a.

(I'll let other people generalize to more abstract types if they want...)

1 Comment

If you don't know the mappend function, how can you possibly be expected to come up with the type signature Monoid a => a -> a -> a? And in this case, typing in the natural type signature search of String -> String -> String doesn't list the right function until quite late in the list of results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.