Nothing is the Maybe constructor for absence: it contains no value. A Maybe value is therefore either Just a value or Nothing, allowing a pure function to report failure without crashing. Nothing also represents an optional result or argument. section 3.3.2
Parsing an optional file path
A parser can return Just filePath when it receives exactly one path, and Nothing for every other argument list. Its result type becomes Maybe FilePath. Pattern matching handles both cases; fromMaybe supplies a default when the result is Nothing. section 3.3.2
Nothing carries meaning through pattern matching:
- Use Nothing to encode a missing value or recoverable fault as data. section 3.3.2
- Match Nothing separately because it contains no value to extract. section 3.3.2
- In alter, Nothing can mean either that a key is absent or that an existing mapping should be deleted; Just supplies an inserted or updated value. section 5.2
Listing 3.5 A simple argument-parsing function with Maybe
parseArguments :: [String] -> Maybe FilePath parseArguments [filePath] = Just filePath #1 parseArguments _ = Nothing #2
Browse a complete argument parser that returns Nothing when its input does not contain exactly one file path. section 3.3.2

