<div dir="ltr"><div><div>(S Integer) is not an instance of Bar.  I solved this by doing the following<br><br></div>You can get around this using an empty instance declaration for (S Integer) like so<br><br></div>instance Bar (S Integer)<br><div class="gmail_extra"><br></div><div class="gmail_extra">Now, the compiler will know that (S Integer) is an instance of this.  It doesn't matter if there is no definition of inc' as you won't be using it.<br><br></div><div class="gmail_extra">However, I don't understand why a class definition will contain itself as a constraint on one of its method.  By doing so,<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">That is, whenever you do something like this<br><br>class Bar a where<br>  inc' ::  Bar (S a) => a -> S a<br><br>instance Bar Integer where<br>  inc' x = S x<br><br></div><div class="gmail_extra">The resulting expression will also have to be an instance of Bar (.ie.,instance Bar (S Integer) <br>)  I just don't think this makes any sense.  Also, tried searching for any such type signatures in Hoogle, but didn't come across anything like this.<br><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jan 6, 2015 at 11:09 PM, Nicholls, Mark <span dir="ltr"><<a href="mailto:nicholls.mark@vimn.com" target="_blank">nicholls.mark@vimn.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div link="blue" vlink="purple" lang="EN-GB">
<div>
<p class="MsoNormal"><span style="font-size:11pt;font-family:"Calibri","sans-serif";color:rgb(31,73,125)">I can do the basic Haskell…I’ve done a course even, but as I don’t use it… I quickly degenerate into a beginner.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:"Calibri","sans-serif";color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:"Calibri","sans-serif";color:rgb(31,73,125)">I think I’ve refound my feet….I will post it to the café and see what happens.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:"Calibri","sans-serif";color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal" style="margin-left:36pt"><b><span style="font-size:10pt;font-family:"Tahoma","sans-serif"" lang="EN-US">From:</span></b><span style="font-size:10pt;font-family:"Tahoma","sans-serif"" lang="EN-US"> Beginners [mailto:<a href="mailto:beginners-bounces@haskell.org" target="_blank">beginners-bounces@haskell.org</a>]
<b>On Behalf Of </b>David McBride<br>
<b>Sent:</b> 06 January 2015 4:41 PM<br>
<b>To:</b> The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell<br>
<b>Subject:</b> Re: [Haskell-beginners] typeclass woes...how to constain a typeclass to be "closed" under an operation....<u></u><u></u></span></p><div><div class="h5">
<p class="MsoNormal" style="margin-left:36pt"><u></u> <u></u></p>
<div>
<p class="MsoNormal" style="margin-left:36pt">I think you've slightly surpassed the skill level of this list.  You might try on haskell-cafe, and I would bet you could get an in depth answer on stackoverflow.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36pt"><u></u> <u></u></p>
<div>
<p class="MsoNormal" style="margin-left:36pt">On Tue, Jan 6, 2015 at 3:46 AM, Nicholls, Mark <<a href="mailto:nicholls.mark@vimn.com" target="_blank">nicholls.mark@vimn.com</a>> wrote:<u></u><u></u></p>
<div>
<div>
<p class="MsoNormal" style="margin-left:36pt">I dont seem to have any replies<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36pt">Booo<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36pt">Is my question too stupid? Or boring? Or unintelligable?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36pt"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36pt">Its quite common in maths to have operations in a theory that are (set) closed, i just want to translate that notion to a typeclass<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36pt"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36pt">I have a suggestion that does work<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36pt"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36pt">Class Foo m where<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36pt">   op :: m a -> m (S a)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36pt"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36pt">That is closed, but now were working on types of kind • -> •, which is another leap of complexity<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36pt"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36pt">Is this the idiom/pattern i should follow? Or can the closure contraint be expressed directly?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36pt"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36pt"><br>
<br>
Excuse the spelling, sent from a phone with itty bitty keys, it like trying to sow a button on a shirt with a sausage.
<u></u><u></u></p>
<div>
<p class="MsoNormal" style="margin-left:36pt"><u></u> <u></u></p>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:12pt;margin-left:36pt">
<br>
On 5 Jan 2015, at 10:54, Nicholls, Mark <<a href="mailto:nicholls.mark@vimn.com" target="_blank">nicholls.mark@vimn.com</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="margin-top:5pt;margin-bottom:5pt">
<div>
<div>
<p class="MsoNormal" style="margin-left:36pt">
> {-# LANGUAGE TypeFamilies, MultiParamTypeClasses, FlexibleContexts,  FlexibleInstances, GADTs #-}<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
 <u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
lets say I have a data type<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
 <u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
> data S a = S a deriving Show<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
 <u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
and a nice simple typeclass<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
 <u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
> class Foo a where<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
>   inc :: a -> S a<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
 <u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
make Integer an instance and....<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
 <u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
> instance Foo Integer where<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
>   inc x = S x<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
 <u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
brilliant...<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
 <u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
now lets say I want my typeclass to enforce that any result of inc is also of a type that is an instance of the typeclass<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
I'll follow my nose...which causes me a problem that makes me realise I maybe I don't understand whats going on.<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
 <u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
> class Bar a where<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
>   inc' :: (Bar (S a)) => a -> S a<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
 <u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
follow it to....<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
 <u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
> instance Bar Integer where<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
>   inc' x = S x<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
 <u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
this WORKS!...even though "S Integer" is not an instance of Bar!...maybe I don't understand.<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
 <u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
> -- x = inc' (1 :: Integer)<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
 <u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
This would go BOOM ....”no instance of (Bar (S Integer))"<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
...so that makes sense....<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
 <u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
How do I force Haskell to check the constraint before I evaluate an expression?<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
 <u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
follow my nose?<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
 <u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
> -- class (Baz (S a)) => Baz a where<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
> --  inc'' :: a -> S a<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
 <u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
BOOM ...."Cycle in class declaration"....<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
booo..but I suppose thats understandable....<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
 <u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
so<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
 <u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
a) is my use of typeclasses correct?...or am I missing something?<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
b) if so, how do I force the compiler to make sure my typeclass operations is nicely closed (under the typeclass)?<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
 <u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36pt">
 <u></u><u></u></p>
</div>
<p style="margin-left:36pt"><br>
<br>
CONFIDENTIALITY NOTICE<br>
<br>
This e-mail (and any attached files) is confidential and protected by copyright (and other intellectual property rights). If you are not the intended recipient please e-mail the sender and then delete the email and any attached files immediately. Any further
 use or dissemination is prohibited.<br>
<br>
While MTV Networks Europe has taken steps to ensure that this email and any attachments are virus free, it is your responsibility to ensure that this message and any attachments are virus free and do not affect your systems / data.<br>
<br>
Communicating by email is not 100% secure and carries risks such as delay, data corruption, non-delivery, wrongful interception and unauthorised amendment. If you communicate with us by e-mail, you acknowledge and assume these risks, and you agree to take appropriate
 measures to minimise these risks when e-mailing us.<br>
<br>
MTV Networks International, MTV Networks UK & Ireland, Greenhouse, Nickelodeon Viacom Consumer Products, VBSi, Viacom Brand Solutions International, Be Viacom, Viacom International Media Networks and VIMN and Comedy Central are all trading names of MTV Networks
 Europe.  MTV Networks Europe is a partnership between MTV Networks Europe Inc. and Viacom Networks Europe Inc.  Address for service in Great Britain is 17-29 Hawley Crescent, London, NW1 8TT.<u></u><u></u></p>
</div>
</blockquote>
</div>
</div>
<blockquote style="margin-top:5pt;margin-bottom:5pt">
<div>
<p class="MsoNormal" style="margin-left:36pt">_______________________________________________<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><u></u><u></u></p>
</div>
</blockquote>
<p style="margin-left:36pt"><br>
<br>
CONFIDENTIALITY NOTICE<br>
<br>
This e-mail (and any attached files) is confidential and protected by copyright (and other intellectual property rights). If you are not the intended recipient please e-mail the sender and then delete the email and any attached files immediately. Any further
 use or dissemination is prohibited.<br>
<br>
While MTV Networks Europe has taken steps to ensure that this email and any attachments are virus free, it is your responsibility to ensure that this message and any attachments are virus free and do not affect your systems / data.<br>
<br>
Communicating by email is not 100% secure and carries risks such as delay, data corruption, non-delivery, wrongful interception and unauthorised amendment. If you communicate with us by e-mail, you acknowledge and assume these risks, and you agree to take appropriate
 measures to minimise these risks when e-mailing us.<br>
<br>
MTV Networks International, MTV Networks UK & Ireland, Greenhouse, Nickelodeon Viacom Consumer Products, VBSi, Viacom Brand Solutions International, Be Viacom, Viacom International Media Networks and VIMN and Comedy Central are all trading names of MTV Networks
 Europe.  MTV Networks Europe is a partnership between MTV Networks Europe Inc. and Viacom Networks Europe Inc.  Address for service in Great Britain is 17-29 Hawley Crescent, London, NW1 8TT.<u></u><u></u></p>
</div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:12pt;margin-left:36pt">
<br>
_______________________________________________<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><u></u><u></u></p>
</div>
<p class="MsoNormal" style="margin-left:36pt"><u></u> <u></u></p>
</div>
</div></div></div><div><div class="h5">
<p></p>
<p><br><br>CONFIDENTIALITY NOTICE<br><br>This e-mail (and any attached files) is confidential and protected by copyright (and other intellectual property rights). If you are not the intended recipient please e-mail the sender and then delete the email and any attached files immediately. Any further use or dissemination is prohibited.<br><br>While MTV Networks Europe has taken steps to ensure that this email and any attachments are virus free, it is your responsibility to ensure that this message and any attachments are virus free and do not affect your systems / data.<br><br>Communicating by email is not 100% secure and carries risks such as delay, data corruption, non-delivery, wrongful interception and unauthorised amendment. If you communicate with us by e-mail, you acknowledge and assume these risks, and you agree to take appropriate measures to minimise these risks when e-mailing us.<br><br>MTV Networks International, MTV Networks UK & Ireland, Greenhouse, Nickelodeon Viacom Consumer Products, VBSi, Viacom Brand Solutions International, Be Viacom, Viacom International Media Networks and VIMN and Comedy Central are all trading names of MTV Networks Europe.  MTV Networks Europe is a partnership between MTV Networks Europe Inc. and Viacom Networks Europe Inc.  Address for service in Great Britain is 17-29 Hawley Crescent, London, NW1 8TT.<br></p></div></div></div>

<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">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></blockquote></div><br></div></div>