Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

/prog/BOL 2012

Name: Anonymous 2012-01-22 12:03

identity is of type for all types A, A to A.
define function identity of x:
   return x.
end.

constant is of type for all types A and B, A to B to A.
define function constant of x of y:
   return x.
end.

define factorial of type int to int of n:
   if n equals 0, then: return 1.
   else: return n times factorial of (n minus 1).
end.

Name: Anonymous 2012-01-26 3:35

>>46

sure, why not.

here's a start....


    identity is of type for all types A, A to A.
    define function identity of x:
       return x.
    end.

    constant is of type for all types A and B, A to B to A.
    define function constant of x of y:
       return x.
    end.

    define factorial of type int to int of n:
       if n equals 0, then: return 1.
       else: return n times factorial of (n minus 1).
    end.
type_declaration : identifier 'is' 'of' 'type' type_expression '.'
                 ;

type_expression : optional_type_quanitification type_sequence
                ;

optional_type_quanitification : type_quantification ','
                              |
                              ;

type_quantification : 'for' 'all' 'types' type_list
                    ;

type_sequence : type_expression
              | type_sequence 'to' type_name
              ;

type_list_ : type_expression
           | type_list_ ',' type_expression
           ;

type_list : type_expression
          | type_list_ ',' 'and' type_expression
          ;

argument_list_declaration_ : identifier
                           | argument_list_declaration ',' identifier
                           ;

argument_list_declaration :  identifier                              COMMENT: are functions allowed to not take any arguments?
                          | argument_list_declaration_ ',' 'and' identifier
                          ;

type_name : identifier
          ;

optional_function_type : 'of' 'type' type_expression
                       |
                       ;

function_definition : 'define' identifier optional_function_type 'of' argument_list_declaration ':' function_body 'end' '.'

function_body : ....

expression : ...

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List