<div dir="ltr">The problem I see with this is it becomes very brittle to just silently accept bad class member names.<div><br></div><div style>Before, if I had a method</div><div style><br></div><div style>class Foo a where</div>
<div style>  bar :: a -&gt; Int</div><div style>  bar _ = 0</div><div style><br></div><div style>and I went to implement something with a typo</div><div style><br></div><div style>instance Foo Int where</div><div style>  baz = id</div>
<div style><br></div><div style>then I&#39;d get an error, but your proposal it&#39;d just silently be accepted, and lead to to long nights searching for why my instance wasn&#39;t doing what I expected long after I&#39;d shipped my product.</div>
<div style><br></div><div style>This kind of class isn&#39;t an academic concern, many real world classes are defined with 2-3 members circularly. Consider Foldable or Traversable.</div><div style><br></div><div style>newtype Baz = Baz a</div>
<div style><br></div><div style>instance Foldable Baz where</div><div style>  foldmap f (Baz a) = f a</div><div style><br></div><div style>is an innocent typo that would then just mean that foldMap when applied to Baz will silently loop forever with no warning to the programmer. Traversable Baz behaves similarly with the cyclic between sequenceA+fmap and traverse.</div>
<div style><br></div><div style>I&#39;d argue that I&#39;ve made typos on member names <b>far</b> more often than I&#39;ve wanted this feature.</div><div style><br></div><div style>In fact, I&#39;ve actually tried to live with a very similar lexical scoping design in a toy language of mine I called Kata. In Kata, you could just introduce new members by writing them in a &#39;public&#39; block, and constrain subclasses by putting in members without definitions, but it was sufficiently brittle that I wound up adding another syntactic construct which could only be used to instantiate definitions not make new names. That resolve the issue and made the language much nicer to play around in.</div>
<div style><br></div><div style>I&#39;d really rather not switch from a design that is robust and usually does the right thing to one that is more brittle and prone to introducing hard to find bugs. =(</div><div style><br>
</div><div style>-Edward</div><div style><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Apr 30, 2013 at 7:05 PM, Doug McIlroy <span dir="ltr">&lt;<a href="mailto:doug@cs.dartmouth.edu" target="_blank">doug@cs.dartmouth.edu</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Max&#39;s idea (see below) of a second where clause is cute, but<br>
not sanctioned by Haskell syntax.<br>
<br>
Iavor wrote, &quot;It would be quite arbitrary to restrict this only<br>
to instances.&quot;<br>
<br>
Actually what I have in mind is to make the language MORE<br>
consistent, by eliminating distinctions between instance-wheres<br>
and ordinary declaration-wheres.  Currently instance-wheres may<br>
only declare class methods, while declaration-wheres may declare<br>
variables at will.  Also instance-wheres may not declare type<br>
signatures, while declaration-wheres may.  I propose dropping<br>
these restrictions on instance-wheres.<br>
<br>
Hazard: Adding a method to an existing class could accidentally<br>
capture a name that was previously local to an instance-where.<br>
Capture can be prevented by declaring type signatures for local<br>
variables.  The compiler might warn when such defensive<br>
declarations are lacking.<br>
<br>
Doug<br>
<br>
On Mon, 29 Apr 2013 15:56 Iavor Diatchki &lt;<a href="mailto:iavor.diatchki@gmail.com">iavor.diatchki@gmail.com</a>&gt; wrote<br>
<div><div class="h5"><br>
Hello,<br>
<br>
I think that if we want something along those lines, we should consider a<br>
more general construct that allows declarations to scope over other<br>
declarations (like SML&#39;s `local` construct).  It would be quite arbitrary<br>
to restrict this only to instances.<br>
<br>
-Iavor<br>
<br>
<br>
<br>
On Mon, Apr 29, 2013 at 2:41 PM, Max Bolingbroke &lt;<a href="mailto:batterseapower@hotmail.com">batterseapower@hotmail.com</a><br>
&gt; wrote:<br>
<br>
&gt; You could probably get away with just using two &quot;where&quot; clauses:<br>
&gt;<br>
&gt; instance Foo a where<br>
&gt;     bar = ...<br>
&gt;   where<br>
&gt;     auxilliary = ...<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On 28 April 2013 18:42, Edward Kmett &lt;<a href="mailto:ekmett@gmail.com">ekmett@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt;&gt; Makes sense. I&#39;m not sure what a good syntactic story would be for that<br>
&gt;&gt; feature though. Just writing down member names that aren&#39;t in the class<br>
&gt;&gt; seems to be too brittle and error prone, and new keywords seems uglier than<br>
&gt;&gt; the current situation.<br>
&gt;&gt;<br>
&gt;&gt; Sent from my iPad<br>
&gt;&gt;<br>
&gt;&gt; On Apr 28, 2013, at 1:24 PM, Doug McIlroy &lt;<a href="mailto:doug@cs.dartmouth.edu">doug@cs.dartmouth.edu</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; &gt; Not always. For example, you can&#39;t mess with the declaration<br>
&gt;&gt; &gt; of a standard class, such as Num.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; On Sun, Apr 28, 2013 at 12:06 PM, Edward Kmett &lt;<a href="mailto:ekmett@gmail.com">ekmett@gmail.com</a>&gt;<br>
&gt;&gt; wrote:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; You can always put those helper functions in the class and then just<br>
&gt;&gt; not<br>
&gt;&gt; &gt;&gt; export them from the module.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; On Sun, Apr 28, 2013 at 10:49 AM, Doug McIlroy &lt;<a href="mailto:doug@cs.dartmouth.edu">doug@cs.dartmouth.edu</a><br>
&gt;&gt; &gt;wrote:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; Is there any strong reason why the where clause in an instance<br>
&gt;&gt; &gt;&gt; declaration cannot declare anything other than class<br>
&gt;&gt; &gt;&gt; operators? If not, I suggest relaxing the restriction.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; It is not unusual for declarations of class operators to<br>
&gt;&gt; &gt;&gt; refer to special auxiliary functions. Under current rules<br>
&gt;&gt; &gt;&gt; such functions have to be declared outside the scope in<br>
&gt;&gt; &gt;&gt; which they are used.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Doug McIlroy<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; Haskell-prime mailing list<br>
&gt;&gt; <a href="mailto:Haskell-prime@haskell.org">Haskell-prime@haskell.org</a><br>
&gt;&gt; <a href="http://www.haskell.org/mailman/listinfo/haskell-prime" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-prime</a><br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Haskell-prime mailing list<br>
&gt; <a href="mailto:Haskell-prime@haskell.org">Haskell-prime@haskell.org</a><br>
&gt; <a href="http://www.haskell.org/mailman/listinfo/haskell-prime" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-prime</a><br>
&gt;<br>
&gt;<br>
<br>
</div></div>Content-Type: text/html; charset=UTF-8<br>
</blockquote></div><br></div>