Skip to content

Instantly share code, notes, and snippets.

@fogfish
Created March 27, 2022 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fogfish/f1632c56f473f7283d76ae15dd62b4d1 to your computer and use it in GitHub Desktop.
Save fogfish/f1632c56f473f7283d76ae15dd62b4d1 to your computer and use it in GitHub Desktop.
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