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. phantom type (PICCA Frederic-Emmanuel) 2. Re: phantom type (Francesco Ariis) ---------------------------------------------------------------------- Message: 1 Date: Sat, 31 Mar 2018 07:54:50 +0000 From: PICCA Frederic-Emmanuel <frederic-emmanuel.pi...@synchrotron-soleil.fr> To: "The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell" <beginners@haskell.org> Subject: [Haskell-beginners] phantom type Message-ID: <a2a20ec3b8560d408356cac2fc148e530107dd5...@sun-dag3.synchrotron-soleil.fr> Content-Type: text/plain; charset="us-ascii" Hello, Here my problem. I extract some information from a database and put them into a type with 50 parameters Type MyData = MyData Int String ... But I need to be able to differenciate two different case. depending on the String content. something like if the String start with "ref-" it is a Caracterization and if not it is a Collect So I end up with this solution data Unchecked data Caracterization data Collect data MyData t = MyData Int String ... now I defined a function getMyDataFromDatabase :: ... -> Mydata Unchecked and isCollect in order to verify that I have a Collect and not something Else isACollect :: MyData Unchecked -> Either Text (MyData Collect). which use coerc in order to avoid copying all the members. It is great. now Here is my problem. I create a method myMethod :: MyData Collect -> IO () but I want my method to work for MyData Collect and Mydata Caracterization but not Unchecked. So It seems to me that I can not just do myMethod :: MyData t -> IO () what is the right way to solve this problem ? thanks for your help. Frederic ------------------------------ Message: 2 Date: Sat, 31 Mar 2018 10:40:11 +0200 From: Francesco Ariis <fa...@ariis.it> To: beginners@haskell.org Subject: Re: [Haskell-beginners] phantom type Message-ID: <20180331084011.5ixszt3pboaov...@x60s.casa> Content-Type: text/plain; charset=us-ascii On Sat, Mar 31, 2018 at 07:54:50AM +0000, PICCA Frederic-Emmanuel wrote: > I create a method > > myMethod :: MyData Collect -> IO () > > but I want my method to work for MyData Collect and Mydata Caracterization > but not Unchecked. > > So It seems to me that I can not just do > > myMethod :: MyData t -> IO () > > > what is the right way to solve this problem ? Hello Frederic, I am in a rush so I cant write a minimal example, but wouldn't a typeclass + make Collect and Cara instances of that typeclass do? -F ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 117, Issue 18 ******************************************