Skip to content

Updates to Basics / Values and Types, up through the text section #11

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

cdsmith
Copy link
Collaborator

@cdsmith cdsmith commented Jan 13, 2023

Some of these changes are debatable, so I'd love to get your feedback.

Some of these changes are debatable, so I'd love to get your feedback.
@netlify
Copy link

netlify bot commented Jan 13, 2023

Deploy Preview for haskell-docs ready!

Name Link
🔨 Latest commit 8ee6f04
🔍 Latest deploy log https://app.netlify.com/sites/haskell-docs/deploys/63c11436a3e9d10008e3157e
😎 Deploy Preview https://deploy-preview-11--haskell-docs.netlify.app/basics/types
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@reubenharry
Copy link
Owner

Thanks for doing this! Partway through reviewing (but will finish later today).

Generally, my comments are aimed at the style, in particular trying to avoid explanatory prose where possible in favour of clear examples followed by commentary (not always possible)

Copy link
Owner

@reubenharry reubenharry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, review complete. Sorry for the number and detail of the comments! (I figured that being picky was the best way to align on style). Feel free to disagree, of course.

General feedback: I'm putting a very high cost on prose in the main narrative of the docs, so most of the comments are of the form: is there a way that this information can be communicated implicitly or references against a different section. The reasons are:

  1. Avoid overwhelming reader with too many concepts
  2. Give the reader a choice of how deeply to read (i.e. ignoring comments, boxes).

@@ -2,89 +2,224 @@
comments: true
---

## The type of Booleans
Haskell's type system is such an important feature, and so useful for understanding the language, that it is a good place to begin. This section will explore different Haskell values and their types.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"This section will explore different Haskell values and their types." - on reflection, I could probably leave out this sentence, since it's evidence from the table of contents.


* An *expression* is a piece of Haskell source code that describes a value.
* A *value* is the meaning of an expression.
* A *type* is a category of values or expressions that can be used in the same ways.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newcomers may be primed to misinterpret the word "category" here if they've heard of the Haskell link to category theory.

* A *value* is the meaning of an expression.
* A *type* is a category of values or expressions that can be used in the same ways.

For example, `True` is a Haskell *value*. Its *type* is `Bool`. There are several other Haskell *expressions* (like `True && True` or `False || True`) that have the same value. In Haskell, we can state this as:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion would be:

"For example, True is a Haskell value. Its type is Bool. Other Haskell expressions may have the same value:"

Then in code comments, we could state, in case still unclear, that (True && True) is an expression with the same value as True.

`True` is a value in Haskell. Its *type* is `Bool`. In Haskell, we can state this as:
## The type of Boolean values

Here are three words that are central to understanding Haskell.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sympathise with the intent here, and now realize I was using "value" not very carefully - thanks for addressing that! My only objection is that I want to avoid didactic prose as much as possible. My suggestion would be to put lines 11-13 in a "!!! Note" box after the repl example.

That fits the intended style better, which is: example + comments + parenthetic commentary

```

Similarly,
1. A source file contains *declarations* instead expressions, so we define new variables. It's also possible write `example1 = True :: Bool`, but it's unusual. More commonly, Haskell source files contain the type of a definition on a separate line from the value as shown here.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just:

"A source file contains declarations, like example1 = True. It's also possible write example1 = True :: Bool, but more commonly, Haskell source files contain the type of a definition on a separate line from the value as shown here."


`Int` is a type for integers, as in:
`Int` is one type for integers. An `Int` is a signed integer with a fixed number of bits, but the exact number of bits depends on the Haskell implementation and architecture.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this additional info be in a footnote?

x = 5
```

Sometimes you might want to work with integers whose values can be arbitrarily large. For this, there's another type: `Integer`. The same expression, `5`, can be used to describe an `Integer`, as well!
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be nice in an optional "??? Tip" section.

y2 = 5 * 1000000000000000000
```

An expression like `5` that can more than one type is said to be *overloaded*. It can describe different values depending on the type it's used as.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the subsequent Gotcha section, and the part you added, I think this is redundant.

```haskell
{-# LANGUAGE OverloadedStrings #-} --(1)!
import Data.Text (Text)
Floating point numbers are fixed precision, so doing computations with them can result in rounding error. An exact option for numbers with a fractional part is `Rational`, which can represent any rational number (that is, any fraction) exactly.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Footnote or optional text box.

c2 = 'b'
```

`Text` is the best type for most sequences of characters. However, there's a bit of boilerplate needed to use it.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a slight preference for not saying there's boilerplate, but just having code comments for the import line and the extension line, in the service of a "show, don't tell" style. But I won't die on this hill.

@cdsmith
Copy link
Collaborator Author

cdsmith commented Jan 20, 2023

I'm going to close this while I decide what I think about contributing to documentation with copyleft licenses...

@cdsmith cdsmith closed this Jan 20, 2023
@reubenharry
Copy link
Owner

I'm going to close this while I decide what I think about contributing to documentation with copyleft licenses...

@cdsmith Some context: I don't know anything about licenses, and added this on the suggestion of someone on discourse: https://discourse.haskell.org/t/haskell-guide-cross-posted-on-reddit/5605/8 .

The last thing I want is to have a license which discourages anyone from contributing, so I'm more than happy to change/remove this. What would you recommend as a non-controversial choice?

@reubenharry
Copy link
Owner

I'm going to close this while I decide what I think about contributing to documentation with copyleft licenses...

@cdsmith Some context: I don't know anything about licenses, and added this on the suggestion of someone on discourse: https://discourse.haskell.org/t/haskell-guide-cross-posted-on-reddit/5605/8 .

The last thing I want is to have a license which discourages anyone from contributing, so I'm more than happy to change/remove this. What would you recommend as a non-controversial choice?

I replaced the copyleft license with the permissive Creative commons one for now.

@cdsmith cdsmith reopened this Jan 21, 2023
@reubenharry
Copy link
Owner

Hi, I just wanted to check in on this PR, in the spirit of moving towards a "version 1" of this guide. I'm happy to attempt the suggested changes myself if you'd prefer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants