```
trace "{1}" x : (filter' p xs)
```

parses as

```
(trace "{1}" x) : (filter' p xs)
```

Similarly,

```
trace "{2}" filter' p xs
```

parses as

```
(trace "{2}" filter') p xs
```

If you want the other interpretation, you need to write `trace "{1}" (x : (filter' p xs))`

and `trace "{2}" (filter' p xs)`

, respectively.

I'm not sure about your question #3. Why would {3} execute multiple times? It's not part of a loop / recursion.

Let's step through the evaluation of

```
filterFirst even [2,2]
```

The interpreter wants to print the result, so we have to compute the result.

We enter the definition of `filterFirst`

(the outside part of an expression is always evaluated first), giving

```
case (trace "{3}" (filter' p xs)) of
(x : xs) -> trace "{4}" [x]
otherwise -> trace "{5}" []
where
p = even
xs = [2,2]
```

Here we need to make a decision. `case`

needs to know which branch to evaluate, so it needs to know which pattern matches (`x : xs`

or `otherwise`

). So the first thing it does is to evaluate the expression we're analyzing:

```
trace "{3}" (filter' p xs)
where
p = even
xs = [2,2]
```

Here the outermost expression is a call to `trace`

, which now prints `{3}`

and hands over to

```
filter' p xs
where
p = even
xs = [2,2]
```

Now the outermost expression is a call to `filter'`

, which is defined as

```
filter' p (x:xs) | p x = trace "{1}" x : (filter' p xs)
| otherwise = trace "{2}" filter' p xs
filter' p [] = []
```

Again we have to make a decision: Which equation do we use? The choice depends on the value of the second argument, so this triggers the evaluation of (the outermost layer of) `xs = [2,2]`

. Well, nothing interesting happens here because `[2,2]`

is already fully evaluated.

`[2,2]`

is syntactic sugar for `2 : (2 : [])`

, so this matches the first equation, binding

```
p = even
x = 2
xs = 2 : [] -- same as [2]
```

We now have to evaluate the guard behind the pattern:

```
p x
even 2
True
```

Success! Our return value is `trace "{1}" x : (filter' p xs)`

, which (as mentioned above) is an application of `(:)`

to two arguments, `trace "{1}" x`

and `filter' p xs`

.

No further evaluation happens here. Recall that we're still trying to evaluate

```
case ... of
(x : xs) -> trace "{4}" [x]
otherwise -> trace "{5}" []
```

so we only care if the outermost constructor of the list is `:`

or `[]`

, and we know it's `:`

now. We select the first branch, which yields

```
trace "{4}" [x]
where
x = trace "{1}" x_inner
xs = filter' p xs_inner
x_inner = 2
xs_inner = 2 : []
p = even
```

This is slightly confusing because you've named all your variables `x`

and `xs`

. If we inline all variables whose values we already know, the bindings reduce to:

```
trace "{4}" [x]
where
x = trace "{1}" 2
xs = filter' even (2 : [])
```

`xs`

is not used at all and `x`

is only used once, so this is really equivalent to

```
trace "{4}" [trace "{1}" 2]
```

Evaluating this first prints `{4}`

(from `trace`

), then yields

```
[trace "{1}" 2]
-- syntactic sugar for
(trace "{1}" 2) : []
```

Here the list printing code starts working: We've got a list of at least one element, so it outputs `[`

(the start of the list). To print the first element itself, we need to evaluate it:

```
trace "{1}" 2
```

This finally prints `{1}`

and yields `2`

, which lets the list-printing code output `2`

and `]`

(for the end of the list).

And that's it!

`otherwise`

being an unused variable. You mean`_`

.