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: 
The higher-order function you are looking for is

```
concatMap :: (a -> [b]) -> [a] -> [b]

```

In your case, choosing `a ~ Char, b ~ Char` (and observing that `String` is just a type synonym for `[Char]`), we get

```
concatMap :: (Char -> String) -> String -> String

```

So once you write a function

```
escape :: Char -> String
escape ' ' = "%20"
escape c = [c]

```

you can lift that to work over strings by just writing

```
sanitize :: String -> String
sanitize = concatMap escape

```
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

```