shithub: mc

Download patch

ref: 21eb277c5a5d3178eed36c23466cd4abdede5122
parent: 8775024dce46b5ba730b8f892111d9d7b7c56a66
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Jan 21 11:05:56 EST 2017

Shuffle around documentation for leaf types.

--- a/doc/lang.txt
+++ b/doc/lang.txt
@@ -362,132 +362,131 @@
         must be explicitly cast if you want to convert, and the casts must
         be of compatible types, as will be described later.
 
-            4.1.1. Primitive types:
+        4.1.1. Primitive types:
 
-                    void
-                    bool            char
-                    int8            uint8
-                    int16           uint16
-                    int32           uint32
-                    int64           uint64
-                    int             uint
-                    long            ulong
-                    float32         float64
+                void
+                bool            char
+                int8            uint8
+                int16           uint16
+                int32           uint32
+                int64           uint64
+                int             uint
+                long            ulong
+                flt32         flt64
 
-		'void' is a type and a value  although for the sake of
-		genericity, you can assign between void types, return values
-		of void, and so on.  This allows generics to not have to
-		somehow work around void being a toxic type. The void value is
-		named `void`.
+            'void' is a type and a value  although for the sake of
+            genericity, you can assign between void types, return values
+            of void, and so on.  This allows generics to not have to
+            somehow work around void being a toxic type. The void value is
+            named `void`.
 
-                It is interesting to note that these types are not keywords,
-                but are instead merely predefined identifiers in the type
-                namespace.
+            It is interesting to note that these types are not keywords,
+            but are instead merely predefined identifiers in the type
+            namespace.
 
-                bool is a type that can only hold true and false. It can be
-                assigned, tested for equality, and used in the various boolean
-                operators.
+            bool is a type that can only hold true and false. It can be
+            assigned, tested for equality, and used in the various boolean
+            operators.
 
-		char is a 32 bit integer type, and is guaranteed to hold
-		exactly one Unicode codepoint. It can be assigned integer
-		literals, tested against, compared, and all the other usual
-		numeric types.
+            char is a 32 bit integer type, and is guaranteed to hold
+            exactly one Unicode codepoint. It can be assigned integer
+            literals, tested against, compared, and all the other usual
+            numeric types.
 
-                The various [u]intXX types hold, as expected, signed and
-                unsigned integers of the named sizes respectively.
-                Similarly, floats hold floating point types with the
-                indicated precision.
+            The various [u]intXX types hold, as expected, signed and
+            unsigned integers of the named sizes respectively.
+            Similarly, floats hold floating point types with the
+            indicated precision.
 
-                    var x : int         declare x as an int
-                    var y : float32     declare y as a 32 bit float
+                var x : int         declare x as an int
+                var y : float32     declare y as a 32 bit float
 
 
-            4.1.2. Composite types:
+        4.1.2. Composite types:
 
-                    pointer
-                    slice           array
+                pointer
+                slice           array
 
-                Pointers are, as expected, values that hold the address of
-                the pointed to value. They are declared by appending a '#'
-                to the type. Pointer arithmetic is not allowed. They are
-                declared by appending a '#' to the base type
+            Pointers are, as expected, values that hold the address of
+            the pointed to value. They are declared by appending a '#'
+            to the type. Pointer arithmetic is not allowed. They are
+            declared by appending a '#' to the base type
 
-                Arrays are a group of N values, where N is part of the type.
-                Arrays of different sizes are incompatible. Arrays in
-                Myrddin, unlike many other languages, are passed by value.
-                They are declared by appending a '[SIZE]' to the base type.
+            Arrays are a group of N values, where N is part of the type,
+            meaning that different sizes are incompatible. They are
+            passed by value. Their size must be a compile time constant.
 
-                Slices are similar to arrays in many contemporary languages.
-                They are reference types that store the length of their
-                contents. They are declared by appending a '[,]' to the base
-                type.
+            Slices are similar to arrays in many contemporary languages.
+            They are reference types that store the length of their
+            contents. They are declared by appending a '[,]' to the base
+            type.
 
-                    foo#        type: pointer to foo
-                    foo[123]    type: array of 123 foo
-                    foo[,]      type: slice of foo
+                foo#        type: pointer to foo
+                foo[N]      type: array size N of foo
+                foo[:]      type: slice of foo
 
-            4.1.3. Aggregate types:
+        4.1.3. Aggregate types:
 
-                    tuple           struct
-                    union
+                tuple           struct
+                union
 
-                Tuples are the traditional product type. They are declared
-                by putting the comma separated list of types within square
-                brackets.
+            Tuples are the traditional product type. They are declared
+            by putting the comma separated list of types within square
+            brackets.
 
-                Structs are aggregations of types with named members. They
-                are declared by putting the word 'struct' before a block of
-                declaration cores (ie, declarations without the storage type
-                specifier).
+            Structs are aggregations of types with named members. They
+            are declared by putting the word 'struct' before a block of
+            declaration cores (ie, declarations without the storage type
+            specifier).
 
-                Unions are the traditional sum type. They consist of a tag
-                (a keyword prefixed with a '`' (backtick)) indicating their
-                current contents, and a type to hold. They are declared by
-                placing the keyword 'union' before a list of tag-type pairs.
-                They may also omit the type, in which case, the tag is
-                sufficient to determine which option was selected.
+            Unions are the traditional sum type. They consist of a tag
+            (a keyword prefixed with a '`' (backtick)) indicating their
+            current contents, and a type to hold. They are declared by
+            placing the keyword 'union' before a list of tag-type pairs.
+            They may also omit the type, in which case, the tag is
+            sufficient to determine which option was selected.
 
-                    [int, int, char]            a tuple of 2 ints and a char
+                [int, int, char]            a tuple of 2 ints and a char
 
-                    struct                      a struct containing an int named
-                        a : int                 'a', and a char named 'b'.
-                        b : char
-                    ;;
+                struct                      a struct containing an int named
+                    a : int                 'a', and a char named 'b'.
+                    b : char
+                ;;
 
-                    union                       a union containing one of
-                        `Thing int              int or char. The values are not
-                        `Other float32          named, but they are tagged.
-                    ;;
+                union                       a union containing one of
+                    `Thing int              int or char. The values are not
+                    `Other float32          named, but they are tagged.
+                ;;
 
 
-            4.1.4. Generic types:
+        4.1.4. Generic types:
 
-                    tyvar           typaram
-                    tyname
+                tyvar           typaram
+                tyname
 
-                A tyname is a named type, similar to a typedef in C, however
-                it genuinely creates a new type, and not an alias. There are
-                no implicit conversions, but a tyname will inherit all
-                constraints of its underlying type.
+            A tyname is a named type, similar to a typedef in C, however
+            it genuinely creates a new type, and not an alias. There are
+            no implicit conversions, but a tyname will inherit all
+            constraints of its underlying type.
 
-                A typaram is a parametric type. It is used in generics as
-                a placeholder for a type that will be substituted in later.
-                It is an identifier prefixed with '@'. These are only valid
-                within generic contexts, and may not appear elsewhere.
+            A typaram is a parametric type. It is used in generics as
+            a placeholder for a type that will be substituted in later.
+            It is an identifier prefixed with '@'. These are only valid
+            within generic contexts, and may not appear elsewhere.
 
-                A tyvar is an internal implementation detail that currently
-                leaks in error messages out during type inference, and is a
-                major cause of confusing error messages. It should not be in
-                this manual, except that the current incarnation of the
-                compiler will make you aware of it. It looks like '@$type',
-                and is a variable that holds an incompletely inferred type.
+            A tyvar is an internal implementation detail that currently
+            leaks in error messages out during type inference, and is a
+            major cause of confusing error messages. It should not be in
+            this manual, except that the current incarnation of the
+            compiler will make you aware of it. It looks like '@$type',
+            and is a variable that holds an incompletely inferred type.
 
-                    type mine = int             creates a tyname named
-                                                'mine', equivalent to int.
+                type mine = int             creates a tyname named
+                                            'mine', equivalent to int.
 
 
-                    @foo                        creates a type parameter
-                                                named '@foo'.
+                @foo                        creates a type parameter
+                                            named '@foo'.
     4.2. Type Inference:
 
         The myrddin type system is a system similar to the Hindley Milner
@@ -503,162 +502,114 @@
         It begins by initializing all leaf nodes with the most specific
         known type for them as follows:
 
-        4.6.1 Types for leaf nodes:
+    5.2. Literal Values
 
-            Variable        Type
-            ----------------------
-            var foo         $t
+        5.1.1. Atomic Literals:
 
-                A type variable is the most specific type for a declaration
-                or function without any specified type
+                literal:    strlit | chrlit | intlit |
+                            boollit | voidlit | floatlit |
+                            funclit | seqlit | tuplit
 
-            var foo : t     t
+                strlit:     \"(byte|escape)*\"
+                chrlit:     \'(utf8seq|escape)\'
+                char:       <any byte value>
+                boollit:    "true"|"false"
+                voidlit:    "void"
+                escape:     <any escape sequence>
+                intlit:     "0x" digits | "0o" digits | "0b" digits | digits
+                floatlit:   digit+"."digit+["e" digit+]
 
-                If a type is specified, that type is taken for the
-                declaration.
+            5.1.1.1. String Literals:
 
-            "asdf"          byte[:]
+                String literals represent a compact method of representing a
+                byte array. Any byte values are allowed in a string literal,
+                and will be spit out again by the compiler unmodified, with
+                the exception of escape sequences.
 
-                String literals are byte arrays.
+                There are a number of escape sequences supported for both character
+                and string literals:
+                    \n          newline
+                    \r          carriage return
+                    \t          tab
+                    \b          backspace
+                    \"          double quote
+                    \'          single quote
+                    \v          vertical tab
+                    \\          single slash
+                    \0          nul character
+                    \xDD        single byte value, where DD are two hex digits.
+                    \u{xxx}     unicode escape, emitted as utf8.
 
+                String literals begin with a ", and continue to the next
+                unescaped ".
 
-            'a'             char
+                    eg: "foo\"bar"
 
-                Char literals are of type 'char'
-
-            void            void
+                Multiple consecutive string literals are implicitly merged to create
+                a single combined string literal. To allow a string literal to span
+                across multiple lines, the new line characters must be escaped.
+                
+                    eg: "foo" \
+                        "bar"
 
-                void is a literal value of type void.
+                They have the type `byte[:]`
 
-            true            bool
-            false           bool
+            5.1.1.2. Character Literals:
 
-                true/false are boolean literals
+                Character literals represent a single codepoint in the
+                character set. A character starts with a single quote,
+                contains a single codepoint worth of text, encoded either as
+                an escape sequence or in the input character set for the
+                compiler (generally UTF8).  They share the same set of escape
+                sequences as string literals.
 
-            123             $t::(integral,numeric)
+                    eg: 'א', '\n', '\u{1234}'
 
-                Integer literals get a fresh type variable of type with
-                the constraints for int-like types.
+                They have the type `char`.
 
-            123.1           $t::(floating,numeric)
+            5.1.1.3. Integer Literals
 
-                Float literals get a fresh type variable of type with
-                the constraints for float-like types.
+                Integers literals are a sequence of digits, beginning with a digit
+                and possibly separated by underscores. They may be prefixed with
+                "0x" to indicate that the following number is a hexadecimal value,
+                0o to indicate an octal value, or 0b to indicate a binary value.
+                Decimal values are not prefixed.
 
-            {a,b:t; }       ($a,t -> $b)
+                    eg: 0x123_fff, 0b1111, 0o777, 1234
 
-                Function literals get the most specific type that can
-                be determined by their signature.
+                They have the type `@a::(numeric,integral)
 
+            5.1.1.4: Boolean Literals:
 
-        num-binop:
+                Boolean literals are spelled `true` or `false`.
+                Unsurprisingly, they evaluate to `true` or `false`
+                respectively.
 
-                +           -               *               /               %
-                +=          -=              *=              /=              %
+                    eg: true, false
 
-            Number binops require the constraint 'numeric' for both the
+                They have the type `bool`
 
-        num-unary:
-            -           +
-            Number binops require the constraint 'numeric'.
+            5.1.1.4: Boolean Literals:
 
-        int-binop:
-            |           &               ^               <<              >>
-            |=          &=              ^=              <<=             >>
-        int-unary:
-            ~           ++              --
+                Void literals are spelled `void`. They evaluate to the void
+                value, a value that takes zero bytes storage, and contains
+                only the value `void`. Like my soul.
 
-        bool-binop:
-            ||          &&              ==              !=
-            <           <=              >               >=
+                    eg: void
 
-5. VALUES AND EXPRESSIONS:
+                They have type `void`.
 
-    5.2. Literal Values
+            5.1.1.5: Floating point literals:
 
-        5.1.1. Atomic Literals:
+                Floating-point literals are also a sequence of digits beginning with a
+                digit and possibly separated by underscores. Floating point
+                literals are always in decimal.
 
-                literal:    strlit | chrlit | floatlit |
-                            boollit | voidlit | intlit |
-                            funclit | seqlit | tuplit
+                    eg: 123.456, 10.0e7, 1_000.
 
-                strlit:     \"(byte|escape)*\"
-                chrlit:     \'(utf8seq|escape)\'
-                char:       <any byte value>
-                escape:     <any escape sequence>
-                intlit:     "0x" digits | "0o" digits | "0b" digits | digits
-                floatlit:   digit+"."digit+["e" digit+]
-                boollit:    "true"|"false"
-                voidlit:    "void"
+                They have type `@a::(numeric,floating)`
 
-            Integers literals are a sequence of digits, beginning with a digit
-            and possibly separated by underscores. They may be prefixed with
-            "0x" to indicate that the following number is a hexadecimal value,
-            0o to indicate an octal value, or 0b to indicate a binary value.
-            Decimal values are not prefixed.
 
-                eg: 0x123_fff, 0b1111, 0o777, 1234
-
-            Integer literals have the type `@a::(numeric,integral)`.
-
-            Floating-point literals are also a sequence of digits beginning with a
-            digit and possibly separated by underscores. Floating point
-            literals are always in decimal.
-
-                eg: 123.456, 10.0e7, 1_000.
-
-            Floating point literals have the type `@a::(numeric,floating)`.
-
-            String literals represent a compact method of representing a byte
-            array. Any byte values are allowed in a string literal, and will be
-            spit out again by the compiler unmodified, with the exception of
-            escape sequences.
-
-            There are a number of escape sequences supported for both character
-            and string literals:
-                \n          newline
-                \r          carriage return
-                \t          tab
-                \b          backspace
-                \"          double quote
-                \'          single quote
-                \v          vertical tab
-                \\          single slash
-                \0          nul character
-                \xDD        single byte value, where DD are two hex digits.
-                \u{xxx}     unicode escape, emitted as utf8.
-
-            String literals begin with a ", and continue to the next
-            unescaped ".
-
-                eg: "foo\"bar"
-
-            Multiple consecutive string literals are implicitly merged to create
-            a single combined string literal. To allow a string literal to span
-            across multiple lines, the new line characters must be escaped.
-            
-                eg: "foo" \
-                    "bar"
-
-            String literals have the type `byte[:]`
-
-            Character literals represent a single codepoint in the character
-            set. A character starts with a single quote, contains a single
-            codepoint worth of text, encoded either as an escape sequence
-            or in the input character set for the compiler (generally UTF8).
-            They share the same set of escape sequences as string literals.
-
-                eg: 'א', '\n', '\u{1234}'
-
-            Character literals have the type `char`
-
-            Boolean literals are either the keyword "true" or the keyword
-            "false".
-
-                eg: true, false
-
-            Boolean literals have the type `bool`
-
         5.1.2. Sequence and Tuple Literals:
             
                 seqlit:     "[" structelts | arrayelts "]"
@@ -707,7 +658,12 @@
             Example: Tuple literals:
                 (1,), (1,'b',"three")
 
+            A tuple has the type of its constituent values grouped
+            into a tuple:
 
+                (@a, @b, @c, ..., @z)
+
+
         5.1.3. Function Literals:
 
                 funclit:        "{" arglist "\n" blockbody "}"
@@ -748,6 +704,9 @@
                     var b = {; a + 1}
                 }
 
+            A function literal has the arity of its argument list,
+            and shares their type if it is provided. Otherwise,
+            they are left generic. The same applies to the return type.
 
         5.1.4: Labels: