Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Making my own type belong to Data.Ord (Patrik Iselind) 2. Re: Making my own type belong to Data.Ord (Francesco Ariis) 3. Re: Making my own type belong to Data.Ord (Patrik Iselind) ---------------------------------------------------------------------- Message: 1 Date: Sat, 20 Jan 2018 21:20:33 +0100 From: Patrik Iselind <patrik....@gmail.com> To: beginners@haskell.org Subject: [Haskell-beginners] Making my own type belong to Data.Ord Message-ID: <d8ba8ad9-8e03-8400-e4d9-814a7ba85...@gmail.com> Content-Type: text/plain; charset=windows-1252; format=flowed Hi, I'm trying to follow the "Real World Haskell" book online and have reached exercise 12 in chapter three. See the bottom of http://book.realworldhaskell.org/read/defining-types-streamlining-functions.html for reference. 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. -- Patrik Iselind ------------------------------ Message: 2 Date: Sat, 20 Jan 2018 21:27:52 +0100 From: Francesco Ariis <fa...@ariis.it> To: beginners@haskell.org Subject: Re: [Haskell-beginners] Making my own type belong to Data.Ord Message-ID: <20180120202752.4nsc5lswjl2zw...@x60s.casa> Content-Type: text/plain; charset=us-ascii 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 ------------------------------ Message: 3 Date: Sat, 20 Jan 2018 21:48:26 +0100 From: Patrik Iselind <patrik....@gmail.com> To: beginners@haskell.org Subject: Re: [Haskell-beginners] Making my own type belong to Data.Ord Message-ID: <23095b91-a353-c4b3-32d5-86e276b69...@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Den 2018-01-20 kl. 21:27, skrev Francesco Ariis: > 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 I wouldn't mind writing it, at all. It's probably the way i would do it if i knew more Haskell. My problem is just that the book i follow hasn't covered that topic yet, so even if i could google how to do it i guess i shouldn't until the book has covered the topic. As i understand it this would be the 'preferred' way in the real world, is this correctly understood? > , just write a > > myTypeCompare :: SomeData -> SomeData -> Ordering > > function to use with `sortBy` from `Data.List`. > Does that make sense? That would make sense, i seem to remember something along those lines from previous topics covered in the book. Thanks a lot Francesco, much appreciated! // Patrik ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 115, Issue 8 *****************************************