Created
March 27, 2022 19:03
-
-
Save fogfish/592438570ea7cc63a5be48b1bd7658a7 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
/* | |
FromEq is a combinator that lifts T ⟼ T ⟼ bool function to | |
an instance of Eq type trait | |
*/ | |
type FromEq[T any] func(T, T) bool | |
// implementation of Eq type class | |
func (f FromEq[T]) Equal(a, b T) bool { return f(a, b)} | |
// Equal is a pure function that compares two integers | |
func Equal(a, b int) bool { return a == b } | |
/* | |
The combinator creates a new instance of Eq trait | |
that "knows" how to compare int. | |
*/ | |
var Int Eq[int] = eq.FromEq[int](Equal) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment