Question: I'm relatively new to Haskell and I'm struggling to figure out a way to implement Haskell's `span` function. However, my problem is more general than that in that I don't know how to make a function return a list of lists or list of tuples containing the elements I want. My problem with a list of lists such as: 

```
[[1],[2]]

```

is that I can't make the function add an element to the first list in the list of lists. I only know how to append another list to the list of lists.

In short, if you explain to me how to implement the `span` function, this all should hopefully come clear to me.

Answer: 
So I *think* what you're saying is that you know how to recursively append to a list by doing something like

```
foobar :: [x] -> [y]
foobar (  []) = []
foobar (x:xs) = {- ...stuff... -} : foobar xs

```

but you have no idea how to do that with *two* lists:

```
foobar :: [x] -> ([y], [z])
foobar (x:xs) = ???

```

In general, when the result isn't a list, but something that contains a list, you end up doing something like this:

```
foobar :: [x] -> ([y], [z])
foobar (x:xs) =
  let
    y = {- whatever -}
    z = {- whatever -}
    (ys, zs) = foobar xs   -- The recursive call
  in  (y:ys, z:zs)

```

The same applies if, say, the result is a monadic action

```
foobar :: [x] -> IO [y]
foobar (x:xs) = do
  y  <- {- whatever -}
  ys <- foobar xs
  return (y:ys)

```

Note that this forces the function to not be lazy.
The general pattern I think you'll want to use here is the following:

```
span :: (a -> Bool) -> [a] -> ([a], [a])
span pred [] = ([], [])
span pred (x:xs) = if pred x then _ else _  -- fill in the blanks
    where (prefix', suffix') = span pred xs

```

There are two non-obvious things there. First, note the pattern match in the `where` condition. This means that we're:

1. Calling `span pred xs`, which produces a pair of lists;
2. Pattern matching on this pair;
3. Naming the first and second element of the pair `prefix'` and `suffix'` respectively.

I suspect that step #2, the pattern match on the result of the recursive call, is something you might not have understood.

The second non-obvious thing is *recursion*. It's a tricky thing because, counterintutively, to solve a problem with recursion you need to assume that you've already solved it, but for the "wrong" argument--a tough step to picture yourself taking if you haven't solved it yet! But the trick is this:

* Imagine you've actually already solved the problem, but for the **tail** of the list. That's what the `prefix'` and `suffix'` variables contain: a correct solution but for the wrong list--the tail of the one you're actually trying to solve for.
* Given that (non)solution, how could you reuse it to arrive at a correct solution for *your* problem?