Integral of $f^2$ exists, but integral of $f$ doesn't. I'm looking for function $f:(0,1)\to \mathbb{R}$, such that $\int f^2$ exists, but $\int f$ doesn't.
Is it fine to take $f(x)=1$ where $\frac{1}{2}<x<1$, and  $f(x)=-1$ where $0<x\leq\frac{1}{2}$?
Thank you.
 A: The Dirichlet function will not work but a modified one maybe:
Let $$
f(x)=\begin{cases}1 & \hbox{ for } x\in (R\setminus Q)\cap(0,1)\\
-1&\hbox{ for } x\in Q\cap (0,1)
\end{cases}
$$
Then $f$ is not Riemann integrable (see Dirichlet function) but $f(x)^{2}\equiv 1$ and therefore Riemann integrable over (0,1)...
If we would use the Lebesgue integral it would be impossible to find such a function, since $L^{2}(0,1)\subset L^{1}(0,1)$.
A: Hint: Since you're integrating only over $(0,1)$, then the only way for an integral not to exist is (assuming $f$ is well-behaved, e.g measurable) if $f$ blows up too fast. Given this, do you think it's possible for such an $f$ to exist?
Edit: My answer was for Lebesgue integration. I believe that other answers/comments address the Riemann case.
A: Lebesgue's criterion states that a function is Riemann integrable on a bounded interval if and only if it is bounded and its set of discontinuities has measure zero. Make an example that is discontinuous on a set of positive measure. 
