Fixing a `let` binding bug which was causing a failed test for `sort`.

I've also added a test for `let` to verify the behaviour directly,
rather than depending on the stdlib to catch the issue.