Question: Why does this throw an error?

```
myTest :: Int -> [Int]
myTest a
    | a == 0          = []
    | otherwise  = x ++ map(myTest) x
    where x = [a-1]

```

I would expect that it would make a list going from a to 1. Instead I get the error:

```
couldn't match the expected type 'Int' against inferred type '[Int]'
in the first argument of 'map', namely '(myTest)'
in the second argument of '(++)', namely 'map (myTest) x'

```

This obviously isn't the best way to make this list, but it is a simplified version of a more complicated problem I am having.

I basically have a function `foo :: a -> [a]`, and in the resulting list I need to call `foo` on every element expanding it into another list. In the end I want one big list where every element is a base case.

I am fairly new at Haskell so I am probably missing something fairly basic.

Answer: 
The signature of `myTest` is `Int -> [Int]`.

The signature of `map` is `(a -> b) -> [a] -> [b]`, and since `myTest` is the first argument, that makes it `(Int -> [Int]) -> [Int] -> [[Int]]`.

But your function expects it to produce an `[Int]`, not an `[[Int]]`.

**Edit to add:** I think what you want is simply

```
myTest a
    | a == 0     = []
    | otherwise  = [a] ++ myTest (a-1)

```

although this is probably not what you *should* want (it's much more heavyweight than an idiomatic Haskell solution), but without seeing your actual problem that this is a simplification of, it's hard to tell.
Else's answer is better because is uses (:) instead of (++). In your case you can use either, because (:) adds a single element to the front of the list, and that's what you're trying to do.

(++) is a relatively expensive operation because it copies the spine of the left hand list. (:) is cheap because it never copies anything, it just creates a new cons cell that contains your new head element.

So always use (:) instead of (++) if you can.

EDIT: Just trying to explain since Else didn't post an explanation for his code.