Question: I wanted to write a Haskell function that takes a string, and replaces any space characters with the special code %20. For example:

```
sanitize "http://cs.edu/my homepage/I love spaces.html"
-- "http://cs.edu/my%20homepage/I%20love%20spaces.html"

```

I am thinking to use the concat function, so I can concatenates a list of lists into a plain list.

Answer: 
Using a comprehension also works, as follows,

```
changer :: [Char] -> [Char]
changer xs = [ c | v <- xs , c <- if (v == ' ') then "%20" else [v] ]

```
You can use `intercalate` function from `Data.List` module. It does an [`intersperse`](http://hackage.haskell.org/package/base-4.7.0.1/docs/src/Data-List.html#intersperse) with given separator and list, then concats the result.

```
sanitize = intercalate "%20" . words

```

or using pattern matching :

```
sanitize [] = []
sanitize (x:xs) = go x    xs
          where   go ' '  []     = "%20" 
                  go y    []     = [y] 
                  go ' '  (x:xs) = '%':'2':'0': go x xs  
                  go y    (x:xs) = y: go x xs

```