Created
March 27, 2022 18:52
-
-
Save fogfish/f1632c56f473f7283d76ae15dd62b4d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package eq | |
/* | |
eqInt declares a new instance of Eq trait, which is a real type. | |
The real type "knows" everything about equality in its own domain. | |
The instance of Eq is created as type over string, it is an intentional | |
technique to create a namespace using Golang constants. | |
The instance of trait is referenced as eq.Int in the code. | |
*/ | |
type eqInt string | |
// the type "implements" equality behavior | |
func (eqInt) Equal(a, b int) bool { return a == b } | |
/* | |
Int is an instance of Eq trait for int domain as immutable value so that | |
other functions can use this constant like `eq.Int.Equal(...)` | |
*/ | |
const Int = eqInt("eq.int") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment