-
Notifications
You must be signed in to change notification settings - Fork 48
Changes to Getting To Know Lean #223
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
base: master
Are you sure you want to change the base?
Conversation
If {anchorName SumProd}`α` and {anchorName SumProd}`β` are types that contain $`n` and $`k` distinct values, respectively, then {anchorTerm SumProd}`α ⊕ β` contains $`n + k` distinct values and {anchorTerm SumProd}`α × β` contains $`n \times k` distinct values. | ||
For instance, {anchorName fragments}`Bool` has two values: {anchorName BoolNames}`true` and {anchorName BoolNames}`false`, and {anchorName Unit}`Unit` has one value: {anchorName BooloUnit}`Unit.unit`. | ||
The product {anchorTerm fragments}`Bool × Unit` has the two values {anchorTerm BoolxUnit}`(true, Unit.unit)` and {anchorTerm BoolxUnit}`(false, Unit.unit)`, and the sum {anchorTerm fragments}`Bool ⊕ Unit` has the three values {anchorTerm BooloUnit}`Sum.inl true`, {anchorTerm BooloUnit}`Sum.inl false`, and {anchorTerm BooloUnit}`Sum.inr Unit.unit`. | ||
The product {anchorTerm fragments}`Bool × Unit` can have the two values {anchorTerm BoolxUnit}`(true, Unit.unit)` and {anchorTerm BoolxUnit}`(false, Unit.unit)`, and the sum {anchorTerm fragments}`Bool ⊕ Unit` can have the three values {anchorTerm BooloUnit}`Sum.inl true`, {anchorTerm BooloUnit}`Sum.inl false`, and {anchorTerm BooloUnit}`Sum.inr Unit.unit`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pay attention to the change made here, I put "can have" instead of "have" directly, as SumType
defined below don't have anything by default, but it can have the sum of all the possible variation of types it possess (I don't know how to explain obvious things)
def one : ProdType:= (false, Unit.unit) | ||
def two : ProdType:= (true, Unit.unit) | ||
``` | ||
Similarly, $`2 \times 1 = 2`, and $`2 + 1 = 3`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept the punchline at the end to keep it as a conclusion, alternatively, it might be suitable to add a text telling a bit more about this approach to computing/modeling ?
Functions like {anchorName maximum3Type}`maximum` that appear to take more than one argument are in fact functions that take one argument and then return a new function. | ||
This new function takes the next argument, and the process continues until no more arguments are expected. | ||
This can be seen by providing one argument to a multiple-argument function: {anchorTerm maximum3Type}`#check maximum 3` yields {anchorInfo maximum3Type}`maximum 3 : Nat → Nat`, giving it another Nat yields {anchorInfo maximum3Type}`maximum 3 4 : Nat`. {anchorTerm stringAppendHelloType}`#check spaceBetween "Hello "` yields {anchorInfo stringAppendHelloType}`spaceBetween "Hello" : String → String`, giving it another String yields {anchorInfo stringAppendHelloType}`spaceBetween "Hello" "world" : String`. | ||
Using a function that returns a function to implement multiple-argument functions is called _currying_ after the mathematician Haskell Curry, and Lean use currying by default as a core design choice related to its type system, a concept that will be explained later (Is it ?) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually couldn't find more information about currying in the book, this vague statement can be replaced with something more useful hopefully
:::paragraph | ||
Lean's standard library includes a canonical linked list datatype, called {anchorName fragments}`List`, and special syntax that makes it more convenient to use. | ||
Lists are written in square brackets. | ||
Lean's standard library includes a canonical linked list datatype, called {anchorName fragments}`List`, and special syntaxes that makes it more convenient to use. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either syntax that makes
or syntaxes that make
. But I think it should be syntax
(singular). There is one special syntax, namely the one with brackets. There is another syntax with cons/nil, but this sentence is only referring to the bracket syntax, and not this other one.
This PR regroup any future changes to not spam, its a continuation of my previous PRs
The changes done are aimed at fostering discussion into what to actually change in the book, the work already done is massive and my changes may be irrelevant, incorrect, etc as I am a complete beginner so please take everything as a feedback rather than an actual request for changes. A PR allow me to write everything how I see it instead of explaining how I would see them etc.
Again, thank you for the work you've done so far, its quite big!