<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">How to make code warning-free – Haskell – Aelve Guide</title><id>https://guide.aelve.com/haskell/feed/category/qkostv6r</id><updated>2017-07-11T21:25:07Z</updated><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/feed/category/qkostv6r"/><entry><id>ogh2yr1a</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">Defined but not used</title><updated>2017-07-11T21:25:07Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;Defined but not used&lt;/span&gt;

&lt;/h1&gt;&lt;p&gt;Sometimes you have functions or types that you don&#39;t use anywhere in the module and don&#39;t export. In this case you will get these warnings:&lt;/p&gt;
&lt;div class=&#34;sourceCode&#34;&gt;&lt;pre class=&#34;sourceCode&#34;&gt;&lt;code class=&#34;sourceCode&#34;&gt;test.hs:6:1-3: warning: [-Wunused-top-binds] …
    Defined but not used: ‘foo’

test.hs:11:1-14: warning: [-Wunused-top-binds] …
    Defined but not used: type constructor or class ‘Foo’&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;One way to silence them is to add &lt;code&gt;{-# OPTIONS -Wno-unused-top-binds #-}&lt;/code&gt; to your module. Another is to add &lt;code&gt;_&lt;/code&gt; in front of all unused functions&#39; names, like this:&lt;/p&gt;
&lt;div class=&#34;sourceCode&#34;&gt;&lt;pre class=&#34;sourceCode&#34;&gt;&lt;code class=&#34;sourceCode&#34;&gt;&lt;span class=&#34;ot&#34;&gt;_foo ::&lt;/span&gt; &lt;span class=&#34;dt&#34;&gt;Int&lt;/span&gt;
_foo &lt;span class=&#34;fu&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;dv&#34;&gt;1&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Unfortunately, this only works with functions and not types. Moreover, sometimes you can&#39;t modify function names as they are generated (by Template Haskell, for instance). In this case you can add a fake “usage” to the end of the file:&lt;/p&gt;
&lt;div class=&#34;sourceCode&#34;&gt;&lt;pre class=&#34;sourceCode&#34;&gt;&lt;code class=&#34;sourceCode&#34;&gt;foo,&lt;span class=&#34;ot&#34;&gt; bar ::&lt;/span&gt; &lt;span class=&#34;dt&#34;&gt;Int&lt;/span&gt;
foo &lt;span class=&#34;fu&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;dv&#34;&gt;1&lt;/span&gt;
bar &lt;span class=&#34;fu&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;dv&#34;&gt;2&lt;/span&gt;
&lt;span class=&#34;co&#34;&gt;-------------------------------------&lt;/span&gt;
&lt;span class=&#34;ot&#34;&gt;_unused ::&lt;/span&gt; ()
_unused &lt;span class=&#34;fu&#34;&gt;=&lt;/span&gt; const () (foo, bar)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The same could be done for types:&lt;/p&gt;
&lt;div class=&#34;sourceCode&#34;&gt;&lt;pre class=&#34;sourceCode&#34;&gt;&lt;code class=&#34;sourceCode&#34;&gt;&lt;span class=&#34;kw&#34;&gt;type&lt;/span&gt; &lt;span class=&#34;dt&#34;&gt;Foo&lt;/span&gt; &lt;span class=&#34;fu&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;dt&#34;&gt;Int&lt;/span&gt;
&lt;span class=&#34;kw&#34;&gt;type&lt;/span&gt; &lt;span class=&#34;dt&#34;&gt;Bar&lt;/span&gt; &lt;span class=&#34;fu&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;dt&#34;&gt;Bool&lt;/span&gt;
&lt;span class=&#34;co&#34;&gt;-------------------------------------&lt;/span&gt;
&lt;span class=&#34;ot&#34;&gt;_unusedTypes ::&lt;/span&gt; (&lt;span class=&#34;dt&#34;&gt;Foo&lt;/span&gt;, &lt;span class=&#34;dt&#34;&gt;Bar&lt;/span&gt;)
_unusedTypes &lt;span class=&#34;fu&#34;&gt;=&lt;/span&gt; undefined&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;(If you don&#39;t want to use &lt;code&gt;undefined&lt;/code&gt;, you can use &lt;code&gt;Proxy&lt;/code&gt;.)&lt;/p&gt;
</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/how-to-make-code-warning-free-qkostv6r#item-ogh2yr1a"/></entry><entry><id>hwrzaskh</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">OverlappingInstances</title><updated>2017-03-23T22:40:25Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;OverlappingInstances&lt;/span&gt;

&lt;/h1&gt;&lt;p&gt;Starting from GHC 7.10, instead of &lt;code&gt;{-# LANGUAGE OverlappingInstances #-}&lt;/code&gt; you have to mark specific instances with &lt;code&gt;{-# OVERLAPPABLE #-}&lt;/code&gt;, &lt;code&gt;{-# OVERLAPPING #-}&lt;/code&gt; or &lt;code&gt;{-# OVERLAPS #-}&lt;/code&gt;. So, if you want to use overlapping instances, here&#39;s how you can do it:&lt;/p&gt;
&lt;div class=&#34;sourceCode&#34;&gt;&lt;pre class=&#34;sourceCode&#34;&gt;&lt;code class=&#34;sourceCode&#34;&gt;&lt;span class=&#34;ot&#34;&gt;#if __GLASGOW_HASKELL__ &amp;lt; 710&lt;/span&gt;
&lt;span class=&#34;ot&#34;&gt;{-# LANGUAGE OverlappingInstances #-}&lt;/span&gt;
&lt;span class=&#34;ot&#34;&gt;#  define _OVERLAPPING_&lt;/span&gt;
&lt;span class=&#34;ot&#34;&gt;#  define _OVERLAPPABLE_&lt;/span&gt;
&lt;span class=&#34;ot&#34;&gt;#  define _OVERLAPS_&lt;/span&gt;
&lt;span class=&#34;ot&#34;&gt;#else&lt;/span&gt;
&lt;span class=&#34;ot&#34;&gt;#  define _OVERLAPPING_ {-# OVERLAPPING #-}&lt;/span&gt;
&lt;span class=&#34;ot&#34;&gt;#  define _OVERLAPPABLE_ {-# OVERLAPPABLE #-}&lt;/span&gt;
&lt;span class=&#34;ot&#34;&gt;#  define _OVERLAPS_ {-# OVERLAPS #-}&lt;/span&gt;
&lt;span class=&#34;ot&#34;&gt;#endif&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now you can just mark your instances as &lt;code&gt;instance _OVERLAPPING_ ...&lt;/code&gt; instead of &lt;code&gt;instance {-# OVERLAPPING #-}&lt;/code&gt;, and it&#39;ll work without warnings on all GHC versions.&lt;/p&gt;
</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/how-to-make-code-warning-free-qkostv6r#item-hwrzaskh"/></entry></feed>