<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"MS Mincho";
panose-1:2 2 6 9 4 2 5 8 3 4;}
@font-face
{font-family:"MS Mincho";
panose-1:2 2 6 9 4 2 5 8 3 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
{font-family:"\@MS Mincho";
panose-1:2 2 6 9 4 2 5 8 3 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
{mso-style-priority:99;
mso-style-link:"Balloon Text Char";
margin:0cm;
margin-bottom:.0001pt;
font-size:8.0pt;
font-family:"Tahoma","sans-serif";}
span.BalloonTextChar
{mso-style-name:"Balloon Text Char";
mso-style-priority:99;
mso-style-link:"Balloon Text";
font-family:"Tahoma","sans-serif";}
span.EmailStyle19
{mso-style-type:personal;
font-family:"Calibri","sans-serif";
color:windowtext;}
span.EmailStyle20
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="color:#1F497D">lets try it the other way around
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">> instance Foo' SNat1 where<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">> type Bar' SNat1 = Z1<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">> bar' = SZ1<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">that works!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">(my language will be wrong here…but the jist is)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">So in some something of kind <o:p>
</o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">“*->*” is substitutable for a parameter of kind “k -> *”<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">“Nat->*” is substitutable for a parameter of kind “k -> *”<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">“*->*” is substitutable for a parameter of kind “* -> *”<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">“Nat->*” is NOT substitutable for a parameter of kind “* -> *”<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Hmmmm<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">So why would I ever want to define a type class of kind<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">(* -> *) -> Constraint<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Instead of <o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">(k -> *) -> Constraint<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">I think I don’t completely understand what’s going on.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Nicholls, Mark
<br>
<b>Sent:</b> 06 May 2015 1:02 PM<br>
<b>To:</b> haskell-cafe@haskell.org<br>
<b>Subject:</b> minor confusion over kinds....<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">And what “*” means as opposed to other things e.g. an explicit name "Nat" or a kind variable "k"<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">> {-# LANGUAGE DataKinds #-}<o:p></o:p></p>
<p class="MsoNormal">> {-# LANGUAGE ExplicitForAll #-}<o:p></o:p></p>
<p class="MsoNormal">> {-# LANGUAGE FlexibleContexts #-}<o:p></o:p></p>
<p class="MsoNormal">> {-# LANGUAGE FlexibleInstances #-}<o:p></o:p></p>
<p class="MsoNormal">> {-# LANGUAGE GADTs #-}<o:p></o:p></p>
<p class="MsoNormal">> {-# LANGUAGE MultiParamTypeClasses #-}<o:p></o:p></p>
<p class="MsoNormal">> {-# LANGUAGE PolyKinds #-}<o:p></o:p></p>
<p class="MsoNormal">> {-# LANGUAGE StandaloneDeriving #-}<o:p></o:p></p>
<p class="MsoNormal">> {-# LANGUAGE TypeFamilies #-}<o:p></o:p></p>
<p class="MsoNormal">> {-# LANGUAGE TypeOperators #-}<o:p></o:p></p>
<p class="MsoNormal">> {-# LANGUAGE UndecidableInstances #-}<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">what I want is a typeclass with instances of type level Naturals<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">here's the class, the parameter is of kind (* -> *) i.e. a is some sort of wrapper that maps from types to values<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">> class Foo (a :: * -> *) where<o:p></o:p></p>
<p class="MsoNormal">> type Bar a<o:p></o:p></p>
<p class="MsoNormal">> bar :: a (Bar a)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">lets ignore DataKinds define Zero and Succ as distinct types<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">uninhabited...but of kind "*" and "k -> *"<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">> data Z1<o:p></o:p></p>
<p class="MsoNormal">> data S1 nat<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">SNat1 :: * -> *<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">> data SNat1 a where<o:p></o:p></p>
<p class="MsoNormal">> SZ1 :: SNat1 Z1<o:p></o:p></p>
<p class="MsoNormal">> SS1 :: SNat1 a -> SNat1 (S1 a)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">off we go...<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">> instance Foo SNat1 where<o:p></o:p></p>
<p class="MsoNormal">> type Bar SNat1 = Z1<o:p></o:p></p>
<p class="MsoNormal">> bar = SZ1<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">now lets do it the datakind route<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">> data Nat where<o:p></o:p></p>
<p class="MsoNormal">> Z :: Nat<o:p></o:p></p>
<p class="MsoNormal">> S :: Nat -> Nat<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">ahhh...SNat is of kind "Nat -> *"<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">> data SNat a where<o:p></o:p></p>
<p class="MsoNormal">> SZ :: SNat 'Z<o:p></o:p></p>
<p class="MsoNormal">> SS :: SNat a -> SNat ('S a)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">so I cant make it an instance of the same type class<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">"The first argument of ‘Foo’ should have kind ‘* -> *’,<o:p></o:p></p>
<p class="MsoNormal"> but ‘SNat’ has kind ‘Nat -> *’<o:p></o:p></p>
<p class="MsoNormal"> In the instance declaration for ‘Foo SNat’"<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">> --instance Foo SNat where<o:p></o:p></p>
<p class="MsoNormal">> -- type Bar SNat = 'Z<o:p></o:p></p>
<p class="MsoNormal">> -- bar = SZ<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">unless I redefine my class (which seems a bit silly)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">> class Foo' (a :: k -> *) where<o:p></o:p></p>
<p class="MsoNormal">> type Bar' a :: k<o:p></o:p></p>
<p class="MsoNormal">> bar' :: a (Bar' a)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">now it works.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">> instance Foo' SNat where<o:p></o:p></p>
<p class="MsoNormal">> type Bar' SNat = 'Z<o:p></o:p></p>
<p class="MsoNormal">> bar' = SZ<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">clearly named kinds (?) are somehow distinct from unnames ones?<o:p></o:p></p>
</div>
</div>
<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></body>
</html>