Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Monad (functional programming)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Verifying the monad laws === Returning to the <code>Maybe</code> example, its components were declared to make up a monad, but no proof was given that it satisfies the monad laws. This can be rectified by plugging the specifics of <code>Maybe</code> into one side of the general laws, then algebraically building a chain of equalities to reach the other side: '''Law 1:''' eta(a) >>= f(x) β (Just a) >>= f(x) β f(a) '''Law 2:''' <!--@ col 8 --> ma >>= eta(x) <!--@ col 32 --> β ma <!--@ col 8 --> '''if''' ma '''is''' (Just a) '''then''' <!--@ col 12 --> eta(a) <!--@ col 32 --> β Just a <!--@ col 8 --> '''else''' <!--@ col 36--> '''or''' <!--@ col 12 --> Nothing <!--@ col 32 --> β Nothing <!--@ col 8 --> '''end if''' '''Law 3:''' <!--@ col 8 --> '''('''ma >>= f(x)''')''' >>= g(y) <!--@ col 52 --> β ma >>= '''('''f(x) >>= g(y)''')''' <!--@ col 8 --> '''if''' (ma >>= f(x)) '''is''' (Just b) '''then''' <!--@ col 52 --> '''if''' ma '''is''' (Just a) '''then''' <!--@ col 12 --> g(ma >>= f(x)) <!--@ col 56 --> (f(x) >>= g(y)) a <!--@ col 8 --> '''else''' <!--@ col 52 --> '''else''' <!--@ col 12 --> Nothing <!--@ col 56 --> Nothing <!--@ col 8 --> '''end if''' <!--@ col 52 --> '''end if''' <!--@ col 16 --> β '''if''' ma '''is''' (Just a) '''and''' f(a) '''is''' (Just b) '''then''' <!--@ col 20 --> (g β f) a <!--@ col 16 --> '''else if''' ma '''is''' (Just a) '''and''' f(a) '''is Nothing then''' <!--@ col 20 --> Nothing <!--@ col 16 --> '''else''' <!--@ col 20 --> Nothing <!--@ col 16 --> '''end if'''
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)