<div dir="ltr"><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif">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.</font></font></font><div>
<font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif"><br></font></font></font></div><div><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif">Given </font></font></font></div><div>
<font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif"><br></font></font></font></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif"><div>
data Person =</div></font></font></font></div><div><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif"><div> Man {name :: String, age :: Int, prostateCondition :: Condition}</div></font></font></font></div>
<div><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif"><div> | Woman {name :: String, age :: Int, ovaryCondition :: Condition}</div></font></font></font></div></blockquote><div><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif"><div>
<br></div><div>I'd like to define something like this.</div><div><br></div></font></font></font></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif"><div>
type MensGroup = [Man]</div></font></font></font></div></blockquote><div><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif"><div><br></div><div>Is there a way to do something like that?</div></font></font></font><div dir="ltr">
<font><font face="'trebuchet ms', sans-serif"><i><font color="#003333"><br>-- Russ </font></i></font></font></div><div dir="ltr"><font><font face="'trebuchet ms', sans-serif"><i><font color="#003333"><br>
</font></i></font></font></div>
<br><br><div class="gmail_quote">On Tue, Dec 14, 2010 at 1:06 PM, Russ Abbott <span dir="ltr"><<a href="mailto:russ.abbott@gmail.com">russ.abbott@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<div dir="ltr"><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif">That's good. (It's more or less the way I was doing it.) What I wanted to avoid was this.</font></font></font><div><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif"><br>
</font></font></font></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif"><div>getGenderSpecificCondition ( Man _ _ cond) = cond</div>
</font></font></font></div><div><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif"><div>getGenderSpecificCondition (Woman _ _ cond) = cond</div></font></font></font></div></blockquote><div><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif"><div>
<br></div><div>I know it seems like a small thing, but I would like to be able to write it like this.</div></font></font></font></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<div><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif"><div><div>getGenderSpecificCondition p</div></div></font></font></font></div><div><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif"><div>
<div> | p == (Man _ _ cond) = cond</div></div></font></font></font></div><div><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif"><div><div> | p == (Woman _ _ cond) = cond</div></div><div><br></div>
</font></font></font></div></blockquote><div><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif"><div>But that's not legal syntax. A pattern can't appear in that context. But this does the job.</div>
<div><br></div></font></font></font></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif"><div>
<span style="color:rgb(0, 0, 0);font-family:arial"><div><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif"><div><div><div>getGenderSpecificCondition :: Person -> Condition</div>
<div>getGenderSpecificCondition p</div><div> | isMan p = prostateCondition p</div><div> | isWoman p = ovaryCondition p</div><div> </div><div>isMan ( Man _ _ cond) = True</div><div>isMan _ = False</div><div>isWoman (Woman _ _ cond) = True</div>
<div>isWoman _ = False</div></div></div><div><br></div></font></font></font></div></span></div></font></font></font></div></blockquote><font color="#003333" face="'trebuchet ms', sans-serif">That works! prostateCondition and ovaryCondition are both defined on Person. (I'm surprised to see that.)</font><div>
<font color="#003333" face="'trebuchet ms', sans-serif"><br></font></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font color="#003333" face="'trebuchet ms', sans-serif"><div>
*Person> Group [Man "Harry" 32 OK, Woman "Sally" 29 Good]</div></font></div><div><font color="#003333" face="'trebuchet ms', sans-serif"><div>Harry(32, OK)</div></font></div>
<div><font color="#003333" face="'trebuchet ms', sans-serif"><div>Sally(29, Good)</div><div><br></div></font></div></blockquote><span style="font-family:'trebuchet ms', sans-serif;color:rgb(0, 51, 51)">Also </span><br>
<blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font color="#003333" face="'trebuchet ms', sans-serif"><div><br></div><div><div>*Person> prostateCondition (Woman "Sally" 29 Good)</div>
<div>*** Exception: No match in record selector prostateCondition</div><div>*Person> prostateCondition (Man "Harry" 29 Good)</div><div>Good</div></div><div><br></div></font></div></blockquote><div><font color="#003333" face="'trebuchet ms', sans-serif"><div>
<br></div></font><div><div dir="ltr"><font><font face="'trebuchet ms', sans-serif"><i><font color="#003333">-- Russ </font></i></font></font></div><div><div></div><div class="h5"><div dir="ltr"><font><font face="'trebuchet ms', sans-serif"><i><font color="#003333"><br>
</font></i></font></font></div>
<br><br><div class="gmail_quote">On Tue, Dec 14, 2010 at 12:31 PM, Michael Katelman <span dir="ltr"><<a href="mailto:katelman@uiuc.edu" target="_blank">katelman@uiuc.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
Perhaps this?<br>
<br>
<a href="https://gist.github.com/741048" target="_blank">https://gist.github.com/741048</a><br>
<br>
-Mike<br>
<div><div></div><div><br>
On Tue, Dec 14, 2010 at 2:27 PM, Russ Abbott <<a href="mailto:russ.abbott@gmail.com" target="_blank">russ.abbott@gmail.com</a>> wrote:<br>
> What I'm after is a version of my example that compiles. Can you make one?<br>
><br>
> -- Russ<br>
><br>
><br>
> On Tue, Dec 14, 2010 at 12:18 PM, Antoine Latter <<a href="mailto:aslatter@gmail.com" target="_blank">aslatter@gmail.com</a>> wrote:<br>
>><br>
>> Sorry, I really don't know enough about what you're after to attempt that.<br>
>><br>
>> But you'll need to change you're signatures of the form:<br>
>><br>
>> > function :: Person -> Foo<br>
>><br>
>> to something of the form:<br>
>><br>
>> > function :: Person p => p -> Foo<br>
>><br>
>> Because again, a type class can not be used as a type.<br>
>><br>
>> Antoine<br>
>><br>
>> On Tue, Dec 14, 2010 at 2:12 PM, Russ Abbott <<a href="mailto:russ.abbott@gmail.com" target="_blank">russ.abbott@gmail.com</a>><br>
>> wrote:<br>
>> > What got fouled up is all the adjustments I had to make to the other<br>
>> > declarations.<br>
>> > Can you complete the example so that it compiles using<br>
>> ><br>
>> > class Person p where ...<br>
>> ><br>
>> > I'd very much like to see an example that actually compiles.<br>
>> ><br>
>> > Thanks.<br>
>> > -- Russ<br>
>> ><br>
>> > On Tue, Dec 14, 2010 at 11:58 AM, Antoine Latter <<a href="mailto:aslatter@gmail.com" target="_blank">aslatter@gmail.com</a>><br>
>> > wrote:<br>
>> >><br>
>> >> On Tue, Dec 14, 2010 at 1:52 PM, Russ Abbott <<a href="mailto:russ.abbott@gmail.com" target="_blank">russ.abbott@gmail.com</a>><br>
>> >> wrote:<br>
>> >> > If gender is a field in a Person type, then a Person must have both<br>
>> >> > an<br>
>> >> > ovaryCondition and a prostateCondition. That seems awkward.<br>
>> >> > Regarding<br>
>> >> > class Person p where<br>
>> >> > I started down that path but got completely fouled up.<br>
>> >><br>
>> >> How did this get fouled up? Every class declaration must take<br>
>> >> arguments - here, 'p' is the argument for the class.<br>
>> >><br>
>> >> Thanks,<br>
>> >> Antoine<br>
>> ><br>
>> ><br>
><br>
><br>
</div></div><div><div></div><div>> _______________________________________________<br>
> Beginners mailing list<br>
> <a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
> <a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
><br>
><br>
</div></div></blockquote></div><br></div></div></div></div></div>
</blockquote></div><br></div></div>