| 1 |
// run |
| 2 |
|
| 3 |
// Copyright 2021 The Go Authors. All rights reserved. |
| 4 |
// Use of this source code is governed by a BSD-style |
| 5 |
// license that can be found in the LICENSE file. |
| 6 |
|
| 7 |
package main |
| 8 |
|
| 9 |
import "fmt" |
| 10 |
|
| 11 |
type Exp[Ty any] interface { |
| 12 |
Eval() Ty |
| 13 |
} |
| 14 |
|
| 15 |
// For now, a lone type parameter is not permitted as RHS in a type declaration (issue #45639). |
| 16 |
// type Lit[Ty any] Ty |
| 17 |
// |
| 18 |
// func (lit Lit[Ty]) Eval() Ty { return Ty(lit) } |
| 19 |
// func (lit Lit[Ty]) String() string { return fmt.Sprintf("(lit %v)", Ty(lit)) } |
| 20 |
|
| 21 |
type Eq[Ty any] struct { |
| 22 |
a Exp[Ty] |
| 23 |
b Exp[Ty] |
| 24 |
} |
| 25 |
|
| 26 |
func (e Eq[Ty]) String() string { |
| 27 |
return fmt.Sprintf("(eq %v %v)", e.a, e.b) |
| 28 |
} |
| 29 |
|
| 30 |
// For now, a lone type parameter is not permitted as RHS in a type declaration (issue #45639). |
| 31 |
// var ( |
| 32 |
// e0 = Eq[int]{Lit[int](128), Lit[int](64)} |
| 33 |
// e1 = Eq[bool]{Lit[bool](true), Lit[bool](true)} |
| 34 |
// ) |
| 35 |
|
| 36 |
func main() { |
| 37 |
// For now, a lone type parameter is not permitted as RHS in a type declaration (issue #45639). |
| 38 |
// fmt.Printf("%v\n", e0) |
| 39 |
// fmt.Printf("%v\n", e1) |
| 40 |
} |