I feel like this seemingly simple and essential thing is completely cryptic to me. What does 'let' expression mean? I have tried to google, but the results are full of concepts that I don't understand.
Here is some code I wrote during a lecture. It identifies if a given string is a palindrome. I don't quite understand where the return keyword is either. Is it the 'in'? What is the scope of this function? I am at a loss.
module Main where
isPalindrome :: Text -> Bool
isPalindrome text1
= let
list = toString text1
backwards = reverse list
in list == backwards
What does 'in' mean, when it comes after 'let'?
I come from learning C#, and functional programming is unknown to me.
Thank you.
A let
-block allows you to create local variables. The general form is
let
var1 = expression
var2 = another expression
var3 = stuff
in
result expression
The result of this is whatever result expression
is, but you can use var1
, var2
and var3
inside result expression
(and inside expression
, another expression
, and stuff
as well). You can think of let
and in
as being brackets around the bunch of local variables you want to define. And yes, the thing after in
is what you're returning.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With