Skip to content

Instantly share code, notes, and snippets.

@fogfish
Created March 27, 2022 19:03
Show Gist options
  • Save fogfish/592438570ea7cc63a5be48b1bd7658a7 to your computer and use it in GitHub Desktop.
Save fogfish/592438570ea7cc63a5be48b1bd7658a7 to your computer and use it in GitHub Desktop.
/*
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