-
Notifications
You must be signed in to change notification settings - Fork 26
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
WIP: Expanded documentation (inc. @gteege's manual) #334
base: master
Are you sure you want to change the base?
Conversation
I've split this PR into two parts --- the majority of the commits (but not the majority of the changes) come from what is now #338; this PR notionally depends on changes introduced there. |
5f8dd18
to
85c55a0
Compare
cf29dc8
to
b9e2ae0
Compare
cf69c6d
to
2b81607
Compare
57dec82
to
a6597d8
Compare
5233f89
to
2a21bc0
Compare
80b66cd
to
a6166cf
Compare
Most of the transformation was done automatically with a gnarly mess of Emacs-Lisp, and was cleaned up a bit (especially the custom TeX macros) by hand. This is a temporary location --- I'll be working on folding this into the rest of the manual, copy-editing, etc. [skip ci][skip lemma]
The 'introduction' expands the 'getting started' documentation, a quick installation reference, and the first programs. The 'reference' is intended to combines the previous (proto-reference) documentation with Gunnar Teege's manual, expanding and clarifying them. [skip ci][skip lemma]
[skip ci][skip lemma]
[skip ci][skip lemma]
[skip ci][skip lemma]
[skip ci][skip lemma]
Split up the old 'getting started' page; the examples can be fleshed out some more and cleaned up, which is on the todo list. [skip ci][skip lemma]
[skip ci][skip lemma]
[skip ci][skip lemma]
…ASH ^{10}) [skip ci][skip lemma]
[skip ci][skip lemma]
[skip ci][skip lemma]
…SQUASH ^{13}) [skip ci][skip lemma]
[skip ci][skip lemma]
[skip ci][skip lemma]
[skip ci][skip lemma]
[skip ci][skip lemma]
…. (SQUASH ^{17}) [skip ci][skip lemma]
[skip ci][skip lemma]
[skip ci][skip lemma]
[skip ci][skip lemma]
[skip ci][skip lemma]
…SH ^{22}) A gentle, step-wise introduction to the `add' function unfolds, where we build up the language's capabilities piecewise. Instead of diving into a polymorphic type definition, let's start with a very simple function, and build from there. [skip ci][skip lemma]
…{23}) [skip ci][skip lemma]
[skip ci][skip lemma]
[skip ci][skip lemma]
[skip ci][skip lemma]
[skip ci][skip lemma]
[skip ci][skip lemma]
[skip ci][skip lemma]
[skip ci][skip lemma]
Based on discussions with Peter Chubb, some of my own experiments to clarify behaviours, and presented here for first review. Much, much more work is needed, of course. [skip ci][skip lemma]
Includes changes derived from feedback from Louis Cheung -- thanks!
3e0764a
to
f5dc7f1
Compare
and there are several quotation types: | ||
|
||
- ``$id:(IDENT)`` introduces ``IDENT`` as an identifier; | ||
- ``$ty:(TYPE-NAME)`` refers to the type ``TYPE-NAME``; |
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.
It's not necessarily a "type name". It can be any type, including the parameterised ones, like $ty:(Array t)
.
- ``$id:(IDENT)`` introduces ``IDENT`` as an identifier; | ||
- ``$ty:(TYPE-NAME)`` refers to the type ``TYPE-NAME``; | ||
- ``$exp:(EXPRESSION)`` inserts code to execute ``EXPRESSION``; | ||
- ``$spec:(TYPE-NAME)`` injects an appropriate C typecast; and |
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.
The purpose of this antiquote is not for typecasting. It only uses typecast's syntax, but the generated C code will be a higher-order function application. The entire antiquoted C mechanism uses the antiquotation is the Haskell C parser, repurposed. Thus we have to choose antiquotes that already exist in the C parser, and they should make sense intuitively. In this case, the typecast antiquote is the best that I can find that makes some sense (that there is one dispatch function for each function type A -> B
and that's the "spec" for us to choose which dispatch function to invoke), but apparently less so compared to the others like $ty
or $exp
.
Quotation types influence this transformation, | ||
and there are several quotation types: | ||
|
||
- ``$id:(IDENT)`` introduces ``IDENT`` as an identifier; |
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.
It doesn't quite introduce an identifier. It "instantiates" a polymorphic function/type's name. So we only need to use $id
when the function/type is polymorphic, so that it can derive the monomorphised name.
|
||
We can then implement this function in C:: | ||
$ty:(U32) u32_from_u8 ($ty:(U8) x) { return x; } |
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'm not quite sure if antiquoting U8
or U32
are good examples. Usually these type don't need antiquotation at all. We know that they become u8
and u32
defined by the stdlib. I'm afraid it will mislead users to use them this way and lead to a more verbose antiquoted C.
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.
my intent here (and, indeed, in most of this rewrite) is to introduce each specific element relatively carefully and clearly: exemplifying the syntax via trivially simple examples before getting to more complex (and realistic) examples feels (to me) to be a good way to introduce this, and my eventual goal is to provide more reference description. I posit the example of the trivial Cogent type U8
being transformed into the C type u8
is what I want to illustrate here. I will add some more words to suggest this is highly unusual to see, though.
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.
Alternatively you can just be vague about the type, say T
(we don't even need to know what it is, as long as it's used in the Cogent program), if you think it still keeps the matter simple for your purpose.
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.
Thinking about it twice, antiquoting primitive types isn't that bad, or at least I shouldn't feel bad about it, as I never complain about the verbosity of the antiquoted C files.
|
||
type Result t e = < Ok t | Err e > |
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 think better examples would be to use the structural types in antiquotes directly (e.g. $ty:((U32, U8))
). Type names aren't really a thing in Cogent's structural type system, they gets desugared away very early in the compilation. I would like the doc to discourage users to focus on type synonyms too much.
where the type definition ``t1`` was previously generated. | ||
Beware that the |cogent| compiler | ||
may not always emit the type's definition, | ||
even if it emits a reference to 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.
Maybe be a bit more explicit: the Cogent type appearing in antiquotes have to be types that already get used in the Cogent code ("used" means that it not only appears in the code, but also used by the entry-point functions or their dependencies.
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.
And a common troubleshooting: if it generates a new C type name t42
but without the definition of it, it's usually because some new Cogent type is used in the antiquote.
|
||
Antiquoted C introduces an *antiquote*, | ||
which takes the form | ||
``$``, quotation type, ``:``, and a (usually parenthesised) term; |
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.
If it's a single word starting with lowercase, then no parens are needed. It's still useful to reduce the verbosity. On the other hand, if it antiquotes a tuple, then at least two pairs of parens are needed, one for the antiquote, and one for the tuple.
``$esc`` and ``$escstm``: No Escape In Sight | ||
-------------------------------------------- | ||
|
||
``$esc:(PREPROCESSOR-DIRECTIVE)`` and |
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.
The thing inside the $esc
and $escstm
doesn't have to be a cpp directive. It can be anything that the user doesn't want the Cogent compiler to see. The only different is that $esc
is top-level, and $escstm
is on the statement level. The only criterion is that if you remove the entire $esc
and $escstm` antiquotes, the rest should still be valid antiquote C.
this PR substantially expands the Cogent documentation. the result is in two parts:
rendered preview: https://cogent--334.org.readthedocs.build/en/334/