Skip to content

Instantly share code, notes, and snippets.

@rightfold
Last active August 29, 2015 14:04
Show Gist options
  • Save rightfold/bde32a98f424b661da35 to your computer and use it in GitHub Desktop.
Save rightfold/bde32a98f424b661da35 to your computer and use it in GitHub Desktop.
If you could say
> ordBy :: Eq a => (a -> a -> Ordering) -> instance Ord a
> ordBy f = instance Ord a where compare = f
and then something like
> sort #(ordBy blabla) xs
then you don't need `sortBy` anymore!
You could even have two instances `Monoid Int`!
> sumInt :: instance Monoid Int
> sumInt = instance Monoid Int where
> mempty = 0
> mappend = (+)
>
> productInt :: instance Monoid Int
> productInt = instance Monoid Int where
> mempty = 1
> mappend = (*)
>
> sum = mconcat #sumInt
> product = mconcat #productInt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment