Saturday, 14 September 2013

What does the "Just" syntax mean in Haskell?

What does the "Just" syntax mean in Haskell?

I have scoured the internet for an actual explanation of what this keyword
does. Every Haskell tutorial that I have looked at just starts using it
randomly and never explains what it does (and I've looked at many).
Here's a basic piece of code from Real World Haskell that uses Just. I
understand what the code does, but I don't understand what the purpose or
function of "Just" is.
lend amount balance = let reserve = 100
newBalance = balance - amount
in if balance < reserve
then Nothing
else Just newBalance
From what I have observed, it is related to "Maybe" typing, but that's
pretty much all I have managed to learn.
A good explanation of what Just means would be very much appreciated.

No comments:

Post a Comment