Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repurpose Sign Example for Maybe Type in Documentation #120

Open
NickSeagull opened this issue Sep 8, 2024 · 0 comments
Open

Repurpose Sign Example for Maybe Type in Documentation #120

NickSeagull opened this issue Sep 8, 2024 · 0 comments

Comments

@NickSeagull
Copy link
Contributor

The current example function, getSign, determines if a number is positive, negative, or zero by returning one of three values: Positive, Negative, or Zero. However, this classification can be debated, as zero is often considered to have no sign at all. Given this interpretation, the example could better demonstrate the use of the Maybe type.

Proposed Change:

Modify the existing getSign function to return a Maybe Sign type, where:

  • Just Positive indicates a positive number.
  • Just Negative indicates a negative number.
  • Nothing represents zero, reflecting that zero has no sign.

Updated Code Example:

data Sign = Positive | Negative

-- Returns Maybe Sign to reflect the absence of sign for zero
getSign :: Int -> Maybe Sign
getSign n
  | n > 0 = Just Positive
  | n < 0 = Just Negative
  | otherwise = Nothing

Benefits:

  • Aligns with the mathematical interpretation that zero has no sign.
  • Demonstrates a practical use case for Maybe, making it easier to understand when and why to use this type in Haskell.

Impact on Documentation:

This change would update the Sign example in the documentation to provide a clearer and more nuanced understanding of Maybe. It would serve as a concrete illustration of how to handle values that might not exist, improving the educational value of the example.

Additional Context:

This suggestion is based on the reasoning that zero lacks a positive or negative sign, making Maybe a more suitable approach for this specific use case.

@NickSeagull NickSeagull added this to Docs Sep 8, 2024
@NickSeagull NickSeagull moved this to Todo in Docs Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

1 participant