<?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">Keywords and syntax – Haskell – Aelve Guide</title><id>https://guide.aelve.com/haskell/feed/category/rx8z5mha</id><updated>2017-05-01T23:35:33Z</updated><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/feed/category/rx8z5mha"/><entry><id>aapfhb5j</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">data family</title><updated>2017-05-01T23:35:33Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;data family&lt;/span&gt;

&lt;/h1&gt;</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/keywords-and-syntax-rx8z5mha#item-aapfhb5j"/></entry><entry><id>d1ip46q9</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">type family</title><updated>2017-05-01T23:35:29Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;type family&lt;/span&gt;

&lt;/h1&gt;</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/keywords-and-syntax-rx8z5mha#item-d1ip46q9"/></entry><entry><id>mh9nz3y4</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">stock, newtype, anyclass</title><updated>2017-05-01T23:34:13Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;stock, newtype, anyclass&lt;/span&gt;

&lt;/h1&gt;&lt;p&gt;See &lt;a href=&#34;https://downloads.haskell.org/%7Eghc/master/users-guide/glasgow_exts.html#deriving-strategies&#34;&gt;GHC Guide on deriving strategies&lt;/a&gt;.&lt;/p&gt;
</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/keywords-and-syntax-rx8z5mha#item-mh9nz3y4"/></entry><entry><id>jyk4bwqp</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">pattern</title><updated>2017-05-01T23:26:03Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;pattern&lt;/span&gt;

&lt;/h1&gt;</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/keywords-and-syntax-rx8z5mha#item-jyk4bwqp"/></entry><entry><id>mxrx8vgf</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">mdo</title><updated>2017-05-01T23:25:36Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;mdo&lt;/span&gt;

&lt;/h1&gt;&lt;p&gt;hello&lt;/p&gt;
</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/keywords-and-syntax-rx8z5mha#item-mxrx8vgf"/></entry><entry><id>ou580jki</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">proc</title><updated>2017-05-01T22:53:30Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;proc&lt;/span&gt;

&lt;/h1&gt;</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/keywords-and-syntax-rx8z5mha#item-ou580jki"/></entry><entry><id>x4iz1s65</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">role, nominal, representational, phantom</title><updated>2017-05-01T22:50:44Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;role, nominal, representational, phantom&lt;/span&gt;

&lt;/h1&gt;&lt;p&gt;In recent versions of GHC there is a notion of roles (see &lt;a href=&#34;https://downloads.haskell.org/%7Eghc/latest/docs/html/users_guide/glasgow_exts.html#roles&#34;&gt;GHC Guide&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Types that have the same representation (e.g. a type and its newtype) can be converted between each other with &lt;code&gt;coerce&lt;/code&gt; or with &lt;code&gt;-XGeneralizedNewtypeDeriving&lt;/code&gt;. Roles exist to constrain ways in which types can be converted. For instance, this definition will disallow converting &lt;code&gt;Set a&lt;/code&gt; to &lt;code&gt;Set b&lt;/code&gt; even if &lt;code&gt;b&lt;/code&gt; is a newtype of &lt;code&gt;a&lt;/code&gt;:&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; role &lt;span class=&#34;dt&#34;&gt;Set&lt;/span&gt; nominal&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The reason it&#39;s not safe to convert a &lt;code&gt;Set&lt;/code&gt; is that the set will have a different structure depending on the &lt;code&gt;Ord&lt;/code&gt; instance of what&#39;s stored inside, and instances can be different for newtypes even if the representations are the same.&lt;/p&gt;
&lt;p&gt;There are three roles:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;nominal&lt;/code&gt;:&lt;/strong&gt; types must be completely identical after type family reduction&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;representational&lt;/code&gt;:&lt;/strong&gt; types must have the same representation&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;phantom&lt;/code&gt;:&lt;/strong&gt; the type can be disregarded&lt;/li&gt;
&lt;/ul&gt;
</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/keywords-and-syntax-rx8z5mha#item-x4iz1s65"/></entry><entry><id>n2j51qdp</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">rec</title><updated>2017-05-01T22:50:29Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;rec&lt;/span&gt;

&lt;/h1&gt;</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/keywords-and-syntax-rx8z5mha#item-n2j51qdp"/></entry></feed>