This can be achieved with the following example. Also in gist.
\documentclass{article}
%include polycode.fmt
%if False
\begin{code}
module Main where
\end{code}
%endif
\begin{document}
\begin{code}
main = do
-- comment with _
print "Hello World"
\end{code}
\end{document}
When using an underscore in a comment latex fails with the following error:
This can be achieved with the following example. Also in gist.