<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
</head>
<body dir="auto">
<div>Accchhhh</div>
<div><br>
</div>
<div>Thats another level of pain, i'm not a big haskeller so i'll have to wrestle with it to get all the knobs and dials working, leave it with me for the moment and i'll start wrestling with cabal<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.
<div><br>
</div>
</div>
<div><br>
On 29 Apr 2015, at 12:43, Richard Eisenberg <<a href="mailto:eir@cis.upenn.edu">eir@cis.upenn.edu</a>> wrote:<br>
<br>
</div>
<blockquote type="cite">
<div>
<div>Hello Mark,</div>
<div><br>
</div>
<div>Your suspicion that your singleton tree type is wrong is well-founded.</div>
<div><br>
</div>
<div>The problem is that, in my opinion, that exercise is mentioned too early in the tutorial. To properly implement a singleton type for a parameterized type, like a binary tree, you will need `data family Sing (a :: k)`, as explained just a little bit further
 down in the post. You'll need to rewrite your definition for singleton numbers and booleans to work with `Sing` as well.</div>
<div><br>
</div>
<div>Your code except the definition for SBranch is all correct. The problem with your definition is that you don't get the right information when pattern-matching. For example, say you have x with type `SBTree a`. If you successfully pattern match against
 `SBranch SZ SLeaf SLeaf`, you would want to learn `a ~ Branch Z Leaf Leaf`. But that's not what you'll get in your implementation: you'll get a type error saying that we don't know that `a0` is an `SNat`, where `a ~ Branch a0 Leaf Leaf`, or something like
 that. The type-level information is simply encoded in the wrong place for this to work out.</div>
<div><br>
</div>
<div>Write back and I'll give you the full answer if this isn't enough to get you moving in the right direction!</div>
<div><br>
</div>
<div>Richard</div>
<br>
<div>
<div>On Apr 28, 2015, at 10:45 AM, "Nicholls, Mark" <<a href="mailto:nicholls.mark@vimn.com">nicholls.mark@vimn.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<blockquote type="cite">
<div lang="EN-US" link="blue" vlink="purple" style="font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; ">
<div class="WordSection1" style="page: WordSection1; ">
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); ">Can someone check my answer (no I’m not doing an assessment…I’m actually learning stuff out of interest!)<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); "> </span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB">working through<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB"> </span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB"><a href="https://www.fpcomplete.com/user/konn/prove-your-haskell-for-great-safety/dependent-types-in-haskell" style="color: purple; text-decoration: underline; ">https://www.fpcomplete.com/user/konn/prove-your-haskell-for-great-safety/dependent-types-in-haskell</a><o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); "> </span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); ">still there is a section about singleton types and the exercise is<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); "> </span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); ">“Exercise: Define the binary tree type and implement its singleton type.”<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); "> </span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); ">Ok, I think I’m probably wrong….a binary tree is something like…<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); "> </span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); ">> data BTree a = Leaf | Branch a (BTree a) (BTree a)<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); "> </span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); ">With DataKind<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); "> </span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); ">My logic goes…<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); ">Leaf is an uninhabited type, so I need a value isomorphic to it….<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); "> </span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); ">Easy?<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); "> </span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); ">> data SBTree a where<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); ">>   SLeaf :: SBTree Leaf<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); "> </span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); ">Things like<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); ">Branch Integer Leaf  (Branch String Leaf Leaf)<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); ">Are uninhabited…so I need to add<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); "> </span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); ">>   SBranch :: (a :: *) -> (SBTree (b :: BTree *)) -> (SBTree (c :: BTree *)) -> SBTree (Branch a b c)<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); "> </span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); ">?<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); "> </span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); ">It compiles…but….is it actually correct?<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); "><o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); ">Things like<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); "> </span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); ">> y = SBranch (SS (SS SZ)) SLeaf SLeaf<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); ">> z = SBranch (SS (SS SZ)) (SBranch SZ SLeaf SLeaf) SLeaf<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); "> </span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); ">Seem to make sense ish.<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="color: rgb(31, 73, 125); "> </span></div>
<div>
<div style="border-style: solid none none; border-top-width: 1pt; border-top-color: rgb(181, 196, 223); padding: 3pt 0cm 0cm; ">
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<b><span style="font-size: 10pt; font-family: Tahoma, sans-serif; ">From:</span></b><span style="font-size: 10pt; font-family: Tahoma, sans-serif; "><span class="Apple-converted-space"> </span>Nicholls, Mark<span class="Apple-converted-space"> </span><br>
<b>Sent:</b><span class="Apple-converted-space"> </span>28 April 2015 9:33 AM<br>
<b>To:</b><span class="Apple-converted-space"> </span>Nicholls, Mark<br>
<b>Subject:</b><span class="Apple-converted-space"> </span>sds<o:p></o:p></span></div>
</div>
</div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<o:p> </o:p></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB">Hello,<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB"> </span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB">working through<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB"> </span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB"><a href="https://www.fpcomplete.com/user/konn/prove-your-haskell-for-great-safety/dependent-types-in-haskell" style="color: purple; text-decoration: underline; ">https://www.fpcomplete.com/user/konn/prove-your-haskell-for-great-safety/dependent-types-in-haskell</a><o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB"> </span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB">but a bit stuck...with an error...<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB"> </span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB">> {-# LANGUAGE DataKinds, TypeFamilies, TypeOperators, UndecidableInstances, GADTs, StandaloneDeriving #-}<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB"> </span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB">> data Nat = Z | S Nat<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB"> </span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB">> data Vector a n where<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB">>   Nil  :: Vector a Z<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB">>   (:-) :: a -> Vector a n -> Vector a (S n)<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB">> infixr 5 :-<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB"> </span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB">I assume init...is a bit like tail but take n - 1 elements from the front....but...<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB"> </span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB">> init' :: Vector a ('S n) -> Vector a n<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB">> init' (x :- Nil) = Nil<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB">> init' (x :- xs@(_ :- _)) = x :- (init' xs)<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB"> </span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB">> zipWithSame :: (a -> b -> c) -> Vector a n -> Vector b n -> Vector c n<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB">> zipWithSame f Nil Nil = Nil<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB">> zipWithSame f (x :- xs) (y :- xs@(_ :- _)) = Nil<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB"> </span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<b><span lang="EN-GB" style="font-size: 8pt; font-family: Tahoma, sans-serif; color: teal; ">Mark Nicholls<span class="Apple-converted-space"> </span></span></b><span lang="EN-GB" style="font-size: 8pt; font-family: Tahoma, sans-serif; color: teal; ">| Senior
 Technical Director, Programmes & Development - Viacom International Media Networks</span><span lang="EN-GB" style="font-size: 8pt; color: rgb(31, 73, 125); "><br>
</span><b><span lang="EN-GB" style="font-size: 8pt; font-family: Tahoma, sans-serif; color: teal; ">A:</span></b><span lang="EN-GB" style="font-size: 8pt; color: rgb(31, 73, 125); "> </span><span lang="EN-GB" style="font-size: 8pt; font-family: Tahoma, sans-serif; color: teal; ">17-29
 Hawley Crescent London NW1 8TT |<span class="Apple-converted-space"> </span><b>e:</b><span class="Apple-converted-space"> </span><a href="mailto:mik@vimn.com" style="color: purple; text-decoration: underline; ">Nicholls.Mark@vimn.com</a><span class="Apple-converted-space"> </span>T<b>:</b></span><span lang="EN-GB" style="font-size: 8pt; color: rgb(31, 73, 125); "> </span><span lang="EN-GB" style="font-size: 8pt; font-family: Tahoma, sans-serif; color: teal; ">+44
 (0)203 580 2223<o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB" style="font-size: 10pt; color: rgb(31, 73, 125); "> </span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB" style="color: rgb(31, 73, 125); "><image001.png></span><span style="color: rgb(31, 73, 125); "><o:p></o:p></span></div>
<div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span lang="EN-GB"> </span></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>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" style="color: purple; text-decoration: underline; ">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" style="color: purple; text-decoration: underline; ">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
</div>
</blockquote>
</div>
<br>
</div>
</blockquote>
<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>