Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/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. Re: Type unions (Russ Abbott) 2. Re: Type unions (Hector Guilarte) 3. Re: Equivalence of Inheritance (Russ Abbott) ---------------------------------------------------------------------- Message: 1 Date: Tue, 14 Dec 2010 13:10:35 -0800 From: Russ Abbott <russ.abb...@gmail.com> Subject: Re: [Haskell-beginners] Type unions To: Tobias Brandt <tob.bra...@googlemail.com> Cc: beginners <beginners@haskell.org> Message-ID: <aanlktimyeea9-rxrvf_tkrg2loyhnjkm+app6n0oo...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" My typo started this most recent confusion. When I wrote data AorB = A | B compiles with error. That raises the question of what it really means! I meant to say data AorB = A | B compiles *without *error. That raises the question of what it really means! * -- Russ * On Tue, Dec 14, 2010 at 1:04 PM, Tobias Brandt <tob.bra...@googlemail.com>wrote: > On 14 December 2010 22:02, Hector Guilarte <hector...@gmail.com> wrote: > > Tobias you replied at the same time I was answering, you did explained > what > > is happening, > > however, you said something which isn't right. As I mentioned before, > "Type > > Constructors" and > > "Value Constructors" are in different scopes, and so, their names can be > > used again... > > if you don't believe me, give it a try with this example. > > I believe you. As I said, I was talking crap :-) > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20101214/08d7218c/attachment-0001.htm> ------------------------------ Message: 2 Date: Tue, 14 Dec 2010 16:59:43 -0430 From: Hector Guilarte <hector...@gmail.com> Subject: Re: [Haskell-beginners] Type unions To: russ.abb...@gmail.com Cc: beginners <beginners@haskell.org> Message-ID: <aanlktim8lp6_4qgvojehxzlj0vsjsy5z5eyvdzab3...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" But did you already understand what's happening? > data AorB = A | B is pretty much like an enumeration the same as > data DayOfTheWeek = Monday | Tuesday | Wednesday | ... | Sunday it stores no values of any type, you could even have DayOfTheWeek as a constructor in the same declaration of the data DayOfTheWeek, because they are in different scopes: > data DayOfTheWeek = Monday | Tuesday | Wednesday | ... | Sunday | DayOfTheWeek and by no means, that A or B on the right hand side of your data AorB are referencing the data A nor the data B... In the end, you could have: data A = Aconstructor Int data B = Bconstructor Int data AorB = A A | B B f :: Int -> AorB f x | even x = A (Aconstructor x) | otherwise = B (Bconstructor x) I just added a Value to each constructor of the data AorB, which happens to be named the same as the value they store... What I'm about to do is something I haven't tried, but I don't see why it shouldn't compile: > data Try = Int Int in data Try you have a constructor named Int, and it has a value of type Int, I'm trying to explain it the best I can, but I don't know if I managed to do it clearly, please let me know if there's something where I wasn't clear enough. Hector On Tue, Dec 14, 2010 at 4:40 PM, Russ Abbott <russ.abb...@gmail.com> wrote: > My typo started this most recent confusion. When I wrote > > data AorB = A | B > > compiles with error. > That raises the question of what it really means! > > > I meant to say > > data AorB = A | B > > compiles *without *error. > That raises the question of what it really means! > > * > -- Russ * > > > On Tue, Dec 14, 2010 at 1:04 PM, Tobias Brandt > <tob.bra...@googlemail.com>wrote: > >> On 14 December 2010 22:02, Hector Guilarte <hector...@gmail.com> wrote: >> > Tobias you replied at the same time I was answering, you did explained >> what >> > is happening, >> > however, you said something which isn't right. As I mentioned before, >> "Type >> > Constructors" and >> > "Value Constructors" are in different scopes, and so, their names can be >> > used again... >> > if you don't believe me, give it a try with this example. >> >> I believe you. As I said, I was talking crap :-) >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20101214/3889c0ad/attachment-0001.htm> ------------------------------ Message: 3 Date: Tue, 14 Dec 2010 13:30:32 -0800 From: Russ Abbott <russ.abb...@gmail.com> Subject: Re: [Haskell-beginners] Equivalence of Inheritance To: Michael Katelman <katel...@uiuc.edu> Cc: beginners <beginners@haskell.org> Message-ID: <aanlktinzhz5h1w3ukh=0ssheo74qadojwfuzsn0fh...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" Now that this is straightened out, I went back to what I was doing in the first place and realized that I haven't solved my problem. Given data Person = Man {name :: String, age :: Int, prostateCondition :: Condition} | Woman {name :: String, age :: Int, ovaryCondition :: Condition} I'd like to define something like this. type MensGroup = [Man] Is there a way to do something like that? * -- Russ * * * On Tue, Dec 14, 2010 at 1:06 PM, Russ Abbott <russ.abb...@gmail.com> wrote: > That's good. (It's more or less the way I was doing it.) What I wanted to > avoid was this. > > getGenderSpecificCondition ( Man _ _ cond) = cond > getGenderSpecificCondition (Woman _ _ cond) = cond > > > I know it seems like a small thing, but I would like to be able to write it > like this. > > getGenderSpecificCondition p > | p == (Man _ _ cond) = cond > | p == (Woman _ _ cond) = cond > > But that's not legal syntax. A pattern can't appear in that context. But > this does the job. > > getGenderSpecificCondition :: Person -> Condition > getGenderSpecificCondition p > | isMan p = prostateCondition p > | isWoman p = ovaryCondition p > > isMan ( Man _ _ cond) = True > isMan _ = False > isWoman (Woman _ _ cond) = True > isWoman _ = False > > That works! prostateCondition and ovaryCondition are both defined on > Person. (I'm surprised to see that.) > > *Person> Group [Man "Harry" 32 OK, Woman "Sally" 29 Good] > Harry(32, OK) > Sally(29, Good) > > Also > > > *Person> prostateCondition (Woman "Sally" 29 Good) > *** Exception: No match in record selector prostateCondition > *Person> prostateCondition (Man "Harry" 29 Good) > Good > > > *-- Russ * > * > * > > > On Tue, Dec 14, 2010 at 12:31 PM, Michael Katelman <katel...@uiuc.edu>wrote: > >> Perhaps this? >> >> https://gist.github.com/741048 >> >> -Mike >> >> On Tue, Dec 14, 2010 at 2:27 PM, Russ Abbott <russ.abb...@gmail.com> >> wrote: >> > What I'm after is a version of my example that compiles. Can you make >> one? >> > >> > -- Russ >> > >> > >> > On Tue, Dec 14, 2010 at 12:18 PM, Antoine Latter <aslat...@gmail.com> >> wrote: >> >> >> >> Sorry, I really don't know enough about what you're after to attempt >> that. >> >> >> >> But you'll need to change you're signatures of the form: >> >> >> >> > function :: Person -> Foo >> >> >> >> to something of the form: >> >> >> >> > function :: Person p => p -> Foo >> >> >> >> Because again, a type class can not be used as a type. >> >> >> >> Antoine >> >> >> >> On Tue, Dec 14, 2010 at 2:12 PM, Russ Abbott <russ.abb...@gmail.com> >> >> wrote: >> >> > What got fouled up is all the adjustments I had to make to the other >> >> > declarations. >> >> > Can you complete the example so that it compiles using >> >> > >> >> > class Person p where ... >> >> > >> >> > I'd very much like to see an example that actually compiles. >> >> > >> >> > Thanks. >> >> > -- Russ >> >> > >> >> > On Tue, Dec 14, 2010 at 11:58 AM, Antoine Latter <aslat...@gmail.com >> > >> >> > wrote: >> >> >> >> >> >> On Tue, Dec 14, 2010 at 1:52 PM, Russ Abbott <russ.abb...@gmail.com >> > >> >> >> wrote: >> >> >> > If gender is a field in a Person type, then a Person must have >> both >> >> >> > an >> >> >> > ovaryCondition and a prostateCondition. That seems awkward. >> >> >> > Regarding >> >> >> > class Person p where >> >> >> > I started down that path but got completely fouled up. >> >> >> >> >> >> How did this get fouled up? Every class declaration must take >> >> >> arguments - here, 'p' is the argument for the class. >> >> >> >> >> >> Thanks, >> >> >> Antoine >> >> > >> >> > >> > >> > >> > _______________________________________________ >> > Beginners mailing list >> > Beginners@haskell.org >> > http://www.haskell.org/mailman/listinfo/beginners >> > >> > >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20101214/75a6d80f/attachment.htm> ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 30, Issue 28 *****************************************