[ int, int ] foo1( int ); // overloaded foo functions [ double ] foo2( int ); void bar( int, double, double ); bar( foo( 3 ), foo( 3 ) );
The type resolver only has the tuple return types to resolve the call to
Comparison of C∀ and Go tuples.
C∀ | Go |
---|---|
#include <fstream.hfa> [int, int ] f() { return [3, 7]; } void g( int a, int b ) { sout | a | b; } int main() { sout | f(); g( f() ); int a, b, c; [a, b] = f(); sout | a | b; c = f().1; sout | c; c = f().0; sout | c; [10] int w = { a, b }; sout | nlOff; for ( i; 10 ) sout | w[i]; sout | nlOn; sout | nl; // Go does not have tuple variables [int, int, int] t = [1, 2, 3]; sout | t; [a, b] = [t.2, t.0]; // reorder and drop tuple elements sout | a | b; } |
package main import "fmt" func f() (int, int) { return 3, 7 } func g( a, b int ) { fmt.Println( a, b ) } func main() { fmt.Println( f() ) g( f() ) a, b := f() fmt.Println( a, b ) _, c := f() fmt.Println(c) c, _ = f() fmt.Println(c) w := [10]int{ a, b } fmt.Println(w) } |
Variadic functions are provides by the new kind of parameter type,
For example, a type-safe variadic print function to replace
forall( T,ttype Params | { void print(T); void print(Params); } ) void print(T arg, Params rest) { print(arg); print(rest); // recursive usage } void print( int x ) { printf( "%d", x ); } void print( double x ) { printf( "%g", x ); } void print( const char * x ) { printf( "%s", x ); } // all other basic types struct S { int x, y; }; // user type void print( S s ) { print( "{ ", s.x, ",", s.y, " }" ); } int main() { print( 5, " ", 3.5, " ", (S){ 1, 2 }, "\n" ); }
It is possible to use
forall( T | sized(T),ttype Params | { void ?{}( T &, Params ); } ) T *new ( Params p ) { return &(*malloc()){ p }; // run constructor } forall( R, S ) struct pair { R first; S second; } forall( R, S ) void ?{}( pair(R, S) &, R, S ); pair( int, char ) * x =new ( 42, '!' );
The