Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Haskell
Wiki community
Recent changes
Random page
HaskellWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Handling errors in Haskell
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
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!
== No value using the Maybe type == There is simply no value there. This isn't a problem in the system. It means you don't care why there isn't a value, or you already know. <hask>Maybe a</hask> Typical example: <haskell> lookup :: Eq a => a -> [(a,b)] -> Maybe b </haskell> That is, take some key <hask>a</hask> that can be compared for equality, and a list of pairs where the first is the same type of the key <hask>a</hask> and maybe return the <hask>b</hask> of the pair, or nothing. So one might pattern match on this: <haskell> case lookup name person of Nothing -> "no name specified" Just name -> "Name: " <> name </haskell> Or use a deconstructing function: <haskell> maybe "no name specified" ("Name: " <>) (lookup name person) </haskell> Again, depends on the code and the person writing it whether an explicit case is used. Often monads like <hask>Maybe</hask> are composed to make a chain of possibly-nothing values: <haskell> lookup "height" profile >>= parseInt >>= flip lookup recommendedSizes </haskell> So lookup a height from a person's profile (might not exist), parse it as integer (might not parse), then use that as a key to lookup from a mapping list of age to clothes size: <hask>[(Int,Text)]</hask>
Summary:
Please note that all contributions to HaskellWiki are considered to be released under simple permissive license (see
HaskellWiki:Copyrights
for details). If you don't want your writing to be edited mercilessly and redistributed at will, then don't submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
DO NOT SUBMIT COPYRIGHTED WORK WITHOUT PERMISSION!
Cancel
Editing help
(opens in new window)
Toggle limited content width