Skip to content

Instantly share code, notes, and snippets.

@apstndb
Created April 22, 2020 14:54
Show Gist options
  • Save apstndb/8bda40aaa8da92bd3eab85860faedea9 to your computer and use it in GitHub Desktop.
Save apstndb/8bda40aaa8da92bd3eab85860faedea9 to your computer and use it in GitHub Desktop.

Revisions

  1. apstndb renamed this gist Apr 22, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. apstndb created this gist Apr 22, 2020.
    38 changes: 38 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    ```
    $ ./go2go run main.go2
    true
    ```

    ```
    $ ./go2go translate main.go2
    $ cat main.go
    // Code generated by go2go; DO NOT EDIT.


    //line main.go2:1
    package main

    //line main.go2:1
    import "fmt"

    //line main.go2:13
    type Test struct{}

    func (Test) Equal(_ Test) bool {
    return true
    }

    func main() {
    fmt.Println(instantiate୦୦Eq୦main୮aTest(Test{}, Test{}))
    }
    //line main.go2:9
    func instantiate୦୦Eq୦main୮aTest(left, right Test,) bool {
    return left.Equal(right)
    }

    //line main.go2:11
    type Importable୦ int

    //line main.go2:11
    var _ = fmt.Errorf
    ```
    21 changes: 21 additions & 0 deletions main.go2
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    package main

    import "fmt"

    contract contract(T) {
    T Equal(T) bool
    }

    func Eq(type T contract)(left, right T) bool {
    return left.Equal(right)
    }

    type Test struct {}

    func (Test) Equal(_ Test) bool {
    return true
    }

    func main() {
    fmt.Println(Eq(Test{}, Test{}))
    }