[Haskell-beginners] Making my own type belong to Data.Ord
Francesco Ariis
fa-ml at ariis.it
Sat Jan 20 20:27:52 UTC 2018
On Sat, Jan 20, 2018 at 09:20:33PM +0100, Patrik Iselind wrote:
> It's the very last exercise on the page concerning constructing a Convex
> Hull. I have no problem implementing a Graham Scan in non-functional
> languages as i have far more experience with those. But the book hasn't yet
> covered how i make my own data belong to for example the Data.Ord class. The
> question then for me is how am i supposed to sort my coordinates?
>
> Type classes are not covered for another three chapters in the book. Given
> this it seems to me that i should be able to solve this without using
> Data.Ord, i just cannot see how. Any pointers would be highly appreciated.
Hello Patrik,
as you suggested, implementing an instance of Data.Ord would be ok; if
you don't want that, just write a
myTypeCompare :: SomeData -> SomeData -> Ordering
function to use with `sortBy` from `Data.List`.
Does that make sense?
-F
More information about the Beginners
mailing list