<div dir="ltr"><div dir="ltr" style="font-size:12.8000001907349px">> If all you can do with WibblePackage is recover either a Foo or a Bar, why not just use Either Foo Bar?</div><div><br></div><div>Typically, I just go straight for "data types a la carte" when I need any kind of type-level disjunction.  Define the type synonym:</div><div><br></div><div><font face="monospace, monospace">type (:+:) a b = Either a b</font></div><div><br></div><div>and define a type class</div><div><br></div><div><font face="monospace, monospace">class (:<:) a b where</font></div><div><font face="monospace, monospace">  inj :: a -> b</font></div><div><br></div><div>with some appropriate instances (as specified in the paper)[1], and you can chain disjunctions almost automatically:</div><div><br></div><div><font face="monospace, monospace">data Commercial = Commercial</font></div><div><font face="monospace, monospace">data Retail = Retail</font></div><div><font face="monospace, monospace">data Investment = Investment</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">type Bank = Retail :+: Commercial :+: Investment</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">bac :: Bank</font></div><div><font face="monospace, monospace">bac = inj $ Retail</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">[1]: <a href="http://www.cs.ru.nl/~W.Swierstra/Publications/DataTypesALaCarte.pdf">http://www.cs.ru.nl/~W.Swierstra/Publications/DataTypesALaCarte.pdf</a></font></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jun 19, 2015 at 9:10 AM, Patrick Chilton <span dir="ltr"><<a href="mailto:chpatrick@gmail.com" target="_blank">chpatrick@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">This is a frequent antipattern: <a href="https://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existential-typeclass/" target="_blank">https://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existential-typeclass/</a><div><br></div><div>If all you can do with WibblePackage is recover either a Foo or a Bar, why not just use Either Foo Bar?</div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Fri, Jun 19, 2015 at 5:09 PM, Nicholls, Mark <span dir="ltr"><<a href="mailto:nicholls.mark@vimn.com" target="_blank">nicholls.mark@vimn.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">





<div lang="EN-GB" link="blue" vlink="purple">
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">The design pattern is very well known in the OO community…most of the use cases evaporate in Haskell….in some sense its part of the language…<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Haskell is my 9<sup>th</sup> or 10<sup>th</sup> language, I can barely write “hello world” without the manual, so I’m still at times I’m still trying to discover
 the basic idioms…<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">How to put heterogenuos things in a list…and yet not loose all type information (I know about HList…but I think that’s for special occasions)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></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""> Haskell-Cafe [mailto:<a href="mailto:haskell-cafe-bounces@haskell.org" target="_blank">haskell-cafe-bounces@haskell.org</a>]
<b>On Behalf Of </b>Anupam Jain<br>
<b>Sent:</b> 19 June 2015 5:04 PM<br>
<b>To:</b> haskell-cafe Cafe<br>
<b>Subject:</b> Re: [Haskell-cafe] Do people use visitor pattern in Haskell...<u></u><u></u></span></p>
</div>
</div><div><div>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I discovered the same general pattern foroop <br>
<br>
On Friday, June 19, 2015, Nicholls, Mark <<a href="mailto:nicholls.mark@vimn.com" target="_blank">nicholls.mark@vimn.com</a>> wrote:<u></u><u></u></p>
<div>
<div>
<p class="MsoNormal">My initial guess would be no…its built into the language<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">But….<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">I find myself tempted to use it (in order to match on a type that’s the instance of a typeclass)…which makes me think I’ve missed something.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">So…<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">> data Foo = Foo<u></u><u></u></p>
<p class="MsoNormal">> data Bar = Bar<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Ooo…this looks like an OO design pattern…surely wrong?<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">> class Wibble a where<u></u><u></u></p>
<p class="MsoNormal">>   visit :: (Foo -> b) -> (Bar -> b) -> a -> b<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">> instance Wibble Foo where<u></u><u></u></p>
<p class="MsoNormal">>   visit f _ x = f x<u></u><u></u></p>
<p class="MsoNormal">> instance Wibble Bar where<u></u><u></u></p>
<p class="MsoNormal">>   visit _ f x = f x<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">I want a list of Wibbles....<u></u><u></u></p>
<p class="MsoNormal">hmmm...<u></u><u></u></p>
<p class="MsoNormal">(Wibble a) => [a] is clearly wrong...<u></u><u></u></p>
<p class="MsoNormal">I want [(Wibble a) =>a]<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">so I package it up?<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">> data WibblePackage where<u></u><u></u></p>
<p class="MsoNormal">>   WibblePackage :: (Wibble a) => a -> WibblePackage<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">lets try this now…so pointless function across Wibbles in a list.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">> fizzBuzz :: [WibblePackage] -> Integer<u></u><u></u></p>
<p class="MsoNormal">> fizzBuzz []       = 0<u></u><u></u></p>
<p class="MsoNormal">> fizzBuzz ((WibblePackage x) : xs) = (visit (\_ -> 1) (\_ -> 2) x) + (fizzBuzz xs)<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">> help :: Integer<u></u><u></u></p>
<p class="MsoNormal">> help = fizzBuzz [WibblePackage Foo,WibblePackage Bar]<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">That works!<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">OO nerds will get uptight about “closing” the Wibble typeclass….but I’ve managed to create a list of different types and have a mechanism for recovering the type.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">How would a Haskell nerd do this? (I have looked, but they look more complicated….maybe to my OO eye).<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
</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.<u></u><u></u></p>
</div>
<p class="MsoNormal"><br>
<br>
-- <br>
Sent from my hyper-communicator<u></u><u></u></p>
</div></div></div>
</div><div><div>
<p></p>
<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></div></div></div>

<br></div></div><span class="">_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
<br></span></blockquote></div><br></div>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div>