‘Let’ there be functions!

Often you hear that to declare a function in GHCi, you have to precede it with “let” – this is to “let” the interpreter know that you are giving it a declaration, rather than a statement.

Well, last night, I did the unthinkable. I forgot the leading ‘let’… gasp!

Fortunately, GHCi forgave me. It turns out you do not need ‘let’ anymore when declaring functions in GHCi. You can use it, but it’s not strictly necessary. See this page for more information: https://phabricator.haskell.org/D1299

The essence is that GHCi will try to parse the input string as a statement, and if successful, it will run it as a statement. Otherwise, it will run it as a declaration.

GHCi said, “‘Let’ there be functions!”  And so it came to be.

But Haskellers cried and gnashed their teeth, beseeching GHCi,”Oh great one, can you not tell when there be declarations, and when there be statements?”

And so GHCi realized how the parser could be used to determine the difference automatically,  and struck down this let-down! And the Haskellers agreed that it was good.

“Let” me know if the Biblical humor gets annoying… Actually don’t – I can already tell…


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s