Using DeclareUnicodeCharacter locally (in document, not preamble)

It's only made preamble only to save a few dozen bytes that were useful last century, you could turn that off...

\documentclass{article}


\makeatletter
\let\@onlypreamble\@gobble
\makeatother
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}

\begin{document}



\begin{center}

\DeclareUnicodeCharacter{03BB}{$\lambda$}
\DeclareUnicodeCharacter{2190}{$\leftarrow$}
\DeclareUnicodeCharacter{21D2}{$\Rightarrow$}
\texttt{(λ x ⇒ y ← x; y)}
\end{center}
\end{document}

You can use newunicodechar, which has the advantage of working also with XeLaTeX and LuaLaTeX.

You need to keep a copy of \newunicodechar.

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{etoolbox}    
\usepackage{newunicodechar}
\let\xnewunicodechar\newunicodechar
\AfterEndPreamble{\let\newunicodechar\xnewunicodechar}

\begin{document}

\begin{center}

\newunicodechar{λ}{$\lambda$}
\newunicodechar{⇒}{$\rightarrow$}
\newunicodechar{←}{$\leftarrow$}
\texttt{(λ x ⇒ y ← x; y)}
\end{center}
\end{document}

enter image description here