tag:blogger.com,1999:blog-30492580335656537382024-03-09T18:46:27.784-08:00Biosimilarityleithaushttp://www.blogger.com/profile/01069099703796397027noreply@blogger.comBlogger66125tag:blogger.com,1999:blog-3049258033565653738.post-55350036960883216172015-02-06T15:58:00.001-08:002015-02-06T16:18:02.382-08:00Why Synereo?<span style="font-family: Arial, Helvetica, sans-serif;">A new decentralized, distributed social network is emerging, and naturally people are curious. Gideon Rosenblatt asks a key question: Why Synereo instead of Facebook?</span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjF39k5wPAjkaQUuOhyiWyrTT0DHFDNy9WfWaxz1vQ7wgFa0rcBXrdyPl5LI9zzzkBGVEOCDXVj2bjwa4MuFjN-I-Dpa-hL6ty_5VViVRW4-zg1TYJt5oIfBLN5yHJc9qU8_hbxvcqThqW5/s1600/SynereoWebSiteSS1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjF39k5wPAjkaQUuOhyiWyrTT0DHFDNy9WfWaxz1vQ7wgFa0rcBXrdyPl5LI9zzzkBGVEOCDXVj2bjwa4MuFjN-I-Dpa-hL6ty_5VViVRW4-zg1TYJt5oIfBLN5yHJc9qU8_hbxvcqThqW5/s1600/SynereoWebSiteSS1.jpg" height="175" width="320" /></a></div>
<br />
<span style="font-family: Arial, Helvetica, sans-serif;">i provide an answer here in six basic points that cover <span style="background-color: white; color: #141823; line-height: 21.466667175293px;">architecture and information flow consequences for resiliency, autonomy, and privacy, as well as important aspects of the user experience, user compensation and the attention economy.</span></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="background-color: white; color: #141823; line-height: 21.466667175293px;"><br /></span></span>
<br />
<div style="text-align: center;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="background-color: white; color: #141823; line-height: 21.466667175293px;"><b>TL;DR: you are the network, not the product.</b></span></span></div>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="background-color: white; color: #141823; line-height: 21.466667175293px;"><br /></span></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.0" style="background-color: #f6f7f8; color: #141823; line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.0.$end:0:$0:0">1) A distributed, decentralized architecture is more resilient against certain kinds of attacks. From a hacker hacking a centralized service and scooping up all the credit card data from a single database to a government shutting down a service providi</span></span><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="background-color: #f6f7f8; color: #141823; line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0">ng information counter to the incumbent narrative, a distributed, decentralized architecture is more resilient against these kinds of attacks. Clearly, this is not the architecture that Facebook enjoys or promotes. It can't because its revenue model wouldn't work well in this setting.</span></span></span></span><br />
<span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="background-color: #f6f7f8; color: #141823; line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></span></span></span>
<span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="background-color: #f6f7f8; color: #141823; line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"><span style="font-family: Arial, Helvetica, sans-serif;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792837524:0.0.$right.0.$left.0.0.1:$comment-body.0.0" style="line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792837524:0.0.$right.0.$left.0.0.1:$comment-body.0.0.$end:0:$0:0">2) Above this architecture, Synereo provides a qualitative notion of identity. This is not about identity as token because that notion of identity doesn't serve individuals who have rich internal multifaceted presence. What is needed is to be</span></span><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792837524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792837524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792837524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"> able to reveal enough about oneself to participate legitimately in a conversation without necessarily revealing information that is either sensitive or irrelevant. Consider a self-governance or participatory democracy process like <a href="http://conteneo.co/san-jose-residents-play-4th-annual-budget-games/">the budget games</a>. Were these conducted in an online situation people might be less likely to participate if the games revealed information about their political views that made them the target of unwanted attention. In the US such issues have included healthcare reform and gay marriage. On the other hand, a government representative needs assurances that the online participants are actually registered voters in their districts and not bots. Synereo allows users to reveal enough identity-related information to participate in a variety of processes without necessarily provding personally identifiable information. If someone is pursuing employment from an employer that is ok with them working remotely, then the employment application process doesn't have to reveal the candidates' residential address. Again, this approach doesn't fit with Facebook's revenue model.</span></span></span></span></span></span></span><br />
<span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="background-color: #f6f7f8; color: #141823; line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792837524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792837524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792837524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></span></span></span></span></span></span>
<span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="background-color: #f6f7f8; color: #141823; line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792837524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792837524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792837524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"><span style="font-family: Arial, Helvetica, sans-serif;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793097524:0.0.$right.0.$left.0.0.1:$comment-body.0.0" style="line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793097524:0.0.$right.0.$left.0.0.1:$comment-body.0.0.$end:0:$0:0">3) Synereo makes strong guarantees about never letting Synereo code see user data in the clear (unless users' give explicit permission). Despite these guarantees, Synereo provides a sophisticated search mechanism that allows users to search content thr</span></span><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793097524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793097524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793097524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0">oughout the slice of the network visible to them. <a href="https://www.facebook.com/graphsearcher">Facebook just rolled out a graph search</a>. <a href="http://www.wordstream.com/blog/ws/2013/10/24/">Many people are very concerned about what this means about privacy</a>. If you would like to know more about how Synereo achieves this, awesome! Please contact me and i will personally explain the mechanism in as much detail as you would like. <a href="http://ctp.di.fct.unl.pt/SLMC/">Beyond this Synereo is based on a mathematical model of decentralized and distributed computing that allows for the specification and enforcement of information flow policies</a>. The language for these policies is exceedingly rich -- considerably richer than friends, friends-of-friends, etc. These policies can be autonomously developed and assembled into larger policies. The polices can be checked for desirable properties. This provides the basis for smart contracts that allows for just-in-time assembling of services from subcontractors. In other words, Synereo can help groups assemble temporarily to form an organization to complete a task or provide a service. This level of sophistication just doesn't exist in Facebook. It doesn't even exist in Ethereum. The Synereo white paper describes an example of information flow policies as relates to public health and public safety. We believe Synereo's feature set makes it an ideal mechanism for participatory self-governance.</span></span></span></span></span></span></span></span></span></span><br />
<span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="background-color: #f6f7f8; color: #141823; line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792837524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792837524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792837524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793097524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793097524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793097524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></span></span></span></span></span></span></span></span></span>
<span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="background-color: #f6f7f8; color: #141823; line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792837524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792837524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792837524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793097524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793097524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793097524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"><span style="font-family: Arial, Helvetica, sans-serif;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793372524:0.0.$right.0.$left.0.0.1:$comment-body.0.0" style="line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793372524:0.0.$right.0.$left.0.0.1:$comment-body.0.0.$end:0:$0:0">4) Synereo provides the attention economy model. This allows participants in the network to begin to get some of the reward for their participation. It's not just that the monetization of attention deployed in social networks is commonly estimated in t</span></span><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793372524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793372524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793372524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0">he 10's of billions of USD. Nor that Facebook users never see a penny of that. It's also that as a result of the shift in distribution mechanism the creative classes are under unbearable pressure. When a guitarist of the stature of David Torn gets 8USD from Pandora for 100,000s of plays of one of his tunes, making a living as a guitarist becomes nearly untenable. This is not a one time occurrence. Read <a href="http://zoekeating.tumblr.com/post/108898194009/what-should-i-do-about-youtube">Zoe Keating's article about how YouTube is treating her</a> as they roll out their new music service. This same scenario is playing out in journalism, photography, etc. The creative classes are under siege. The attention economy provides a direct way for creative people to earn compensation for their creative outpouring. Facebook simply doesn't have such a model and it would directly undermine their existing revenue model.</span></span></span></span></span></span></span></span></span></span></span></span></span><br />
<span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="background-color: #f6f7f8; color: #141823; line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792837524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792837524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792837524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793097524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793097524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793097524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793372524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793372524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793372524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></span></span></span></span></span></span></span></span></span></span></span></span>
<span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="background-color: #f6f7f8; color: #141823; line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792837524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792837524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792837524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793097524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793097524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793097524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793372524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793372524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793372524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"><span style="font-family: Arial, Helvetica, sans-serif;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793787524:0.0.$right.0.$left.0.0.1:$comment-body.0.0" style="line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793787524:0.0.$right.0.$left.0.0.1:$comment-body.0.0.$end:0:$0:0">5) Synereo provides users with a new level of control over what shows up in their feed. At this level of detail we can say that Synereo identifies two basic types of entities, ports and filters. A port can either be a source of information (like one of</span></span><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793787524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793787524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793787524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"> your friends from whom you receive posts, or an rss feed to which you are subscribed, or a mailing list to which you are subscribed, or a device on the Internet of things, or ...) or a sink for information (like one of your friends, or an rss feed to which you publish, or ... ). A filter is something applied to the stream of information flowing into or out of a port to further refine what goes into or comes out of the stream. Notice that when you combine a filter with a port you get a new port. This kind of 'algebra' of information flow components gives users a new toolkit for controlling what they see in their feed. It also has fairly natural UI metaphors that have a long history of success as a means of conveying the presentation of streams of events. This leads is to the last point.</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br />
<span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="background-color: #f6f7f8; color: #141823; line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792837524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792837524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792837524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793097524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793097524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793097524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793372524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793372524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793372524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793787524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793787524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793787524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
<span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="background-color: #f6f7f8; color: #141823; line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792342524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792837524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792837524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018792837524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793097524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793097524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793097524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793372524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793372524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793372524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793787524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793787524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018793787524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0"><span style="font-family: Arial, Helvetica, sans-serif;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018794227524:0.0.$right.0.$left.0.0.1:$comment-body.0.0" style="line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018794227524:0.0.$right.0.$left.0.0.1:$comment-body.0.0.$end:0:$0:0">6) Synereo provides new UI experiences that allow for users to see more about the dynamics of information flow. As a simple example, Facebook organizes the posts of all your friends into a single interleaved stream. If you were to uninterleave this int</span></span><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018794227524:0.0.$right.0.$left.0.0.1:$comment-body.0.3" style="line-height: 17.0666675567627px;"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018794227524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0"><span data-reactid=".9x.1:3:1:$comment10154018791987524_10154018794227524:0.0.$right.0.$left.0.0.1:$comment-body.0.3.0.$end:0:$0:0">o several streams that were synced by timestamp you would see how your friends' posts were related to each other in time. <a href="https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=7&ved=0CEMQtwIwBg&url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DCjSr9Iui1ko&ei=DFnVVMjbKcKtogS3m4GQBg&usg=AFQjCNG5WBNQqVeWSkJYrD_wyqgpKXW6JA&sig2=44adMKqQWhtbFDoIR0-9SQ&bvm=bv.85464276,d.cGU">Picture in your mind's eye 5 timelines running left to right. One timeline for one of 5 friends.</a> Each timeline provides an iconic representation of that friend's posts. When posts stack up in a near vertical line it means that your friends are posting at the same time. This gives you a way to see into the temporal dynamics of the communications of your group of friends. The reason i chose 5 is because there are 5 lines in a single musical staff. Just as the vertical stacking of notes on a staff represents play these notes at the same time, i.e. play a chord, chords in the 'score' representation of timelines allow for people to see how peoples actions are related in time. Any 6yr old can learn to read the temporal dynamics off of a single staff. A good conductor can read and hear in her mind 7 staves. So, the surface of inborn information processing capacity of the human mind for processing temporal dynamics is not even being scratched, let alone the depths plumbed. Facebook does not actually have a vested interest in users being able to utilize their capacity. They have a vested interest in directing attention in a way that maximizes return for their investors.</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>leithaushttp://www.blogger.com/profile/01069099703796397027noreply@blogger.com4tag:blogger.com,1999:blog-3049258033565653738.post-16647858996011431102014-12-21T20:44:00.001-08:002014-12-22T11:53:26.445-08:00Enzymatic interactionIt is traditional for me, around this time of year, to provide holiday (brain) candy for folks in my technical community. This year's offering comes from a conversation with Marius Buliga about <a href="https://github.com/chorasimilarity/chemlambda-gui">chemlambda</a> in which he referred to <a href="http://en.wikipedia.org/wiki/Lambda_calculus#Beta_reduction"><span style="background-color: #f9f9f9; color: #252525; font-family: sans-serif; line-height: 17.2479991912842px;">β</span>-reduction</a> in the <a href="http://en.wikipedia.org/wiki/Lambda_calculus"><span style="background-color: #f9f9f9; color: #252525; font-family: sans-serif; line-height: 17.2479991912842px;">λ</span>-calculus</a> as an <a href="http://en.wikipedia.org/wiki/Enzyme">enzyme</a>. This got me to thinking about explicitly modeling the COMM rule in the π-calculus as an enzyme. It turns out you can do this quite easily and it has a lot of applications!<br />
<br />
For simplicity, i'll use the <a href="http://dl.acm.org/citation.cfm?id=1705674">reflective, higher-order π-calculus</a>, but extend the basic calculus with a primitive process, <span style="background-color: white; color: #222222; font-family: Arial, Helvetica, sans-serif;">COMM</span>:<br />
<br />
<div style="background-color: white; color: #222222;">
<span style="font-family: Arial, Helvetica, sans-serif;">P, Q ::= 0 | COMM | x?( y )P | x!( P ) | *x | P|Q<br />x, y ::= @P</span></div>
<div style="background-color: white; color: #222222;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="color: #222222;">
<span style="background-color: white;">(Note that i've adopted a slightly friendlier syntax since i first developed the reflective π-calculus. Instead of writing </span><span style="font-family: Arial, Helvetica, sans-serif;"><span style="background-color: white; color: black;">«</span><span style="background-color: #eeeeee; color: black;"> </span><span style="background-color: white;">P </span><span style="background-color: white; color: black;">»</span></span><span style="background-color: white;"> and </span><span style="font-family: Arial, Helvetica, sans-serif;"><span style="background-color: white; color: black;">» </span><span style="background-color: white;">x </span><span style="background-color: white; color: black;">«</span></span><span style="background-color: white;">, i now write <span style="font-family: Arial, Helvetica, sans-serif;">@P</span> and <span style="font-family: Arial, Helvetica, sans-serif;">*x</span>. This echoes the C and C++ programming language notation for acquiring a reference and dereferencing a pointer, respectively -- which is the key insight of the reflective calculus. We can get a kind of pointer arithmetic for channel names if we treat them as quoted process terms.)</span><br />
<div style="background-color: white;">
<br /></div>
<div style="background-color: white;">
<span style="font-family: inherit;"><a href="http://en.wikipedia.org/wiki/%CE%A0-calculus#Structural_congruence">Structural equivalence</a> includes <a href="http://en.wikipedia.org/wiki/Lambda_calculus#Alpha_equivalence">alpha-equivalence</a> and makes </span><span style="font-family: arial, sans-serif;">( P, | , 0 ) </span><span style="font-family: inherit;">a <a href="http://en.wikipedia.org/wiki/Monoid#Commutative_monoid">commutative monoid</a>. Of interest to us is</span></div>
</div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif;">
<br /></div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif;">
COMM | P = P | COMM</div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif;">
<br /></div>
<div style="background-color: white; color: #222222;">
<span style="font-family: inherit;">So, </span><span style="font-family: arial, sans-serif;">COMM </span><span style="font-family: inherit;">mixes into a parallel composition.</span></div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif;">
<br /></div>
<div style="background-color: white; color: #222222;">
<span style="font-family: inherit;">Notice that COMM cannot penetrate an abstraction barrier, i.e. </span><br />
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: inherit;"><br /></span></div>
</div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif;">
<br /></div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif;">
x?( y )P | COMM != x?( y )( P | COMM )<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; margin-left: 1em; text-align: right;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiL4KxNIawkHUa1bRcWJJ5hmt52QBzhyphenhyphenGIdVpDZaL_FwGWIXbpsZjTEZFFjZQsHhc_kdYxPJmsuDk2eg2LHTiJzHKrVRbxyjbQADhJYd_YQM7DLrh7XT2wMdFYfq5UmveJiXTH1xw9olSaW/s1600/EnzymaticReductionInRHOCalculus.jpg" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiL4KxNIawkHUa1bRcWJJ5hmt52QBzhyphenhyphenGIdVpDZaL_FwGWIXbpsZjTEZFFjZQsHhc_kdYxPJmsuDk2eg2LHTiJzHKrVRbxyjbQADhJYd_YQM7DLrh7XT2wMdFYfq5UmveJiXTH1xw9olSaW/s1600/EnzymaticReductionInRHOCalculus.jpg" height="320" width="275" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Enzymatic reduction in reflective π-calculus</td></tr>
</tbody></table>
</div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif;">
<br /></div>
<div style="background-color: white; color: #222222;">
<span style="font-family: inherit;">There is an interesting design choice as to whether</span></div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif;">
<br /></div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif;">
x!( Q ) | COMM = x!( Q | COMM ) </div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif;">
<br /></div>
<div style="background-color: white; color: #222222;">
<span style="font-family: inherit;">Treating </span><span style="font-family: Arial, Helvetica, sans-serif;">COMM</span><span style="font-family: inherit;"> as enzymatic, the </span><span style="font-family: Arial, Helvetica, sans-serif;">COMM</span><span style="font-family: inherit;">-rule</span></div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif;">
<br /></div>
<div style="color: #222222;">
<span style="background-color: white; font-family: arial, sans-serif;">x?( y )P | COMM | x!( Q ) </span><span style="background-color: white; color: #444444; font-family: Arial, Helvetica, sans-serif; font-size: 18px; line-height: 20px;">→</span><span style="background-color: white; font-family: arial, sans-serif;"> P{ @Q/y } | COMM </span></div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif;">
<br /></div>
<div style="background-color: white; color: #222222;">
<span style="font-family: inherit;">results in the standard dynamics, </span><i><span style="font-family: inherit;">if there is just one </span><span style="font-family: Arial, Helvetica, sans-serif;">COMM</span><span style="font-family: inherit;"> process in the expression</span></i><span style="font-family: inherit;">. If there are more </span><span style="font-family: Arial, Helvetica, sans-serif;">COMM</span><span style="font-family: inherit;"> processes, then we get a spectrum of so-called <a href="http://cs.stackexchange.com/questions/11893/what-does-true-concurrency-mean">true concurrency semantics</a>, with the usual true concurrency semantics identified with the limiting equation</span></div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif;">
<br /></div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif;">
COMM = COMM | COMM</div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif;">
<br /></div>
<div style="background-color: white; color: #222222;">
<span style="font-family: inherit;">which allows to saturate a parallel composition with </span><span style="font-family: Arial, Helvetica, sans-serif;">COMM</span><span style="font-family: inherit;"> in every place where an interaction could take place.</span></div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif;">
<br /></div>
<div style="background-color: white; color: #222222;">
<span style="font-family: inherit;">Writing </span><span style="font-family: arial, sans-serif;">COMM<sup>i</sup> </span><span style="font-family: inherit;">for</span><span style="font-family: arial, sans-serif;"> COMM | ... | COMM </span><span style="font-family: inherit;">( </span><span style="font-family: Arial, Helvetica, sans-serif;">i</span><span style="font-family: inherit;"> times ), another set of dynamics arise from rules of the form</span></div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif;">
<br /></div>
<div style="color: #222222;">
<span style="background-color: white; font-family: arial, sans-serif;">x?( y )P | COMM</span><sup style="background-color: white; font-family: arial, sans-serif;">n</sup><span style="background-color: white; font-family: arial, sans-serif;"> | x!( Q ) </span><span style="background-color: white; color: #444444; font-family: Arial, Helvetica, sans-serif; font-size: 18px; line-height: 20px;">→</span><span style="font-family: arial, sans-serif;"><span style="background-color: white;"> </span><span style="background-color: white;">P{ @Q/y } | COMM</span></span><sup style="background-color: white; font-family: arial, sans-serif;">m</sup></div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif;">
<br /></div>
<div style="background-color: white; color: #222222;">
<span style="font-family: inherit;">with </span><span style="font-family: Arial, Helvetica, sans-serif;">m < n</span></div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif;">
<br /></div>
<div style="background-color: white; color: #222222;">
<span style="font-family: inherit;">This bears resemblance to the <a href="http://en.wikipedia.org/wiki/Ethereum">Ethereum</a> platform's idea of <a href="https://www.ethereum.org/pdfs/EthereumWhitePaper.pdf">"gas" for a smart contract's calculation</a>. Mike Stay points out that associating a cost with communication makes it look like an action in physics. Notice that you can get some very interesting dynamics with </span><span style="font-family: arial, sans-serif;">COMM</span><span style="font-family: inherit;">-consuming interaction rules in the presence of </span><span style="font-family: arial, sans-serif;">COMM</span><span style="font-family: inherit;">-releasing abstractions.</span></div>
<div style="background-color: white; color: #222222;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #222222;">
<div style="background-color: white;">
<span style="font-family: inherit;">One example interpretation that i think works well and provides significant motivation is to treat </span><span style="font-family: arial, sans-serif;">COMM</span><span style="font-family: inherit;"> as a compute node. A finite number of </span><span style="font-family: arial, sans-serif;">COMM</span><span style="font-family: inherit;">s represent a finite number of nodes on which processes can run. Likewise, it is possible to</span><span style="font-family: inherit;"> model acquisition and release of nodes with cost-based </span><span style="font-family: arial, sans-serif;">COMM</span><span style="font-family: inherit;">-rules and certain code factorings. For example, call a process inert if </span><span style="font-family: arial, sans-serif;">P | COMM</span><span style="font-family: inherit;"> cannot reduce and purely inert if </span><span style="font-family: arial, sans-serif;">P</span><span style="font-family: inherit;"> inert and </span><span style="font-family: arial, sans-serif;">P != Q | COMM</span><span style="font-family: inherit;"> for any </span><span style="font-family: arial, sans-serif;">Q</span><span style="font-family: inherit;">. Now, suppose</span></div>
<div style="background-color: white; font-family: arial, sans-serif;">
<br /></div>
<div>
<span style="background-color: white; font-family: arial, sans-serif;">COMM: x?( y )P | COMM</span><sup style="background-color: white; font-family: arial, sans-serif;">n</sup><span style="background-color: white; font-family: arial, sans-serif;"> | x!( Q ) </span><span style="background-color: white; color: #444444; font-family: Arial, Helvetica, sans-serif; font-size: 18px; line-height: 20px;">→</span><span style="background-color: white; font-family: arial, sans-serif;"> P{ @( Q | COMM )/y } | COMM</span><sup style="background-color: white; font-family: arial, sans-serif;">n-1</sup></div>
<div style="background-color: white; font-family: arial, sans-serif;">
<br /></div>
<div>
<div style="background-color: white;">
<span style="font-family: inherit;">and only allow purely inert processes in output position, i.e. </span><span style="font-family: arial, sans-serif;">x!( Q )</span><span style="font-family: inherit;">, with Q inert. </span><span style="font-family: inherit;">Then interaction acquires a node and dereference, </span><span style="font-family: arial, sans-serif;">*x</span><span style="font-family: inherit;"> releases one. For example,</span></div>
<div style="background-color: white;">
<span style="font-family: inherit;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">x?( y )( *y ) | COMM | x!( Q ) </span></div>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="background-color: white; color: #444444; font-size: 18px; line-height: 20px;">→</span><span style="background-color: white;"> </span></span><br />
<div style="background-color: white;">
<span style="font-family: Arial, Helvetica, sans-serif;">*@( COMM | Q ) </span></div>
<span style="background-color: white; color: black; text-align: center;">≡</span><span style="background-color: white; color: black; text-align: center;"> </span><br />
<div style="background-color: white;">
<span style="font-family: Arial, Helvetica, sans-serif;">COMM | Q</span></div>
</div>
</div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif;">
<br /></div>
<div style="background-color: white; color: #222222;">
<span style="font-family: inherit;">In terms of possible <a href="http://en.wikipedia.org/wiki/Higher_category_theory">higher category theory</a> models, the reification of the 2-cell-like </span><span style="font-family: arial, sans-serif;">COMM</span><span style="font-family: inherit;">-rule as a 1-cell-like </span><span style="font-family: arial, sans-serif;">COMM</span><span style="font-family: inherit;"> process ought to provide a fairly simple way to make one of Mike Stay's recent higher category models work without suffering too many reductions, which has been the principal stumbling block of late. Notice that in this setting we can treat </span><span style="font-family: arial, sans-serif;">x?( y )( COMM | P ) </span><span style="font-family: inherit;">as an explicit annotation by the programmer that interaction under an abstraction is admitted. If they want to freeze abstraction contexts, they just don't put </span><span style="font-family: arial, sans-serif;">COMM</span><span style="font-family: inherit;"> under an abstraction where an interaction could take place. In more detail</span></div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif;">
<br /></div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif;">
x?( y )( u?( v )P | COMM | u!( Q ) )</div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif;">
<br /></div>
<div style="background-color: white; color: #222222;">
<span style="font-family: inherit;">constitutes a programmer-supplied annotation, it's okay to reduce under the ( y )-abstraction, while</span></div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif;">
<br /></div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif;">
x?( y )( u?( v )P | u!( Q ) )</div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif;">
<br /></div>
<div style="background-color: white; color: #222222;">
<span style="font-family: inherit;">is an indication that the term under this abstraction is frozen, until it is released by communication on </span><span style="font-family: Arial, Helvetica, sans-serif;">x</span><span style="font-family: inherit;">.</span></div>
<div style="background-color: white; color: #222222;">
<span style="font-family: inherit;"><br /></span>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZlMPqIAiL-7sdJL_KEGjAX8DK_JVn3IuILezvXBsznOx-KKztp883Irs-jztEfP7Vgc5pQbQihhTe0Uxndhrfp4BJdzvnv7I_-s66hukIeUHx1xO1jv8luIArKppsNUng1UyJo9PxYRnp/s1600/CompositionalPrograms.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZlMPqIAiL-7sdJL_KEGjAX8DK_JVn3IuILezvXBsznOx-KKztp883Irs-jztEfP7Vgc5pQbQihhTe0Uxndhrfp4BJdzvnv7I_-s66hukIeUHx1xO1jv8luIArKppsNUng1UyJo9PxYRnp/s1600/CompositionalPrograms.jpg" height="277" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Compositional interpretations of physical processes</td></tr>
</tbody></table>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><br /></span></div>
<div style="background-color: white; color: #222222;">
<span style="font-family: inherit;">This very simple insight of Marius' that interaction is enzymatically enabled creates a wide variety of dynamics that have broad range of applications! Merry Christmas to all and a Happy New Year!</span></div>
leithaushttp://www.blogger.com/profile/01069099703796397027noreply@blogger.com2tag:blogger.com,1999:blog-3049258033565653738.post-47227506183942431402014-05-29T16:07:00.000-07:002014-05-29T16:07:16.936-07:00Trust the principle
<div class="p1">
The cryptographic e-cash community was caught off-guard by BitCoin's adoption and success. <a href="http://crypto.stanford.edu/~xb/fc12/bitcoin.pdf">One group of researchers from PARC and Standford took heed and contemplated what factors contributed to that success</a>. Distribution and decentralization was one of the key features they identified as contributing to BitCoin's adoption and success. From the paper:</div>
<blockquote class="tr_bq">
<b>No central point of trust.</b> Bitcoin has a completely distributed architecture, without any single trusted entity. Bitcoin assumes that the majority of nodes in its network are honest, and resorts to a majority vote mechanism for double spending avoidance, and dispute resolution. In contrast, most e-cash schemes require a centralized bank who is trusted for purposes of e-cash issuance, and double-spending detection. This greatly appeals to individuals who wish for a freely-traded currency not in control by any governments, banks, or authorities — from libertarians to drug-dealers and other underground economy proponents (note that apart from the aforementioned illegal usages, there are numerous legitimate uses as well, which will be mentioned later). In a spirit similar to the original motivation for a distributed Internet, such a purely decentralized system guarantees that no single entity, no matter how initially benevolent, can succumb to the temptation or be coerced by a government into subverting it for its own benefit.</blockquote>
<div class="p1">
One way to look at the relationship of trust between individual and network in a distributed and decentralized architecture is that you can trust the network if you trust the underlying, organizing principles of the network. This kind of trust works differently than trust placed on any single or central individual. </div>
<div class="p1">
<br /></div>
<div class="p1">
There's a funny twist in this. While, on the one hand, it is possible to be physically present with an individual, to sit together with them, to look at them, hear them, and on the other, principles can seem to be much more abstract, much more removed, principles are often easier to grasp than individuals. <a href="http://quoteinvestigator.com/2010/12/27/eye-for-eye-blind/">As Gandhi's biographer, Louis Fischer, pointed out, the principle of 'an eye for an eye' can have the consequence of leaving everybody blind</a>. Yet, as history shows, the principle of Satyagraha and non-violent, peaceful protest, central to Gandhi's efforts, and a substantial influence on Martin Luther King's plays out differently. We can see into the workings of principles in a way that we often can't with individuals. This is not to say that individuals and even institutions can't embody a quality or principle that we wish to bring into the network. However, we have to see the whole of an individual before we can tell if they do indeed embody that quality or principle. We don't always have that access or that perspective on an individual.</div>
<div class="p1">
<br /></div>
<div class="p1">
<a href="https://bitcoin.org/bitcoin.pdf">BitCoin's architecture</a> weaves together principles that make the most of individuals more self-centered aspects such desire for personal gain and reticence to trust each other, and puts them in service of a higher aim, a trustworthy network. In short, it lets people be themselves, mostly honest, with some conceit, some deceit, and a need to connect to something greater. This asks for a qualitatively different relationship between the individual and the network: trust the principle that organizes the network by letting people be what they are.</div>
leithaushttp://www.blogger.com/profile/01069099703796397027noreply@blogger.com2tag:blogger.com,1999:blog-3049258033565653738.post-14037543232852062652014-05-15T11:13:00.000-07:002014-05-15T11:14:29.070-07:00splicious : facebook :: protunity : linkedinPeople don't really know what's gone into the development of www.splicious.net. A year before we launched the splicious crowd funding campaign we launched www.protunity.com. This was a test case to drive out the technology. One way to understand the relationships of these networks is via those old SAT-style analogies:<br />
<br />
<div style="text-align: center;">
splicious : facebook :: protunity : linkedin </div>
<br />
The underlying technology (barring lots of improvement between when we launched Protunity and now) is the same . Therefore, the splicious campaign is not like other campaigns where what they have is a vision, but no actual solution. We have a solution that's already at a certain level of maturity.<br />
<br />
We wanted to wait to bring this offering to market until we had at least that level of maturity. Additionally, we wanted to have an economic model that made sense, one that grows a self-sustaining network, free of ads and free of other corporate sponsorship. That's where the emerging cryptocurrency movement suddenly came into play. With BitCoin and other cryptocurrencies we can provide a distributed network that is self-sustaining.<br />
<br />
Really, if you look at the numbers, in terms of capital investment, and person-years, as well as technological innovation, we've provided 99.999% of the solution. We're looking to see if there's enough interest for people to help us with 0.001%. That's what we need to roll out the splicious network.<br />
<br />
We're confident that with even that level of engagement we can grow the network to a global alternative to the existing social messaging platforms. One that balances privacy and trust, one that values creativity and engagement, one that puts you back in charge of what you see of your Internet-communications, and who sees what you share.leithaushttp://www.blogger.com/profile/01069099703796397027noreply@blogger.com0tag:blogger.com,1999:blog-3049258033565653738.post-34132055937533606302014-05-14T13:15:00.000-07:002014-05-14T13:23:40.829-07:00Imagine all the people...<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Humans are social. We have a built-in urge to share observations, insights, thoughts and feelings. We have a need to feel received. The social media with their ubiquity, easy access, and ease of use meet this need relatively well. The simple feedback mechanism, clicking a “like” or “+1” button can be a powerful expression of sentiment and connection.</span><br />
<span style="color: #222222; font-family: Arial; font-size: 15px; line-height: 1.15; white-space: pre-wrap;"><br /></span>
<span style="color: #222222; font-family: Arial; font-size: 15px; line-height: 1.15; white-space: pre-wrap;">But, are you concerned about who can see communications meant for your friends, family, or colleagues, from your email to your FB posts?</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: #222222; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Are you concerned that your creative output and personally identifiable information are bought and sold by social media companies, advertisers, and whoever else they sell it on to?</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: #222222; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Is your feed overrun with ads and TMI that you can’t organize? Or worse, organized by someone else’s algorithm?</span><br />
<span style="color: #222222; font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><br /></span>
<span style="color: #222222; font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">Imagine a world where social media served </span><span style="color: #222222; font-family: Arial; font-size: 15px; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">you</span><span style="color: #222222; font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">. Period. </span><br />
<div class="separator" style="clear: both; text-align: center;">
<span style="color: #222222; font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_Icfm3EV06YtJFl7-R9gzw8yf0qzCBPpJr4MGK9h88ujvoNTkPWqXbCsPjCVdZud9uPSDBz4fqo75W2UWeKpu1s3BhxxpXN4VUb1YOxJehepjwwglz8CUMKqkZSbjCxi_gKU0JxVzacco/s1600/JohnLennon1.jpeg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_Icfm3EV06YtJFl7-R9gzw8yf0qzCBPpJr4MGK9h88ujvoNTkPWqXbCsPjCVdZud9uPSDBz4fqo75W2UWeKpu1s3BhxxpXN4VUb1YOxJehepjwwglz8CUMKqkZSbjCxi_gKU0JxVzacco/s1600/JohnLennon1.jpeg" height="197" width="200" /></a></span></div>
<br />
<span style="color: #222222; font-family: Arial; font-size: 15px; line-height: 1.15; white-space: pre-wrap;"><br /></span>
<span style="color: #222222; font-family: Arial; font-size: 15px; line-height: 1.15; white-space: pre-wrap;">What if the online outlets for your creativity, your music, political commentary, stories, recipes and designs were also outlets for earning money? </span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: #222222; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">What if they could allow you to support yourself and your friends, monetarily?</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: #222222; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">What if they could make it easy for you to play a more active role in deciding what you see and when, and who sees what you share?</span><br />
<br />
<a href="http://www.splicious.net/" style="font-family: Arial; font-size: 15px; line-height: 1.15; white-space: pre-wrap;">Splicious is a social communications platform designed from the ground up to solve these problems</a><span style="font-family: Arial; font-size: 15px; line-height: 1.15; white-space: pre-wrap;">.</span><br />
<span style="font-family: Arial; font-size: 15px; line-height: 1.15; white-space: pre-wrap;"><br /></span>
<span style="font-family: Arial; font-size: 15px; line-height: 1.15; white-space: pre-wrap;">Splicious helps you </span></div>
<ul style="margin-bottom: 0pt; margin-top: 0pt;">
<li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><a href="https://www.youtube.com/watch?v=NICs0j85wgo">focus</a></span></div>
</li>
<ul style="margin-bottom: 0pt; margin-top: 0pt;">
<li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: circle; text-decoration: none; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">dynamically organize your own ad-free feed, </span></div>
</li>
<li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: circle; text-decoration: none; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">label and search your messages and posts</span></div>
</li>
</ul>
<li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><a href="https://www.youtube.com/watch?v=f700b6IHZcc">conduct safe and easy transactions, using popular cryptocurrencies, like BitCoin</a>, to</span></div>
</li>
<ul style="margin-bottom: 0pt; margin-top: 0pt;">
<li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: circle; text-decoration: none; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">buy and sell stuff, or</span></div>
</li>
<li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: circle; text-decoration: none; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">raise money for a cause, or</span></div>
</li>
<li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: circle; text-decoration: none; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">or support people whose online contributions you value -- so they can keep doing what they love -- and </span></div>
</li>
<li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: circle; text-decoration: none; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">and never give a penny to Wall St</span></div>
</li>
</ul>
<li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><a href="https://www.youtube.com/watch?v=Tz2pmVGgrG4">and balance privacy AND trust</a></span></div>
</li>
<ul style="margin-bottom: 0pt; margin-top: 0pt;">
<li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: circle; text-decoration: none; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">with protocols for meeting new people</span></div>
</li>
<li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: circle; text-decoration: none; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">and verifying their claims with mutually trusted friends</span></div>
</li>
</ul>
</ul>
<span style="font-family: Arial; font-size: 15px; line-height: 1.15; white-space: pre-wrap;"></span><br />
<div>
<span style="font-family: Arial; font-size: 15px; line-height: 1.15; white-space: pre-wrap;"><span style="font-family: Arial; font-size: 15px; line-height: 1.15; white-space: pre-wrap;"><br /></span></span></div>
<span style="font-family: Arial; font-size: 15px; line-height: 1.15; white-space: pre-wrap;">We’re not coming to you with just a vision or a bright idea. Other teams have underestimated just how hard this problem is. </span><a href="https://docs.google.com/document/d/1aM5OIJWOyW89rHdUg6d9-YVbItdtxxiosP_fXZQaRdg/edit#" style="font-family: Arial; font-size: 15px; line-height: 1.15; white-space: pre-wrap;">The Splicious team has worked for 4.5 years to bring you this offering</a><span style="font-family: Arial; font-size: 15px; line-height: 1.15; white-space: pre-wrap;">. We know it can be prettier. We know it can be easier to use on mobile platforms like cell phones. We know there are a million ways it can be improved. That’s all a part of rolling out the network for your use. And we would love to do that work. </span><br />
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 15px; line-height: 1.15; white-space: pre-wrap;"><br /></span>
<span style="font-family: Arial; font-size: 15px; line-height: 1.15; white-space: pre-wrap;">We just need to know if the world we imagine is the world you want. That’s why we’re asking for your help to fund this phase of the project. </span><a href="https://www.youtube.com/watch?v=CWEGtoe14jE" style="font-family: Arial; font-size: 15px; line-height: 1.15; white-space: pre-wrap;">Here’s Mike Stay to tell you how we plan to roll out the network and how you can help us</a><span style="font-family: Arial; font-size: 15px; line-height: 1.15; white-space: pre-wrap;">.</span></div>
leithaushttp://www.blogger.com/profile/01069099703796397027noreply@blogger.com1tag:blogger.com,1999:blog-3049258033565653738.post-20404675015220524432014-05-10T12:13:00.004-07:002014-05-10T15:32:23.000-07:00What do you lead with in a new offering? How about what enables us to improve our connection?<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.571428298950195px;">
The <a href="http://www.splicious.net/">Splicious</a> team has wrestled with what to lead with in attempting to get their message out to more people. Recently, someone gave us some outlier feedback that we felt was well worth discussing. He suggested that the biggest differentiator of the Splicious offering was <a href="https://www.youtube.com/watch?v=Tz2pmVGgrG4">our approach to distributed identity</a>. Of all the engagement from potential users, his is effectively the lone voice. What we've gotten back, repeatedly, from user engagement is that there's a pretty big bifurcation in the market.</div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.571428298950195px;">
<ul>
<li style="margin-left: 15px;">Those that are interested in the use of cryptocurrency to increase their ability to trade with others.</li>
<li style="margin-left: 15px;">Those that are concerned about privacy and identity on the Internet.</li>
</ul>
<div>
If our sample size is representative, the first category is <i>many</i> times larger than the second. The second actually decomposes into two subcategories: the hacker/cryptocommunity and the wealthy. Both groups are exceedingly small in numbers. The average person is happy to make wry jokes about the Snowden revelations on FaceBook, but that is more or less the extent of the engagement (and implied level of concern) we are able to observe in most folks. </div>
</div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.571428298950195px;">
<br /></div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.571428298950195px;">
Clearly, many people have an in-built urge to share their observations, insights, thoughts and feelings and to feel received through a simple feedback mechanism, an expression of sentiment, such as clicking the "like" or "+1" button. Basically, people have an urge to connect and feel connected. The social media matches this urge relatively well. </div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.571428298950195px;">
<br /></div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.571428298950195px;">
What's especially sticky in the modern social media experience is the ratio of attention to reward. For a small output of attention (read a short post, click the like button; make a short post, check to see who's liked it) people get an enormous pay-off: they feel connected to community. We hypothesize this provides an important indicator for how to take this a little farther: make small increases on the demand for attention at the point of contact.</div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.571428298950195px;">
<br /></div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.571428298950195px;">
The feedback we've gotten from people who do engage is that extending the basic social media framework with a small delta, where the action of expressing sentiment is linked to the transfer of a small amount of money -- like a mBTC (roughly 50c) or smaller -- resonates. Once this notion lands people can see other opportunities for themselves: crowdfunding of very simple and small activities, like writing a song, or taking a photo; microfinancing a small project; and, more generally, engaging in a distributed marketplace.</div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.571428298950195px;">
<br /></div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.571428298950195px;">
While much of the hard work has been about </div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.571428298950195px;">
<ul>
<li style="margin-left: 15px;">making the platform truly distributed, </li>
<li style="margin-left: 15px;">addressing privacy and security, </li>
<li style="margin-left: 15px;">working out a mathematically sound model that informs: </li>
<ul>
<li style="margin-left: 15px;">the programming model, </li>
<li style="margin-left: 15px;">the architecture, and </li>
<li style="margin-left: 15px;">means to express, reason about, and mechanically enforce privacy and security policies</li>
</ul>
</ul>
That's not interesting to most people at this point in history. Eventually, it may be; but, to be honest, if all of that work remained as invisible to most people as how their car, or their plumbing, or computer works, i would be perfectly happy. Right now, based on our limited engagement with the market, it seems to us that people are much more interested in how to get more from the experience of connecting. i think there's a great deal of wisdom in that, personally. We are going to have to come together as a global community if we are going to successfully face the challenges coming our way. That, in a nutshell, is why we lead with <a href="https://www.youtube.com/watch?v=f700b6IHZcc">Splicious for the creative</a>.</div>
leithaushttp://www.blogger.com/profile/01069099703796397027noreply@blogger.com0tag:blogger.com,1999:blog-3049258033565653738.post-44054210940810481482014-05-05T11:30:00.001-07:002014-05-06T14:24:51.334-07:00Splicious: the role of cryptocurrency in our transition to a new economics<div class="p1">
Yesterday, Frank Sheldon, author of <a href="http://www.amazon.com/Far-From-The-Sea-Know-ebook/dp/B00JUK34PE/ref=sr_1_1?ie=UTF8&qid=1399314594&sr=8-1&keywords=far+from+the+sea+we+know">Far from the Sea We Know</a>, sent the Splicious team <a href="http://gigaom.com/2014/05/04/such-dogecoin-much-validity-how-one-altcoin-may-have-turned-into-cryptocurrencys-best-marketing-tool/">an article about <span id="goog_406633618"></span>Dogecoin<span id="goog_406633619"></span> as an alternative to Bitcoin</a>. <a href="https://plus.google.com/+MikeStay/posts">Mike Stay</a>, one of the developer's on splicious, also brought up the possibility of using <a href="http://dogecoin.com/">Dogecoin</a> for many of the reasons indicated in the article Frank sent.</div>
<div class="p1">
Our real position at splicious is that <a href="http://en.wikipedia.org/wiki/Cryptocurrency">cryptocurrency</a>, as a general category of technology, is going to be a big part of the transition to the new economics. As such splicious will support not just <a href="https://bitcoin.org/en/">BitCoin (BTC)</a>, but also others and especially those that attend to privacy and security, like <a href="http://zerocoin.org/">ZeroCoin</a>, as well as ease of use, like Dogecoin.</div>
<div class="p2">
<br /></div>
<div class="p1">
We ended up choosing BTC as the first cryptocurrency we support largely because of its visibility. Specifically, we felt that if <a href="http://www.ihavebitcoins.com/featured/bitcoin-community-cheering-mark-zuckerberg/">Zuckerberg makes a very public announcement about BitCoin</a>, and <a href="http://www.redditblog.com/2013/02/new-gold-payment-options-bitcoin-and.html">Reddit directly supports BitCoin</a>, etc, then this was the best first proxy for the phenomenon. Perhaps this was a lapse in moral judgment on our part.</div>
<div class="p2">
<br /></div>
<div class="p1">
The challenge we face is that there is so much to explain in our offering -- from that value of the network being <a href="http://en.wikipedia.org/wiki/Distributed_computing">distributed</a>; to the value of <a href="https://www.youtube.com/watch?v=Tz2pmVGgrG4">distributed identity</a>; to the value of <a href="https://docs.google.com/document/d/1aM5OIJWOyW89rHdUg6d9-YVbItdtxxiosP_fXZQaRdg/edit#heading=h.ndihpob06tu0">the underlying mathematics</a>; to the value of <a href="http://www.gurdjiefflegacy.org/40articles/individual.htm">reciprocal maintenance</a>; and <a href="https://www.youtube.com/watch?v=QPKKQnijnsM">how existing capital instruments are now failing to meet this, their designated purpose</a>; and the role of cryptocurrency in being able to realize at least some aspects of this in a functioning Internet-based technology -- that we have to cut something somewhere. Explaining what Dogecoin is and how it compares to BTC and how cryptocurrency, in general, is part of a much larger transition we are undergoing, as a culture, felt like a step too far.</div>
<div class="p2">
<br /></div>
<div style="background-color: white; color: #141823; line-height: 9.65999984741211px; margin-bottom: 6px;">
</div>
<div class="p1">
Instead, we were hoping to use a little <a href="http://en.wikipedia.org/wiki/Metonymy">metonymy</a>, both in our message and in our initial coding efforts. On the other hand, much of what is happening with Dogecoin feels directionally correct. We're very grateful to Frank for reminding us of that! If you like what you're reading, head on over to <a href="http://www.rockethub.com/projects/42500-splicious">our crowd funding site and contribute today</a>!</div>
leithaushttp://www.blogger.com/profile/01069099703796397027noreply@blogger.com1tag:blogger.com,1999:blog-3049258033565653738.post-85378696705585163682014-05-05T10:39:00.000-07:002014-05-05T11:59:54.745-07:00Splicious - your network, your dataIt's been a very long time since i posted here. Part of the reason is that for the last four years i've been working with increasing intensity on an exciting project. It's been really fun working on splicious and especially fun to think about what it might mean for communications on the Internet; but, until it reached a certain level of maturity, none of us on the project felt we could really talk very publicly about what we were doing. Now, we feel we're ready to engage.<br />
<br />
Splicious is a distributed social communications platform that provides three core benefits<br />
<ul>
<li><a href="https://www.youtube.com/watch?v=Tz2pmVGgrG4">a simple approach to distributed identity</a></li>
<li><a href="https://www.youtube.com/watch?v=NICs0j85wgo">a simple approach to searching message and post level content both in realtime and throughout the history of your communications</a></li>
<li><a href="https://www.youtube.com/watch?v=f700b6IHZcc">integration with popular cryptocurrency, like BitCoin, so that people can directly support content creators and curators</a></li>
</ul>
<div>
We feel this directly addresses two social trends we have been observing with some alarm.</div>
<div>
<ul>
<li><span style="background-color: white; color: #333333; font-family: Times, 'Times New Roman', serif; line-height: 20px;"><a href="http://www.huffingtonpost.com/2014/05/03/edward-snowden-surveillance_n_5259544.html?utm_hp_ref=politics">Privacy and information flow in internet-based communications has been severely compromised, with corporate and government agencies being able to access and profit by personally identifiable information and no real corresponding transparency on the part of these agencies to balance the situation</a>.</span></li>
<li><span style="background-color: white; color: #333333; line-height: 20px;"><span style="font-family: Times, Times New Roman, serif;"><a href="https://www.youtube.com/watch?v=QPKKQnijnsM">Capital has been concentrating in such a small sector of society as to virtually cease to perform its principal function: provide a tool whereby we can all take care of each other and the planet</a>.</span></span></li>
</ul>
</div>
<div>
<span style="background-color: white; color: #333333; font-family: Times, 'Times New Roman', serif; line-height: 20px;">Knowing that the corporate exchange of personal information (including personally identifiable information) is a >9B$ market, we feel it should be possible to turn the whole model on its head. We put a novel social media UI on the front end of our communications platform. This UI lets people decide for themselves how much that information is worth to them, and using BitCoin, lets them directly support people who provide them with information they find valuable.</span></div>
<div>
<span style="background-color: white; color: #333333; line-height: 20px;"><span style="font-family: Times, Times New Roman, serif;"><br /></span></span></div>
<div>
<span style="color: #333333; font-family: Times, Times New Roman, serif;"><span style="background-color: white; line-height: 20px;">We've been running initial user trials and have gotten some very positive feedback. <a href="https://www.youtube.com/watch?v=nRmu9-AL2OM">Here's what Vlad Patryshev, ex-Googler and privacy/security guy for Google's first social network, had to say about his experience with splicious</a>. </span></span></div>
<div>
<span style="color: #333333; font-family: Times, Times New Roman, serif;"><span style="background-color: white; line-height: 20px;"><br /></span></span></div>
<div>
<span style="color: #333333; font-family: Times, Times New Roman, serif;"><span style="background-color: white; line-height: 20px;">Now we're at the most exciting stage of the project. We've invested 4.5 years of our lives into this effort. The collective capital investment exceeds 2M$. Now we need to see if we're on the mark: if there are enough people who feel that there is a problem worth addressing here; and that splicious comes close enough to the mark that a sufficient number are willing to get behind this solution. That's why really we're running a <a href="http://www.rockethub.com/projects/42500-splicious">crowd funding campaign on RocketHub</a>. When enough of us come together to work on something we believe in, that's when change happens.</span></span></div>
<div>
<span style="color: #333333; font-family: Times, Times New Roman, serif;"><span style="background-color: white; line-height: 20px;"><br /></span></span></div>
<div>
<span style="color: #333333; font-family: Times, Times New Roman, serif;"><span style="background-color: white; line-height: 20px;"><a href="https://www.youtube.com/watch?v=g5EMJyeXYIs">The reason we've structured the ask in the way we have is due to the high quality bar that splicious has to meet</a>. T</span></span><span style="background-color: white; color: #37404e; line-height: 18px;"><span style="font-family: Times, Times New Roman, serif;">he fact that a user can search all the communications they have access to; and they can send and receive BitCoin as support for sharing content means that users can suffer a much greater risk if the system fails to deliver as promised. This is why we have to roll the service out in a very careful, step-by-step fashion and why we are only allowing 1000 users initially. That's also why we are asking for new crowd funding at each 10-fold increase in the number of users.</span></span></div>
leithaushttp://www.blogger.com/profile/01069099703796397027noreply@blogger.com0tag:blogger.com,1999:blog-3049258033565653738.post-6419309902901310602011-08-25T07:17:00.001-07:002011-08-29T15:49:35.150-07:00i am not a monad i am a free algebra! (Pt 4)<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxGhw5jpf3iWmO0YodJMixAneg8vfw96fob7JSFUDLZZjDzuCYbbihs8ZxLFGCO73U4YA7S2mwc9xPJDi3Gp7cC3tJE8-YcqB9WefXSQtIVzeflWic5rcss-afhuKrZxwDY79o0Htk1Lbs/s1600/PMcGoohan.jpeg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 266px; height: 213px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxGhw5jpf3iWmO0YodJMixAneg8vfw96fob7JSFUDLZZjDzuCYbbihs8ZxLFGCO73U4YA7S2mwc9xPJDi3Gp7cC3tJE8-YcqB9WefXSQtIVzeflWic5rcss-afhuKrZxwDY79o0Htk1Lbs/s400/PMcGoohan.jpeg" border="0" alt="" id="BLOGGER_PHOTO_ID_5644797753485248610" /></a>
<br /><h2 dir="ltr" id="internal-source-marker_0.9012197516858578"><span style="color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "><span class="Apple-style-span">This post is a part of a series of posts attempting make explicit some folklore and wisdom of the commons that computer scientists enjoy but neither mainstream programmers nor mainstream mathematicians have exposure to. Both of these cultures would benefit from this common wisdom and so it feels like telling this story is of a certain utility. The caveat is that unlike the other posts the pay-off is cumulative not immediate. i'm not going to present some eye-catching bauble as with the post on Conway Games. Instead, you're going to have to steep in this stuff a bit before the goodness kicks in.</span></span></h2><div><span class="Apple-style-span"><span class="Apple-style-span"><div style="background-color: transparent; "><span id="internal-source-marker_0.9134873251896352" style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">It’s worth summarizing what we’ve said so far. A very broad class of algebras, corresponding to what are commonly known as algebraic data types, have purely syntactic presentations in terms of a freely generated structure and a collection of relations. Once we have this general idea in mind, whether we are programmers, computer scientists, mathematicians or logicians, we are probably pretty comfortable with the idea of polymorphism and so are probably pretty comfortable with the idea that ‘freely generated structure’ has potentially many polymorphic interpretations ranging from simple concatenation of symbols to languages generated by (Chomsky) grammars, and that a similar intuition applies to relations. Here’s a little table summarizing some of this content with examples.</span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span><div dir="ltr" style="font-size: medium; white-space: normal; font-family: Times; "><table style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-collapse: collapse; width: 624px; "><colgroup><col width="*"><col width="*"><col width="*"></colgroup><tbody><tr style="height: 0px; "><td style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: rgb(170, 170, 170); border-right-color: rgb(170, 170, 170); border-bottom-color: rgb(170, 170, 170); border-left-color: rgb(170, 170, 170); vertical-align: top; padding-top: 7px; padding-right: 7px; padding-bottom: 7px; padding-left: 7px; "><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></td><td style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: rgb(170, 170, 170); border-right-color: rgb(170, 170, 170); border-bottom-color: rgb(170, 170, 170); border-left-color: rgb(170, 170, 170); vertical-align: top; padding-top: 7px; padding-right: 7px; padding-bottom: 7px; padding-left: 7px; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Mainstream mathematics</span></td><td style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: rgb(170, 170, 170); border-right-color: rgb(170, 170, 170); border-bottom-color: rgb(170, 170, 170); border-left-color: rgb(170, 170, 170); vertical-align: top; padding-top: 7px; padding-right: 7px; padding-bottom: 7px; padding-left: 7px; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Computer science</span></td></tr><tr style="height: 0px; "><td style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: rgb(170, 170, 170); border-right-color: rgb(170, 170, 170); border-bottom-color: rgb(170, 170, 170); border-left-color: rgb(170, 170, 170); vertical-align: top; padding-top: 7px; padding-right: 7px; padding-bottom: 7px; padding-left: 7px; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Generators</span></td><td style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: rgb(170, 170, 170); border-right-color: rgb(170, 170, 170); border-bottom-color: rgb(170, 170, 170); border-left-color: rgb(170, 170, 170); vertical-align: top; padding-top: 7px; padding-right: 7px; padding-bottom: 7px; padding-left: 7px; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Symbols</span></td><td style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: rgb(170, 170, 170); border-right-color: rgb(170, 170, 170); border-bottom-color: rgb(170, 170, 170); border-left-color: rgb(170, 170, 170); vertical-align: top; padding-top: 7px; padding-right: 7px; padding-bottom: 7px; padding-left: 7px; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Grammars</span></td></tr><tr style="height: 0px; "><td style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: rgb(170, 170, 170); border-right-color: rgb(170, 170, 170); border-bottom-color: rgb(170, 170, 170); border-left-color: rgb(170, 170, 170); vertical-align: top; padding-top: 7px; padding-right: 7px; padding-bottom: 7px; padding-left: 7px; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Relations</span></td><td style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: rgb(170, 170, 170); border-right-color: rgb(170, 170, 170); border-bottom-color: rgb(170, 170, 170); border-left-color: rgb(170, 170, 170); vertical-align: top; padding-top: 7px; padding-right: 7px; padding-bottom: 7px; padding-left: 7px; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Equations</span></td><td style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: rgb(170, 170, 170); border-right-color: rgb(170, 170, 170); border-bottom-color: rgb(170, 170, 170); border-left-color: rgb(170, 170, 170); vertical-align: top; padding-top: 7px; padding-right: 7px; padding-bottom: 7px; padding-left: 7px; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Structural equivalence</span></td></tr><tr style="height: 0px; "><td style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: rgb(170, 170, 170); border-right-color: rgb(170, 170, 170); border-bottom-color: rgb(170, 170, 170); border-left-color: rgb(170, 170, 170); vertical-align: top; padding-top: 7px; padding-right: 7px; padding-bottom: 7px; padding-left: 7px; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Examples</span></td><td style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: rgb(170, 170, 170); border-right-color: rgb(170, 170, 170); border-bottom-color: rgb(170, 170, 170); border-left-color: rgb(170, 170, 170); vertical-align: top; padding-top: 7px; padding-right: 7px; padding-bottom: 7px; padding-left: 7px; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Monoids, </span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Groups, </span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Rings, </span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Fields, </span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Vector spaces, ...</span></td><td style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: rgb(170, 170, 170); border-right-color: rgb(170, 170, 170); border-bottom-color: rgb(170, 170, 170); border-left-color: rgb(170, 170, 170); vertical-align: top; padding-top: 7px; padding-right: 7px; padding-bottom: 7px; padding-left: 7px; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Lambda calculus, </span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">π-calculus, </span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">ambient calculus, ...</span></td></tr><tr style="height: 0px; "><td style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: rgb(170, 170, 170); border-right-color: rgb(170, 170, 170); border-bottom-color: rgb(170, 170, 170); border-left-color: rgb(170, 170, 170); vertical-align: top; padding-top: 7px; padding-right: 7px; padding-bottom: 7px; padding-left: 7px; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></td><td style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: rgb(170, 170, 170); border-right-color: rgb(170, 170, 170); border-bottom-color: rgb(170, 170, 170); border-left-color: rgb(170, 170, 170); vertical-align: top; padding-top: 7px; padding-right: 7px; padding-bottom: 7px; padding-left: 7px; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Example monoid specification:</span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Generators: ISO character set</span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Relations:</span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">s ++ “” == s == “” ++ s</span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">s1 ++ ( s2 ++ s3 )</span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">==</span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">(s1 ++ s2) ++ s3</span></td><td style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: rgb(170, 170, 170); border-right-color: rgb(170, 170, 170); border-bottom-color: rgb(170, 170, 170); border-left-color: rgb(170, 170, 170); vertical-align: top; padding-top: 7px; padding-right: 7px; padding-bottom: 7px; padding-left: 7px; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Example language specification:</span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Generators are given by the grammar</span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">E ::= Var | \ x -> E | E E</span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Relations:</span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">alpha-equivalence:</span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">\ x -> E ≈ \ y -> (E{y/x})</span></td></tr></tbody></table></div>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><h3 dir="ltr" style="font-size: medium; white-space: normal; font-family: Times; "><span style="font-size: 14pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">A smattering of Universal Algebra</span></h3><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVdlgovcjG8fV1FSMlUFs3OEZ6Ul_71ot5LooG5Qo4fp3ZSbA7U28JXZuO1Y-9xrVgjTEk1uKyKx7bLWNPXL9c93p1QIGo0OB3FRqJXcKVbhlLnNrNFqZaIE5yncwMhUhTsrqsXuUrA7ck/s1600/ScareCrowWizOzDiploma.jpeg" style="font-size: medium; white-space: normal; font-family: Times; " onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 256px; height: 192px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVdlgovcjG8fV1FSMlUFs3OEZ6Ul_71ot5LooG5Qo4fp3ZSbA7U28JXZuO1Y-9xrVgjTEk1uKyKx7bLWNPXL9c93p1QIGo0OB3FRqJXcKVbhlLnNrNFqZaIE5yncwMhUhTsrqsXuUrA7ck/s400/ScareCrowWizOzDiploma.jpeg" border="0" alt="" id="BLOGGER_PHOTO_ID_5644798642494810482" /></a><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">There is one thing the mainstream mathematician is likely to have that modern programmer does not, and that is some passing familiarity with the core notions of Universal Algebra. Universal algebra presents a general theory of what an algebra (read algebraic data type) is and spells out for a given algebraic theory what it means to have a presentation and a model and what constitutes a purely syntactic model.</span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Actually, armed with what we already have we can present the core notions via a simple grammar! Let’s begin with the idea of an algebraic expression.</span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Operation . AlgebraicExpr ::= Symbol “(” AlgebraicExpr* “)”</span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Name . Symbol ::= Identifier</span><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">This would correspond to the Scala code</span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">trait AlgebraicExpr </span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">case class Operation( </span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> symbol : Symbol, </span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> actuals : List[AlgebraicExp] </span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">) extends AlgebraicExpr</span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">trait Symbol</span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">case class Name( identifier : [| Identifier |] ) extends Symbol</span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><h4 dir="ltr" style="font-size: medium; white-space: normal; font-family: Times; "><span style="font-size: 12pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">A short detour through 2-level type decomposition</span></h4><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Notice that we have deferred providing a semantic interpretation of the type </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Identifier</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">. We did this because there was no production for it in the grammar, and our interpretation scheme allows us to be lazy about this. Further notice that Scala gives us a way to be permanently lazy about missing productions. Because our scheme interprets grammatical categories as types, both parametric polymorphism (that’s generics to you!) and type members offer reasonable semantic targets for lazily interpreting missing productions. We parametrize in terms of the type corresponding to the category that is missing a production. In the case above we have</span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">trait Symbol[Identifier]</span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">case class Name[Identifier]( </span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> identifier : Identifier </span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">) extends Symbol[Identifier]</span><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Now, if a production (or several!) for </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Identifier</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> ever gets codified we can inject it into our semantic interpretation. So, suppose we have two types of identifiers, </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">String</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">s and </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">UUID</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">s.</span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">LocallyUnique . Identifier ::= String</span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">GloballyUnique . Identifier ::= UUID</span><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">These would give rise to the productions above which correspond to the type specifications below.</span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">trait Identifier</span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">case class LocallyUnique( s : String ) extends Identifier</span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">case class GloballyUnique( u : UUID ) extends Identifier</span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Then we are free to provide the concrete interpretations of </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Symbol</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> via instantiation of the parametric type. Notice that in Scala we could improve on our interpretation of </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Symbol</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> and remain lazy with type variance constraints. We don’t want any old type (such as </span><span style="font-size: 11pt; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; " >Int</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">) supplied in the type parameter, but only those types that really do act as </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Identifier</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">s. In other words,</span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">trait Identifier</span><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">trait Symbol[ID <: Identifier]</span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">case class Name[ID <: Identifier]( </span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> identifier : ID </span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">) extends Symbol[ID]</span><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Now, only the *</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Unique case class</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">es are available types for substitution in the type parameter. Moreover, if we decide to add path-based identifiers later</span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Pathbased . Identifier ::= Identifier ( “.” Identifier )*</span><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">We can likewise add our semantic interpretation in a similarly lazy, compositional fashion, without perturbing our existing code.</span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">case class Pathbased( </span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> id : Identifier, </span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> p : List[Identifier] </span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">) extends Identifier</span><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Of course, this benefit isn’t entirely for free. If we do use this method, then our </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">AlgebraicExpr</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> type will also have to have been parametric in </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Identifier</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> because it has a dependency on </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Symbol</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> which is so parametrized. It’s a small price to pay: it just means that the interpretation needed to be cognizant of this strategy from the outset. Now that we know about the strategy we can incorporate it from the beginning.</span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">trait AlgebraicExpr[ID <: Identifier] </span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">case class Operation[ID <: Identifier]( </span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> symbol : Symbol[ID], </span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> actuals : List[AlgebraicExp[ID]] </span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">) extends AlgebraicExpr[ID]</span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">trait Symbol[ID <: Identifier]</span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">case class Name[ID <: Identifier]( </span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> identifier : ID</span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">) extends Symbol[ID]</span><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">And now you, gentle reader, have a basic understanding of 2-level type decomposition. One last point before returning to the main topic, the use of type parameters as a means of lazily handling missing productions opens another possibility: recursion. In terms of our example, consider the following class of </span><span style="font-size: 11pt; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; " >Symbol</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">s</span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">case class Quotation[ID <: Identifier]( </span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> expr : AlgebraicExpr[ID] </span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">) extends Symbol[ID]</span><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">This allows for a wholly new class of </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Symbol</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">s which are </span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">quotations</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> of </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">AlgebraicExpr</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">s. The general strategy of using recursion in 2-level type decomposition is well known. This specific application to the general area of the creation of symbols is less well known and has some significant implications -- that are beyond the scope of this discussion. Suffice it to say that this technique -- parametrizing syntactic categories in syntactic categories -- can be projected back from our semantic domain (where we introduced it) to the syntactic domain of specifying free(ly generated) structures. This opens up a whole new level of expressiveness at the syntactic level corresponding to the expressiveness we are accustomed to with the introduction of parametric polymorphism. In some very real sense, the type definition language of Haskell can be seen as a model or blueprint for a much richer syntax specification mechanism. Note bene: this is bleeding edge thinking! Apart from Haskell, itself, there does not exist a tool for specifying abstract syntax in this fashion. (Ok, CS community, i know you can take a hint.) (Scala coders beware! Scala generics will not allow you to tie the recursive knot this way without some trouble. Instead, use type members and you will be happier.)</span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><h3 dir="ltr" style="font-size: medium; white-space: normal; font-family: Times; "><span style="font-size: 14pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">A smattering of Universal Algebra (continued)</span></h3><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">With that discussion under our belt we can now reconstruct our grammar for </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">AlgebraicExpr</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">s</span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Operation . AlgebraicExpr ::= Symbol “(” AlgebraicExpr* “)”</span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Using the same trick as above, we can simply defer any interpretation of </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Symbol</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">. [Note: from now on, when there’s little risk of confusion, i’m going to drop the use of quotations around elements concrete syntax like the parens in the production above, and use a different font, instead. And, consistent with this, i’ll use font to indicate a variety of categories present in our specification. So, the above production becomes</span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: 'Droid Serif'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Operation</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> . </span><span style="font-size: 11pt; font-family: 'Droid Serif'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">AlgebraicExpr</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> ::= </span><span style="font-size: 11pt; font-family: 'Droid Serif'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Symbol</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">(</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> </span><span style="font-size: 11pt; font-family: 'Droid Serif'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">AlgebraicExpr</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">* </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">)</span><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Thus endeth the notational convention sidebar.]</span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">trait AlgebraicExpr[Symbol] </span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">case class Operation[Symbol]( </span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> symbol : Symbol, </span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> actuals : List[AlgebraicExp[Symbol]] </span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">) extends AlgebraicExpr[Symbol]</span><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">So, if s, s1, s2, … are </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Symbol</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">s (whatever </span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">those</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> are), then </span>
<br /></div></span></span><span class="Apple-style-span" style="font-family: Times; font-size: medium; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "><div><span class="Apple-style-span" style="font-family: Times; font-size: medium; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">
<br /></span></span></div>s</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">()</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">, s1</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">(</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> s</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">() )</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">, s2</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">( </span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">s</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">(), </span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">s1</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">( </span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">s</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">() ) )</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">, s3</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">( </span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">s</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">(), </span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">s1</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">( </span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">s</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">() ), </span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">s1</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">( </span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">s</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">() ) )</span></span><span class="Apple-style-span"><span class="Apple-style-span"><div style="background-color: transparent; "><p dir="ltr" style="margin-left: 36pt; margin-top: 0pt; margin-bottom: 0pt; "><span class="Apple-style-span" style="font-size: 11pt; background-color: transparent;"><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span></p><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">would be recognized by this grammar as </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">AlgebraicExpr</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">s. Moving toward an eventual semantic interpretation of these purely syntactic gadgets, we’re going to identify expressions of the form s</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">()</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> as </span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">constants</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">. That is, they will eventually be interpreted in much the same way we normally interpret constants in a functional language, as pure functions of zero </span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">arity</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">. Likewise, we’d like to interpret expressions of the form s1</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">(</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> s</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">() )</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> as applications of a unary function, which we’ll write [| s1 |] to the constant [| s |]. </span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">By now, you’ve probably spotted the general convention in this posting (which is a convention in programming language semantics at large is) to use [| - |] (pronounced ‘meaning of’) as denoting the </span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">compositional</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> semantic interpretation of some piece of syntax to its target semantics. Thus, we have a general specification of the semantic interpretation of our </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">AlgebraicExpr</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">s.</span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">[| s</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">(</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> e1, …, eN</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> )</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> |] = [| s |]( [| e1 |], …, [| eN |] )</span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">In terms of our Scala code we can write this down, too.</span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">trait Semantics[</span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> Symbol, </span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> Value, </span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> Operator <: { def apply [X] ( actuals : List[X] ) : X } </span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> ] {</span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> def meaning( s : Symbol ) : Operator</span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> def meaning( expr : AlgebraicExpr[Symbol] ) : Value = {</span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> val op = meaning( expr.symbol )( actuals.map( meaning ) )</span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> }</span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">}</span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Those familiar with Universal algebra will notice that we have skirted around the issues of syntactic considerations of arity. That is, our grammar allows for both </span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span><ul style="font-size: medium; white-space: normal; font-family: Times; "><li style="list-style-type: disc; font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">the expression s1</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">(</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> s</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">() )</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> and </span></li><li style="list-style-type: disc; font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">the expression s1</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">(</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> s</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">(), </span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">s</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">() )</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">. </span></li></ul>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">If s1 denotes a single function, there’s a potential for a problem. In an era where polymorphism is commonplace, we recognize that s1 probably stands for a whole family of functions each with different arity. We probably ought to give a nod to this (and some related issues) by adjusting the meaning function of our semantics as</span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">def meaning( s : Symbol, arity : Int ) : Operator</span><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">to allow us to pick out which </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Operator</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> in the family a given symbol denotes. As an example, consider our friends the Boolean algebras. It is perfectly reasonable and consistent to interpret </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">true</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> as the zero-ary conjunction and -- because conjunction is associative -- we have a version of it for every possible arity. In other words, we have a reasonably complete presentation of a Boolean algebra with </span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: 'Droid Serif'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Conjunction</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> . </span><span style="font-size: 11pt; font-family: 'Droid Serif'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">BooleanExpr</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> ::= </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">And</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">(</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> </span><span style="font-size: 11pt; font-family: 'Droid Serif'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">BooleanExpr</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">* </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">)</span><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: 'Droid Serif'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Negation</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> . </span><span style="font-size: 11pt; font-family: 'Droid Serif'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">BooleanExpr</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> ::= </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">~</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> </span><span style="font-size: 11pt; font-family: 'Droid Serif'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">BooleanExpr</span><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">together with the DeMorgan’s law which we could write</span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Or(</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> b1</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">, </span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">b2</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> )</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> := </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">~ And( ~</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">b1</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">, ~</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">b2 </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">)</span><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span class="Apple-style-span" style="white-space: normal; font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">This raises interesting points about syntactic sugar and compositional semantics -- but let’s not get too ahead of ourselves, but instead, pop up a level closer to our aim. Even with this we can sketch out what we mean by an algebraic theory and a model. An algebraic theory is going to be given by a collection of </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Symbol</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">s and an assignment of (sets of ) arity (resp., arities). Taken together with a collection of equations. What are those? In the interest of narrative tension, they will have to wait until the next post! ;-) For now, let me close with this: if you've spotted a connection between our </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">AlgebraicExpr</span><span style="font-size: 11pt; font-family: 'Arial'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">s and case class instances, this is no accident! It's all part of this underlying structure i'm hoping to expose.</span></div></span></span></div>leithaushttp://www.blogger.com/profile/01069099703796397027noreply@blogger.com4tag:blogger.com,1999:blog-3049258033565653738.post-43905133578643702292011-08-19T00:22:00.001-07:002011-08-19T01:33:37.660-07:00i am not a monad i am a free algebra! (Pt 3)<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9FBJ1tDv1f-2gLN4t4y_yqM_BeG38ue-ssFPVjbdWeqqPGsafpL63Q9xBeF9dQf0Iejo8o4r3KzmBuOVtol3F-_0C7ot1b7_pVpW4VJWnR-2aruSsgqPQoBMYV40gXDsALJK3UskPkuL2/s1600/PMcGoohan.jpeg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 266px; height: 213px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9FBJ1tDv1f-2gLN4t4y_yqM_BeG38ue-ssFPVjbdWeqqPGsafpL63Q9xBeF9dQf0Iejo8o4r3KzmBuOVtol3F-_0C7ot1b7_pVpW4VJWnR-2aruSsgqPQoBMYV40gXDsALJK3UskPkuL2/s400/PMcGoohan.jpeg" border="0" alt="" id="BLOGGER_PHOTO_ID_5642464170591449378" /></a>
<br /><h2 dir="ltr" id="internal-source-marker_0.9012197516858578"><span style="color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "><span class="Apple-style-span">This post is a part of a series of posts attempting make explicit some folklore and wisdom of the commons that computer scientists enjoy but neither mainstream programmers nor mainstream mathematicians have exposure to. Both of these cultures would benefit from this common wisdom and so it feels like telling this story is of a certain utility. The caveat is that unlike the other posts the pay-off is cumulative not immediate. i'm not going to present some eye-catching bauble as with the post on Conway Games. Instead, you're going to have to steep in this stuff a bit before the goodness kicks in.</span></span></h2><div><span style="color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "><span class="Apple-style-span">
<br /></span></span></div><div><span class="Apple-style-span"><div style="background-color: transparent; "><h4 dir="ltr" id="internal-source-marker_0.9012197516858578" style="font-size: medium; font-family: Times; "><span style="font-size: 12pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">A short detour through LBNF</span></h4><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">If we look at the LBNF grammar formalism, the correspondence to type construction in a functional language is very clear. The primary difference between LBNF and ordinary BNF is that each alternative or choice is given a </span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">label</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> (hence the ‘L’ in LBNF). Thus, while an ordinary BNF rule is of the form</span>
<br /><span class="Apple-style-span" style="font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Cat "::=" Item* ;</span><span class="Apple-style-span" style="font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span class="Apple-style-span" style="font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">where </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Cat </span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">is the syntactic category of the rule that corresponds to the expansion given by the list of elements in </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Item*</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">, the body of the rule, an LBNF rule is of the form</span>
<br /><span class="Apple-style-span" style="font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Label "." Cat "::=" Item* ;</span><span class="Apple-style-span" style="font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span class="Apple-style-span" style="font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">where the </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Label</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> is added to disambiguate various alternatives. So, the heart of an LBNF grammar for LBNF grammars is given here.</span>
<br /><span class="Apple-style-span" style="font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">--The rules of the grammar</span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Rule . Def ::= Label "." Cat "::=" [Item] ;</span>
<br /><span class="Apple-style-span" style="font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">-- Items</span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Terminal . Item ::= String ;</span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">NTerminal . Item ::= Cat ;</span>
<br /><span class="Apple-style-span" style="font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">-- Categories</span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">IdCat . Cat ::= Ident ;</span>
<br /><span class="Apple-style-span" style="font-size: 11pt; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /></div></span><span class="Apple-style-span" style="font-family: Times; font-size: medium; "><div style="background-color: transparent; "><span id="internal-source-marker_0.9012197516858578" style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Notice that the category </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Item</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> has two different alternatives, conveniently labeled </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Terminal</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> and </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">NTerminal</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">, illustrating the role of the label in disambiguating alternatives. In fact, it works just like a tag in a discriminated union, which is exactly the machinery in Scala's case classes.</span></div></span><span class="Apple-style-span"><div style="font-family: Times; font-size: medium; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">
<br /></span></div><div style="font-family: Times; font-size: medium; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">From this we can relatively easily intuit a direct mapping from LBNF rules to type specifications in an (object-)functional language like Scala.</span></div><div style="background-color: transparent; "><span class="Apple-style-span"><span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;">
<br /></span></span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">C1 "." T "::=" Item</span><span style="font-size: 6.6pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: sub; white-space: pre-wrap; ">11</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">, …, Item</span><span style="font-size: 6.6pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: sub; white-space: pre-wrap; ">1M</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> ;</span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">C2 "." T "::=" Item</span><span style="font-size: 6.6pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: sub; white-space: pre-wrap; ">21</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">, …, Item</span><span style="font-size: 6.6pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: sub; white-space: pre-wrap; ">2N</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> ;</span><span class="Apple-style-span" style="font-size: 11pt; background-color: transparent;"><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span class="Apple-style-span" style="font-size: 11pt; background-color: transparent;"><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">These rules correspond to </span>
<br /><span class="Apple-style-span" style="font-size: 11pt; background-color: transparent;"><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">trait T</span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">case C1( i</span><span style="font-size: 6.6pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: sub; white-space: pre-wrap; ">11</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> :</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> [| </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Item</span><span style="font-size: 6.6pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: sub; white-space: pre-wrap; ">11</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> |], …, </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">i</span><span style="font-size: 6.6pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: sub; white-space: pre-wrap; ">1M</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> : [| </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Item</span><span style="font-size: 6.6pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: sub; white-space: pre-wrap; ">1M</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> |] ) </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">extends T</span><span class="Apple-style-span" style="font-size: 11pt; background-color: transparent;"><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">case C2( i</span><span style="font-size: 6.6pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: sub; white-space: pre-wrap; ">21</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> :</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> [| </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Item</span><span style="font-size: 6.6pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: sub; white-space: pre-wrap; ">21</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> |], …, </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">i</span><span style="font-size: 6.6pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: sub; white-space: pre-wrap; ">2N</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> : [| </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Item</span><span style="font-size: 6.6pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: sub; white-space: pre-wrap; ">2N</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> |] ) </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">extends T</span><span class="Apple-style-span" style="font-size: 11pt; background-color: transparent;"><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span class="Apple-style-span" style="font-size: 11pt; background-color: transparent;"><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">where [| </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Item</span><span style="font-size: 6.6pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: sub; white-space: pre-wrap; ">ij</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> |] denotes the trait to which the category </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Item</span><span style="font-size: 6.6pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: sub; white-space: pre-wrap; ">ij</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> has been translated.</span></div><div style="background-color: transparent; "><span class="Apple-style-span"><span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;">
<br /></span></span></div></span><span class="Apple-style-span" style="font-family: Times; font-size: medium; "><div style="background-color: transparent; "><span id="internal-source-marker_0.9012197516858578" style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Thus, if we write down our old friend, a basic grammar for the lambda calculus we have</span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Mention . LambdaTerm ::= Ident ;</span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Abstraction . LambdaTerm ::= "lambda" Ident* "." LambdaTerm ;</span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Application . LambdaTerm ::= LambdaTerm "(" LambdaTerm* ")" ;</span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">this would result in</span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">trait LambdaTerm</span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">case class Mention( i : [| Ident |] ) extends LambdaTerm</span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">case class Abstraction( fmls : List[Ident], body : LambdaTerm ) extends LambdaTerm</span>
<br /><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">case class Application( op : LambdaTerm, actls : List[LambdaTerm] ) extends LambdaTerm</span></div></span><span class="Apple-style-span"><div style="background-color: transparent; "><span class="Apple-style-span" style="background-color: transparent; "><span style="color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; "></span></span><span class="Apple-style-span"><span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;">
<br /></span></span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">The correspondence to type construction in a language that supports a purer functional style such as Haskell, or even OCaml is even clearer. (The reader is encourage to compare the Haskell type definition (sub)language to LBNF. The main difference lies in type parameterization. i submit that this would be an excellent addition to the idea of grammars and language processing.) The crucial point, though, is that because type representation in an actual computer must effectively be symbolic, aka syntactic, grammars are simply an alternative mechanism for specifying type structure, and -- at least in the case of Scala -- they can constitute a significantly more compact notation (and have the side-effect of producing a parser!). Indeed, this is why many, many, many computer science papers use a grammar-like style for specifying abstract syntax as a way of representing type structure or domain models.</span>
<br /><span class="Apple-style-span" style="font-size: 11pt; background-color: transparent;"><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">It is worth pointing out that though this understanding is common wisdom in computer science it is not common wisdom in either mainstream programming or in mainstream mathematics. In fact, it is not even common wisdom in branches and subcultures of mainstream mathematics in which Category Theory is a principal tool. For example, when i was presenting some results at GroupoidFest 2008 i made an assumption that my audience -- who were for the most part quite facile with Category Theory -- would understand the use of such a notation as a means of specifying algebraic structure -- as i've noted above, a very common practice in theoretical computer science papers. Sadly, my audience did not understand this use of notation. Indeed, it is very sad to me that these excellent and brilliant practitioners do not have the benefits of these tools because they allow for a highly structured and elegant presentation of a range of algebraic structures that are of significant interest.</span></div><div style="font-family: Times; font-size: medium; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">
<br /></span></div><div style="font-family: Times; font-size: medium; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">So, the modern programmer should recognize that she is on much the same footing as the mainstream mathematician when it comes to acquiring this tool set. </span></div></span></div>leithaushttp://www.blogger.com/profile/01069099703796397027noreply@blogger.com0tag:blogger.com,1999:blog-3049258033565653738.post-19975228964577124612011-08-18T23:00:00.001-07:002011-08-19T00:20:27.176-07:00i am not a monad i am a free algebra! (Pt 2)<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFhhiUhDYW_ZT6tTA_6cQQp83l16z6FZMZRVJouj_ledKNyNLy1V3HhOMBsjmmhDFwsjAx8e7PnBPcEnN8zpeMi3lsYoBkl26nD8WQNxlmoxsw__xKSc5iDieMaZqTKi-pN1UJFQMc55EN/s1600/PMcGoohan.jpeg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 266px; height: 213px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFhhiUhDYW_ZT6tTA_6cQQp83l16z6FZMZRVJouj_ledKNyNLy1V3HhOMBsjmmhDFwsjAx8e7PnBPcEnN8zpeMi3lsYoBkl26nD8WQNxlmoxsw__xKSc5iDieMaZqTKi-pN1UJFQMc55EN/s400/PMcGoohan.jpeg" border="0" alt="" id="BLOGGER_PHOTO_ID_5642443755300367682" /></a>
<br /><h2 dir="ltr" id="internal-source-marker_0.9012197516858578"><span style="color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "><span class="Apple-style-span" style="font-weight: normal;">This post is a part of a series of posts attempting make explicit some folklore and wisdom of the commons that computer scientists enjoy but neither mainstream programmers nor mainstream mathematicians have exposure to. Both of these cultures would benefit from this common wisdom and so it feels like telling this story is of a certain utility. The caveat is that unlike the other posts the pay-off is cumulative not immediate. i'm not going to present some eye-catching bauble as with the post on Conway Games. Instead, you're going to have to steep in this stuff a bit before the goodness kicks in.</span></span></h2><span class="Apple-style-span"><div style="font-size: medium; background-color: transparent; "><h3 dir="ltr" id="internal-source-marker_0.9012197516858578" style="font-weight: bold; font-family: Times; "><span style="color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; font-family: Arial; font-size: 14pt; ">The Language connection</span></h3><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">The relationship between List[G] and Set[G] is a microcosm in which we see a reflection of a very general phenomenon. For all of the situations the web programmer is likely to face all of the algebras (data types) they will deal with will have a presentation in terms of some freely generated data structure (e.g. List) and a (possibly empty) set of constraints on that (such as the equations on Set that forget order and remove duplicates). In fact, a very large number of practical, day-to-day data types will ultimately boil down to a structure that could be represented by List[G] plus some constraints -- this fact corresponds to the way in which many algebras “factor through” List[G]. It also gives some indication of the "universality" of List as a data type -- one of the primary reasons why it worked so well when paired with the core functional apparatus of the lambda calculus in early functional languages, such as Lisp and Scheme.</span>
<br /><span class="Apple-style-span" style="font-size: 11pt; background-color: transparent; "><span style="color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; font-family: Arial; font-size: 11pt; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Keeping that observation in the back of our minds let's turn to the evident connection to language processing. The connection to languages -- both generating and recognizing, i.e. parsing -- mentioned above is very strong and also a part of the folklore at the intersection of the computer science and meta-mathematics communities. Looking at the example of monoid, this should not be shocking. The free monoid is exactly isomorphic to the structure generated by the Kleene star-like operation of BNF grammars. More generally, a grammar is just another way of specifying a freely generated structure. The constructors of a context-free grammar (CFG), for example, are more general than word concatenation and hence generate more structures than the generators and relations presentations of classical algebras like monoids, groups, rings, fields, etc. The principle, however, is the same: they represent a means of freely generating structures from a simple set of rules for generating new structures from old ones. It’s just that the rules allow constructs other than simple concatenation. </span></div><div style="font-size: medium; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">
<br /></span></div><div style="font-size: medium; background-color: transparent; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">One new thing that arises in this context is that the dual operation to generation, namely recognition or parsing, gets a lot more interesting in this setting and has close connections to phenomena a functional programmer is already familiar with, such as pattern matching, and perhaps more surprisingly type-checking. We'll talk more about that later in the series.</span>
<br /><span class="Apple-style-span" style="font-weight: bold; font-size: 11pt; background-color: transparent; "><span style="color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; font-family: Arial; font-size: 11pt; "></span></span>
<br /><h4 dir="ltr" style="font-weight: bold; font-family: Times; "><span style="color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; font-family: Arial; font-size: 12pt; ">A nod to Curry, Howard and Chomsky</span></h4><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Of particular interest to the computer scientist and programmer is the fact that grammar constructors have close correspondence to type constructors. Again, this is not an accident! For the computer scientist and logician this is another piece of folklore and wisdom of the commons to be exploited to win friends and influence computers. The programmer, though, might not be as familiar with these correspondences which arise from the intimate connections between types, logical formulae and algebras. To spell out the relationships just a bit, there are families of isomorphisms between types and logical formulae that fall under the rubric, the Curry-Howard isomorphism, or propositions-as-types paradigm. For many practical purposes we can view logical formulae and types as essentially two different ways of looking at the same thing. Again, more on this later, just bear in mind that the two notions are somehow effectively the same. Instead, we want to spend a little more time with the relationship between logical formulae and algebras.</span>
<br /><span class="Apple-style-span" style="font-size: 11pt; background-color: transparent; "><span style="color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; font-family: Arial; font-size: 11pt; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">The relationship between logical formulae, or more generally, logics and algebras is of the same kind as the one described in the previous post between List[G] and the free monoid over G. List[G] is a model of the algebraic theory of (the free) monoid (over G). In the same way, algebras are models of the logics in which we write our logical formulae. Different logics correspond to different algebras. For example, most programmers are pretty familiar with Boolean operations, such as &. As such they are aware that if </span>
<br /><span class="Apple-style-span" style="font-size: 11pt; background-color: transparent; "><span style="color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; font-family: Arial; font-size: 11pt; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">val A1 : Boolean = …;</span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">val A2 : Boolean = …;</span>
<br /><span class="Apple-style-span" style="font-size: 11pt; background-color: transparent; "><span style="color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; font-family: Arial; font-size: 11pt; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">that is A1, A2 are of type Boolean, then A1 & A2 == A2 & A1 and also that A1 & A1 == A1. But wait a minute? Aren’t those the same equations we saw holding for Set[G]? Indeed they are! The Set data structure is a model of Boolean logic. In fact, it’s a bit more complex than that. There are such things as Boolean algebras. Boolean algebras are models of Boolean logics and Set is a kind of canonical model that can be seen to underlie all the Boolean algebras. That is, Set[G] plays in the role of the ‘purely syntactical’ model of the Boolean algebras which in turn model the logics (while Set[G] as we know has a purely syntactical model in terms of List[G]).</span></div><div style="background-color: transparent; "><span class="Apple-style-span"><span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;">
<br /></span></span></div></span><span class="Apple-style-span"><div style="font-family: Times; font-size: medium; background-color: transparent; "><span id="internal-source-marker_0.9012197516858578" style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">This sort of relationship is not restricted to the Boolean situation. For example, J-Y Girards's classical linear logic (CLL) sports two distinct flavors of conjunctions (respectively, disjunctions) as well as an involutive negation (meaning that ~~A is logically equivalent to A -- a fact that doesn't hold in many logics important to computing). We get canonical purely syntactic models of formulae in CLL via algebraic structures known as quantales. Fortunately, i don't have to trot out the very fancy definition of a quantale to convey it to a modern programmer. Instead, i can note that given some carrier set G, every quantale has a purely syntactic model in terms of the set of sequences of subsets of G. This we can write down! It's simply the data type List[Set[G]]. There, that's the canonical free quantale. As an ordinary programmer you were already an expert in classical linear logic; you just didn't know it!</span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">In fact, this is a very real pay-off from this kind of thinking. It begins to organize and simplify the veritable zoo of data structures and provide some coherence to the various means of reasoning about them. There are actually a handful of principles and operations at work that give rise to a great deal of the complexity we see at play in day-to-day programming. Most programmers feel this in their bones, but don't quite have a way to express it effectively. This is one way.</span></div></span><span class="Apple-style-span"><div style="background-color: transparent; "><span class="Apple-style-span" style="font-size: 11pt; background-color: transparent; "><span style="color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; font-family: Arial; font-size: 11pt; "></span></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">More specifically, we teased apart some of these relationships in order to see that in all the cases we've seen so far every structure, be it algebra, type or formula ultimately boils down to -- or in the words of the trade -- </span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">factors through</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> a purely syntactical model. On reflection, we've said that a type is (another way of looking at the content of) a logical formulae of some logic -- which in turn has some canonical purely syntactic algebraic model. This fact is what underlies the correspondence between the operators of various grammars types (such as CFG) and type constructors. Ultimately, we need a concrete representation of the types over which we compute in order to do calculations (such as type conformance, or building a new type from a parametric type constructor and a type parameter). Since we know that these type gadgets ultimately factor through some purely syntactical representation what better device than grammars for describing these? Grammars, after all, are our compositional mechanism for describing, computing with and reasoning about syntax.</span></div></span>leithaushttp://www.blogger.com/profile/01069099703796397027noreply@blogger.com5tag:blogger.com,1999:blog-3049258033565653738.post-22218950333034918102011-08-18T19:25:00.000-07:002011-08-19T00:04:45.373-07:00i am not a monad i am a free algebra! (Pt 1)<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheLeLgReYCWLIhaI9uuGWoUh8iFZK7ead5xiQFLIsDcxrsbmJJCrIDlXF2NUwBQ9plqdozfi3TEQvHuhJow8cFIU1dxB28-F_Kj1aB_PgBrmq7ngw99ILc_FJWNWgbflTg8iFqYYuPD-1W/s1600/PMcGoohan.jpeg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 266px; height: 213px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheLeLgReYCWLIhaI9uuGWoUh8iFZK7ead5xiQFLIsDcxrsbmJJCrIDlXF2NUwBQ9plqdozfi3TEQvHuhJow8cFIU1dxB28-F_Kj1aB_PgBrmq7ngw99ILc_FJWNWgbflTg8iFqYYuPD-1W/s400/PMcGoohan.jpeg" border="0" alt="" id="BLOGGER_PHOTO_ID_5642391861012884930" /></a>
<br /><div style="background-color: transparent; "><h2 dir="ltr" id="internal-source-marker_0.9012197516858578"><span style="color: rgb(0, 0, 0); background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "><span class="Apple-style-span" style="font-weight: normal; ">This post is a part of a series of posts attempting make explicit some folklore and wisdom of the commons that computer scientists enjoy but neither mainstream programmers nor mainstream mathematicians have exposure to. Both of these cultures would benefit from this common wisdom and so it feels like telling this story is of a certain utility. The caveat is that unlike the other posts the pay-off is cumulative not immediate. i'm not going to present some eye-catching bauble as with the post on Conway Games. Instead, you're going to have to steep in this stuff a bit before the goodness kicks in.</span></span></h2><h2 dir="ltr" id="internal-source-marker_0.9012197516858578" style="font-family: Times; font-size: medium; "><span style="font-size: 18pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">What is a free algebra?</span></h2><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">In true agile style, let’s begin with a concrete example. Let’s begin with a monoid. The free monoid over some generators, g1, …, gN, is just all the finite sequences we can make from the elements g1, …, gN. The smallest such is the empty sequence. The set of next such smallest are just the elements themselves. Then we have all sequences of length two, of which there are [exercise: how many and why?]. And so on. Someone coming from computer science will notice that this is also the set of all words over the set G = { g1, …, gN }, sometimes written G*. This set of sequences is equipped with a natural binary operation which is closed on the set, namely concatenation. That is, if w1 and w2 are in G*, then w1w2 is also in G*. If g1 through gN were characters (such as those in the ISO character set), then we would recognize G* as the set of strings.</span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; font-size: 11pt; background-color: transparent;"></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">We call this monoid ‘free’ because there are no constraints on the operation of concatenating elements. We simply generate all the possible combinations of characters in any order. Notice that one way to </span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">represent</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> or </span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">model</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> this data type would be to use List. That is, the type List[G] is exactly isomorphic to G*, down to using list concatenation (l1 ++ l2) for word concatenation (w1w2). The relationship between List[G] and G* is exactly the relationship between monad and monoid, but i get ahead of myself. The point i wish to make is that from a certain vantage we can treat List[G] as a concrete model of G*. Now, if we were to move from List[G] to Set[G], removing the possibility of duplicates and ignoring order, this would be the same as if we had introduced some constraints on (a polymorphic implementation of) the operation of concatenation (on the type Set[G]). Specifically, we would be requiring that for any words, w, w1 and w2 we have</span><ul style="font-family: Times; font-size: medium; "><li style="list-style-type: disc; font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">w ++ w == w (that is, if w in Set[G], then w U w = w)</span></li><li style="list-style-type: disc; font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">w1 ++ w2 == w2 ++ w1 (that is, if w1, w2 in Set[G], then w1 U w2 = w2 U w1)</span></li></ul>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">In other words, constraints are </span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">identities</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">. </span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; font-size: 11pt; background-color: transparent;"></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Notice that constraints also do two other things. They shrink down the size of the collection of inhabitants of the type. For generators g1, …, gN, there are an infinite number of lists; yet, for the same collection of generators there are exactly 2^N sets. While 2^N might look large, it is dwarfed by the countable infinity. Likewise, we cannot see certain structure. To make this point clear, note that we might have a concrete implementation of Set[G] that actually uses List[G] to hold the elements of the collection, but makes certain that with operations that add to the collection, for example, they never allow duplicates.</span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; font-size: 11pt; background-color: transparent;"></span>
<br /><h3 dir="ltr" style="font-family: Times; font-size: medium; "><span style="font-size: 14pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Algebras and data types</span></h3><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Returning to the monoid as a freely generated algebra, we can recognize that a monoid is also an abstract data type. We can write it down.</span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; font-size: 11pt; background-color: transparent;"></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">trait Monoid[G] {</span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> def identity : G</span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> def compose( g1 : G, g2 : G ) : G</span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">}</span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; font-size: 11pt; background-color: transparent;"></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">It obeys certain laws, namely, if MG : Monoid[G] then for all g, g1, g2, g3 : G, we require </span><ul style="font-family: Times; font-size: medium; "><li style="list-style-type: disc; font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">MG.compose( MG.identity, g ) == g == MG.compose( g, MG.identity)</span></li><li style="list-style-type: disc; font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; "><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">MG.compose( MG.compose( g1, g2 ), g3 ) == MG.compose( g1, MG.compose( g2, g3 ) )</span></li></ul>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">In this case, the (set of inhabitants of the) type G is called the carrier (set) of the monoid, Monoid[G]. (Notice the distinction between Monoid[G] and G. There might be many, many monoid operations that work with some carrier set G. Mathematicians and computer scientists might abuse terminology and call G a monoid, but they are very aware that the monoid has additional structure, namely the binary operation, compose, and that there may be many well defined compositions over G. This point will become crucial later when we talk about how to represent and think about monads, and more generally when we think about how to structure code in such a way that we can get substantive reuse.)</span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; font-size: 11pt; background-color: transparent;"></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">An observation that is vitally important to get across is that there is a </span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">canonical</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> way to implement the free monoid over G, and that is List[G]. Moreover, this solution is entirely syntactic. There is no additional calculation in List( g1, …, gK ) other than to record the elements of the container and their order. This is important because it is true of all free algebras: they always have a canonical syntactic representation. </span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; font-size: 11pt; background-color: transparent;"></span>
<br /><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">This observation is even more important in computer science than in other mathematical disciplines because of the relationships between algebras and data types. There’s a reason why functional languages enjoy </span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">algebraic</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> data types. There’s more to be said about this, but we have to wait for the next post.</span></div>leithaushttp://www.blogger.com/profile/01069099703796397027noreply@blogger.com0tag:blogger.com,1999:blog-3049258033565653738.post-29670563029168362422011-07-23T01:08:00.000-07:002011-07-23T13:30:24.982-07:00Gozintas and Gozoutas revisited<span class="Apple-style-span" style="border-collapse: collapse; color: rgb(51, 51, 51); font-family: arial, sans-serif; font-size: 13px; "><div><div> <style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Arial; color: #333233} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Arial; color: #333233; min-height: 15.0px} li.li1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Arial; color: #333233} ul.ul1 {list-style-type: disc} </style> <p class="p1">The Option monad -- in fact, all of the standard container monads that have an empty structure (like the None in Option) -- are <i>intuitionistic</i>. What do i mean by that? i mean there is a canonical interpretation of the monad as a kind of negation without an <a href="http://en.wikipedia.org/wiki/Law_of_excluded_middle">excluded middle</a>. Without the jargon we can understand this as follows. We know that the type A => Option[Option[A]] always has an inhabitant: here's an implementation</p> <ul class="ul1"> <li class="li1">def optSqrd [A] ( a : A ) : Option[Option[A]] = Some(Some( a )) // note that there are a lot more, for example</li> <li class="li1">def halfOptSqrd [A] ( a : A ) : Option[Option[A]] = if (scala.math.random > .5) { Some( if scala.math.random > .5 { Some( a ) } else { None } ) else { None }</li> </ul> <p class="p1">However, the type Option[Option[A]] => A is not guaranteed to have an inhabitant. Either the inner or the outer Option may be None and so we may simply not be able to produce the A. More generally, for any monadic container, C, that may be empty, we have a witness for A => C[C[A]] (this is just two applications of unit). However, we cannot find a reliable witness for C[C[A]] => A for the same reasons that the Option[Option[A]] => A map fails to exist. This is in exact correspondence with the failure of excluded middle in <a href="http://en.wikipedia.org/wiki/Intuitionistic_logic">Intuitionistic Logic</a>. In Intuitionistic Logic we may readily prove A => ~~A, but we cannot prove ~~A => A. Of course, this observation begs the question as to whether there are more correspondences to be had. Is there a case where the monad does have a kind of excluded middle or <a href="http://en.wikipedia.org/wiki/Involution_(mathematics)">involutive</a> negation?</p> <p class="p2"><br /></p> <p class="p1">The truth is that i came to write this post as i was thinking about co-monads and was looking for good examples to explain some points in the forthcoming Monadic Design Patterns for the Web. i'd forgotten -- or rather only just remembered -- that the linear exponential !(-), of <a href="http://en.wikipedia.org/wiki/Linear_logic">Classical Linear Logic</a>, is a paradigmatic co-monad. To see this, let's investigate its (<a href="http://en.wikipedia.org/wiki/De_Morgan's_laws">DeMorgan</a>) dual, ?(-), and observe its monadicity. To see that we have a unit for ?(-) consider what we require. The type of unit for this monad would be unit : A => ?A. In this setting the arrow will actually be a <i>linear </i>map, which we'll write using lollipop, - -o -; thus, in the logical world we write the type of the unit map as the formula: A -o ?A.</p> <p class="p2"><br /></p> <p class="p1">Similarly, in the logical world, to exhibit a map is to exhibit a <i>proof</i>. So, what we require is a <i>proof of the formula</i> A -o ?A. Here it is</p> <p class="p2"><br /></p> <p class="p1">|- ~A, A ( axiom)</p> <p class="p1">|- ~A, ?A (dereliction)</p> <p class="p1">|- ~A # ?A (par)</p> <p class="p1">|- A -o ?A (defn of -o)</p> <p class="p2"><br /></p><p class="p2">(Translating this back into programming terms, you won't be far off if you think of axioms as providing us a set of functions of type A => A, while the other proof rules are higher-order widgets taking functions and returning new ones. Thus dereliction will take a map m: ( A1, ..., An ) => B and return a new map dereliction( m ) : ( A1, ..., An ) => ?B, etc. The analogy is a little off because Linear Logic enjoys so many symmetries that functional programming does not.)</p><p class="p2"><br /></p> <p class="p1">In a similar manner to how we derived our unit map, to see that we have a bind map we have to exhibit a proof of the formula ??A -o ?A. Here it is</p> <p class="p2"><br /></p> <p class="p1">|- ~A, A (axiom)</p> <p class="p1">|- ~A, ?A (dereliction)</p> <p class="p1">|- ?A, ~A (exchange)</p> <p class="p1">|- ?A, !~A (weakening)</p> <p class="p1">|- ?A, !!~A (weakening)</p> <p class="p1">|- ?A, ~??A (DeMorgan)</p> <p class="p1">|- ~??A, ?A (exchange)</p> <p class="p1">|- ~??A # ?A (par)</p> <p class="p1">|- ??A -o ?A (defn of -o)</p> <p class="p2"><br /></p> <p class="p1">Now, to get the co-monadic structure of !(-) we simply exchange roles in the proofs. To get co-unit, aka extract, we need to exhibit a proof !A -o A. Here it is</p> <p class="p2"><br /></p> <p class="p1">|- ~A, A (axiom)</p> <p class="p1">|- A, ~A (exchange)</p> <p class="p1">|- A, ?~A (dereliction)</p> <p class="p1">|- A, ~!A (DeMorgan)</p> <p class="p1">|- ~!A, A (exchange)</p> <p class="p1">|- ~!A # A (par)</p> <p class="p1">|- !A -o A (defn of -o)</p> <p class="p2"><br /></p> <p class="p1">(Notice how the structure of this proof mimics its dual -- the proof of A -o ?A -- with two exchanges judiciously inserted at key points.)</p><p class="p1">Similarly we need a proof of !A -o !!A to exhibit an interpretation of co-bind</p> <p class="p2"><br /></p> <p class="p1">|- ~A, A (axiom)</p> <p class="p1">|- A, ~A (exchange)</p> <p class="p1">|- A, ?~A (dereliction)</p><p class="p1">|- ?~A, A (exchange)</p> <p class="p1">|- ?~A, !A (weakening)</p> <p class="p1">|- ?~A, !!A (weakening)</p> <p class="p1">|- ~!A, !!A (DeMorgan)</p> <p class="p1">|- ~!A # !!A (par)</p> <p class="p1">|- !A -o !!A</p> <p class="p2"><br /></p> <p class="p1">This gives the core of a linear monad/co-monad pair to which we may look for guidance about how to develop a deeper and more orderly investigation of monads, co-monads and data/control structure interpretations of those APIs. The linear situation with its pair of exponentials, ? and !, that are linked by a DeMorgan relation provides a monad and co-monad that are intertwined in just the right way to ensure that every request, !A, to unpack an A from a container is always hooked up to a container, ?A, that contains an A. Moreover, the linear situation is also rich enough to encode Intuitionistic Logic (and hence all the computational phenomena in the lambda calculus -- which is the foundation on which Scala is built). This gives us some clue that there might be a more general and rich underlying way to hook up monads and comonads to get much more robust, yet fine-grained views of our containers and control structures. Not to give too much away, but the monadic broker described in <a href="http://biosimilarity.blogspot.com/2011/02/channel-based-communication-monadically.html">this post</a> uses <a href="http://en.wikipedia.org/wiki/Delimited_continuation">delimited continuations</a> to provide exactly the same guarantees about matching up Gozintas with Gozoutas, as do the Linear Logic exponentials, yet in a non-blocking I/O <a href="http://en.wikipedia.org/wiki/Nodejs">Node.js</a>-style. More on this in subsequent posts.</p></div></div></span>leithaushttp://www.blogger.com/profile/01069099703796397027noreply@blogger.com7tag:blogger.com,1999:blog-3049258033565653738.post-60882567235374351512011-05-24T11:18:00.000-07:002011-06-23T11:39:17.516-07:00Of monads and games<h3><span class="Apple-style-span">Motivation</span></h3><br />This work began with a desire to construct a simple and easily understandable example to illustrate separating out the monad API from the underlying structure that supports it. In Haskell this division of labor is well understood. The monad API is a type class that takes the constructor for the underlying data type as a parameter. In Scala this separation is less well exposed. The monadic API is organized as a trait (FilterMonadic) and folded into the data constructor type. Thus, Set, following a more OO-style, has these methods on the class. This organization actually gives less reuse, in particular as it comes to conversions between data structures, and the point is to have an example that illustrates this clearly -- while being pretty much immediately understandable and yet interesting and compelling.<br /><br />The simplest example would be to have duplicate container-like structure, such as a pair of containers serving as components of some larger structure, either of which would serve to support the monadic API for the larger structure. Casting about for a symmetric structure having a container-like capability in each component i readily recognized Conway games as nearly tailor-made for this job. What is a Conway game, you ask, and why do we care about them?<br /><br /><h3><span class="Apple-style-span">Discussion of Conway games</span></h3><br /><a href="http://en.wikipedia.org/wiki/John_Horton_Conway">John Horton Conway</a>, in his inimitably playful style, found a simple data structure that supported or modeled the operations of the field of Real numbers. His data structure, however, not only captured the Reals but also many, many more of the notions of number, quantity and order that had been proposed, including <a href="http://en.wikipedia.org/wiki/Transfinite_number">Cantor’s infinities</a> and <a href="http://en.wikipedia.org/wiki/Non-standard_analysis">Robinson’s infinitessimals</a>. Moreover, Conway’s data structure is incredibly simple and easily understood and -- best of all -- has an interpretation as a representation of <a href="http://en.wikipedia.org/wiki/Game_semantics">two-player games</a>! So, just by playing along with Conway we get to organize and gain insight into how numbers work. It also turns out that the game interpretation really has a pay-off in it’s own right. For example, <a href="http://en.wikipedia.org/wiki/Elwyn_Berlekamp">Elwyn Berlekamp</a>, one of Conway’s collaborators, has done an analysis of <a href="http://en.wikipedia.org/wiki/Go_(game)">the game of go</a>, using Conway games, and found powerful new strategies, such as <a href="http://math.berkeley.edu/~berlek/cgt/gobook.html">chilling</a>. For a mathematician and computer scientist that’s motivation enough to spend a little time with them.<br /><br />A Conway game can be thought of as a representation of a game at a given state of play. Specifically, it is really just a pair, the left part of which represents Player’s options, or moves in the game; and, the right part of which represents Opponent’s options, or moves in the game. The beauty of this way of thinking is that it may be used recursively. An option, or move, is just simply a game, i.e. a pair of options for Player and Opponent. By nesting in this way, we can represent all possibly plays of a given game. In Scala code, we might write this idea down as<br /><br /><div id="paste" class="lang-scala code"><br /><div class="code"><table class="syntaxtable"><tbody><tr><td class="linenos"><pre>1<br />2<br />3<br />4</pre></td><td class="code"><div class="syntax"><pre><span class="k">trait</span> <span class="nc">ConwayGame</span> <span class="o">{</span><br /><span class="k">def</span> <span class="n">left</span> <span class="k">:</span> <span class="kt">Set</span><span class="o">[</span><span class="kt">ConwayGame</span><span class="o">]</span><br /><span class="k">def</span> <span class="n">right</span> <span class="k">:</span> <span class="kt">Set</span><span class="o">[</span><span class="kt">ConwayGame</span><span class="o">]</span><br /><span class="o">}</span><br /></pre></div><br /></td></tr></tbody></table></div><br /></div><br /><br /><br />Then we could provide some simple concrete implementations as<br /><br /><div id="paste" class="lang-scala code"><br /><div class="code"><table class="syntaxtable"><tbody><tr><td class="linenos"><pre>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9</pre></td><td class="code"><div class="syntax"><pre><span class="k">case</span> <span class="k">object</span> <span class="nc">EmptyGame</span> <span class="k">extends</span> <span class="nc">ConwayGame</span> <span class="o">{</span><br /><span class="k">def</span> <span class="n">left</span> <span class="k">:</span> <span class="kt">Set</span><span class="o">[</span><span class="kt">ConwayGame</span><span class="o">]</span> <span class="o">=</span> <span class="nc">Set</span><span class="o">.</span><span class="n">empty</span><br /><span class="k">def</span> <span class="n">right</span> <span class="k">:</span> <span class="kt">Set</span><span class="o">[</span><span class="kt">ConwayGame</span><span class="o">]</span> <span class="o">=</span> <span class="nc">Set</span><span class="o">.</span><span class="n">empty</span><br /><span class="o">}</span><br /><br /><span class="k">case</span> <span class="k">class</span> <span class="nc">Game</span><span class="o">(</span><br /><span class="k">override</span> <span class="k">val</span> <span class="n">left</span> <span class="k">:</span> <span class="kt">Set</span><span class="o">[</span><span class="kt">ConwayGame</span><span class="o">],</span><br /><span class="k">override</span> <span class="k">val</span> <span class="n">right</span> <span class="k">:</span> <span class="kt">Set</span><span class="o">[</span><span class="kt">ConwayGame</span><span class="o">]</span><br /><span class="o">)</span> <span class="k">extends</span> <span class="nc">ConwayGame</span><br /></pre></div><br /></td></tr></tbody></table></div><br /></div><br /><br />Now, we see that this definition is perfectly well founded. The EmptyGame, also known as 0, is a valid Scala object. It can be passed around as a value and inspected for its left and right components -- which just happen to be empty. Further, we can use our case class, Game, together with 0, to make the Conway game that represents unity, aka 1. We could write this at the Scala REPL prompt with<br /><br />scala> val one = Game( Set( EmptyGame ), Set.empty )<br />one: Game = Game(Set(EmptyGame),Set())<br /><br />Anyone familiar with the von Neumann encoding of the Naturals can see where this is going. (And anyone not will get the gist with the next bit... ) So, we’ll skip ahead, in a bit, and talk about how to model addition. First, though, we should take a look at Conway’s own notation. He writes games like this<br /><br />G = { GL, … | GR, … }<br /><br />The notation is much like set (comprehension) notation except that the bar in the middle of braces denotes the separation of the left and right components. The left (respectively, right) components of the game, G, are indexed by GL (respectively, GR). Thus, in Conway’s notation, the empty game, 0, is { | }, and 1 is { { | } | }. Whether you’re a math fanboy (resp, fangrrl) or not, you have to admit this is much more compact than the Scala code. So, we’ll at least write a toString that prints games out like this. (See the <a href="https://github.com/leithaus/SpecialK/tree/moniker/src/main/scala/com/biosimilarity/lift/lib/game">github project</a>.)<br /><br />On to addition! Since this structure -- like the game of go -- is simultaneously incredibly simple and incredibly rich let’s allow for the possibility that there might be multiple ways to define addition. So, rather than encode addition on Games, let’s create a Calculator that provides a notion of addition (and some of the other arithmetic operations). First, we’ll record the operations we expect to show up on the Calculator.<br /><br /><div id="paste" class="lang-scala code"><br /><div class="code"><table class="syntaxtable"><tbody><tr><td class="linenos"><pre> 1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13</pre></td><td class="code"><div class="syntax"><pre><span class="k">trait</span> <span class="nc">ConwayOps</span> <span class="o">{</span><br /><span class="k">def</span> <span class="n">add</span><span class="o">(</span><br /><span class="n">g1</span> <span class="k">:</span> <span class="kt">ConwayGame</span><span class="o">,</span><br /><span class="n">g2</span> <span class="k">:</span> <span class="kt">ConwayGame</span><br /><span class="o">)</span> <span class="k">:</span> <span class="kt">ConwayGame</span><br /><span class="k">def</span> <span class="n">minus</span><span class="o">(</span><br /><span class="n">g</span> <span class="k">:</span> <span class="kt">ConwayGame</span><br /><span class="o">)</span> <span class="k">:</span> <span class="kt">ConwayGame</span><br /><span class="k">def</span> <span class="n">multiply</span><span class="o">(</span><br /><span class="n">g1</span> <span class="k">:</span> <span class="kt">ConwayGame</span><span class="o">,</span><br /><span class="n">g2</span> <span class="k">:</span> <span class="kt">ConwayGame</span><br /><span class="o">)</span> <span class="k">:</span> <span class="kt">ConwayGame</span><br /><span class="o">}</span><br /></pre></div><br /></td></tr></tbody></table></div><br /></div><br /><br />And, then we’ll provide a concrete implementation.<br /><br /><div id="paste" class="lang-scala code"><br /><div class="code"><table class="syntaxtable"><tbody><tr><td class="linenos"><pre> 1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93</pre></td><td class="code"><div class="syntax"><pre><span class="k">class</span> <span class="nc">ConwayCalculator</span><br /><span class="k">extends</span> <span class="nc">ConwayOps</span><br /><span class="k">with</span> <span class="nc">ConwayRelations</span> <span class="o">{</span><br /><span class="c">// generators</span><br /><span class="k">override</span> <span class="k">def</span> <span class="n">add</span> <span class="o">(</span><br /><span class="n">g1</span> <span class="k">:</span> <span class="kt">ConwayGame</span><span class="o">,</span><br /><span class="n">g2</span> <span class="k">:</span> <span class="kt">ConwayGame</span><br /><span class="o">)</span> <span class="k">:</span> <span class="kt">ConwayGame</span> <span class="o">=</span> <span class="o">{</span><br /><span class="n">g1</span> <span class="k">match</span> <span class="o">{</span><br /><span class="k">case</span> <span class="nc">EmptyGame</span> <span class="k">=></span> <span class="n">g2</span><br /><span class="k">case</span> <span class="k">_</span> <span class="k">=></span> <span class="o">{</span><br /><span class="n">g2</span> <span class="k">match</span> <span class="o">{</span><br /><span class="k">case</span> <span class="nc">EmptyGame</span> <span class="k">=></span> <span class="n">g1</span><br /><span class="k">case</span> <span class="k">_</span> <span class="k">=></span> <span class="o">{</span><br /><span class="nc">Game</span><span class="o">(</span><br /><span class="o">(</span><br /><span class="n">g1</span><span class="o">.</span><span class="n">left</span><span class="o">.</span><span class="n">mapf</span><span class="o">(</span> <span class="n">add</span><span class="o">(</span> <span class="k">_</span><span class="o">,</span> <span class="n">g2</span> <span class="o">)</span> <span class="o">)</span><br /><span class="o">++</span><br /><span class="n">g2</span><span class="o">.</span><span class="n">left</span><span class="o">.</span><span class="n">mapf</span><span class="o">(</span> <span class="n">add</span><span class="o">(</span> <span class="n">g1</span><span class="o">,</span> <span class="k">_</span> <span class="o">)</span> <span class="o">)</span><br /><span class="o">),</span><br /><span class="o">(</span><br /><span class="n">g1</span><span class="o">.</span><span class="n">right</span><span class="o">.</span><span class="n">mapf</span><span class="o">(</span> <span class="n">add</span><span class="o">(</span> <span class="k">_</span><span class="o">,</span> <span class="n">g2</span> <span class="o">)</span> <span class="o">)</span><br /><span class="o">++</span><br /><span class="n">g2</span><span class="o">.</span><span class="n">right</span><span class="o">.</span><span class="n">mapf</span><span class="o">(</span> <span class="n">add</span><span class="o">(</span> <span class="n">g1</span><span class="o">,</span> <span class="k">_</span> <span class="o">)</span> <span class="o">)</span><br /><span class="o">)</span><br /><span class="o">)</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="k">override</span> <span class="k">def</span> <span class="n">minus</span> <span class="o">(</span><br /><span class="n">g</span> <span class="k">:</span> <span class="kt">ConwayGame</span><br /><span class="o">)</span> <span class="k">:</span> <span class="kt">ConwayGame</span> <span class="o">=</span> <span class="o">{</span><br /><span class="nc">Game</span><span class="o">(</span> <span class="n">g</span><span class="o">.</span><span class="n">right</span><span class="o">.</span><span class="n">mapf</span><span class="o">(</span> <span class="n">minus</span> <span class="o">),</span> <span class="n">g</span><span class="o">.</span><span class="n">left</span><span class="o">.</span><span class="n">mapf</span><span class="o">(</span> <span class="n">minus</span> <span class="o">)</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="k">override</span> <span class="k">def</span> <span class="n">multiply</span> <span class="o">(</span><br /><span class="n">g1</span> <span class="k">:</span> <span class="kt">ConwayGame</span><span class="o">,</span><br /><span class="n">g2</span> <span class="k">:</span> <span class="kt">ConwayGame</span><br /><span class="o">)</span> <span class="k">:</span> <span class="kt">ConwayGame</span> <span class="o">=</span> <span class="o">{</span><br /><span class="k">def</span> <span class="n">mComp</span><span class="o">(</span><br /><span class="n">gtpl</span> <span class="k">:</span> <span class="o">(</span><br /><span class="kt">ConwayGame</span><span class="o">,</span><br /><span class="kt">ConwayGame</span><br /><span class="o">)</span><br /><span class="o">)</span> <span class="k">=</span> <span class="o">{</span><br /><span class="n">add</span><span class="o">(</span><br /><span class="n">add</span><span class="o">(</span><br /><span class="n">multiply</span><span class="o">(</span> <span class="n">gtpl</span><span class="o">.</span><span class="n">_1</span><span class="o">,</span> <span class="n">g2</span> <span class="o">),</span><br /><span class="n">multiply</span><span class="o">(</span> <span class="n">g1</span><span class="o">,</span> <span class="n">gtpl</span><span class="o">.</span><span class="n">_2</span> <span class="o">)</span><br /><span class="o">),</span><br /><span class="n">minus</span><span class="o">(</span> <span class="n">multiply</span><span class="o">(</span> <span class="n">gtpl</span><span class="o">.</span><span class="n">_1</span><span class="o">,</span> <span class="n">gtpl</span><span class="o">.</span><span class="n">_2</span> <span class="o">)</span> <span class="o">)</span><br /><span class="o">)</span><br /><span class="o">}</span><br /><br /><span class="nc">Game</span><span class="o">(</span><br /><span class="o">(</span><br /><span class="n">g1</span><span class="o">.</span><span class="n">left</span><span class="o">.</span><span class="n">zip</span><span class="o">(</span> <span class="n">g2</span><span class="o">.</span><span class="n">left</span> <span class="o">).</span><span class="n">mapf</span><span class="o">(</span> <span class="n">mComp</span> <span class="o">)</span><br /><span class="o">++</span> <span class="n">g1</span><span class="o">.</span><span class="n">right</span><span class="o">.</span><span class="n">zip</span><span class="o">(</span> <span class="n">g2</span><span class="o">.</span><span class="n">right</span> <span class="o">).</span><span class="n">mapf</span><span class="o">(</span> <span class="n">mComp</span> <span class="o">)</span><br /><span class="o">),</span><br /><span class="o">(</span><br /><span class="n">g1</span><span class="o">.</span><span class="n">left</span><span class="o">.</span><span class="n">zip</span><span class="o">(</span> <span class="n">g2</span><span class="o">.</span><span class="n">right</span> <span class="o">).</span><span class="n">mapf</span><span class="o">(</span> <span class="n">mComp</span> <span class="o">)</span><br /><span class="o">++</span> <span class="n">g1</span><span class="o">.</span><span class="n">right</span><span class="o">.</span><span class="n">zip</span><span class="o">(</span> <span class="n">g2</span><span class="o">.</span><span class="n">left</span> <span class="o">).</span><span class="n">mapf</span><span class="o">(</span> <span class="n">mComp</span> <span class="o">)</span><br /><span class="o">)</span><br /><span class="o">)</span><br /><span class="o">}</span><br /><br /><span class="c">// relations</span><br /><span class="c">// identity</span><br /><span class="k">override</span> <span class="k">def</span> <span class="n">`===`</span> <span class="o">(</span><br /><span class="n">g1</span> <span class="k">:</span> <span class="kt">ConwayGame</span><span class="o">,</span><br /><span class="n">g2</span> <span class="k">:</span> <span class="kt">ConwayGame</span><br /><span class="o">)</span> <span class="k">:</span> <span class="kt">Boolean</span> <span class="o">=</span> <span class="o">{</span><br /><span class="o">(</span> <span class="o">(</span> <span class="n">g1</span><span class="o">.</span><span class="n">left</span><span class="o">.</span><span class="n">equals</span><span class="o">(</span> <span class="n">g2</span><span class="o">.</span><span class="n">left</span> <span class="o">)</span> <span class="o">)</span> <span class="o">&&</span> <span class="o">(</span> <span class="n">g1</span><span class="o">.</span><span class="n">right</span><span class="o">.</span><span class="n">equals</span><span class="o">(</span> <span class="n">g2</span><span class="o">.</span><span class="n">right</span> <span class="o">)</span> <span class="o">)</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="c">// equality</span><br /><span class="k">override</span> <span class="k">def</span> <span class="n">`=G=`</span> <span class="o">(</span><br /><span class="n">g1</span> <span class="k">:</span> <span class="kt">ConwayGame</span><span class="o">,</span><br /><span class="n">g2</span> <span class="k">:</span> <span class="kt">ConwayGame</span><br /><span class="o">)</span> <span class="k">:</span> <span class="kt">Boolean</span> <span class="o">=</span> <span class="o">{</span><br /><span class="o">(</span> <span class="n">`G>=`</span><span class="o">(</span> <span class="n">g1</span><span class="o">,</span> <span class="n">g2</span> <span class="o">)</span> <span class="o">&&</span> <span class="n">`G>=`</span><span class="o">(</span> <span class="n">g2</span><span class="o">,</span> <span class="n">g1</span> <span class="o">)</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="c">// order</span><br /><span class="k">override</span> <span class="k">def</span> <span class="n">`G>=`</span> <span class="o">(</span><br /><span class="n">g1</span> <span class="k">:</span> <span class="kt">ConwayGame</span><span class="o">,</span><br /><span class="n">g2</span> <span class="k">:</span> <span class="kt">ConwayGame</span><br /><span class="o">)</span> <span class="k">:</span> <span class="kt">Boolean</span> <span class="o">=</span> <span class="o">{</span><br /><span class="o">(</span><br /><span class="n">g2</span><span class="o">.</span><span class="n">left</span><span class="o">.</span><span class="n">forall</span><span class="o">(</span> <span class="o">(</span> <span class="n">g2L</span> <span class="k">:</span> <span class="kt">ConwayGame</span> <span class="o">)</span> <span class="k">=></span> <span class="o">!</span> <span class="n">`G>=`</span><span class="o">(</span> <span class="n">g2L</span><span class="o">,</span> <span class="n">g1</span> <span class="o">)</span> <span class="o">)</span><br /><span class="o">&&</span> <span class="n">g1</span><span class="o">.</span><span class="n">right</span><span class="o">.</span><span class="n">forall</span><span class="o">(</span> <span class="o">(</span> <span class="n">g1R</span> <span class="k">:</span> <span class="kt">ConwayGame</span> <span class="o">)</span> <span class="k">=></span> <span class="o">!</span> <span class="n">`G>=`</span><span class="o">(</span> <span class="n">g2</span><span class="o">,</span> <span class="n">g1R</span> <span class="o">)</span> <span class="o">)</span><br /><span class="o">)</span><br /><span class="o">}</span><br /><span class="o">}</span><br /></pre></div><br /></td></tr></tbody></table></div><br /></div><br /><br />i feel compelled to offer just a quick observation regarding the fidelity of this code with respect to Conway’s code. While these definitions are nearly verbatim representations of Conway’s original definitions, Conway’s construction is a mathematical construction. So, he is very happy to have infinite left and right components. Because Scala is strict by default, these definitions would have to be modified to be lazy enough to model (some of) the infinite constructions Conway considers. These subtleties, however, are not of primary concern to us, here. Our focus here is to use the essence of the Conway data structure to illustrate a point about monads and design patterns. That said, let’s take a look at addition. Using our calculator, if we add 1 to 0 what do we get?<br /><br />scala> val one = Game( Set( EmptyGame ), Set.empty )<br />val one = Game( Set( EmptyGame ), Set.empty )<br />one: com.biosimilarity.lift.lib.game.conway.Game = {{|}|}<br /><br />scala> val zero = EmptyGame<br />val zero = EmptyGame<br />zero: com.biosimilarity.lift.lib.game.conway.EmptyGame.type = {|}<br /><br />scala> val calc = new ConwayCalculator()<br />val calc = new ConwayCalculator()<br />calc: com.biosimilarity.lift.lib.game.conway.ConwayCalculator = com.biosimilarity.lift.lib.game.conway.ConwayCalculator@4662a3a1<br /><br />scala> calc.add( one, zero )<br />calc.add( one, zero )<br />res0: com.biosimilarity.lift.lib.game.conway.ConwayGame = {{|}|}<br /><br />scala> calc.add( zero, one )<br />calc.add( zero, one )<br />res1: com.biosimilarity.lift.lib.game.conway.ConwayGame = {{|}|}<br /><br />scala><br /><br />This would hardly count as a mathematical proof of the correctness of our encoding. However, given that the encoding is a near verbatim representation of Conway’s original definitions, it gives us some confidence that we got it right enough for our main purpose.<br /><br /><h3><span class="Apple-style-span">Recap of the monad API</span></h3><br />For this discussion we use the BMonad version of the monad API. So, if the trait Monad (see below) represents the (signatures) of the standard category theoretic presentation of monads<br /><br /><div id="paste" class="lang-scala code"><br /><div class="code"><table class="syntaxtable"><tbody><tr><td class="linenos"><pre>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9</pre></td><td class="code"><div class="syntax"><pre><span class="c">// How the category boyz be looking at things monadically</span><br /><span class="k">trait</span> <span class="nc">Monad</span><span class="o">[</span><span class="kt">M</span><span class="o">[</span><span class="k">_</span><span class="o">]]</span> <span class="o">{</span><br /><span class="k">def</span> <span class="n">fmap</span> <span class="o">[</span><span class="kt">A</span>,<span class="kt">B</span><span class="o">]</span> <span class="o">(</span> <span class="n">f</span> <span class="k">:</span> <span class="kt">A</span> <span class="k">=></span> <span class="kt">B</span> <span class="o">)</span> <span class="k">:</span> <span class="kt">M</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="k">=></span> <span class="kt">M</span><span class="o">[</span><span class="kt">B</span><span class="o">]</span><br /><span class="k">def</span> <span class="n">unit</span> <span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="o">(</span> <span class="n">a</span> <span class="k">:</span> <span class="kt">A</span> <span class="o">)</span> <span class="k">:</span> <span class="kt">M</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span><br /><span class="k">def</span> <span class="n">mult</span> <span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="o">(</span> <span class="n">mma</span> <span class="k">:</span> <span class="kt">M</span><span class="o">[</span><span class="kt">M</span><span class="o">[</span><span class="kt">A</span><span class="o">]]</span> <span class="o">)</span> <span class="k">:</span> <span class="kt">M</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span><br /><span class="k">def</span> <span class="n">bind</span> <span class="o">[</span><span class="kt">A</span>,<span class="kt">B</span><span class="o">]</span> <span class="o">(</span> <span class="n">ma</span> <span class="k">:</span> <span class="kt">M</span><span class="o">[</span><span class="kt">A</span><span class="o">],</span> <span class="n">f</span> <span class="k">:</span> <span class="kt">A</span> <span class="k">=></span> <span class="kt">M</span><span class="o">[</span><span class="kt">B</span><span class="o">]</span> <span class="o">)</span> <span class="k">:</span> <span class="kt">M</span><span class="o">[</span><span class="kt">B</span><span class="o">]</span> <span class="o">=</span> <span class="o">{</span><br /><span class="n">mult</span><span class="o">(</span> <span class="n">fmap</span><span class="o">(</span> <span class="n">f</span> <span class="o">)(</span> <span class="n">ma</span> <span class="o">)</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="o">}</span><br /></pre></div><br /></td></tr></tbody></table></div><br /></div><br /><br />then the trait BMonad (below) represents an alternative presentation (in terms of a method called bind) that is common in the Haskel community.<br /><br /><div id="paste" class="lang-scala code"><br /><div class="code"><table class="syntaxtable"><tbody><tr><td class="linenos"><pre> 1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14</pre></td><td class="code"><div class="syntax"><pre><span class="c">// How the Haskell boyz be looking at things monadically</span><br /><span class="k">trait</span> <span class="nc">BMonad</span><span class="o">[</span><span class="kt">M</span><span class="o">[</span><span class="k">_</span><span class="o">]]</span> <span class="nc">extends</span> <span class="nc">Monad</span><span class="o">[</span><span class="kt">M</span><span class="o">]</span> <span class="o">{</span><br /><span class="k">override</span> <span class="k">def</span> <span class="n">fmap</span> <span class="o">[</span><span class="kt">A</span>,<span class="kt">B</span><span class="o">]</span> <span class="o">(</span><br /><span class="n">f</span> <span class="k">:</span> <span class="kt">A</span> <span class="k">=></span> <span class="kt">B</span><br /><span class="o">)</span> <span class="k">:</span> <span class="kt">M</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="k">=></span> <span class="kt">M</span><span class="o">[</span><span class="kt">B</span><span class="o">]</span> <span class="o">=</span> <span class="o">{</span><br /><span class="o">(</span> <span class="n">ma</span> <span class="k">:</span> <span class="kt">M</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /><span class="n">bind</span><span class="o">(</span> <span class="n">ma</span><span class="o">,</span> <span class="o">(</span> <span class="n">a</span> <span class="k">:</span> <span class="kt">A</span> <span class="o">)</span> <span class="k">=></span> <span class="n">unit</span><span class="o">(</span> <span class="n">f</span><span class="o">(</span> <span class="n">a</span> <span class="o">)</span> <span class="o">)</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="k">override</span> <span class="k">def</span> <span class="n">mult</span> <span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="o">(</span> <span class="n">mma</span> <span class="k">:</span> <span class="kt">M</span><span class="o">[</span><span class="kt">M</span><span class="o">[</span><span class="kt">A</span><span class="o">]]</span> <span class="o">)</span> <span class="k">:</span> <span class="kt">M</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="o">=</span> <span class="o">{</span><br /><span class="n">bind</span><span class="o">[</span><span class="kt">M</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span>,<span class="kt">A</span><span class="o">](</span> <span class="n">mma</span><span class="o">,</span> <span class="o">(</span> <span class="n">ma</span> <span class="o">)</span> <span class="k">=></span> <span class="n">ma</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="k">override</span> <span class="k">def</span> <span class="n">bind</span> <span class="o">[</span><span class="kt">A</span>,<span class="kt">B</span><span class="o">]</span> <span class="o">(</span> <span class="n">ma</span> <span class="k">:</span> <span class="kt">M</span><span class="o">[</span><span class="kt">A</span><span class="o">],</span> <span class="n">f</span> <span class="k">:</span> <span class="kt">A</span> <span class="k">=></span> <span class="kt">M</span><span class="o">[</span><span class="kt">B</span><span class="o">]</span> <span class="o">)</span> <span class="k">:</span> <span class="kt">M</span><span class="o">[</span><span class="kt">B</span><span class="o">]</span><br /><span class="o">}</span><br /></pre></div><br /></td></tr></tbody></table></div><br /></div><br /><br />It turns out that we will also need some additional structure on our monad which we encapsulate in the trait MonadPlus. The additional structure allows us to interpret our monad more directly as if it were an additive structure with a +-like operation and an additive identity which we access via the zero method.<br /><br /><div id="paste" class="lang-scala code"><br /><div class="code"><table class="syntaxtable"><tbody><tr><td class="linenos"><pre>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9</pre></td><td class="code"><div class="syntax"><pre><span class="c">// More monadically good richness</span><br /><span class="k">trait</span> <span class="nc">MonadPlus</span><span class="o">[</span><span class="kt">M</span><span class="o">[</span><span class="k">_</span><span class="o">]]</span> <span class="o">{</span><br /><span class="n">self</span> <span class="k">:</span> <span class="kt">Monad</span><span class="o">[</span><span class="kt">M</span><span class="o">]</span> <span class="k">=></span><br /><span class="kt">def</span> <span class="kt">zero</span> <span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="kt">:</span> <span class="kt">M</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span><br /><span class="k">def</span> <span class="n">plus</span> <span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="o">(</span> <span class="n">ma1</span> <span class="k">:</span> <span class="kt">M</span><span class="o">[</span><span class="kt">A</span><span class="o">],</span> <span class="n">ma2</span> <span class="k">:</span> <span class="kt">M</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="o">)</span> <span class="k">:</span> <span class="kt">M</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span><br /><span class="k">def</span> <span class="n">msum</span> <span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="o">(</span> <span class="n">lma</span> <span class="k">:</span> <span class="kt">List</span><span class="o">[</span><span class="kt">M</span><span class="o">[</span><span class="kt">A</span><span class="o">]]</span> <span class="o">)</span> <span class="k">:</span> <span class="kt">M</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="o">=</span> <span class="o">{</span><br /><span class="o">(</span> <span class="n">zero</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="o">/:</span> <span class="n">lma</span> <span class="o">)(</span> <span class="n">plus</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="o">}</span><br /></pre></div><br /></td></tr></tbody></table></div><br /></div><br /><br /><h3><span class="Apple-style-span">Realizing the monad API</span></h3><br />This API separates the monad type constructor from the monad methods. That is, they are not methods on M. They are methods on Monad (respectively, BMonad). This design choice is very much analogous to our choice to model the arithmetic operations on Conway games on a separate Calculator class. In the same way that we might invent different kinds of calculators for different ways to realize arithmetic operations on Conway games (and not perturb our Conway game code!), this affords us the opportunity to model different ways to interpret the monad API on the same underlying structure. To see the monad API at work let’s see how we might interpret the Option structure monadically.<br /><br />One crucial point about the code below is that when we make this design choice we are swimming upstream relative to choices made in Scala’s basic design. In particular, Scala’s for-notation desugaring makes some strong assumptions about the factorization of the monad methods. To allow our design pattern to play well in the Scala ecosystem (be used in for-comprehensions) we have to provide an adapter (represented here in the inheritance of ForNotationAdapter)<br /><br /><div id="paste" class="lang-scala code"><br /><div class="code"><table class="syntaxtable"><tbody><tr><td class="linenos"><pre> 1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20</pre></td><td class="code"><div class="syntax"><pre><span class="c">// Option interpreted as a monad</span><br /><span class="k">class</span> <span class="nc">OptionMonad</span><span class="o">[</span><span class="kt">A</span><span class="o">](</span> <span class="o">)</span><br /><span class="k">extends</span> <span class="nc">ForNotationAdapter</span><span class="o">[</span><span class="kt">Option</span>,<span class="kt">A</span><span class="o">]</span><br /><span class="k">with</span> <span class="nc">Monad</span><span class="o">[</span><span class="kt">Option</span><span class="o">]</span> <span class="o">{</span><br /><span class="k">override</span> <span class="k">def</span> <span class="n">fmap</span> <span class="o">[</span><span class="kt">S</span>,<span class="kt">T</span><span class="o">](</span> <span class="n">f</span> <span class="k">:</span> <span class="kt">S</span> <span class="k">=></span> <span class="kt">T</span> <span class="o">)</span> <span class="k">:</span> <span class="kt">Option</span><span class="o">[</span><span class="kt">S</span><span class="o">]</span> <span class="k">=></span> <span class="kt">Option</span><span class="o">[</span><span class="kt">T</span><span class="o">]</span> <span class="o">=</span> <span class="o">{</span><br /><span class="o">(</span> <span class="n">la</span> <span class="k">:</span> <span class="kt">Option</span><span class="o">[</span><span class="kt">S</span><span class="o">]</span> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /><span class="n">la</span> <span class="k">match</span> <span class="o">{</span><br /><span class="k">case</span> <span class="nc">Some</span><span class="o">(</span> <span class="n">s</span> <span class="o">)</span> <span class="k">=></span> <span class="nc">Some</span><span class="o">(</span> <span class="n">f</span><span class="o">(</span> <span class="n">s</span> <span class="o">)</span> <span class="o">)</span><br /><span class="k">case</span> <span class="k">_</span> <span class="k">=></span> <span class="nc">None</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="k">override</span> <span class="k">def</span> <span class="n">unit</span> <span class="o">[</span><span class="kt">S</span><span class="o">]</span> <span class="o">(</span> <span class="n">s</span> <span class="k">:</span> <span class="kt">S</span> <span class="o">)</span> <span class="k">:</span> <span class="kt">Option</span><span class="o">[</span><span class="kt">S</span><span class="o">]</span> <span class="o">=</span> <span class="nc">Some</span><span class="o">[</span><span class="kt">S</span><span class="o">](</span> <span class="n">s</span> <span class="o">)</span><br /><span class="k">override</span> <span class="k">def</span> <span class="n">mult</span> <span class="o">[</span><span class="kt">S</span><span class="o">]</span> <span class="o">(</span> <span class="n">lls</span> <span class="k">:</span> <span class="kt">Option</span><span class="o">[</span><span class="kt">Option</span><span class="o">[</span><span class="kt">S</span><span class="o">]]</span> <span class="o">)</span> <span class="k">:</span> <span class="kt">Option</span><span class="o">[</span><span class="kt">S</span><span class="o">]</span> <span class="o">=</span> <span class="o">{</span><br /><span class="n">lls</span> <span class="k">match</span> <span class="o">{</span><br /><span class="k">case</span> <span class="nc">Some</span><span class="o">(</span> <span class="nc">Some</span><span class="o">(</span> <span class="n">s</span> <span class="o">)</span> <span class="o">)</span> <span class="k">=></span> <span class="nc">Some</span><span class="o">(</span> <span class="n">s</span> <span class="o">)</span><br /><span class="k">case</span> <span class="k">_</span> <span class="k">=></span> <span class="nc">None</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="o">}</span><br /></pre></div><br /></td></tr></tbody></table></div><br /></div><br /><br /><h3>Discussion of Conway game structure to interpret the monad API</h3><br /><h4>Poking a hole in Conway</h4><br />As it stands our presentation of the Conway game structure is not sufficient as a target for interpreting the monadic API. The monadic API is parametrically polymorphic in a type of element that can be encapsulated in our container structure. Conway games are purer than that! They are either empty or they contain other Conway games.<br /><br />The resemblance of Conway games to Sets gives us a clue for how to rectify the situation. In point of fact, Scala Sets do not correspond to ordinary Set Theory! At least not<a href="http://en.wikipedia.org/wiki/Zermelo%E2%80%93Fraenkel_set_theory"> ZF(C) Set Theory</a>. This is because ZF Set Theory sets do not contain elements that aren’t sets! ZF Set Theory is built entirely from the empty set, {}, in the same way that Conway games are built entirely from the empty game, {|}. As programmers -- whether we know it or not! -- we are quite comfortable with the idea of “poking a hole” in ZF Set Theory; that is, making it parametrically polymorphic in an “atom” type, say A, where the type Set[A] can contain either A’s or Set[A]. So, let’s try the same idea here.<div><br />We make a new type, say GeneralizedConwayGame[A], that is parametric in a type of “atom”, A.<br /><br /><div id="paste" class="lang-scala code"><br /><div class="code"><table class="syntaxtable"><tbody><tr><td class="linenos"><pre>1<br />2<br />3<br />4</pre></td><td class="code"><div class="syntax"><pre><span class="k">trait</span> <span class="nc">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">+A</span><span class="o">]</span> <span class="o">{</span><br /><span class="k">def</span> <span class="n">left</span> <span class="k">:</span> <span class="kt">Set</span><span class="o">[</span><span class="kt">Either</span><span class="o">[</span><span class="kt">A</span>,<span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">A</span><span class="o">]]]</span><br /><span class="k">def</span> <span class="n">right</span> <span class="k">:</span> <span class="kt">Set</span><span class="o">[</span><span class="kt">Either</span><span class="o">[</span><span class="kt">A</span>,<span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">A</span><span class="o">]]]</span><br /><span class="o">}</span><br /></pre></div><br /></td></tr></tbody></table></div><br /></div><br /><br />We can go along and carry out the programme providing the obvious variants of our concrete implementations. For example,<br /><br /><div id="paste" class="lang-scala code"><br /><div class="code"><table class="syntaxtable"><tbody><tr><td class="linenos"><pre> 1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15</pre></td><td class="code"><div class="syntax"><pre><span class="k">case</span> <span class="k">object</span> <span class="nc">EmptyGenConGame</span><br /><span class="k">extends</span> <span class="nc">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">Nothing</span><span class="o">]</span><br /><span class="k">with</span> <span class="nc">GenConRenderer</span><span class="o">[</span><span class="kt">Nothing</span><span class="o">]</span><br /><span class="o">{</span><br /><span class="k">override</span> <span class="k">def</span> <span class="n">left</span> <span class="k">:</span> <span class="kt">Set</span><span class="o">[</span><span class="kt">Either</span><span class="o">[</span><span class="kt">Nothing</span>,<span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">Nothing</span><span class="o">]]]</span> <span class="o">=</span><br /><span class="nc">Set</span><span class="o">.</span><span class="n">empty</span><span class="o">[</span><span class="kt">Either</span><span class="o">[</span><span class="kt">Nothing</span>,<span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">Nothing</span><span class="o">]]]</span><br /><span class="k">override</span> <span class="k">def</span> <span class="n">right</span> <span class="k">:</span> <span class="kt">Set</span><span class="o">[</span><span class="kt">Either</span><span class="o">[</span><span class="kt">Nothing</span>,<span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">Nothing</span><span class="o">]]]</span> <span class="o">=</span><br /><span class="nc">Set</span><span class="o">.</span><span class="n">empty</span><span class="o">[</span><span class="kt">Either</span><span class="o">[</span><span class="kt">Nothing</span>,<span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">Nothing</span><span class="o">]]]</span><br /><span class="o">}</span><br /><br /><span class="k">case</span> <span class="k">class</span> <span class="nc">GenConGame</span><span class="o">[</span><span class="kt">+A</span><span class="o">](</span><br /><span class="n">left</span> <span class="k">:</span> <span class="kt">Set</span><span class="o">[</span><span class="kt">Either</span><span class="o">[</span><span class="kt">A</span>,<span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">A</span><span class="o">]]],</span><br /><span class="n">right</span> <span class="k">:</span> <span class="kt">Set</span><span class="o">[</span><span class="kt">Either</span><span class="o">[</span><span class="kt">A</span>,<span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">A</span><span class="o">]]]</span><br /><span class="o">)</span> <span class="k">extends</span> <span class="nc">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span><br /><span class="k">with</span> <span class="nc">GenConRenderer</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span><br /></pre></div><br /></td></tr></tbody></table></div></div><div><br />(Here's what we are doing, mathematically. The type of ConwayGames can be seen as</div><div><br /></div><div>CG = Pow( CG ) x Pow( CG )</div><div><br /></div><div>The shape of this domain equation tells us that it is solvable. It's solution corresponds precisely to the concrete types we described above. Now, there's another way to arrive at the solution. We make CG parametric.</div><div><br /></div><div>CG[A] = Pow( A ) x Pow( A )</div><div><br /></div><div>then we see that µA.CG[A] gives us the original type of Conway Games. Now that we've made CG parametric, nothing stops us from using these type parameters in interesting ways. So, our recursive equation becomes</div><div><br /></div><div>CG[A] = Pow( CG[A] + A ) x Pow( CG[A] + A )</div><div><br /></div><div>And, as we mention below, this just begs the formulation</div><div><br /></div><div>CG[M,A] = M[CG[M,A] + A] x M[CG[M,A] + A]</div><div><br /></div><div>where we have replaced Pow (the Power set monad) with an arbitrary monad, M. If you look in the <a href="https://github.com/leithaus/SpecialK/tree/moniker/src/main/scala/com/biosimilarity/lift/lib/game">github project</a>, you will see that the calculator definitions for this construction remain nearly unchanged. Thus, we have the field of Reals over an arbitrary monad, M.)</div><br />But, we hit a snag when it comes to supporting the operations of the Calculator! The definition of minus, for example, will require us to “negate” an inhabitant of the type, A. This is where reification -- which is the very heart of what monads do -- comes to the rescue! We simply invent some (largely syntactic) containers for each of the situations we are required to support and we defer any computational interpretation! It will be up to some richer Calculator together with some more detailed information about the type A to give a more detailed interpretation of these calculations.<br /><br />You can see one relatively complete presentation of the required structure in the <a href="https://github.com/leithaus/SpecialK/tree/moniker/src/main/scala/com/biosimilarity/lift/lib/game">github project</a>. Fortunately for us, because we have deferred any computational interpretation of these operations, and merely reified and recorded that the calculations need to be performed, that these operations type check constitutes the bulk of the proof that this is a reasonable model. This is the essential power of syntactic models. What remains of such a mathematical proof would be a (definition of and) demonstration of the coherence of the interaction of the various elements of the structure we’ve posited. The analogy to keep in mind here is to the monadic API, itself. What remains of correctness obligations, after type checking, are the monad laws. These a programmer must prove, by hand.<br /><br />i would be remiss if i didn’t say that this approach to generalizing Conway is an entirely new idea! To the best of my knowledge no one was considered generalizing Conway’s construction in quite this way. Moreover, it leads to a second and even more beautiful generalization in which we replace Set as the left and right component containers with an arbitary monad! It turns out that the structure we derive above is sufficient to carry out this generalization as well. That in itself is justification for the introduction of extra structure because it allows us to define field operations that closely resemble the Reals over more or less arbitrary monads (such as the continuation monad). This opens up whole new possibilities! However, they are beyond the scope of the current discussion.<br /><br />With this structure in hand, it should be clear that there are (at least!) two ways to interpret the monad API using Conway games. The two obvious ways correspond to two different interpretations of the unit method -- one which embeds the element in the left component, the other in the right. Interestingly, for the definition of bind to even type check we are more or less forced to treat the left and right sides symmetrically. So, the substantive difference between the two interpretations is whether unit encapsulates inhabitants of A in the left or right component of a game. In the code below we have recognized this fact by lifting the common code up into a separate trait.<br /><br /><div id="paste" class="lang-scala code"><br /><div class="code"><table class="syntaxtable"><tbody><tr><td class="linenos"><pre> 1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96</pre></td><td class="code"><div class="syntax"><pre><span class="k">trait</span> <span class="nc">GenConPreM</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="o">{</span><br /><span class="k">def</span> <span class="n">gcgBind</span> <span class="o">[</span><span class="kt">S</span>,<span class="kt">T</span><span class="o">]</span> <span class="o">(</span><br /><span class="n">ls</span> <span class="k">:</span> <span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">S</span><span class="o">],</span><br /><span class="n">f</span> <span class="k">:</span> <span class="kt">S</span> <span class="k">=></span> <span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">T</span><span class="o">]</span><br /><span class="o">)</span> <span class="k">:</span> <span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">T</span><span class="o">]</span> <span class="o">=</span> <span class="o">{</span><br /><span class="nc">GenConGame</span><span class="o">(</span><br /><span class="o">(</span> <span class="o">(</span> <span class="nc">Set</span><span class="o">.</span><span class="n">empty</span><span class="o">[</span><span class="kt">Either</span><span class="o">[</span><span class="kt">T</span>,<span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">T</span><span class="o">]]]</span> <span class="k">:</span> <span class="kt">Set</span><span class="o">[</span><span class="kt">Either</span><span class="o">[</span><span class="kt">T</span>,<span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">T</span><span class="o">]]]</span> <span class="o">)</span> <span class="o">/:</span> <span class="n">ls</span><span class="o">.</span><span class="n">left</span> <span class="o">)(</span><br /><span class="o">{</span><br /><span class="o">(</span> <span class="n">acc</span><span class="o">,</span> <span class="n">e</span> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /><span class="n">acc</span> <span class="o">++</span> <span class="nc">List</span><span class="o">(</span><br /><span class="nc">Right</span><span class="o">(</span><br /><span class="n">e</span> <span class="k">match</span> <span class="o">{</span><br /><span class="k">case</span> <span class="nc">Right</span><span class="o">(</span> <span class="n">g</span> <span class="o">)</span> <span class="k">=></span> <span class="n">gcgBind</span><span class="o">(</span> <span class="n">g</span><span class="o">,</span> <span class="n">f</span> <span class="o">)</span><br /><span class="k">case</span> <span class="nc">Left</span><span class="o">(</span> <span class="n">s</span> <span class="o">)</span> <span class="k">=></span> <span class="n">f</span><span class="o">(</span> <span class="n">s</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="o">)</span><br /><span class="o">)</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="o">),</span><br /><span class="o">(</span> <span class="o">(</span> <span class="nc">Set</span><span class="o">.</span><span class="n">empty</span><span class="o">[</span><span class="kt">Either</span><span class="o">[</span><span class="kt">T</span>,<span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">T</span><span class="o">]]]</span> <span class="k">:</span> <span class="kt">Set</span><span class="o">[</span><span class="kt">Either</span><span class="o">[</span><span class="kt">T</span>,<span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">T</span><span class="o">]]]</span> <span class="o">)</span> <span class="o">/:</span> <span class="n">ls</span><span class="o">.</span><span class="n">right</span> <span class="o">)(</span><br /><span class="o">{</span><br /><span class="o">(</span> <span class="n">acc</span><span class="o">,</span> <span class="n">e</span> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /><span class="n">acc</span> <span class="o">++</span> <span class="nc">List</span><span class="o">(</span><br /><span class="nc">Right</span><span class="o">(</span><br /><span class="n">e</span> <span class="k">match</span> <span class="o">{</span><br /><span class="k">case</span> <span class="nc">Right</span><span class="o">(</span> <span class="n">g</span> <span class="o">)</span> <span class="k">=></span> <span class="n">gcgBind</span><span class="o">(</span> <span class="n">g</span><span class="o">,</span> <span class="n">f</span> <span class="o">)</span><br /><span class="k">case</span> <span class="nc">Left</span><span class="o">(</span> <span class="n">s</span> <span class="o">)</span> <span class="k">=></span> <span class="n">f</span><span class="o">(</span> <span class="n">s</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="o">)</span><br /><span class="o">)</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="o">)</span><br /><span class="o">)</span><br /><span class="o">}</span><br /><span class="k">def</span> <span class="n">gcgMfilter</span> <span class="o">[</span><span class="kt">S</span><span class="o">]</span> <span class="o">(</span><br /><span class="n">ls</span> <span class="k">:</span> <span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">S</span><span class="o">],</span><br /><span class="n">pred</span> <span class="k">:</span> <span class="kt">S</span> <span class="k">=></span> <span class="kt">Boolean</span><br /><span class="o">)</span> <span class="k">:</span> <span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">S</span><span class="o">]</span> <span class="o">=</span> <span class="o">{</span><br /><span class="nc">GenConGame</span><span class="o">(</span><br /><span class="o">(</span> <span class="o">(</span> <span class="nc">Set</span><span class="o">.</span><span class="n">empty</span><span class="o">[</span><span class="kt">Either</span><span class="o">[</span><span class="kt">S</span>,<span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">S</span><span class="o">]]]</span> <span class="k">:</span> <span class="kt">Set</span><span class="o">[</span><span class="kt">Either</span><span class="o">[</span><span class="kt">S</span>,<span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">S</span><span class="o">]]]</span> <span class="o">)</span> <span class="o">/:</span> <span class="n">ls</span><span class="o">.</span><span class="n">left</span> <span class="o">)(</span><br /><span class="o">{</span><br /><span class="o">(</span><br /><span class="n">acc</span> <span class="k">:</span> <span class="kt">Set</span><span class="o">[</span><span class="kt">Either</span><span class="o">[</span><span class="kt">S</span>,<span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">S</span><span class="o">]]],</span><br /><span class="n">e</span> <span class="k">:</span> <span class="kt">Either</span><span class="o">[</span><span class="kt">S</span>,<span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">S</span><span class="o">]]</span><br /><span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /><span class="n">e</span> <span class="k">match</span> <span class="o">{</span><br /><span class="k">case</span> <span class="nc">Right</span><span class="o">(</span> <span class="n">g</span> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /><span class="k">val</span> <span class="n">fg</span> <span class="k">:</span> <span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">S</span><span class="o">]</span> <span class="o">=</span><br /><span class="n">gcgMfilter</span><span class="o">[</span><span class="kt">S</span><span class="o">](</span> <span class="n">g</span><span class="o">,</span> <span class="n">pred</span> <span class="o">)</span><br /><span class="k">val</span> <span class="n">rg</span> <span class="k">:</span> <span class="kt">Either</span><span class="o">[</span><span class="kt">S</span>,<span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">S</span><span class="o">]]</span> <span class="o">=</span><br /><span class="nc">Right</span><span class="o">[</span><span class="kt">S</span>,<span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">S</span><span class="o">]](</span> <span class="n">fg</span> <span class="o">)</span><br /><span class="n">acc</span> <span class="o">++</span> <span class="nc">List</span><span class="o">(</span> <span class="n">rg</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="k">case</span> <span class="nc">Left</span><span class="o">(</span> <span class="n">s</span> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /><span class="k">if</span> <span class="o">(</span> <span class="n">pred</span><span class="o">(</span> <span class="n">s</span> <span class="o">)</span> <span class="o">)</span> <span class="o">{</span><br /><span class="n">acc</span> <span class="o">++</span> <span class="nc">List</span><span class="o">(</span> <span class="nc">Left</span><span class="o">(</span> <span class="n">s</span> <span class="o">)</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="k">else</span> <span class="o">{</span><br /><span class="n">acc</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="o">),</span><br /><span class="o">(</span> <span class="o">(</span> <span class="nc">Set</span><span class="o">.</span><span class="n">empty</span><span class="o">[</span><span class="kt">Either</span><span class="o">[</span><span class="kt">S</span>,<span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">S</span><span class="o">]]]</span> <span class="k">:</span> <span class="kt">Set</span><span class="o">[</span><span class="kt">Either</span><span class="o">[</span><span class="kt">S</span>,<span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">S</span><span class="o">]]]</span> <span class="o">)</span> <span class="o">/:</span> <span class="n">ls</span><span class="o">.</span><span class="n">right</span> <span class="o">)(</span><br /><span class="o">{</span><br /><span class="o">(</span><br /><span class="n">acc</span> <span class="k">:</span> <span class="kt">Set</span><span class="o">[</span><span class="kt">Either</span><span class="o">[</span><span class="kt">S</span>,<span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">S</span><span class="o">]]],</span><br /><span class="n">e</span> <span class="k">:</span> <span class="kt">Either</span><span class="o">[</span><span class="kt">S</span>,<span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">S</span><span class="o">]]</span><br /><span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /><span class="n">e</span> <span class="k">match</span> <span class="o">{</span><br /><span class="k">case</span> <span class="nc">Right</span><span class="o">(</span> <span class="n">g</span> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /><span class="k">val</span> <span class="n">fg</span> <span class="k">:</span> <span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">S</span><span class="o">]</span> <span class="o">=</span><br /><span class="n">gcgMfilter</span><span class="o">[</span><span class="kt">S</span><span class="o">](</span> <span class="n">g</span><span class="o">,</span> <span class="n">pred</span> <span class="o">)</span><br /><span class="k">val</span> <span class="n">rg</span> <span class="k">:</span> <span class="kt">Either</span><span class="o">[</span><span class="kt">S</span>,<span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">S</span><span class="o">]]</span> <span class="o">=</span><br /><span class="nc">Right</span><span class="o">[</span><span class="kt">S</span>,<span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">S</span><span class="o">]](</span> <span class="n">fg</span> <span class="o">)</span><br /><span class="n">acc</span> <span class="o">++</span> <span class="nc">List</span><span class="o">(</span> <span class="n">rg</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="k">case</span> <span class="nc">Left</span><span class="o">(</span> <span class="n">s</span> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /><span class="k">if</span> <span class="o">(</span> <span class="n">pred</span><span class="o">(</span> <span class="n">s</span> <span class="o">)</span> <span class="o">)</span> <span class="o">{</span><br /><span class="n">acc</span> <span class="o">++</span> <span class="nc">List</span><span class="o">(</span> <span class="nc">Left</span><span class="o">(</span> <span class="n">s</span> <span class="o">)</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="k">else</span> <span class="o">{</span><br /><span class="n">acc</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="o">)</span><br /><span class="o">)</span><br /><span class="o">}</span><br /><span class="o">}</span><br /></pre></div><br /></td></tr></tbody></table></div><br /></div><br /><br />This allows us to write fairly simple, straightforward interpretations of the monad API.<br /><br /><div id="paste" class="lang-scala code"><br /><div class="code"><table class="syntaxtable"><tbody><tr><td class="linenos"><pre> 1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41</pre></td><td class="code"><div class="syntax"><pre><span class="k">class</span> <span class="nc">GenConLeftM</span><span class="o">[</span><span class="kt">A</span><span class="o">](</span> <span class="o">)</span><br /><span class="k">extends</span> <span class="nc">ForNotationAdapter</span><span class="o">[</span><span class="kt">GeneralizedConwayGame</span>,<span class="kt">A</span><span class="o">]</span><br /><span class="k">with</span> <span class="nc">BMonad</span><span class="o">[</span><span class="kt">GeneralizedConwayGame</span><span class="o">]</span><br /><span class="k">with</span> <span class="nc">MonadFilter</span><span class="o">[</span><span class="kt">GeneralizedConwayGame</span><span class="o">]</span><br /><span class="k">with</span> <span class="nc">GenConPreM</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="o">{</span><br /><span class="k">override</span> <span class="k">def</span> <span class="n">unit</span> <span class="o">[</span><span class="kt">S</span><span class="o">]</span> <span class="o">(</span> <span class="n">s</span> <span class="k">:</span> <span class="kt">S</span> <span class="o">)</span> <span class="k">:</span> <span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">S</span><span class="o">]</span> <span class="o">=</span><br /><span class="nc">GenConGame</span><span class="o">[</span><span class="kt">S</span><span class="o">](</span> <span class="nc">Set</span><span class="o">(</span> <span class="nc">Left</span><span class="o">[</span><span class="kt">S</span>,<span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">S</span><span class="o">]](</span> <span class="n">s</span> <span class="o">)</span> <span class="o">),</span> <span class="nc">Set</span><span class="o">.</span><span class="n">empty</span> <span class="o">)</span><br /><span class="k">override</span> <span class="k">def</span> <span class="n">bind</span> <span class="o">[</span><span class="kt">S</span>,<span class="kt">T</span><span class="o">]</span> <span class="o">(</span><br /><span class="n">ls</span> <span class="k">:</span> <span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">S</span><span class="o">],</span><br /><span class="n">f</span> <span class="k">:</span> <span class="kt">S</span> <span class="k">=></span> <span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">T</span><span class="o">]</span><br /><span class="o">)</span> <span class="k">:</span> <span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">T</span><span class="o">]</span> <span class="o">=</span> <span class="o">{</span><br /><span class="n">gcgBind</span><span class="o">(</span> <span class="n">ls</span><span class="o">,</span> <span class="n">f</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="k">override</span> <span class="k">def</span> <span class="n">mfilter</span> <span class="o">[</span><span class="kt">S</span><span class="o">]</span> <span class="o">(</span><br /><span class="n">ls</span> <span class="k">:</span> <span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">S</span><span class="o">],</span><br /><span class="n">pred</span> <span class="k">:</span> <span class="kt">S</span> <span class="k">=></span> <span class="kt">Boolean</span><br /><span class="o">)</span> <span class="k">:</span> <span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">S</span><span class="o">]</span> <span class="o">=</span> <span class="o">{</span><br /><span class="n">gcgMfilter</span><span class="o">(</span> <span class="n">ls</span><span class="o">,</span> <span class="n">pred</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><br /><span class="k">class</span> <span class="nc">GenConRightM</span><span class="o">[</span><span class="kt">A</span><span class="o">](</span> <span class="o">)</span><br /><span class="k">extends</span> <span class="nc">ForNotationAdapter</span><span class="o">[</span><span class="kt">GeneralizedConwayGame</span>,<span class="kt">A</span><span class="o">]</span><br /><span class="k">with</span> <span class="nc">BMonad</span><span class="o">[</span><span class="kt">GeneralizedConwayGame</span><span class="o">]</span><br /><span class="k">with</span> <span class="nc">MonadFilter</span><span class="o">[</span><span class="kt">GeneralizedConwayGame</span><span class="o">]</span><br /><span class="k">with</span> <span class="nc">GenConPreM</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="o">{</span><br /><span class="k">override</span> <span class="k">def</span> <span class="n">unit</span> <span class="o">[</span><span class="kt">S</span><span class="o">]</span> <span class="o">(</span> <span class="n">s</span> <span class="k">:</span> <span class="kt">S</span> <span class="o">)</span> <span class="k">:</span> <span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">S</span><span class="o">]</span> <span class="o">=</span><br /><span class="nc">GenConGame</span><span class="o">[</span><span class="kt">S</span><span class="o">](</span> <span class="nc">Set</span><span class="o">.</span><span class="n">empty</span><span class="o">[</span><span class="kt">Either</span><span class="o">[</span><span class="kt">S</span>,<span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">S</span><span class="o">]]],</span> <span class="nc">Set</span><span class="o">[</span><span class="kt">Either</span><span class="o">[</span><span class="kt">S</span>,<span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">S</span><span class="o">]]](</span> <span class="nc">Left</span><span class="o">[</span><span class="kt">S</span>,<span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">S</span><span class="o">]](</span> <span class="n">s</span> <span class="o">)</span> <span class="o">)</span> <span class="o">)</span><br /><span class="k">override</span> <span class="k">def</span> <span class="n">bind</span> <span class="o">[</span><span class="kt">S</span>,<span class="kt">T</span><span class="o">]</span> <span class="o">(</span><br /><span class="n">ls</span> <span class="k">:</span> <span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">S</span><span class="o">],</span><br /><span class="n">f</span> <span class="k">:</span> <span class="kt">S</span> <span class="k">=></span> <span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">T</span><span class="o">]</span><br /><span class="o">)</span> <span class="k">:</span> <span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">T</span><span class="o">]</span> <span class="o">=</span> <span class="o">{</span><br /><span class="n">gcgBind</span><span class="o">(</span> <span class="n">ls</span><span class="o">,</span> <span class="n">f</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="k">override</span> <span class="k">def</span> <span class="n">mfilter</span> <span class="o">[</span><span class="kt">S</span><span class="o">]</span> <span class="o">(</span><br /><span class="n">ls</span> <span class="k">:</span> <span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">S</span><span class="o">],</span><br /><span class="n">pred</span> <span class="k">:</span> <span class="kt">S</span> <span class="k">=></span> <span class="kt">Boolean</span><br /><span class="o">)</span> <span class="k">:</span> <span class="kt">GeneralizedConwayGame</span><span class="o">[</span><span class="kt">S</span><span class="o">]</span> <span class="o">=</span> <span class="o">{</span><br /><span class="n">gcgMfilter</span><span class="o">(</span> <span class="n">ls</span><span class="o">,</span> <span class="n">pred</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="o">}</span><br /></pre></div><br /></td></tr></tbody></table></div><br /></div><br /><br />The point is that our Conway code doesn’t change. The underlying structure is rich enough to support two different interpretations of the monad API. So, we merely provide the two distinct witnesses (in Haskell these would be called instance declarations) of the interpretation of the monad API.<br /><br /><h3>Coda</h3><br />Ironically, as i was preparing the code samples for this post i was initially using List[A] as the container for the left and right options. Of course, it should be something closer to Set[A]. So, as i was cleaning up the code i went to change the container to Set[A]. Much to my surprise i discovered that in the Scala collections library Set[A] and List[A] do not share the same variance constraints. List[A] is covariant while Set[A] is <span style="font-style:italic;">in</span>variant. The more i looked into the issue the more puzzled i became. The reason for this is that Set[A] inherits from A => Boolean. Now, this is only one view of the semantics of Set[A] and is also only one way to provide the capability. It would have been perfectly reasonable to provide a view of Set[A] that enabled this feature. Thus, inheritance, as i mentioned at the outset of this post, really, really did afford less reuse.<br /><br />The list of places to go wrong with inheritance is pretty well explored from the <a href="http://www.cas.mcmaster.ca/~emil/publications/fragile/">fragile base class</a> to the <a href="http://www.cs.utexas.edu/users/lavender/papers/behset.pdf">synchronization inheritance anomaly</a>. At the core of this issue is that is-a relationships are almost always in context. Inheritance sublimates the context. This is exactly the opposite of what is needed for maximal reuse -- and actually at odds with O-O <i>principles</i>. Instead, reify the context, give it an explicit computational representation and you will get more reuse.<br /><br />Thus, in the Set vs List case, it's only in some context that we agree that a Set[A] may be interpreted as a function A => Boolean. The context has very specific assumptions about what a function is and what a Set is. If we reify that context, we arrive at something like<br /><br />trait SetsAreFunctions[A,B] { /* you could make this implicit */ def asFunction( s : Set[A] ) : A => B }<br /><br />Notice that one "specialization" of this SetsAreFunctions[A,Float] is a candidate for representing <a href="http://en.wikipedia.org/wiki/Fuzzy_set">fuzzy sets</a>. Another "specialization" SetsAreFunctions[A,Option[Boolean]] is a candidate for various representations of partial functions. In this design our assumptions about the meaning of Set and function have been reified. Further, the act of specialization is much more clear, much more explicit and more highly governed by compiler constraints. If you compare it to what has been frozen into the Scala collections, it has a wider range, is mathematically and computationally more accurate and doesn't introduce an anomalous variance difference between collections that mathematical consistency demands be the same (List comes from the monad of the free monoid, Set is an algebra of this monad guaranteeing idempotency and commutativity of the operation -- variance should not differ!).<br /><br />There's another reason to care about Conway Games that i'll speak about in a little more depth in a subsequent post. To date, there have been two proposals for a notion of location that generalizes to arbitrary data structures supports well known operations like arithmetic and differential calculus these are -- Conway games and Huet's zipper. At first glance these two ideas do not seem to have much in common. However, once we look at these two proposals through the monadic lens we see that they share a striking commonality.</div>leithaushttp://www.blogger.com/profile/01069099703796397027noreply@blogger.com0tag:blogger.com,1999:blog-3049258033565653738.post-91037279097008216222011-02-25T23:13:00.000-08:002011-02-28T11:00:59.883-08:00An argument for Datalog as the data manipulation language in a KV-DB<span class="Apple-style-span"><div style="font-family: arial; font-size: small; ">i just checked in my Prolog Term -> XQuery compiler. The main idea can be expressed in a simple example. The prolog term</div><div style="font-family: arial; font-size: small; "><br /></div><div style="font-family: arial; font-size: small; "><ul><li><span class="Apple-style-span" style="line-height: 14px; ">seven(one("a", "b", "c"), two(X, Y), two("d", "e"))</span></li></ul></div><div style="font-family: arial; font-size: small; "><br /></div><div style="font-family: arial; font-size: small; "><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">compiles to the XQuery term</span></div><div class="page" style="font-family: arial; font-size: small; "><div id="paste" class="lang-xml code"><br /><div class="code"><table class="syntaxtable"><tbody><tr><td class="linenos"><pre> 1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28</pre></td><td class="code"><div class="syntax"><pre>for $xqV1 in root/seven<br />let $xqV2 := $xqV1/*[0] ,<br />$xqV7 := $xqV1/*[1] ,<br />$xqV9 := $xqV1/*[2]<br />where ( count($xqV1/*) = 3 )<br />and ( for $xqV3 in $xqV1/one<br /> let $xqV4 := $xqV3/*[0] ,<br /> $xqV5 := $xqV3/*[1] ,<br /> $xqV6 := $xqV3/*[2]<br /> where ( count($xqV3/*) = 3 )<br /> and ( $xqV4 = a )<br /> and ( $xqV5 = b )<br /> and ( $xqV6 = c )<br /> and ( $xqV2 = $xqV3 )<br />return $xqV3 )<br />and ( for $xqV8 in $xqV1/two<br /> where ( count($xqV8/*) = 2 )<br /> and ( $xqV7 = $xqV8 )<br />return $xqV8 )<br />and ( for $xqV10 in $xqV1/two<br /> let $xqV11 := $xqV10/*[0] ,<br /> $xqV12 := $xqV10/*[1]<br /> where ( count($xqV10/*) = 2 )<br /> and ( $xqV11 = d )<br /> and ( $xqV12 = e )<br /> and ( $xqV9 = $xqV10 )<br />return $xqV10 )<br />return $xqV1<br /></pre></div><br /></td></tr></tbody></table></div></div></div><span class="Apple-style-span" style="border-collapse: collapse; font-size: 13px; "><div class="im" style="font-family: arial, sans-serif; "><div>The interpretation is: find all the XML elements in the DB that (when turned into the obvious prolog terms) unify with the element. So, let us look at the element again</div><div><br /></div></div><div class="im" style="font-family: arial, sans-serif; "><div><span style="font-family: 'Courier New'; ">seven(one("a", "b", "c"), two(X, Y), two("d", "e"))</span></div><div><br /></div></div><div class="im"><div style="font-family: arial, sans-serif; ">This may be interpreted as a prolog pattern with X and Y as variables. This pattern unifies with the term</div><div style="font-family: arial, sans-serif; "><br /></div><div style="font-family: arial, sans-serif; "><span style="font-family: 'Courier New'; ">seven(one("a", "b", "c"), two(true, 10), two("d", "e"))</span></div><div style="font-family: arial, sans-serif; "><br /></div><div style="font-family: arial, sans-serif; ">Producing the substitution <span>X := true, Y := 10</span>.</div><div style="font-family: arial, sans-serif; "><br /></div><div style="font-family: arial, sans-serif; ">Next, notice the obvious and evident isomorphism between the term</div><div style="font-family: arial, sans-serif; "><br /></div><div style="font-family: arial, sans-serif; "><span style="font-family: 'Courier New'; ">seven(one("a", "b", "c"), two(true, 10), two("d", "e"))</span></div><div style="font-family: arial, sans-serif; "><br /></div><div style="font-family: arial, sans-serif; ">-- which is a ground term -- and the XML element</div><br /></div><span style="font-family: 'Courier New'; "><br /><seven><br /> <one><br /> <String>a</String><br /> <String>b</String><br /> <String>c</String><br /> </one><br /> <two><br /> <Bool>true</Bool> <br /> <Int>10<Int><br /> </two> <br /> <two><br /> <String>d</String><br /> <String>e</String><br /> </two><br /></seven><br /></span><div style="font-family: arial, sans-serif; ">Let's call the Prolog -> XML direction of the morphism p and the opposite direction, x. The XQuery generated for our pattern, ptn, will pick out exactly those elements that unify with the pattern -- as if we had selected a xml element, e, from the document, checked </div><div style="font-family: arial, sans-serif; "><span><br /></span></div><div style="font-family: arial, sans-serif; "><span>unifies( x( e ), ptn )</span> </div><div style="color: rgb(80, 0, 80); font-family: arial, sans-serif; "><br /></div><div style="color: rgb(51, 51, 51); font-family: arial, sans-serif; ">and if it does, added it to the result set. Of course, we could implement the approach just like that, but then we would lose all the efficiency of the XQuery engine. So, we use a little category theory and <i style="font-weight: bold; ">pull the unification algorithm through the </i><span>p</span><i style="font-weight: bold; "> direction of the iso</i>. This gives us a compiler from a prolog pattern to XQuery. Running the resulting algorithm on our pattern, ptn, gives the following XQuery (which is generated by the code in <a href="https://github.com/leithaus/SpecialK/blob/XQuery/src/main/scala/com/biosimilarity/lift/model/store/CnxnXML.scala" target="_blank" style="color: rgb(54, 84, 82); ">here</a> beginning at line 265).</div></span><div style="font-family: arial; font-size: small; "><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; "><br /></span></div><div style="font-family: arial; font-size: small; "><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">The beauty of this capability is that -- when coupled with previous idea about <a href="http://biosimilarity.blogspot.com/2011/02/channel-based-communication-monadically.html">a parametrically polymorphic broker</a> -- now the application programmer is completely free to elide distinctions between data being shipped around the internet as messages and data in store. They write programs of the form</span></div><div style="font-family: arial; font-size: small; "><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; "><br /></span></div><div style="font-size: small; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 13px; ">for( event <- channel.get( "seven(one("a", "b", "c"), two(X, Y), two("d", "e"))" ) ) { </span></div><div style="font-size: small; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 13px; "> // event handling code here ... </span></div><div style="font-size: small; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 13px; ">}</span></div><div style="font-family: arial; font-size: small; "><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; "><br /></span></div><div style="font-family: arial; font-size: small; "><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">And they don't really care if channel is a RabbitMQ queue or an instance of the eXist XML DB. Their code will block until such time as the data is available. We provide verbs for consuming the data (get) and just reading the data (fetch and subscribe). In the case of the latter the difference is whether the act of reading is linear (one-off) or replicated (it will keep reading from the channel). </span></div><div style="font-family: arial; font-size: small; "><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; "><br /></span></div><div><span class="Apple-style-span"><span class="Apple-style-span" style="border-collapse: collapse;">(As an aside, flatMap and filter comes into play if they want to do complex event-handling code. For example, </span></span></div><div><span class="Apple-style-span"><span class="Apple-style-span" style="border-collapse: collapse;"><br /></span></span></div><div><div style="border-collapse: separate; "><span class="Apple-style-span" style="border-collapse: collapse; ">for( askEvent <- askChannel.get( askPattern ); bidEvent <- bidChannel.get( bidPattern ) if (meetsTradeRequirements( askEvent, bidEvent ) ) ) {</span></div><div><span class="Apple-style-span"><span class="Apple-style-span" style="border-collapse: collapse;"> issueTradeRequest( askEvent, bidEvent )</span></span></div><div style="border-collapse: separate; "><span class="Apple-style-span" style="border-collapse: collapse; ">}</span></div><div style="border-collapse: separate; "><span class="Apple-style-span" style="border-collapse: collapse; "><br /></span></div></div><div><span class="Apple-style-span"><span class="Apple-style-span" style="border-collapse: collapse;">This code pattern will issueTradeRequests between buyer and seller just when the trade requirements are met between ask and bid.)</span></span></div><div style="font-family: arial; font-size: small; "><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; "><br /></span></div><div style="font-family: arial; font-size: small; "><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">To my mind the expansion in the Prolog to XQuery direction (resp, </span><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">compression in the opposite) </span><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">is a pretty clear demonstration of the expressiveness in Prolog as a data manipulation language and supports the idea of using DataLog as the core of a NoSQL solution (as i do in my Unification-based K-V-DB found on github, <a href="https://github.com/leithaus/SpecialK/tree/XQuery">here</a>.)</span></div><div style="font-family: arial; font-size: small; "><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; "><br /></span></div><div style="font-family: arial; font-size: small; "><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">Of course, it's also a powerful argument for a programming style that's all monads all the time. If you look at the data language here -- XQuery FLWOR expressions -- it's pure monadic structure. Likewise, the threading and session management of the broker is hidden behind another for-comprehension. The key point is that it all just composes!</span></div><div style="font-family: arial; font-size: small; "><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; "><br /></span></div><div style="font-family: arial; font-size: small; "><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">Now, in up-coming posts we borrow another idea from Prolog: backtracking. We'd like the filter capability to be able to pull information from the streams in an explorative fashion and essentially undo this if the conditions aren't met. One of the tricky parts in this is exploring the streams in a fashion that will minimize some of the gotchas associated with interleaved examination of the stream contents. For this we will employ one of <a href="http://okmij.org/ftp/Computation/monads.html#LogicT">Oleg Kiselyov's insights</a>.</span></div></span>leithaushttp://www.blogger.com/profile/01069099703796397027noreply@blogger.com0tag:blogger.com,1999:blog-3049258033565653738.post-19384592354024351232011-02-14T15:09:00.000-08:002011-02-14T23:40:19.863-08:00Channel-based communication, monadicallyThe last time we checked in we looked at messaging from a monadic perspective. This time we want to look at a broader class of communication from the point of view of the monadic design pattern. At the heart of this idea is recognizing that what is currently the rage of key-value databases is actually a situation that has a wide range of potential interpretations all captured by a single parametrically polymorphic pattern. Consumers consume data from keyed locations in the store while producers deposit data to keyed locations in the store. The basic control abstraction that supports this situation is the delimited continuation. If a consumer is asking for data from keyed locations where no data exists the store grabs the consumer's thread's continuation up to the point of the request and stores it at the keyed the location. When a producer provides data to some or all of these locations the store first checks to see if there are any continuations waiting on these keys and -- if there are -- makes the data available to them first. This essentially resumes the consumer's thread's flow of control at the point in it's computation where it requested the data from the keyed location.<div><br /></div><div><br /><div><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinmpQyDQLKUogeZVTL3S7yAtqrYu72sldC5uh2qYP29ggIgC3BZxFKFgt7nX6ftFODvuZV-xcNv7LEOuY1sDL5JZTB6ohauk7v1E6GdSJpWl36ScspayHoKEMY2yEroQgQ-k6WJxWwAcSE/s1600/kvdbmonadicallySS2.jpg"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 250px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinmpQyDQLKUogeZVTL3S7yAtqrYu72sldC5uh2qYP29ggIgC3BZxFKFgt7nX6ftFODvuZV-xcNv7LEOuY1sDL5JZTB6ohauk7v1E6GdSJpWl36ScspayHoKEMY2yEroQgQ-k6WJxWwAcSE/s400/kvdbmonadicallySS2.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5573814723754066514" /></a><br /></div><div>This basic flow of control abstraction is subject to variation in numerous ways including</div><div><ul><li>varying the means of matching keyed location request to keyed location submission;</li><li>varying whether the request consumes the data, removing it from the location or simply passes a copy to a requester</li><li>varying whether a stored continuation is removed from the location when data is supplied or simply passed the data</li></ul><div>The last variation covers a simple pub/sub mechanism. When continuations are persistent (i.e. not removed on matching data production), this is a simple subscription mechanism. When data is persisted this is storage. When it is not, this is message-passing. When key-matching has a certain level of sophistication this arrangement supports basic broadcast capability. If you look at the code sample and the traces in the screenshots you will see that we've used regular expressions as a basic matching. In the specialK repo we use <a href="http://en.wikipedia.org/wiki/Unification_(computing)">unification</a>.</div></div><div><br /></div><div><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirsfb7mUCmozUw0I6rvD8ZhEyvckKGcIguT-dpA2TULYSGJTF6tAXIFzW-cEFwgi9HcAnOnAeNU9HoDuxwVy1ydP-4i5syObX6L8On4Z8HV6q82qSC4r2woxSOGPWth3iqa1qzEpytXLJP/s1600/kvdbmonadicallySS3.jpg"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 309px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirsfb7mUCmozUw0I6rvD8ZhEyvckKGcIguT-dpA2TULYSGJTF6tAXIFzW-cEFwgi9HcAnOnAeNU9HoDuxwVy1ydP-4i5syObX6L8On4Z8HV6q82qSC4r2woxSOGPWth3iqa1qzEpytXLJP/s400/kvdbmonadicallySS3.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5573816155752201890" /></a><br /></div><div><br /></div><div>All of these variations can be captured in a single configurable mechanism -- the configuration of which can be treated as policy governing communication between producers and consumers. To my mind this is really the pattern underlying the web. The web, in microcosm, is a parametrically polymorphic key-value db. Let's look at some code, however, before getting too philosophical.</div><div><br /></div><div>The core of the implementation is in the code below. The full implementation is in the <a href="https://github.com/leithaus/SpecialK/tree/sansBNFC">sansBNFC branch of the specialK repo</a>.</div><br /><div id="paste" class="lang-scala code"><br /><div class="code"><table class="syntaxtable"><tbody><tr><td class="linenos"><pre> 1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br />194<br />195<br />196<br />197<br />198<br />199<br />200<br />201<br />202<br />203<br />204<br />205<br />206<br />207<br />208<br />209<br />210<br />211<br />212<br />213<br />214<br />215<br />216<br />217<br />218<br />219<br />220<br />221<br />222<br />223<br />224<br />225<br />226<br />227<br />228<br />229<br />230<br />231<br />232<br />233<br />234<br />235<br />236<br />237<br />238<br />239<br />240<br />241<br />242<br />243<br />244<br />245<br />246<br />247<br />248<br />249<br />250<br />251<br />252<br />253<br />254<br />255<br />256<br />257<br />258<br />259</pre></td><td class="code"><div class="syntax"><pre><span class="k">package</span> <span class="nn">com.biosimilarity.lift.model.store</span><br /><br /><span class="k">import</span> <span class="nn">com.biosimilarity.lift.lib._</span><br /><br /><span class="k">import</span> <span class="nn">scala.concurrent.</span><span class="o">{</span><span class="nc">Channel</span> <span class="k">=></span> <span class="nc">Chan</span><span class="o">,</span> <span class="k">_</span><span class="o">}</span><br /><span class="k">import</span> <span class="nn">scala.concurrent.cpsops._</span><br /><br /><span class="k">import</span> <span class="nn">scala.util.continuations._</span><br /><span class="k">import</span> <span class="nn">scala.collection.MapProxy</span><br /><span class="k">import</span> <span class="nn">scala.collection.mutable.Map</span><br /><span class="k">import</span> <span class="nn">scala.collection.mutable.HashMap</span><br /><br /><span class="k">trait</span> <span class="nc">MonadicTupleSpace</span><span class="o">[</span><span class="kt">Place</span>,<span class="kt">Pattern</span>,<span class="kt">Resource</span><span class="o">]</span><br /><span class="nc">//</span> <span class="k">extends</span> <span class="nc">MapLike</span><span class="o">[</span><span class="kt">Place</span>,<span class="kt">Resource</span>, <span class="kt">This</span><span class="o">]</span><br /><span class="k">extends</span> <span class="nc">MonadicGenerators</span> <span class="k">with</span> <span class="nc">FJTaskRunners</span><br /><span class="o">{</span><br /><span class="n">self</span> <span class="k">:</span> <span class="kt">WireTap</span> <span class="kt">with</span> <span class="kt">Journalist</span> <span class="k">=></span><br /><br /><span class="k">type</span> <span class="kt">RK</span> <span class="o">=</span> <span class="nc">Option</span><span class="o">[</span><span class="kt">Resource</span><span class="o">]</span> <span class="k">=></span> <span class="nc">Unit</span> <span class="nd">@suspendable</span><br /><span class="c">//type CK = Option[Resource] => Unit @suspendable</span><br /><span class="k">type</span> <span class="kt">Substitution</span> <span class="k"><:</span> <span class="kt">Function1</span><span class="o">[</span><span class="kt">Resource</span>,<span class="kt">Option</span><span class="o">[</span><span class="kt">Resource</span><span class="o">]]</span><br /><br /><span class="k">case</span> <span class="k">class</span> <span class="nc">IdentitySubstitution</span><span class="o">(</span> <span class="o">)</span><br /><span class="k">extends</span> <span class="nc">Function1</span><span class="o">[</span><span class="kt">Resource</span>,<span class="kt">Option</span><span class="o">[</span><span class="kt">Resource</span><span class="o">]]</span> <span class="o">{</span><br /><span class="k">override</span> <span class="k">def</span> <span class="n">apply</span><span class="o">(</span> <span class="n">rsrc</span> <span class="k">:</span> <span class="kt">Resource</span> <span class="o">)</span> <span class="k">=</span> <span class="nc">Some</span><span class="o">(</span> <span class="n">rsrc</span> <span class="o">)</span><br /><span class="o">}</span><br /><br /><span class="k">case</span> <span class="k">class</span> <span class="nc">PlaceInstance</span><span class="o">(</span><br /><span class="n">place</span> <span class="k">:</span> <span class="kt">Place</span><span class="o">,</span><br /><span class="n">stuff</span> <span class="k">:</span> <span class="kt">Either</span><span class="o">[</span><span class="kt">Resource</span>,<span class="kt">List</span><span class="o">[</span><span class="kt">RK</span><span class="o">]],</span><br /><span class="n">subst</span> <span class="k">:</span> <span class="kt">Substitution</span><br /><span class="o">)</span><br /><br /><span class="k">def</span> <span class="n">theMeetingPlace</span> <span class="k">:</span> <span class="kt">Map</span><span class="o">[</span><span class="kt">Place</span>,<span class="kt">Resource</span><span class="o">]</span><br /><span class="k">def</span> <span class="n">theChannels</span> <span class="k">:</span> <span class="kt">Map</span><span class="o">[</span><span class="kt">Place</span>,<span class="kt">Resource</span><span class="o">]</span><br /><span class="k">def</span> <span class="n">theWaiters</span> <span class="k">:</span> <span class="kt">Map</span><span class="o">[</span><span class="kt">Place</span>,<span class="kt">List</span><span class="o">[</span><span class="kt">RK</span><span class="o">]]</span><br /><span class="k">def</span> <span class="n">theSubscriptions</span> <span class="k">:</span> <span class="kt">Map</span><span class="o">[</span><span class="kt">Place</span>,<span class="kt">List</span><span class="o">[</span><span class="kt">RK</span><span class="o">]]</span><br /><br /><span class="k">def</span> <span class="n">fits</span><span class="o">(</span> <span class="n">ptn</span> <span class="k">:</span> <span class="kt">Pattern</span><span class="o">,</span> <span class="n">place</span> <span class="k">:</span> <span class="kt">Place</span> <span class="o">)</span> <span class="k">:</span> <span class="kt">Boolean</span><br /><span class="k">def</span> <span class="n">fitsK</span><span class="o">(</span> <span class="n">ptn</span> <span class="k">:</span> <span class="kt">Pattern</span><span class="o">,</span> <span class="n">place</span> <span class="k">:</span> <span class="kt">Place</span> <span class="o">)</span> <span class="k">:</span> <span class="kt">Option</span><span class="o">[</span><span class="kt">Substitution</span><span class="o">]</span><br /><span class="k">def</span> <span class="n">representative</span><span class="o">(</span> <span class="n">ptn</span> <span class="k">:</span> <span class="kt">Pattern</span> <span class="o">)</span> <span class="k">:</span> <span class="kt">Place</span><br /><br /><span class="c">//def self = theMeetingPlace</span><br /><br /><span class="k">override</span> <span class="k">def</span> <span class="n">itergen</span><span class="o">[</span><span class="kt">T</span><span class="o">](</span> <span class="n">coll</span> <span class="k">:</span> <span class="kt">Iterable</span><span class="o">[</span><span class="kt">T</span><span class="o">]</span> <span class="o">)</span> <span class="k">=</span><br /><span class="nc">Generator</span> <span class="o">{</span><br /><span class="n">gk</span> <span class="k">:</span> <span class="o">(</span> <span class="kt">T</span> <span class="k">=></span> <span class="kt">Unit</span> <span class="kt">@suspendable</span> <span class="o">)</span> <span class="k">=></span><br /><span class="kt">val</span> <span class="kt">collItr</span> <span class="o">=</span> <span class="n">coll</span><span class="o">.</span><span class="n">iterator</span><br /><br /><span class="k">while</span><span class="o">(</span> <span class="n">collItr</span><span class="o">.</span><span class="n">hasNext</span> <span class="o">)</span> <span class="o">{</span><br /><span class="n">gk</span><span class="o">(</span> <span class="n">collItr</span><span class="o">.</span><span class="n">next</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><br /><span class="k">def</span> <span class="n">locations</span><span class="o">(</span><br /><span class="n">map</span> <span class="k">:</span> <span class="kt">Either</span><span class="o">[</span><span class="kt">Map</span><span class="o">[</span><span class="kt">Place</span>,<span class="kt">Resource</span><span class="o">]</span>,<span class="kt">Map</span><span class="o">[</span><span class="kt">Place</span>,<span class="kt">List</span><span class="o">[</span><span class="kt">RK</span><span class="o">]]],</span><br /><span class="n">ptn</span> <span class="k">:</span> <span class="kt">Pattern</span><br /><span class="o">)</span> <span class="k">:</span> <span class="kt">List</span><span class="o">[</span><span class="kt">PlaceInstance</span><span class="o">]</span> <span class="o">=</span> <span class="o">{</span><br /><span class="k">def</span> <span class="n">lox</span><span class="o">[</span><span class="kt">Trgt</span>,<span class="kt">ITrgt</span><span class="o">](</span><br /><span class="n">m</span> <span class="k">:</span> <span class="kt">Map</span><span class="o">[</span><span class="kt">Place</span>,<span class="kt">Trgt</span><span class="o">],</span><br /><span class="n">inj</span> <span class="k">:</span> <span class="kt">Trgt</span> <span class="k">=></span> <span class="kt">ITrgt</span><br /><span class="o">)</span> <span class="k">:</span> <span class="kt">List</span><span class="o">[(</span><span class="kt">Place</span>,<span class="kt">ITrgt</span>,<span class="kt">Substitution</span><span class="o">)]</span><br /><span class="k">=</span> <span class="o">{</span><br /><span class="o">(</span> <span class="o">(</span> <span class="nc">Nil</span> <span class="k">:</span> <span class="kt">List</span><span class="o">[(</span><span class="kt">Place</span>,<span class="kt">ITrgt</span>,<span class="kt">Substitution</span><span class="o">)]</span> <span class="o">)</span> <span class="o">/:</span> <span class="n">m</span> <span class="o">)(</span><br /><span class="o">{</span><br /><span class="o">(</span> <span class="n">acc</span><span class="o">,</span> <span class="n">kv</span> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /><span class="k">val</span> <span class="o">(</span> <span class="n">k</span><span class="o">,</span> <span class="n">v</span> <span class="o">)</span> <span class="k">=</span> <span class="n">kv</span><br /><span class="n">fitsK</span><span class="o">(</span> <span class="n">ptn</span><span class="o">,</span> <span class="n">k</span> <span class="o">)</span> <span class="k">match</span> <span class="o">{</span><br /><span class="k">case</span> <span class="nc">Some</span><span class="o">(</span> <span class="n">s</span> <span class="o">)</span> <span class="k">=></span> <span class="n">acc</span> <span class="o">++</span> <span class="nc">List</span><span class="o">[(</span><span class="kt">Place</span>,<span class="kt">ITrgt</span>,<span class="kt">Substitution</span><span class="o">)](</span> <span class="o">(</span> <span class="n">k</span><span class="o">,</span> <span class="n">inj</span><span class="o">(</span> <span class="n">v</span> <span class="o">),</span> <span class="n">s</span> <span class="o">)</span> <span class="o">)</span><br /><span class="k">case</span> <span class="nc">None</span> <span class="k">=></span> <span class="n">acc</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="o">)</span><br /><span class="o">}</span><br /><span class="k">val</span> <span class="n">triples</span> <span class="k">=</span><br /><span class="n">map</span> <span class="k">match</span> <span class="o">{</span><br /><span class="k">case</span> <span class="nc">Left</span><span class="o">(</span> <span class="n">m</span> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /><span class="n">lox</span><span class="o">[</span><span class="kt">Resource</span>,<span class="kt">Either</span><span class="o">[</span><span class="kt">Resource</span>,<span class="kt">List</span><span class="o">[</span><span class="kt">RK</span><span class="o">]]](</span><br /><span class="n">m</span><span class="o">,</span> <span class="o">(</span> <span class="n">r</span> <span class="o">)</span> <span class="k">=></span> <span class="nc">Left</span><span class="o">[</span><span class="kt">Resource</span>,<span class="kt">List</span><span class="o">[</span><span class="kt">RK</span><span class="o">]](</span> <span class="n">r</span> <span class="o">)</span><br /><span class="o">)</span><br /><span class="o">}</span><br /><span class="k">case</span> <span class="nc">Right</span><span class="o">(</span> <span class="n">m</span> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /><span class="n">lox</span><span class="o">[</span><span class="kt">List</span><span class="o">[</span><span class="kt">RK</span><span class="o">]</span>,<span class="kt">Either</span><span class="o">[</span><span class="kt">Resource</span>,<span class="kt">List</span><span class="o">[</span><span class="kt">RK</span><span class="o">]]](</span><br /><span class="n">m</span><span class="o">,</span> <span class="o">(</span> <span class="n">r</span> <span class="o">)</span> <span class="k">=></span> <span class="nc">Right</span><span class="o">[</span><span class="kt">Resource</span>,<span class="kt">List</span><span class="o">[</span><span class="kt">RK</span><span class="o">]](</span> <span class="n">r</span> <span class="o">)</span><br /><span class="o">)</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="n">triples</span><span class="o">.</span><span class="n">map</span><span class="o">(</span><br /><span class="o">(</span> <span class="n">t</span> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /><span class="k">val</span> <span class="o">(</span> <span class="n">p</span><span class="o">,</span> <span class="n">e</span><span class="o">,</span> <span class="n">s</span> <span class="o">)</span> <span class="k">=</span> <span class="n">t</span><br /><span class="nc">PlaceInstance</span><span class="o">(</span> <span class="n">p</span><span class="o">,</span> <span class="n">e</span><span class="o">,</span> <span class="n">s</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="o">)</span><br /><span class="o">}</span><br /><br /><span class="c">// val reportage = report( Luddite() ) _</span><br /><span class="k">def</span> <span class="n">mget</span><span class="o">(</span><br /><span class="n">channels</span> <span class="k">:</span> <span class="kt">Map</span><span class="o">[</span><span class="kt">Place</span>,<span class="kt">Resource</span><span class="o">],</span><br /><span class="n">registered</span> <span class="k">:</span> <span class="kt">Map</span><span class="o">[</span><span class="kt">Place</span>,<span class="kt">List</span><span class="o">[</span><span class="kt">RK</span><span class="o">]],</span><br /><span class="n">consume</span> <span class="k">:</span> <span class="kt">Boolean</span><br /><span class="o">)(</span> <span class="n">ptn</span> <span class="k">:</span> <span class="kt">Pattern</span> <span class="o">)</span><br /><span class="k">:</span> <span class="kt">Generator</span><span class="o">[</span><span class="kt">Option</span><span class="o">[</span><span class="kt">Resource</span><span class="o">]</span>,<span class="kt">Unit</span>,<span class="kt">Unit</span><span class="o">]</span> <span class="o">=</span><br /><span class="nc">Generator</span> <span class="o">{</span><br /><span class="n">rk</span> <span class="k">:</span> <span class="o">(</span> <span class="kt">Option</span><span class="o">[</span><span class="kt">Resource</span><span class="o">]</span> <span class="k">=></span> <span class="kt">Unit</span> <span class="kt">@suspendable</span> <span class="o">)</span> <span class="k">=></span><br /><span class="kt">shift</span> <span class="o">{</span><br /><span class="kt">outerk</span> <span class="kt">:</span> <span class="o">(</span> <span class="kt">Unit</span> <span class="k">=></span> <span class="kt">Unit</span> <span class="o">)</span> <span class="k">=></span><br /><span class="kt">reset</span> <span class="o">{</span><br /><span class="kt">val</span> <span class="kt">map</span> <span class="o">=</span> <span class="kt">Left</span><span class="o">[</span><span class="kt">Map</span><span class="o">[</span><span class="kt">Place</span>,<span class="kt">Resource</span><span class="o">]</span>,<span class="kt">Map</span><span class="o">[</span><span class="kt">Place</span>,<span class="kt">List</span><span class="o">[</span><span class="kt">RK</span><span class="o">]]](</span> <span class="kt">channels</span> <span class="o">)</span><br /><span class="kt">val</span> <span class="kt">meets</span> <span class="o">=</span> <span class="kt">locations</span><span class="o">(</span> <span class="kt">map</span><span class="o">,</span> <span class="kt">ptn</span> <span class="o">)</span><br /><br /><span class="k">if</span> <span class="o">(</span> <span class="n">meets</span><span class="o">.</span><span class="n">isEmpty</span> <span class="o">)</span> <span class="o">{</span><br /><span class="k">val</span> <span class="n">place</span> <span class="k">=</span> <span class="n">representative</span><span class="o">(</span> <span class="n">ptn</span> <span class="o">)</span><br /><span class="n">tweet</span><span class="o">(</span> <span class="s">"did not find a resource, storing a continuation: "</span> <span class="o">+</span> <span class="n">rk</span> <span class="o">)</span><br /><span class="n">registered</span><span class="o">(</span> <span class="n">place</span> <span class="o">)</span> <span class="k">=</span><br /><span class="n">registered</span><span class="o">.</span><span class="n">get</span><span class="o">(</span> <span class="n">place</span> <span class="o">).</span><span class="n">getOrElse</span><span class="o">(</span> <span class="nc">Nil</span> <span class="o">)</span> <span class="o">++</span> <span class="nc">List</span><span class="o">(</span> <span class="n">rk</span> <span class="o">)</span><br /><span class="n">rk</span><span class="o">(</span> <span class="nc">None</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="k">else</span> <span class="o">{</span><br /><span class="k">for</span><span class="o">(</span><br /><span class="n">placeNRrscNSubst</span> <span class="k"><-</span> <span class="n">itergen</span><span class="o">[</span><span class="kt">PlaceInstance</span><span class="o">](</span><br /><span class="n">meets</span><br /><span class="o">)</span><br /><span class="o">)</span> <span class="o">{</span><br /><span class="k">val</span> <span class="nc">PlaceInstance</span><span class="o">(</span> <span class="n">place</span><span class="o">,</span> <span class="nc">Left</span><span class="o">(</span> <span class="n">rsrc</span> <span class="o">),</span> <span class="n">s</span> <span class="o">)</span> <span class="k">=</span> <span class="n">placeNRrscNSubst</span><br /><br /><span class="n">tweet</span><span class="o">(</span> <span class="s">"found a resource: "</span> <span class="o">+</span> <span class="n">rsrc</span> <span class="o">)</span><br /><span class="k">if</span> <span class="o">(</span> <span class="n">consume</span> <span class="o">)</span> <span class="o">{</span><br /><span class="n">channels</span> <span class="o">-=</span> <span class="n">place</span><br /><span class="o">}</span><br /><span class="n">rk</span><span class="o">(</span> <span class="n">s</span><span class="o">(</span> <span class="n">rsrc</span> <span class="o">)</span> <span class="o">)</span><br /><br /><span class="c">//shift { k : ( Unit => Unit ) => k() }</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="n">tweet</span><span class="o">(</span> <span class="s">"get returning"</span> <span class="o">)</span><br /><span class="n">outerk</span><span class="o">()</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><br /><span class="k">def</span> <span class="n">get</span><span class="o">(</span> <span class="n">ptn</span> <span class="k">:</span> <span class="kt">Pattern</span> <span class="o">)</span> <span class="k">=</span><br /><span class="n">mget</span><span class="o">(</span> <span class="n">theMeetingPlace</span><span class="o">,</span> <span class="n">theWaiters</span><span class="o">,</span> <span class="kc">true</span> <span class="o">)(</span> <span class="n">ptn</span> <span class="o">)</span><br /><span class="k">def</span> <span class="n">fetch</span><span class="o">(</span> <span class="n">ptn</span> <span class="k">:</span> <span class="kt">Pattern</span> <span class="o">)</span> <span class="k">=</span><br /><span class="n">mget</span><span class="o">(</span> <span class="n">theMeetingPlace</span><span class="o">,</span> <span class="n">theWaiters</span><span class="o">,</span> <span class="kc">false</span> <span class="o">)(</span> <span class="n">ptn</span> <span class="o">)</span><br /><span class="k">def</span> <span class="n">subscribe</span><span class="o">(</span> <span class="n">ptn</span> <span class="k">:</span> <span class="kt">Pattern</span> <span class="o">)</span> <span class="k">=</span><br /><span class="n">mget</span><span class="o">(</span> <span class="n">theChannels</span><span class="o">,</span> <span class="n">theSubscriptions</span><span class="o">,</span> <span class="kc">true</span> <span class="o">)(</span> <span class="n">ptn</span> <span class="o">)</span><br /><br /><span class="k">def</span> <span class="n">putPlaces</span><span class="o">(</span><br /><span class="n">channels</span> <span class="k">:</span> <span class="kt">Map</span><span class="o">[</span><span class="kt">Place</span>,<span class="kt">Resource</span><span class="o">],</span><br /><span class="n">registered</span> <span class="k">:</span> <span class="kt">Map</span><span class="o">[</span><span class="kt">Place</span>,<span class="kt">List</span><span class="o">[</span><span class="kt">RK</span><span class="o">]],</span><br /><span class="n">ptn</span> <span class="k">:</span> <span class="kt">Pattern</span><span class="o">,</span><br /><span class="n">rsrc</span> <span class="k">:</span> <span class="kt">Resource</span><br /><span class="o">)</span><br /><span class="k">:</span> <span class="kt">Generator</span><span class="o">[</span><span class="kt">PlaceInstance</span>,<span class="kt">Unit</span>,<span class="kt">Unit</span><span class="o">]</span> <span class="o">=</span> <span class="o">{</span><br /><span class="nc">Generator</span> <span class="o">{</span><br /><span class="n">k</span> <span class="k">:</span> <span class="o">(</span> <span class="kt">PlaceInstance</span> <span class="k">=></span> <span class="kt">Unit</span> <span class="kt">@suspendable</span> <span class="o">)</span> <span class="k">=></span><br /><span class="kt">//</span> <span class="kt">Are</span> <span class="kt">there</span> <span class="kt">outstanding</span> <span class="kt">waiters</span> <span class="kt">at</span> <span class="kt">this</span> <span class="kt">pattern?</span><br /><span class="k">val</span> <span class="n">map</span> <span class="k">=</span> <span class="nc">Right</span><span class="o">[</span><span class="kt">Map</span><span class="o">[</span><span class="kt">Place</span>,<span class="kt">Resource</span><span class="o">]</span>,<span class="kt">Map</span><span class="o">[</span><span class="kt">Place</span>,<span class="kt">List</span><span class="o">[</span><span class="kt">RK</span><span class="o">]]](</span> <span class="n">registered</span> <span class="o">)</span><br /><span class="k">val</span> <span class="n">waitlist</span> <span class="k">=</span> <span class="n">locations</span><span class="o">(</span> <span class="n">map</span><span class="o">,</span> <span class="n">ptn</span> <span class="o">)</span><br /><br /><span class="n">waitlist</span> <span class="k">match</span> <span class="o">{</span><br /><span class="c">// Yes!</span><br /><span class="k">case</span> <span class="n">waiter</span> <span class="o">::</span> <span class="n">waiters</span> <span class="k">=></span> <span class="o">{</span><br /><span class="n">tweet</span><span class="o">(</span> <span class="s">"found waiters waiting for a value at "</span> <span class="o">+</span> <span class="n">ptn</span> <span class="o">)</span><br /><span class="k">val</span> <span class="n">itr</span> <span class="k">=</span> <span class="n">waitlist</span><span class="o">.</span><span class="n">toList</span><span class="o">.</span><span class="n">iterator</span><br /><span class="k">while</span><span class="o">(</span> <span class="n">itr</span><span class="o">.</span><span class="n">hasNext</span> <span class="o">)</span> <span class="o">{</span><br /><span class="n">k</span><span class="o">(</span> <span class="n">itr</span><span class="o">.</span><span class="n">next</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="c">// No...</span><br /><span class="k">case</span> <span class="nc">Nil</span> <span class="k">=></span> <span class="o">{</span><br /><span class="c">// Store the rsrc at a representative of the ptn</span><br /><span class="n">tweet</span><span class="o">(</span> <span class="s">"no waiters waiting for a value at "</span> <span class="o">+</span> <span class="n">ptn</span> <span class="o">)</span><br /><span class="n">channels</span><span class="o">(</span> <span class="n">representative</span><span class="o">(</span> <span class="n">ptn</span> <span class="o">)</span> <span class="o">)</span> <span class="k">=</span> <span class="n">rsrc</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><br /><span class="k">def</span> <span class="n">mput</span><span class="o">(</span><br /><span class="n">channels</span> <span class="k">:</span> <span class="kt">Map</span><span class="o">[</span><span class="kt">Place</span>,<span class="kt">Resource</span><span class="o">],</span><br /><span class="n">registered</span> <span class="k">:</span> <span class="kt">Map</span><span class="o">[</span><span class="kt">Place</span>,<span class="kt">List</span><span class="o">[</span><span class="kt">RK</span><span class="o">]],</span><br /><span class="n">consume</span> <span class="k">:</span> <span class="kt">Boolean</span><br /><span class="o">)(</span> <span class="n">ptn</span> <span class="k">:</span> <span class="kt">Pattern</span><span class="o">,</span> <span class="n">rsrc</span> <span class="k">:</span> <span class="kt">Resource</span> <span class="o">)</span> <span class="k">:</span> <span class="kt">Unit</span> <span class="kt">@suspendable</span> <span class="o">=</span> <span class="o">{</span><br /><span class="k">for</span><span class="o">(</span> <span class="n">placeNRKsNSubst</span> <span class="k"><-</span> <span class="n">putPlaces</span><span class="o">(</span> <span class="n">channels</span><span class="o">,</span> <span class="n">registered</span><span class="o">,</span> <span class="n">ptn</span><span class="o">,</span> <span class="n">rsrc</span> <span class="o">)</span> <span class="o">)</span> <span class="o">{</span><br /><span class="k">val</span> <span class="nc">PlaceInstance</span><span class="o">(</span> <span class="n">wtr</span><span class="o">,</span> <span class="nc">Right</span><span class="o">(</span> <span class="n">rks</span> <span class="o">),</span> <span class="n">s</span> <span class="o">)</span> <span class="k">=</span> <span class="n">placeNRKsNSubst</span><br /><span class="n">tweet</span><span class="o">(</span> <span class="s">"waiters waiting for a value at "</span> <span class="o">+</span> <span class="n">wtr</span> <span class="o">+</span> <span class="s">" : "</span> <span class="o">+</span> <span class="n">rks</span> <span class="o">)</span><br /><span class="n">rks</span> <span class="k">match</span> <span class="o">{</span><br /><span class="k">case</span> <span class="n">rk</span> <span class="o">::</span> <span class="n">rrks</span> <span class="k">=></span> <span class="o">{</span><br /><span class="k">if</span> <span class="o">(</span> <span class="n">consume</span> <span class="o">)</span> <span class="o">{</span><br /><span class="k">for</span><span class="o">(</span> <span class="n">sk</span> <span class="k"><-</span> <span class="n">rks</span> <span class="o">)</span> <span class="o">{</span><br /><span class="n">spawn</span> <span class="o">{</span><br /><span class="n">sk</span><span class="o">(</span> <span class="n">s</span><span class="o">(</span> <span class="n">rsrc</span> <span class="o">)</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="k">else</span> <span class="o">{</span><br /><span class="n">registered</span><span class="o">(</span> <span class="n">wtr</span> <span class="o">)</span> <span class="k">=</span> <span class="n">rrks</span><br /><span class="n">rk</span><span class="o">(</span> <span class="n">s</span><span class="o">(</span> <span class="n">rsrc</span> <span class="o">)</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="k">case</span> <span class="nc">Nil</span> <span class="k">=></span> <span class="o">{</span><br /><span class="n">channels</span><span class="o">(</span> <span class="n">wtr</span> <span class="o">)</span> <span class="k">=</span> <span class="n">rsrc</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><br /><span class="o">}</span><br /><br /><span class="k">def</span> <span class="n">put</span><span class="o">(</span> <span class="n">ptn</span> <span class="k">:</span> <span class="kt">Pattern</span><span class="o">,</span> <span class="n">rsrc</span> <span class="k">:</span> <span class="kt">Resource</span> <span class="o">)</span> <span class="k">=</span><br /><span class="n">mput</span><span class="o">(</span> <span class="n">theMeetingPlace</span><span class="o">,</span> <span class="n">theWaiters</span><span class="o">,</span> <span class="kc">false</span> <span class="o">)(</span> <span class="n">ptn</span><span class="o">,</span> <span class="n">rsrc</span> <span class="o">)</span><br /><span class="k">def</span> <span class="n">publish</span><span class="o">(</span> <span class="n">ptn</span> <span class="k">:</span> <span class="kt">Pattern</span><span class="o">,</span> <span class="n">rsrc</span> <span class="k">:</span> <span class="kt">Resource</span> <span class="o">)</span> <span class="k">=</span><br /><span class="n">mput</span><span class="o">(</span> <span class="n">theChannels</span><span class="o">,</span> <span class="n">theSubscriptions</span><span class="o">,</span> <span class="kc">true</span> <span class="o">)(</span> <span class="n">ptn</span><span class="o">,</span> <span class="n">rsrc</span> <span class="o">)</span><br /><br /><span class="o">}</span><br /><br /><span class="k">import</span> <span class="nn">java.util.regex.</span><span class="o">{</span><span class="nc">Pattern</span> <span class="k">=></span> <span class="nc">RegexPtn</span><span class="o">,</span> <span class="nc">Matcher</span> <span class="k">=></span> <span class="nc">RegexMatcher</span><span class="o">}</span><br /><br /><span class="k">object</span> <span class="nc">MonadicTSpace</span><br /><span class="k">extends</span> <span class="nc">MonadicTupleSpace</span><span class="o">[</span><span class="kt">String</span>,<span class="kt">String</span>,<span class="kt">String</span><span class="o">]</span><br /><span class="k">with</span> <span class="nc">WireTap</span><br /><span class="k">with</span> <span class="nc">Journalist</span><br /><span class="k">with</span> <span class="nc">ConfiggyReporting</span><br /><span class="k">with</span> <span class="nc">ConfiggyJournal</span><br /><span class="o">{</span><br /><br /><span class="k">override</span> <span class="k">type</span> <span class="kt">Substitution</span> <span class="o">=</span> <span class="nc">IdentitySubstitution</span><br /><br /><span class="k">override</span> <span class="k">val</span> <span class="n">theMeetingPlace</span> <span class="k">=</span> <span class="k">new</span> <span class="nc">HashMap</span><span class="o">[</span><span class="kt">String</span>,<span class="kt">String</span><span class="o">]()</span><br /><span class="k">override</span> <span class="k">val</span> <span class="n">theChannels</span> <span class="k">=</span> <span class="k">new</span> <span class="nc">HashMap</span><span class="o">[</span><span class="kt">String</span>,<span class="kt">String</span><span class="o">]()</span><br /><span class="k">override</span> <span class="k">val</span> <span class="n">theWaiters</span> <span class="k">=</span> <span class="k">new</span> <span class="nc">HashMap</span><span class="o">[</span><span class="kt">String</span>,<span class="kt">List</span><span class="o">[</span><span class="kt">RK</span><span class="o">]]()</span><br /><span class="k">override</span> <span class="k">val</span> <span class="n">theSubscriptions</span> <span class="k">=</span> <span class="k">new</span> <span class="nc">HashMap</span><span class="o">[</span><span class="kt">String</span>,<span class="kt">List</span><span class="o">[</span><span class="kt">RK</span><span class="o">]]()</span><br /><br /><span class="k">override</span> <span class="k">def</span> <span class="n">tap</span> <span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="o">(</span> <span class="n">fact</span> <span class="k">:</span> <span class="kt">A</span> <span class="o">)</span> <span class="k">:</span> <span class="kt">Unit</span> <span class="o">=</span> <span class="o">{</span><br /><span class="n">reportage</span><span class="o">(</span> <span class="n">fact</span> <span class="o">)</span><br /><span class="o">}</span><br /><br /><span class="k">def</span> <span class="n">representative</span><span class="o">(</span> <span class="n">ptn</span> <span class="k">:</span> <span class="kt">String</span> <span class="o">)</span> <span class="k">:</span> <span class="kt">String</span> <span class="o">=</span> <span class="o">{</span><br /><span class="n">ptn</span><br /><span class="o">}</span><br /><br /><span class="k">def</span> <span class="n">fits</span><span class="o">(</span> <span class="n">ptn</span> <span class="k">:</span> <span class="kt">String</span><span class="o">,</span> <span class="n">place</span> <span class="k">:</span> <span class="kt">String</span> <span class="o">)</span> <span class="k">:</span> <span class="kt">Boolean</span> <span class="o">=</span> <span class="o">{</span><br /><span class="nc">RegexPtn</span><span class="o">.</span><span class="n">matches</span><span class="o">(</span> <span class="n">ptn</span><span class="o">,</span> <span class="n">place</span> <span class="o">)</span> <span class="o">||</span> <span class="nc">RegexPtn</span><span class="o">.</span><span class="n">matches</span><span class="o">(</span> <span class="n">place</span><span class="o">,</span> <span class="n">ptn</span> <span class="o">)</span><br /><span class="o">}</span><br /><br /><span class="k">def</span> <span class="n">fitsK</span><span class="o">(</span><br /><span class="n">ptn</span> <span class="k">:</span> <span class="kt">String</span><span class="o">,</span><br /><span class="n">place</span> <span class="k">:</span> <span class="kt">String</span><br /><span class="o">)</span> <span class="k">:</span> <span class="kt">Option</span><span class="o">[</span><span class="kt">Substitution</span><span class="o">]</span> <span class="o">=</span> <span class="o">{</span><br /><span class="k">if</span> <span class="o">(</span> <span class="n">fits</span><span class="o">(</span> <span class="n">ptn</span><span class="o">,</span> <span class="n">place</span> <span class="o">)</span> <span class="o">)</span> <span class="o">{</span><br /><span class="nc">Some</span><span class="o">(</span> <span class="nc">IdentitySubstitution</span><span class="o">()</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="k">else</span> <span class="o">{</span><br /><span class="nc">None</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><br /><span class="o">}</span><br /></pre></div><br /></td></tr></tbody></table></div><br /></div><br /><div class="page"><br /><div class="footer"></div><br /></div></div>leithaushttp://www.blogger.com/profile/01069099703796397027noreply@blogger.com3tag:blogger.com,1999:blog-3049258033565653738.post-6599159335979297532011-01-04T05:40:00.000-08:002011-01-04T08:18:36.595-08:00RabbitMQ, monadicallyThis is just so cool i have to write a little bit about it even before i clean it up and prettify it. One of the potentials of delimited continuations is to enable a beautifully simple monadic interface to input streams. Here's an image of a session in operation. <div><div></div><br /></div><div><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjf0FodL3HbLT9w9tyHxreVxHMPshJ-NlQKIzW_rKUKCQPHQBxsDEhyphenhyphenouVnXkrIxAbQ1KHY7i-wjb8eg_C9NuuMoWWFdwRt3QnZrG1sKtiNc_ajOYjnajLN9t4gJC7fn6Gbkui8v2qri8re/s1600/RabbitMonadicallySession.jpg"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 250px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjf0FodL3HbLT9w9tyHxreVxHMPshJ-NlQKIzW_rKUKCQPHQBxsDEhyphenhyphenouVnXkrIxAbQ1KHY7i-wjb8eg_C9NuuMoWWFdwRt3QnZrG1sKtiNc_ajOYjnajLN9t4gJC7fn6Gbkui8v2qri8re/s400/RabbitMonadicallySession.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5558333209041311938" /></a><br />As you can see the primary usage pattern looks like this<div><br /></div><div><span class="Apple-style-span">for( msg <- rabbitMonadically.beginService() ) {</span></div><div><span class="Apple-style-span"> // msg handling code goes here</span></div><div><span class="Apple-style-span"> ...</span></div><div><span class="Apple-style-span">}</span></div><div><br /></div><div>To me this is very intuitive. We are iterating over a stream of messages and handling them in the code body of the "for-loop". All the threading and state management that supports this view is safely tucked away behind this interface.</div><div><br /></div><div>Oleg Kiselyov has been the most eloquent proponent of this idea, and i cannot hope to match the elegance of his code or his prose. However, it's still a great deal of fun to do something for yourself to test your understanding. So, let's implement this design pattern in Scala over RabbitMQ.<div><br /></div><div>It turns out that Tiark Rompf has already done most of the work for us in one of the test suites for delimited continuations! He did it for a stream of HTTP requests; so, his job was actually a little bit harder because he had to deal with TCP/IP socket requests as well. We just crib his code and modify it to suit our purposes. Likewise, i've been cribbing from and comparing with the Lift actor-based API to RabbitMQ. i leave it to you to do the comparison in terms of understandability.</div><div><br /></div><div>BTW, if you'd like to see more of this -- and in nice book format to boot! -- then please consider making a pledge to the <a href="http://www.kickstarter.com/projects/1499410734/monadic-design-patterns-for-the-web-book">Kickstarter project for the Monadic Design Patterns for the Web</a> book.<br /><div class="page"><div id="paste" class="lang-scala code"><div class="code"><table class="syntaxtable"><tbody><tr><td class="linenos"><pre><br /> 1<br /> 2<br /> 3<br /> 4<br /> 5<br /> 6<br /> 7<br /> 8<br /> 9<br /> 10<br /> 11<br /> 12<br /> 13<br /> 14<br /> 15<br /> 16<br /> 17<br /> 18<br /> 19<br /> 20<br /> 21<br /> 22<br /> 23<br /> 24<br /> 25<br /> 26<br /> 27<br /> 28<br /> 29<br /> 30<br /> 31<br /> 32<br /> 33<br /> 34<br /> 35<br /> 36<br /> 37<br /> 38<br /> 39<br /> 40<br /> 41<br /> 42<br /> 43<br /> 44<br /> 45<br /> 46<br /> 47<br /> 48<br /> 49<br /> 50<br /> 51<br /> 52<br /> 53<br /> 54<br /> 55<br /> 56<br /> 57<br /> 58<br /> 59<br /> 60<br /> 61<br /> 62<br /> 63<br /> 64<br /> 65<br /> 66<br /> 67<br /> 68<br /> 69<br /> 70<br /> 71<br /> 72<br /> 73<br /> 74<br /> 75<br /> 76<br /> 77<br /> 78<br /> 79<br /> 80<br /> 81<br /> 82<br /> 83<br /> 84<br /> 85<br /> 86<br /> 87<br /> 88<br /> 89<br /> 90<br /> 91<br /> 92<br /> 93<br /> 94<br /> 95<br /> 96<br /> 97<br /> 98<br /> 99<br /> 100<br /> 101<br /> 102<br /> 103<br /> 104<br /> 105<br /> 106<br /> 107<br /> 108<br /> 109<br /> 110<br /> 111<br /> 112<br /> 113<br /> 114<br /> 115<br /> 116<br /> 117<br /> 118<br /> 119<br /> 120<br /> 121<br /> 122<br /> 123<br /> 124<br /> 125<br /> 126<br /> 127<br /> 128<br /> 129<br /> 130<br /> 131<br /> 132<br /> 133<br /> 134<br /> 135<br /> 136<br /> 137<br /> 138<br /> 139<br /> 140<br /> 141<br /> 142<br /> 143<br /> 144<br /> 145<br /> 146<br /> 147<br /> 148<br /> 149<br /> 150<br /> 151<br /> 152<br /> 153<br /> 154<br /> 155<br /> 156<br /> 157<br /> 158<br /> 159<br /> 160<br /> 161<br /> 162<br /> 163<br /> 164<br /> 165<br /> 166<br /> 167<br /> 168<br /> 169<br /> 170<br /> 171<br /> 172<br /> 173<br /> 174<br /> 175<br /> 176<br /> 177<br /> 178<br /> 179<br /> 180<br /> 181<br /> 182<br /> 183<br /> 184<br /> 185<br /> 186<br /> 187<br /> 188<br /> 189<br /> 190<br /> 191<br /> 192<br /> 193<br /> 194<br /> 195<br /> 196<br /> 197<br /> 198<br /> 199<br /> 200<br /> 201<br /> 202<br /> 203<br /> 204<br /> 205<br /> 206<br /> 207<br /> 208<br /> 209<br /> 210<br /> 211<br /> 212<br /> 213<br /> 214<br /> 215<br /> 216<br /> 217<br /> 218<br /> 219<br /> 220<br /> 221<br /> 222<br /> 223<br /></pre><br /></td> <td class="code"><br /><div class="syntax"><br /> <pre><br /><span class="c">// -*- mode: Scala;-*- </span><br /><span class="c">// Filename: Monadic.scala </span><br /><span class="c">// Authors: lgm </span><br /><span class="c">// Creation: Wed Dec 29 13:57:38 2010 </span><br /><span class="c">// Copyright: Not supplied </span><br /><span class="c">// Description: </span><br /><span class="c">// ------------------------------------------------------------------------</span><br /><br /><span class="k">package</span> <span class="nn">net.liftweb.amqp</span><br /><br /><span class="k">import</span> <span class="nn">scala.util.continuations._</span><br /><span class="c">//import scala.util.continuations.ControlContext._</span><br /><br /><span class="k">import</span> <span class="nn">scala.concurrent.</span><span class="o">{</span><span class="nc">Channel</span> <span class="k">=></span> <span class="nc">Chan</span><span class="o">,</span> <span class="k">_</span><span class="o">}</span><br /><span class="k">import</span> <span class="nn">scala.concurrent.cpsops._</span><br /><br /><span class="k">import</span> <span class="nn">_root_.com.rabbitmq.client._</span><br /><span class="k">import</span> <span class="nn">_root_.scala.actors.Actor</span><br /><br /><span class="k">import</span> <span class="nn">_root_.java.io.ObjectInputStream</span><br /><span class="k">import</span> <span class="nn">_root_.java.io.ByteArrayInputStream</span><br /><span class="k">import</span> <span class="nn">_root_.java.util.Timer</span><br /><span class="k">import</span> <span class="nn">_root_.java.util.TimerTask</span><br /><br /><span class="k">trait</span> <span class="nc">MonadicAMQPDispatcher</span><span class="o">[</span><span class="kt">T</span><span class="o">]</span><br /><span class="nc">extends</span> <span class="nc">FJTaskRunners</span> <span class="o">{</span><br /><br /><span class="k">type</span> <span class="kt">Ticket</span> <span class="o">=</span> <span class="nc">Int</span><br /><br /><span class="k">trait</span> <span class="nc">Generable</span><span class="o">[</span><span class="kt">+A</span>,<span class="kt">-B</span>,<span class="kt">+C</span><span class="o">]</span> <span class="o">{</span><br /><span class="k">def</span> <span class="n">funK</span> <span class="k">:</span> <span class="o">(</span><span class="kt">A</span> <span class="k">=></span> <span class="o">(</span><span class="kt">B</span> <span class="kt">@suspendable</span><span class="o">))</span> <span class="k">=></span> <span class="o">(</span><span class="kt">C</span> <span class="kt">@suspendable</span><span class="o">)</span><br /><br /><span class="kt">def</span> <span class="kt">foreach</span><span class="o">(</span> <span class="kt">f</span> <span class="kt">:</span> <span class="o">(</span><span class="kt">A</span> <span class="k">=></span> <span class="kt">B</span> <span class="kt">@suspendable</span><span class="o">)</span> <span class="o">)</span> <span class="kt">:</span> <span class="kt">C</span> <span class="kt">@suspendable</span> <span class="o">=</span> <span class="o">{</span><br /> <span class="n">funK</span><span class="o">(</span> <span class="n">f</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><br /><span class="k">case</span> <span class="k">class</span> <span class="nc">Generator</span><span class="o">[</span><span class="kt">+A</span>,<span class="kt">-B</span>,<span class="kt">+C</span><span class="o">](</span><br /><span class="k">override</span> <span class="k">val</span> <span class="n">funK</span> <span class="k">:</span> <span class="o">(</span><span class="kt">A</span> <span class="k">=></span> <span class="o">(</span><span class="kt">B</span> <span class="kt">@suspendable</span><span class="o">))</span> <span class="k">=></span> <span class="o">(</span><span class="kt">C</span> <span class="kt">@suspendable</span><span class="o">)</span><br /><span class="o">)</span> <span class="k">extends</span> <span class="nc">Generable</span><span class="o">[</span><span class="kt">A</span>,<span class="kt">B</span>,<span class="kt">C</span><span class="o">]</span> <span class="o">{</span><br /><span class="o">}</span><br /><br /><span class="k">abstract</span> <span class="k">class</span> <span class="nc">SerializedConsumer</span><span class="o">[</span><span class="kt">T</span><span class="o">](</span><br /><span class="k">val</span> <span class="n">channel</span> <span class="k">:</span> <span class="kt">Channel</span><br /><span class="o">)</span> <span class="k">extends</span> <span class="nc">DefaultConsumer</span><span class="o">(</span> <span class="n">channel</span> <span class="o">)</span> <span class="o">{</span><br /><span class="k">override</span> <span class="k">def</span> <span class="n">handleDelivery</span><span class="o">(</span><br /> <span class="n">tag</span> <span class="k">:</span> <span class="kt">String</span><span class="o">,</span><br /> <span class="n">env</span> <span class="k">:</span> <span class="kt">Envelope</span><span class="o">,</span><br /> <span class="n">props</span> <span class="k">:</span> <span class="kt">AMQP.BasicProperties</span><span class="o">,</span><br /> <span class="n">body</span> <span class="k">:</span> <span class="kt">Array</span><span class="o">[</span><span class="kt">Byte</span><span class="o">]</span><br /><span class="o">)</span><br /><span class="o">}</span><br /><br /><span class="k">def</span> <span class="n">acceptConnections</span><span class="o">(</span><br /><span class="n">params</span> <span class="k">:</span> <span class="kt">ConnectionParameters</span><span class="o">,</span><br /><span class="n">host</span> <span class="k">:</span> <span class="kt">String</span><span class="o">,</span><br /><span class="n">port</span> <span class="k">:</span> <span class="kt">Int</span><br /><span class="o">)</span> <span class="k">=</span><br /><span class="nc">Generator</span> <span class="o">{</span><br /> <span class="n">k</span> <span class="k">:</span> <span class="o">(</span> <span class="kt">Channel</span> <span class="k">=></span> <span class="kt">Unit</span> <span class="kt">@suspendable</span> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /><span class="kt">//shift</span> <span class="o">{</span><br /><span class="kt">//innerk</span> <span class="kt">:</span> <span class="o">(</span><span class="kt">Unit</span> <span class="k">=></span> <span class="kt">Unit</span> <span class="kt">@suspendable</span><span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /> <span class="kt">val</span> <span class="kt">factory</span> <span class="o">=</span> <span class="kt">new</span> <span class="kt">ConnectionFactory</span><span class="o">(</span> <span class="kt">params</span> <span class="o">)</span><br /> <span class="kt">val</span> <span class="kt">connection</span> <span class="o">=</span> <span class="kt">factory.newConnection</span><span class="o">(</span> <span class="kt">host</span><span class="o">,</span> <span class="kt">port</span> <span class="o">)</span><br /> <span class="kt">val</span> <span class="kt">channel</span> <span class="o">=</span> <span class="n">connection</span><span class="o">.</span><span class="n">createChannel</span><span class="o">()</span><br /> <span class="n">k</span><span class="o">(</span> <span class="n">channel</span> <span class="o">);</span><br /><span class="c">//}</span><br /><span class="c">//} </span><br /> <span class="o">}</span><br /><span class="o">}</span><br /><br /><span class="k">def</span> <span class="n">beginService</span><span class="o">(</span><br /><span class="n">params</span> <span class="k">:</span> <span class="kt">ConnectionParameters</span><span class="o">,</span><br /><span class="n">host</span> <span class="k">:</span> <span class="kt">String</span><span class="o">,</span><br /><span class="n">port</span> <span class="k">:</span> <span class="kt">Int</span><br /><span class="o">)</span> <span class="k">=</span> <span class="nc">Generator</span> <span class="o">{</span><br /><span class="n">k</span> <span class="k">:</span> <span class="o">(</span> <span class="kt">T</span> <span class="k">=></span> <span class="kt">Unit</span> <span class="kt">@suspendable</span> <span class="o">)</span> <span class="k">=></span><br /> <span class="kt">//shift</span> <span class="o">{</span><br /><span class="kt">println</span><span class="o">(</span> <span class="err">"</span><span class="kt">The</span> <span class="kt">rabbit</span> <span class="kt">is</span> <span class="kt">running...</span> <span class="o">(</span><span class="kt">with</span> <span class="kt">apologies</span> <span class="kt">to</span> <span class="kt">John</span> <span class="kt">Updike</span><span class="o">)</span><span class="err">"</span> <span class="o">)</span><br /><br /><span class="kt">for</span><span class="o">(</span> <span class="kt">channel</span> <span class="kt"><-</span> <span class="kt">acceptConnections</span><span class="o">(</span> <span class="kt">params</span><span class="o">,</span> <span class="kt">host</span><span class="o">,</span> <span class="kt">port</span> <span class="o">)</span> <span class="o">)</span> <span class="o">{</span><br /><span class="n">spawn</span> <span class="o">{</span><br /> <span class="c">// Open bracket</span><br /> <span class="n">println</span><span class="o">(</span> <span class="s">"Connected: "</span> <span class="o">+</span> <span class="n">channel</span> <span class="o">)</span><br /> <span class="k">val</span> <span class="n">ticket</span> <span class="k">=</span> <span class="n">channel</span><span class="o">.</span><span class="n">accessRequest</span><span class="o">(</span> <span class="s">"/data"</span> <span class="o">)</span><br /> <span class="n">channel</span><span class="o">.</span><span class="n">exchangeDeclare</span><span class="o">(</span> <span class="n">ticket</span><span class="o">,</span> <span class="s">"mult"</span><span class="o">,</span> <span class="s">"direct"</span> <span class="o">)</span><br /> <span class="n">channel</span><span class="o">.</span><span class="n">queueDeclare</span><span class="o">(</span> <span class="n">ticket</span><span class="o">,</span> <span class="s">"mult_queue"</span> <span class="o">)</span><br /> <span class="n">channel</span><span class="o">.</span><span class="n">queueBind</span><span class="o">(</span> <span class="n">ticket</span><span class="o">,</span> <span class="s">"mult_queue"</span><span class="o">,</span> <span class="s">"mult"</span><span class="o">,</span> <span class="s">"routeroute"</span> <span class="o">)</span><br /><br /> <span class="k">for</span> <span class="o">(</span> <span class="n">t</span> <span class="k"><-</span> <span class="n">readT</span><span class="o">(</span> <span class="n">channel</span><span class="o">,</span> <span class="n">ticket</span> <span class="o">)</span> <span class="o">)</span> <span class="o">{</span> <span class="n">k</span><span class="o">(</span> <span class="n">t</span> <span class="o">)</span> <span class="o">}</span><br /><br /> <span class="c">// println( "Disconnected: " + channel )</span><br /> <span class="c">// Close bracket</span><br /><span class="o">}</span><br /><span class="o">}</span><br /> <span class="c">//}</span><br /><span class="o">}</span><br /><br /><span class="k">case</span> <span class="k">class</span> <span class="nc">AMQPDelivery</span><span class="o">(</span><br /><span class="n">tag</span> <span class="k">:</span> <span class="kt">String</span><span class="o">,</span><br /><span class="n">env</span> <span class="k">:</span> <span class="kt">Envelope</span><span class="o">,</span><br /><span class="n">props</span> <span class="k">:</span> <span class="kt">AMQP.BasicProperties</span><span class="o">,</span><br /><span class="n">body</span> <span class="k">:</span> <span class="kt">Array</span><span class="o">[</span><span class="kt">Byte</span><span class="o">]</span><br /><span class="o">)</span><br /><br /><span class="k">def</span> <span class="n">callbacks</span><span class="o">(</span> <span class="n">channel</span> <span class="k">:</span> <span class="kt">Channel</span><span class="o">,</span> <span class="n">ticket</span> <span class="k">:</span> <span class="kt">Ticket</span><span class="o">)</span> <span class="k">=</span><br /><span class="nc">Generator</span> <span class="o">{</span><br /> <span class="n">k</span> <span class="k">:</span> <span class="o">(</span> <span class="kt">AMQPDelivery</span> <span class="k">=></span> <span class="kt">Unit</span> <span class="kt">@suspendable</span><span class="o">)</span> <span class="k">=></span><br /><br /> <span class="kt">println</span><span class="o">(</span><span class="err">"</span><span class="kt">level</span> <span class="err">1</span> <span class="kt">callbacks</span><span class="err">"</span><span class="o">)</span><br /><br /> <span class="kt">shift</span> <span class="o">{</span><br /><span class="kt">outerk</span> <span class="kt">:</span> <span class="o">(</span><span class="kt">Unit</span> <span class="k">=></span> <span class="kt">Any</span><span class="o">)</span> <span class="k">=></span><br /><br /><span class="kt">object</span> <span class="kt">TheRendezvous</span><br /><span class="kt">extends</span> <span class="kt">SerializedConsumer</span><span class="o">[</span><span class="kt">T</span><span class="o">](</span> <span class="kt">channel</span> <span class="o">)</span> <span class="o">{</span><br /> <span class="kt">override</span> <span class="kt">def</span> <span class="kt">handleDelivery</span><span class="o">(</span><br /> <span class="kt">tag</span> <span class="kt">:</span> <span class="kt">String</span><span class="o">,</span><br /> <span class="kt">env</span> <span class="kt">:</span> <span class="kt">Envelope</span><span class="o">,</span><br /> <span class="kt">props</span> <span class="kt">:</span> <span class="kt">AMQP.BasicProperties</span><span class="o">,</span><br /> <span class="n">body</span> <span class="k">:</span> <span class="kt">Array</span><span class="o">[</span><span class="kt">Byte</span><span class="o">]</span><br /> <span class="o">)</span> <span class="o">{</span><br /> <span class="n">spawn</span> <span class="o">{</span><br /> <span class="n">println</span><span class="o">(</span><span class="s">"before continuation in callback"</span><span class="o">)</span><br /><br /> <span class="n">k</span><span class="o">(</span> <span class="nc">AMQPDelivery</span><span class="o">(</span> <span class="n">tag</span><span class="o">,</span> <span class="n">env</span><span class="o">,</span> <span class="n">props</span><span class="o">,</span> <span class="n">body</span> <span class="o">)</span> <span class="o">)</span><br /><br /> <span class="n">println</span><span class="o">(</span><span class="s">"after continuation in callback"</span><span class="o">)</span><br /> <br /> <span class="n">outerk</span><span class="o">()</span><br /> <span class="o">}</span><br /> <span class="o">}</span><br /><span class="o">}</span><br /><br /><span class="n">println</span><span class="o">(</span><span class="s">"before registering callback"</span><span class="o">)</span><br /><br /><span class="n">channel</span><span class="o">.</span><span class="n">basicConsume</span><span class="o">(</span><br /><span class="n">ticket</span><span class="o">,</span><br /><span class="s">"mult_queue"</span><span class="o">,</span><br /><span class="kc">false</span><span class="o">,</span><br /><span class="nc">TheRendezvous</span><br /><span class="o">)</span><br /><br /><span class="n">println</span><span class="o">(</span><span class="s">"after registering callback"</span><span class="o">)</span><br /><span class="c">// stop</span><br /> <span class="o">}</span><br /><span class="o">}</span><br /><br /><span class="k">def</span> <span class="n">readT</span><span class="o">(</span> <span class="n">channel</span> <span class="k">:</span> <span class="kt">Channel</span><span class="o">,</span> <span class="n">ticket</span> <span class="k">:</span> <span class="kt">Ticket</span> <span class="o">)</span> <span class="k">=</span><br /><span class="nc">Generator</span> <span class="o">{</span><br /> <span class="n">k</span><span class="k">:</span> <span class="o">(</span> <span class="kt">T</span> <span class="k">=></span> <span class="kt">Unit</span> <span class="kt">@suspendable</span><span class="o">)</span> <span class="k">=></span><br /><span class="kt">shift</span> <span class="o">{</span><br /><span class="kt">outerk:</span> <span class="o">(</span><span class="kt">Unit</span> <span class="k">=></span> <span class="kt">Unit</span><span class="o">)</span> <span class="k">=></span><br /> <span class="kt">reset</span> <span class="o">{</span><br /><br /> <span class="kt">for</span> <span class="o">(</span><br /><span class="kt">amqpD</span> <span class="kt"><-</span> <span class="kt">callbacks</span><span class="o">(</span> <span class="kt">channel</span><span class="o">,</span> <span class="kt">ticket</span> <span class="o">)</span><br /> <span class="o">)</span> <span class="o">{</span><br /><span class="kt">val</span> <span class="kt">routingKey</span> <span class="o">=</span> <span class="kt">amqpD.env.getRoutingKey</span><br /><span class="kt">val</span> <span class="kt">contentType</span> <span class="o">=</span> <span class="n">amqpD</span><span class="o">.</span><span class="n">props</span><span class="o">.</span><span class="n">contentType</span><br /><span class="k">val</span> <span class="n">deliveryTag</span> <span class="k">=</span> <span class="n">amqpD</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">getDeliveryTag</span><br /><span class="k">val</span> <span class="n">in</span> <span class="k">=</span><br /><span class="k">new</span> <span class="nc">ObjectInputStream</span><span class="o">(</span><br /> <span class="k">new</span> <span class="nc">ByteArrayInputStream</span><span class="o">(</span> <span class="n">amqpD</span><span class="o">.</span><span class="n">body</span> <span class="o">)</span><br /><span class="o">)</span><br /><span class="k">val</span> <span class="n">t</span> <span class="k">=</span> <span class="n">in</span><span class="o">.</span><span class="n">readObject</span><span class="o">.</span><span class="n">asInstanceOf</span><span class="o">[</span><span class="kt">T</span><span class="o">];</span><br /><span class="n">k</span><span class="o">(</span> <span class="n">t</span> <span class="o">)</span><br /><span class="n">channel</span><span class="o">.</span><span class="n">basicAck</span><span class="o">(</span><span class="n">deliveryTag</span><span class="o">,</span> <span class="kc">false</span><span class="o">);</span><br /><br /><span class="c">// Is this necessary?</span><br /><span class="n">shift</span> <span class="o">{</span> <span class="n">k</span> <span class="k">:</span> <span class="o">(</span> <span class="kt">Unit</span> <span class="k">=></span> <span class="kt">Unit</span> <span class="o">)</span> <span class="k">=></span> <span class="kt">k</span><span class="o">()</span> <span class="o">}</span><br /> <span class="o">}</span><br /><br /> <span class="n">println</span><span class="o">(</span><span class="s">"readBytes returning"</span><span class="o">)</span><br /> <span class="n">outerk</span><span class="o">()</span><br /> <span class="o">}</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><br /><span class="o">}</span><br /><br /><span class="k">class</span> <span class="nc">StdMonadicAMQPDispatcher</span><span class="o">[</span><span class="kt">T</span><span class="o">](</span><br /><span class="k">val</span> <span class="n">host</span> <span class="k">:</span> <span class="kt">String</span><span class="o">,</span><br /><span class="k">val</span> <span class="n">port</span> <span class="k">:</span> <span class="kt">Int</span><br /><span class="o">)</span> <span class="k">extends</span> <span class="nc">MonadicAMQPDispatcher</span><span class="o">[</span><span class="kt">T</span><span class="o">](</span><br /><span class="o">)</span> <span class="o">{</span><br /><span class="k">def</span> <span class="n">acceptConnections</span><span class="o">()(</span> <span class="k">implicit</span> <span class="n">params</span> <span class="k">:</span> <span class="kt">ConnectionParameters</span> <span class="o">)</span><br /><span class="k">:</span> <span class="kt">Generator</span><span class="o">[</span><span class="kt">Channel</span>,<span class="kt">Unit</span>,<span class="kt">Unit</span><span class="o">]</span> <span class="o">=</span><br /><span class="n">acceptConnections</span><span class="o">(</span> <span class="n">params</span><span class="o">,</span> <span class="n">host</span><span class="o">,</span> <span class="n">port</span> <span class="o">)</span><br /><span class="k">def</span> <span class="n">beginService</span><span class="o">()(</span> <span class="k">implicit</span> <span class="n">params</span> <span class="k">:</span> <span class="kt">ConnectionParameters</span> <span class="o">)</span><br /><span class="k">:</span> <span class="kt">Generator</span><span class="o">[</span><span class="kt">T</span>,<span class="kt">Unit</span>,<span class="kt">Unit</span><span class="o">]</span> <span class="o">=</span><br /><span class="n">beginService</span><span class="o">(</span> <span class="n">params</span><span class="o">,</span> <span class="n">host</span><span class="o">,</span> <span class="n">port</span> <span class="o">)</span><br /><span class="o">}</span><br /><br /><span class="k">object</span> <span class="nc">StdMonadicAMQPDispatcher</span> <span class="o">{</span><br /><span class="k">def</span> <span class="n">apply</span><span class="o">[</span><span class="kt">T</span><span class="o">]</span> <span class="o">(</span><br /><span class="n">host</span> <span class="k">:</span> <span class="kt">String</span><span class="o">,</span> <span class="n">port</span> <span class="k">:</span> <span class="kt">Int</span><br /><span class="o">)</span> <span class="k">:</span> <span class="kt">StdMonadicAMQPDispatcher</span><span class="o">[</span><span class="kt">T</span><span class="o">]</span> <span class="o">=</span> <span class="o">{</span><br /><span class="k">new</span> <span class="nc">StdMonadicAMQPDispatcher</span><span class="o">(</span><br /> <span class="n">host</span><span class="o">,</span> <span class="n">port</span><br /><span class="o">)</span><br /><span class="o">}</span><br /><span class="k">def</span> <span class="n">unapply</span><span class="o">[</span><span class="kt">T</span><span class="o">](</span><br /><span class="n">smAMQPD</span> <span class="k">:</span> <span class="kt">StdMonadicAMQPDispatcher</span><span class="o">[</span><span class="kt">T</span><span class="o">]</span><br /><span class="o">)</span> <span class="k">:</span> <span class="kt">Option</span><span class="o">[(</span><span class="kt">String</span>,<span class="kt">Int</span><span class="o">)]</span> <span class="o">=</span> <span class="o">{</span><br /><span class="nc">Some</span><span class="o">(</span> <span class="o">(</span> <span class="n">smAMQPD</span><span class="o">.</span><span class="n">host</span><span class="o">,</span> <span class="n">smAMQPD</span><span class="o">.</span><span class="n">port</span> <span class="o">)</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="k">def</span> <span class="n">stdCnxnParams</span> <span class="k">:</span> <span class="kt">ConnectionParameters</span> <span class="o">=</span> <span class="o">{</span><br /><span class="k">val</span> <span class="n">params</span> <span class="k">=</span> <span class="k">new</span> <span class="nc">ConnectionParameters</span><br /><span class="n">params</span><span class="o">.</span><span class="n">setUsername</span><span class="o">(</span> <span class="s">"guest"</span> <span class="o">)</span><br /><span class="n">params</span><span class="o">.</span><span class="n">setPassword</span><span class="o">(</span> <span class="s">"guest"</span> <span class="o">)</span><br /><span class="n">params</span><span class="o">.</span><span class="n">setVirtualHost</span><span class="o">(</span> <span class="s">"/"</span> <span class="o">)</span><br /><span class="n">params</span><span class="o">.</span><span class="n">setRequestedHeartbeat</span><span class="o">(</span> <span class="mi">0</span> <span class="o">)</span><br /><span class="n">params</span><br /><span class="o">}</span><br /><br /><span class="k">implicit</span> <span class="k">val</span> <span class="n">defaultConnectionFactory</span> <span class="k">:</span> <span class="kt">ConnectionFactory</span> <span class="o">=</span><br /><span class="k">new</span> <span class="nc">ConnectionFactory</span><span class="o">(</span> <span class="n">defaultConnectionParameters</span> <span class="o">)</span><br /><span class="k">implicit</span> <span class="k">val</span> <span class="n">defaultConnectionParameters</span> <span class="k">:</span> <span class="kt">ConnectionParameters</span> <span class="o">=</span><br /><span class="n">stdCnxnParams</span><br /><span class="k">implicit</span> <span class="k">val</span> <span class="n">defaultHost</span> <span class="k">:</span> <span class="kt">String</span> <span class="o">=</span> <span class="s">"localhost"</span><br /><span class="k">implicit</span> <span class="k">val</span> <span class="n">defaultPort</span> <span class="k">:</span> <span class="kt">Int</span> <span class="o">=</span> <span class="mi">5672</span><br /><span class="o">}</span><br /></pre></div><br /></td></tr></tbody></table></div><br /></div><br /><div class="footer"></div><br /> </div></div></div></div>leithaushttp://www.blogger.com/profile/01069099703796397027noreply@blogger.com1tag:blogger.com,1999:blog-3049258033565653738.post-78720702297461360862010-12-07T13:41:00.000-08:002010-12-07T13:47:45.708-08:00Unburdening myself of my opinion about iOS...<div>i'm writing this entry just to get it out of my nervous system. i'd much rather talk about technology than market trends; however, this one has been bothering me and i wonder if anyone else sees this: iOS is closed. You cannot (without significant effort) run emacs on iOS. You're not supposed to run JVM on iOS. This may be a defining characteristic that determines the bulk of its competition with Android and other OS's.</div><div><br /></div><div>What made the Apple recovery possible, in my mind, was the openness of Mac OS X. It was Unix-based and it was full of open source. This won the hearts and minds of developers who were not in the immediate Apple family. Since the recovery we see the development of the iPhone, and we see a move away from this openness. It is at least plausible that on a phone (where reliability may be an issue of life and death or other mission-critical factors) more control over the OS is a reasonable stance. Further, when we look at the lead iPhone has over other SmartPhones/OS's it's likely to be a tenable stance for some time in the future. However, when we look at the touchpad applications things change. There is no mission-critical argument. These are leisure computing devices even more so than laptops. Hence freedom of development trumps any sort of control arguments. </div><div><br /></div><div>When we look at this in the context of what's happening with the development communities we see that Apple is moving behind the curve. The developer world is moving towards functional languages as a palatable solution to deal with the concurrency requirements from above (Apps must be web and mobile) and below (hardware is multi-core-per-die chips bundled into machines that are bundled into racks...). What is enabling this move for developers is the ubiquity of robust VMs (JVM, .net, LLVM). The iOS is taking a step back from these enablers which means it is taking a step back from the platforms that developers are moving to in droves. That's very dangerous for the class of computing devices Apple is spearheading. That's where i think the Android OS has the most opportunity. Android on a larger touch device allows for a whole new world of UI and application design and supports the new world of development techniques that are emerging to meet this opportunity. </div><div><br /></div><div>i have been so impressed by Apple. They have amazing design sensibilities. They get computing-as-lifestyle better than any other company. It would be very sad for them to have to play catch up in this space. They're much better as leaders than followers. Control, however, has always been their Achilles' heel. Part of being a truly great leader is enabling others to do great things and one of the most important ways of doing that is allowing people to work the way they want to, including using the tools that give them leverage.</div>leithaushttp://www.blogger.com/profile/01069099703796397027noreply@blogger.com6tag:blogger.com,1999:blog-3049258033565653738.post-62637048187734771882010-09-14T15:43:00.000-07:002010-09-14T16:04:11.192-07:00Knots as processes now on arXiv<div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><a href="http://arxiv.org/abs/1009.2107">A draft of our knots-as-processes paper is now available on arXiv</a>. Here's the translation to English: to each knot we assign (calculate, really) a certain kind of computer program -- a program made of concurrently executing smaller programs. These programs are "invariant" -- meaning that <a href="http://en.wikipedia.org/wiki/Reidemeister_move">transformations of the knot that leave the knot essentially unchanged</a> (like untwisting a loop caused by a twist) correspond to transformations of the program (assigned to the knot) that leave the program essentially unchanged. </span></div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><br />Typically, <a href="http://en.wikipedia.org/wiki/Knot_invariant">knot invariants</a> have been algebraic structures (like polynomials -- but also more exotic structures -- like <a href="http://en.wikipedia.org/wiki/Racks_and_quandles">quandles</a>) that are "static". They don't squirm and wiggle on their own the way a computer program might. Our invariants are a new class of invariant because they incorporate this dynamical aspect -- they squirm and wiggle. Moreover, their squirming and wiggling correspond to knot structure in a specific and detailed way.<br /><br />Further, our invariants come with a <b>proof method</b>, known in the literature as <a href="http://en.wikipedia.org/wiki/Bisimulation">bisimulation</a>. The method has been known in science for donkey's years -- two things must be considered the same if you can't find an experiment that distinguishes them. But, it took several hundred years to find a formulation of this method that evinces some of it's real power and flexibility. We illustrate with this application that the proof method of bisimulation is just as applicable to topology as it is to concurrency. This is perhaps the most important contribution of the paper.<br /><br />Further, the programs we use come with their own special family of logics. By "factoring through" our translation we arrive at a family of "knot logics". This allows us to provide a language for picking out <b>classes </b>of knots. This is a unique capability, to the best of our understanding -- though <a href="http://www.msri.org/publications/ln/msri/1997/ldt/conway/1/index.html">Conway's knotation</a> offers more than a little hint of this capability. One of the most exciting potentials in this is the class of applications to reasoning about protein folding.<br /><br />Finally, we show that the invariant is exceptionally fine-grained in the sense that two knots are "equal" if and only if their invariants are "equal". That's about as high a quality detection as is possible. To compare it with other invariants: in the case of <a href="http://en.wikipedia.org/wiki/Jones_polynomial">the Jones polynomial</a>, for which Vaughn Jones got the Fields medal, it was unknown whether it detected knottedness for decades. This invariant comes with a proof method that decides this question at the outset.</span><div><span class="Apple-style-span"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 13px;"><br /></span></span></div><br /><br /><div><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgm2nCckdtG86kZQMxygYioWYWqdolHPRO2gZbDXAAfxzs0clnlhL9COvHzeMVj9yGL2mGyll8Bsm5ctIV1QgvDsErZo7Eu0N5f4bAK3aHCr6VcX3RCYKQmj5AGA5r0nz1PZ5xZWbAsOp6Z/s1600/File:King+Crimson+Discipline.jpeg"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 300px; height: 283px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgm2nCckdtG86kZQMxygYioWYWqdolHPRO2gZbDXAAfxzs0clnlhL9COvHzeMVj9yGL2mGyll8Bsm5ctIV1QgvDsErZo7Eu0N5f4bAK3aHCr6VcX3RCYKQmj5AGA5r0nz1PZ5xZWbAsOp6Z/s400/File:King+Crimson+Discipline.jpeg" border="0" alt="" id="BLOGGER_PHOTO_ID_5516905885371943538" /></a></div><br /><br /><div><span class="Apple-style-span"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 13px;">For those interested in where such ideas come from, in this case the basic idea flew by my mind's eye in 1998 while i was reflecting on the knotwork on <a href="http://en.wikipedia.org/wiki/Discipline_(King_Crimson_album)">the Discipline album</a>. It took me about 3 years from the basic insight to have the skills and direct understanding to write down the idea. It took me about 3 more years to find a collaborator, in the person of David Snyder, patient enough and diligent enough to work with me. His probing questions helped us improve the results -- especially the work on the R3 move. It took us almost 6 years (with lots of stuff going on in between) to pull this draft together.</span></span></div>leithaushttp://www.blogger.com/profile/01069099703796397027noreply@blogger.com0tag:blogger.com,1999:blog-3049258033565653738.post-51093103746111826612010-07-21T12:43:00.000-07:002010-07-21T16:20:59.998-07:00What's *in* a name?i recently read Alexander Kurz, et al's paper on <a href="http://arxiv.org/abs/1006.3027?context=math.CT">algebraic theories over nominal sets</a> with great interest. In connection with that i would like to argue that i believe there is a fundamental flaw in the perception that names should be atomic (without internal structure). However, i believe that that flaw can be easily rectified. Moreover, i believe that work conducted as if names were atomic remains largely undisturbed by the change, but can be enriched by the techniques i present below.<br /><br /><i>Why names cannot be atomic</i><br /><br />The argument against atoms in (foundational) computational theories is straightforward. Algebras and calculi that purport to be foundational accounts of computing, such as the λ-calculus or the π-calculus, endure a fundamental dependency on a theory of names. Specifically, the collection of names in these calculi and other nominal algebras must succumb to the following desiderata.<br /><ul><li>it supports a decidable equality</li><li>it is at least countably infinite</li></ul>now for the questionable desiderata<br /><ul><li>the names have no internal structure</li></ul>When taken together all three require the equality to be an infinite table, an unrealizable oracle. It's not good for a foundational account of computation (or any structure we would like to practically employ in computing, really) to endure a dependency on an unrealizable oracle. Of the three desiderata, there's clearly one that can -- and, i argue, should be -- dropped, namely, the last.<br /><br /><i>Where does name structure come from?</i><br /><br />If we agree -- as every programmer who has to implement any of these structures does -- that names have internal structure, then where does that structure come from? In foundational accounts of computing this question is vital, for if we sneak into our foundational account of computing (such as the λ-calculus or the π-calculus) a dependency on another structure that is computationally complete, then we have robbed out foundational account of computing of it's claim to be foundational. So, where can we look for nominal structure? Why not the proposed theory of computation, itself?<br /><br /><i>Some examples</i><br /><br />The syntax of the λ- and π-calculi can be presented in terms of bi-functors.<br /><br />// The λ-calculus with an explicit representation of divergence<br />M[V,A] = 1 + V + VxA + AxA<br /><br />// The reflective higher order π-calculus<br />M[V,A] = 1 + VxVxA + VxA + AxA + V<br /><br />If we fix V as constant for the moment, then we find our usual suspects as the least fixed points of these functors, µM, w.r.t. A. It turns out that it is perfectly sane to now look for the fixed point w.r.t. V. Then µµM are perfectly realizable types with lots of inhabitants. Moreover, they give rise to a richer notion of substitution (as laid out by Meredith and Radestock). The crucial point is that technique is extensible to virtually every nominal algebra.<br /><br /><i>Doesn't this conflict with Fraenkl-Mostowski Set Theory?</i><br /><br />It turns out that FM-Set Theory, as it is employed by Gabbay and Pitts in their seminal work on nominal theories, does not need its "atoms" to avoid internal structure. Rather, it requires that the operations of the set theoretic apparatus to be inured to it. Using this little observation, we can employ exactly the same trick as above to rid FM-Set Theory of a dependency on an unrealizable oracle.<br /><br />In my view, heavily influenced by computing as it is, i see the basics of set theory as providing some operations for constructing and inspecting, de-structing a data type called Set. Very primitively, we have operations for<br /><br /><ul><li>extensionally constructing sets, '{ ... }' and</li><li>operations for intensionally constructing sets '{ ... | ... }' (comprehensions)</li><li>operations for inspecting sets 'x in ... '</li></ul><br />In this view, nothing prevents me from imagining two different versions of this data type. One of which i will call the 'black' version and one of which i will call the 'red' version. Initially, i might imagine these data types as copies of each other; but, we can only construct and inspect 'black sets' with 'black' braces and 'black' in predicate; and likewise for the 'red sets'. So, never the twain shall meet.<br /><br />Now, once we've built such a structure, there's nothing to prevent us from imagining that the 'atoms' of a 'black' FM-set theory are none other than 'red sets'. Symmetrically, nothing prevents us from imagining that the 'atoms' of a 'red' FM-set theory are none other than 'black sets'. A suggestive use of data type specifications might illustrate the idea<br /><br /><ul><li>Ordinary sets</li></ul>Set ::= '{' Set* '}'<br /><ul><li>Red/black sets</li></ul>BlackSet ::= '{b|' (BlackSet + RedAtom)* '|b}'<br />RedSet ::= '{r|' (RedSet + BlackAtom)* '|r}'<br />RedAtom ::= RedSet<br />BlackAtom ::= BlackSet<br /><br />It should be possible to use algebraic set theory to give a presentation of this idea as an instance of the idea used above.<br /><br /><i>Conclusions</i><br /><br />Lots of useful and interesting computational theory and implementation can take place without inspecting the internal structure of names. Thus, the current state of the theory nominal computational phenomena represents a useful separation of concerns. However, when we acknowledge the real burden on theories of computation that endure a dependency on an unrealizable oracle, we can also begin to explore some of the things that become possible with nominal structure. As mentioned previously, this sort of structure leads to a host of new substitution strategies, only one of which is investigated in Meredith and Radestock's papers. There are other potential benefits as well.<br /><br />It turns out that McBride and others have given a completely generic and precise definition of location within a structure determined by the kinds of functors we see in nominal algebras. Specifically, they demonstrate that the type of pairs ∂µM x µM -- where ∂µM is the type of contexts of µM, and is calculated according to rules that exactly match the calculations of a derivative in ordinary differential calculus -- represents the type of location as originally investigated by Huet in the functional pearl on the Zipper. It becomes possible to realize nominal algebras in which the internal structure of names is given in terms of locations in the terms of the algebras. Formally, M[∂µM x µM,µM] will provide this kind of capability. You can see functioning Haskell code realizing this for the λ-calculus, <a href="http://biosimilarity.blogspot.com/2010/07/softwhere.html">here</a>. This sort of structure is of great interest to those who -- like every programmer on the web -- recognize that there is some basic relationship between names like URLs and the basic structure of the containers they access (like websites).leithaushttp://www.blogger.com/profile/01069099703796397027noreply@blogger.com4tag:blogger.com,1999:blog-3049258033565653738.post-50744621124295745852010-07-20T22:32:00.000-07:002010-07-20T23:46:39.876-07:00Softwhere<div class="page"><div class="content">In this post we give the Haskell code for a lambda calculus in which the variables are locations in lambda terms. This is a very generic procedure. Given a polynomial bi-functor, M[V,A], we can form the type M[(∂µMxµM),µM]. When M is really a <a href="http://arxiv.org/abs/1006.3027?context=math.CT">nominal algebra</a> this results in algebraic terms in which names are really positions in terms. This is another milestone along the way to providing a rational reconstruction of geometry in which geometry arises from computational behavior.</div><div class="content"><div id="paste" class="lang-haskell code"><br /> <div class="code"><div class="syntax"><pre><span class="kr">module</span> <span class="nn">Generators</span><span class="p">(</span><br /> <span class="kt">Term</span><br /> <span class="p">,</span> <span class="kt">MuTerm</span><br /> <span class="p">,</span> <span class="kt">DoTerm</span><br /> <span class="p">,</span> <span class="kt">ReflectiveTerm</span><br /> <span class="p">,</span> <span class="kt">TermLocation</span><br /> <span class="p">,</span> <span class="kt">ClosedTermLocation</span><br /> <span class="p">,</span> <span class="kt">ClosedReflectiveTerm</span><br /> <span class="p">,</span> <span class="n">unfoldLocation</span><br /> <span class="p">,</span> <span class="n">unfoldTerm</span><br /> <span class="p">,</span> <span class="n">makeMention</span><br /> <span class="p">,</span> <span class="n">makeAbstraction</span><br /> <span class="p">,</span> <span class="n">makeApplication</span><br /> <span class="p">,</span> <span class="n">generateTerms</span><br /> <span class="p">)</span><br /> <span class="kr">where</span><br /><br /><span class="c1">-- M[V,A] = 1 + V + VxA + AxA</span><br /><span class="kr">data</span> <span class="kt">Term</span> <span class="n">v</span> <span class="n">a</span> <span class="ow">=</span><br /> <span class="kt">Divergence</span><br /> <span class="o">|</span> <span class="kt">Mention</span> <span class="n">v</span><br /> <span class="o">|</span> <span class="kt">Abstraction</span> <span class="n">v</span> <span class="n">a</span><br /> <span class="o">|</span> <span class="kt">Application</span> <span class="n">a</span> <span class="n">a</span><br /> <span class="kr">deriving</span> <span class="p">(</span><span class="kt">Eq</span><span class="p">,</span> <span class="kt">Show</span><span class="p">)</span><br /><br /><span class="c1">-- μ M</span><br /><span class="kr">data</span> <span class="kt">MuTerm</span> <span class="n">v</span> <span class="ow">=</span> <span class="kt">MuTerm</span> <span class="p">(</span><span class="kt">Term</span> <span class="n">v</span> <span class="p">(</span><span class="kt">MuTerm</span> <span class="n">v</span><span class="p">))</span> <span class="kr">deriving</span> <span class="p">(</span><span class="kt">Eq</span><span class="p">,</span> <span class="kt">Show</span><span class="p">)</span><br /><br /><span class="c1">-- ∂μ M</span><br /><span class="kr">data</span> <span class="kt">DoTerm</span> <span class="n">v</span> <span class="ow">=</span><br /> <span class="kt">Hole</span><br /> <span class="o">|</span> <span class="kt">DoAbstraction</span> <span class="n">v</span> <span class="p">(</span><span class="kt">DoTerm</span> <span class="n">v</span><span class="p">)</span><br /> <span class="o">|</span> <span class="kt">DoLeftApplication</span> <span class="p">(</span><span class="kt">DoTerm</span> <span class="n">v</span><span class="p">)</span> <span class="p">(</span><span class="kt">MuTerm</span> <span class="n">v</span><span class="p">)</span><br /> <span class="o">|</span> <span class="kt">DoRightApplication</span> <span class="p">(</span><span class="kt">MuTerm</span> <span class="n">v</span><span class="p">)</span> <span class="p">(</span><span class="kt">DoTerm</span> <span class="n">v</span><span class="p">)</span><br /> <span class="kr">deriving</span> <span class="p">(</span><span class="kt">Eq</span><span class="p">,</span> <span class="kt">Show</span><span class="p">)</span><br /><br /><span class="c1">-- first trampoline</span><br /><span class="kr">data</span> <span class="kt">ReflectiveTerm</span> <span class="n">v</span> <span class="ow">=</span> <span class="kt">ReflectiveTerm</span> <span class="p">(</span><span class="kt">MuTerm</span> <span class="p">(</span><span class="kt">DoTerm</span> <span class="n">v</span><span class="p">,</span> <span class="kt">ReflectiveTerm</span> <span class="n">v</span><span class="p">))</span><br /> <span class="kr">deriving</span> <span class="p">(</span><span class="kt">Eq</span><span class="p">,</span> <span class="kt">Show</span><span class="p">)</span><br /><br /><span class="c1">-- second trampoline</span><br /><span class="kr">data</span> <span class="kt">TermLocation</span> <span class="n">v</span> <span class="ow">=</span> <span class="kt">TermLocation</span> <span class="p">((</span><span class="kt">DoTerm</span> <span class="n">v</span><span class="p">),</span> <span class="p">(</span><span class="kt">ReflectiveTerm</span> <span class="n">v</span><span class="p">))</span><br /> <span class="kr">deriving</span> <span class="p">(</span><span class="kt">Eq</span><span class="p">,</span> <span class="kt">Show</span><span class="p">)</span><br /><br /><span class="c1">-- first bounce</span><br /><span class="kr">data</span> <span class="kt">ClosedTermLocation</span> <span class="ow">=</span> <span class="kt">ClosedTermLocation</span> <span class="p">(</span><span class="kt">TermLocation</span> <span class="kt">ClosedTermLocation</span><span class="p">)</span><br /> <span class="kr">deriving</span> <span class="p">(</span><span class="kt">Eq</span><span class="p">,</span> <span class="kt">Show</span><span class="p">)</span><br /><br /><span class="c1">-- second bounce</span><br /><span class="kr">data</span> <span class="kt">ClosedReflectiveTerm</span> <span class="ow">=</span><br /> <span class="kt">ClosedReflectiveTerm</span> <span class="p">(</span><span class="kt">ReflectiveTerm</span> <span class="kt">ClosedTermLocation</span><span class="p">)</span><br /> <span class="kr">deriving</span> <span class="p">(</span><span class="kt">Eq</span><span class="p">,</span> <span class="kt">Show</span><span class="p">)</span><br /><br /><span class="c1">-- the isomorphisms implied by the trampolines</span><br /><span class="nf">unfoldLocation</span> <span class="ow">::</span><br /> <span class="kt">ClosedTermLocation</span><br /> <span class="ow">-></span> <span class="p">((</span><span class="kt">DoTerm</span> <span class="kt">ClosedTermLocation</span><span class="p">),</span> <span class="p">(</span><span class="kt">ReflectiveTerm</span> <span class="kt">ClosedTermLocation</span><span class="p">))</span><br /><br /><span class="nf">unfoldLocation</span> <span class="p">(</span><span class="kt">ClosedTermLocation</span> <span class="p">(</span><span class="kt">TermLocation</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">t</span><span class="p">)))</span> <span class="ow">=</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">t</span><span class="p">)</span><br /><br /><span class="nf">unfoldTerm</span> <span class="ow">::</span><br /> <span class="kt">ClosedReflectiveTerm</span><br /> <span class="ow">-></span> <span class="p">(</span><span class="kt">MuTerm</span><br /> <span class="p">((</span><span class="kt">DoTerm</span> <span class="kt">ClosedTermLocation</span><span class="p">),</span> <span class="p">(</span><span class="kt">ReflectiveTerm</span> <span class="kt">ClosedTermLocation</span><span class="p">)))</span><br /><br /><span class="nf">unfoldTerm</span> <span class="p">(</span><span class="kt">ClosedReflectiveTerm</span> <span class="p">(</span><span class="kt">ReflectiveTerm</span> <span class="n">muT</span><span class="p">))</span> <span class="ow">=</span> <span class="n">muT</span><br /><br /><span class="c1">-- variable mention ctor</span><br /><span class="nf">makeMention</span> <span class="ow">::</span> <span class="kt">ClosedTermLocation</span> <span class="ow">-></span> <span class="kt">ClosedReflectiveTerm</span><br /><br /><span class="nf">makeMention</span> <span class="n">ctl</span> <span class="ow">=</span><br /> <span class="p">(</span><span class="kt">ClosedReflectiveTerm</span><br /> <span class="p">(</span><span class="kt">ReflectiveTerm</span> <span class="p">(</span><span class="kt">MuTerm</span> <span class="p">(</span><span class="kt">Mention</span> <span class="p">(</span><span class="n">unfoldLocation</span> <span class="n">ctl</span><span class="p">)))))</span><br /><br /><span class="c1">-- abstraction ctor</span><br /><span class="nf">makeAbstraction</span> <span class="ow">::</span><br /> <span class="kt">ClosedTermLocation</span> <span class="ow">-></span> <span class="kt">ClosedReflectiveTerm</span> <span class="ow">-></span> <span class="kt">ClosedReflectiveTerm</span><br /> <br /><span class="nf">makeAbstraction</span> <span class="n">ctl</span> <span class="n">crt</span> <span class="ow">=</span><br /> <span class="p">(</span><span class="kt">ClosedReflectiveTerm</span><br /> <span class="p">(</span><span class="kt">ReflectiveTerm</span><br /> <span class="p">(</span><span class="kt">MuTerm</span><br /> <span class="p">(</span><span class="kt">Abstraction</span><br /> <span class="p">(</span><span class="n">unfoldLocation</span> <span class="n">ctl</span><span class="p">)</span><br /> <span class="p">(</span><span class="n">unfoldTerm</span> <span class="n">crt</span><span class="p">)))))</span><br /><br /><span class="c1">-- application ctor</span><br /><span class="nf">makeApplication</span> <span class="ow">::</span><br /> <span class="kt">ClosedReflectiveTerm</span> <span class="ow">-></span> <span class="kt">ClosedReflectiveTerm</span> <span class="ow">-></span> <span class="kt">ClosedReflectiveTerm</span><br /><br /><span class="nf">makeApplication</span> <span class="n">crtApplicad</span> <span class="n">crtApplicand</span> <span class="ow">=</span><br /> <span class="p">(</span><span class="kt">ClosedReflectiveTerm</span><br /> <span class="p">(</span><span class="kt">ReflectiveTerm</span><br /> <span class="p">(</span><span class="kt">MuTerm</span><br /> <span class="p">(</span><span class="kt">Application</span><br /> <span class="p">(</span><span class="n">unfoldTerm</span> <span class="n">crtApplicad</span><span class="p">)</span><br /> <span class="p">(</span><span class="n">unfoldTerm</span> <span class="n">crtApplicand</span><span class="p">)))))</span><br /><br /><span class="c1">-- a simple test</span><br /><span class="nf">generateTerms</span> <span class="ow">::</span> <span class="nb">()</span> <span class="ow">-></span> <span class="p">[</span><span class="kt">ClosedReflectiveTerm</span><span class="p">]</span><br /><br /><span class="nf">generateTerms</span> <span class="nb">()</span> <span class="ow">=</span><br /> <span class="c1">-- x</span><br /> <span class="p">[(</span><span class="n">makeMention</span><br /> <span class="p">(</span><span class="kt">ClosedTermLocation</span><br /> <span class="p">(</span><span class="kt">TermLocation</span> <span class="p">(</span><span class="kt">Hole</span><span class="p">,</span> <span class="kt">ReflectiveTerm</span> <span class="p">(</span><span class="kt">MuTerm</span> <span class="kt">Divergence</span><span class="p">))))),</span><br /> <span class="c1">-- \x -> x</span><br /> <span class="p">(</span><span class="n">makeAbstraction</span><br /> <span class="p">(</span><span class="kt">ClosedTermLocation</span><br /> <span class="p">(</span><span class="kt">TermLocation</span> <span class="p">(</span><span class="kt">Hole</span><span class="p">,</span> <span class="kt">ReflectiveTerm</span> <span class="p">(</span><span class="kt">MuTerm</span> <span class="kt">Divergence</span><span class="p">))))</span><br /> <span class="p">(</span><span class="n">makeMention</span><br /> <span class="p">(</span><span class="kt">ClosedTermLocation</span><br /> <span class="p">(</span><span class="kt">TermLocation</span> <span class="p">(</span><span class="kt">Hole</span><span class="p">,</span> <span class="kt">ReflectiveTerm</span> <span class="p">(</span><span class="kt">MuTerm</span> <span class="kt">Divergence</span><span class="p">)))))),</span><br /> <span class="c1">-- ((\x -> x)(\x -> x))</span><br /> <span class="p">(</span><span class="n">makeApplication</span><br /> <span class="p">(</span><span class="n">makeAbstraction</span><br /> <span class="p">(</span><span class="kt">ClosedTermLocation</span><br /> <span class="p">(</span><span class="kt">TermLocation</span> <span class="p">(</span><span class="kt">Hole</span><span class="p">,</span> <span class="kt">ReflectiveTerm</span> <span class="p">(</span><span class="kt">MuTerm</span> <span class="kt">Divergence</span><span class="p">))))</span><br /> <span class="p">(</span><span class="n">makeMention</span><br /> <span class="p">(</span><span class="kt">ClosedTermLocation</span><br /> <span class="p">(</span><span class="kt">TermLocation</span> <span class="p">(</span><span class="kt">Hole</span><span class="p">,</span> <span class="kt">ReflectiveTerm</span> <span class="p">(</span><span class="kt">MuTerm</span> <span class="kt">Divergence</span><span class="p">))))))</span><br /> <span class="p">(</span><span class="n">makeAbstraction</span><br /> <span class="p">(</span><span class="kt">ClosedTermLocation</span><br /> <span class="p">(</span><span class="kt">TermLocation</span> <span class="p">(</span><span class="kt">Hole</span><span class="p">,</span> <span class="kt">ReflectiveTerm</span> <span class="p">(</span><span class="kt">MuTerm</span> <span class="kt">Divergence</span><span class="p">))))</span><br /> <span class="p">(</span><span class="n">makeMention</span><br /> <span class="p">(</span><span class="kt">ClosedTermLocation</span><br /> <span class="p">(</span><span class="kt">TermLocation</span> <span class="p">(</span><span class="kt">Hole</span><span class="p">,</span> <span class="kt">ReflectiveTerm</span> <span class="p">(</span><span class="kt">MuTerm</span> <span class="kt">Divergence</span><span class="p">)))))))]</span><br /></pre></div><br /></div><br /></div><br /><div class="footer"></div><br /> </div><br /> </div>leithaushttp://www.blogger.com/profile/01069099703796397027noreply@blogger.com0tag:blogger.com,1999:blog-3049258033565653738.post-59445698028966923992010-05-29T06:59:00.000-07:002010-05-29T07:19:30.836-07:00Zip tease<div><b><span class="Apple-style-span" style="font-weight: normal; ">The last posting reviewed Huet's original proposal for the Zipper. Before doing a technical deep dive on some of the consequences of that idea i thought i important to provide some context on how the idea has been developed. Since it was brought to light there have been two important variations rung which i discuss below.</span></b></div><div><b><br /></b></div><div><b><span class="Apple-style-span" style="font-weight: normal; "></span>Two kinds of genericity</b></div><div>It turns out that Huet's discovery can be made to work on a much wider class of structures than "just" trees. Intuitively speaking, if their type arguments are "zippable", then virtually all of the common functional data type constructors, including sequencing constructors like product, and branching constructors, like summation or "casing", result in "zippable" types. That is, there are procedures for deriving a notion of zipper capable of traversing and mutating the structure. Essentially, there are two strategies to achieve this genericity: one is based on structural genericity and the other on procedural genericity.</div><div><br /></div><div><b>Genericity of structure</b></div><div><br /></div><div>The former approach relies on being able to define a notion of context for any "reasonable" data structure. Not surprisingly, it turns out that we can give a good definition of "reasonable". What is surprising is that the resulting definition is amenable to an operation that perfectly mimics the notion of derivative from Newton's calculus. The operation is an operation on <i>types</i>. This allows us to give a type-level definition of the notion of location -- just as we did with trees, but now for any type.</div><div><br /></div><div>We can use Scala's type notation to see where the new genericity has been added. The type of trees in the example is already polymorphic: <span class="Apple-style-span" style="font-family:'courier new';">Tree[A]</span>. That's what having that type parameter</div><div><span class="Apple-style-span" style="font-family:'courier new';">A</span> means. The navigation trait is therefore also parametric in <span class="Apple-style-span" style="font-family:'courier new';">A</span>. The navigation trait, however, is hardcoded in the container type, <span class="Apple-style-span" style="font-family:'courier new';">Tree[A]</span>. When we add this second level of genericity, the navigation trait will have to take a second, <i>higher-kinded</i> type parameter for the container because it will work on any container within a range of reasonably defined containers.</div><div><br /></div><div>The use case we have been considering -- navigating and mutating an in-memory representation of a tree -- is then extended to navigating and mutating an in-memory representation of an arbitrary data structure. Moreover, the code is purely functional -- with all of the attendant advantages of purely functional code we have been observing</div><div>since forevever. Obviously, in the context of the web, this particular use case is of considerable interest. Nearly, every web application is of this form: navigating a tree or graph of pages. Usually, that graph of pages is somehow homomorphic, i.e. an image of, the graph of some</div><div>underlying domain data structure, like the data structures of employee records in a payroll system, or the social graph of a social media application like Twitter. Many web applications, such as so-called content management systems, also support the mutation of the graph of</div><div>pages. So, having a method of generating this functionality from the types of the underlying data domain, be they web pages, or some other domain data type, is clearly pertinent to the most focused of application developers.</div><div><br /></div><div>And yet, the notion of a <i>derivative of data types</i> is irresistibly intriguing. It's not simply that it has many other applications besides web navigation and update. That a calculational device that an Englishman discovered some 400+ years ago in his investigations for providing a mathematical framework for gravitation and other physical phenomena should be applicable to structuring computer programs is as surprising as it is elegant and that makes it <i>cool</i>.</div><div><br /></div><div><b>Genericity of control</b></div><div><br /></div><div>The latter approach to generically constructing zippers is just as rich in terms of the world of ideas it opens up as it is in the imminent practicality of its immediate applications. The key insight is to abstract on control, rather than on form. Not surprisingly, then the central tool is the (delimited) continuation. To be clear, in this approach, originally developed by Oleg Kiselyov, navigation is reifed as a function and supplied as a parameter. In this sense, it is not automagically deriving mechanism for navigation, as does the structural approach. The semantics of mutation, on the other hand, is provided with a powerful generative mechanism. More specifically, a dial is provided for the visibility of mutation with respect to different threads of control. In other words, fine-grained constrol on the <i>transactional semantics</i> of mutating the data structure is provided. This is exceptionally powerful because, as we have mentioned in many previous posts, the transactional semantics is one of the principal places on which performance of a system -- especially a high-volume system -- hinges; but, by being based on a form of monad, namely delimited continuations, the abstraction gets the compiler involved. This has the effect of enlisting the compiler in maintaining discipline and sanity on transaction semantics -- which is vitally important when supplying a fine-grained control on something as performance-critical as the semantics and visibility of update.</div>leithaushttp://www.blogger.com/profile/01069099703796397027noreply@blogger.com28tag:blogger.com,1999:blog-3049258033565653738.post-92093868378476014762010-05-25T09:35:00.000-07:002010-05-25T14:30:54.103-07:00Huet's zipperIn this post, rather than pushing the boundaries, i'm going to take a step back and review Huet's original proposal for <a href="http://en.wikipedia.org/wiki/Zipper_(data_structure)">the Zipper</a>. His idea was published in <a href="http://www.st.cs.uni-sb.de/edu/seminare/2005/advanced-fp/docs/huet-zipper.pdf">this functional pearl</a>. My motivations for doing this are manifold. Firstly, i don't think anyone has written up a transliteration into Scala, yet (though, the ScalaZ guys do have an implementation). Secondly, i'm curious regarding how much interest in and understanding of the Zipper there is in the Scala community. Thirdly, this is in preparation for a radical idea in which nominal access (access by name) and positional access (access by location) are put into correspondence by construction. This leads to some pretty wild stuff that i've been contemplating for nearly two years, now.<div><br /></div><div><div>The origin of the zipper rests in the desire to provide an efficient functional representation of a "structure" editor. For example, we might consider navigation and destructive modification of a tree. In a functional representation destructive operations need to be replaced by copying. Done naively, this can be very expensive. In his functional pearl Huet describes a generic approach to the problem of an applicative structure editor. He dubbed it the zipper. The key idea is to denote the location of a position in a tree by splitting it into two pieces: the subtree of focus and the context in which it appears.</div></div><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyxHe9YmiJuk-79YYrRYDvCl5PJ_nhOxVwdRZ3cuBsqscp_rFNKtxEZr61kO6ioAnHbW9Mvi3vBUfOSR_yaRHOoGHaJZyK9bn-Y52mhAr7x6FcdyTTy1fnr58yEuufiATMhB_2Zsq0SJMp/s1600/LocationAndContext.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 279px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyxHe9YmiJuk-79YYrRYDvCl5PJ_nhOxVwdRZ3cuBsqscp_rFNKtxEZr61kO6ioAnHbW9Mvi3vBUfOSR_yaRHOoGHaJZyK9bn-Y52mhAr7x6FcdyTTy1fnr58yEuufiATMhB_2Zsq0SJMp/s400/LocationAndContext.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5475279216147603042" /></a><br /><div>To render this idea in Scala suppose that we have modeled the</div><div>type of a tree as</div><div><br /></div><div><div><span class="Apple-style-span" style="font-family:'courier new';"><br /></span></div></div><div><br /></div><br /><br /><div id="paste" class="lang-scala code"><br /><div class="code"><table class="syntaxtable"><tbody><tr><td class="linenos"><div class="linenodiv"><pre> 1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19</pre></div></td><td class="code"><div class="syntax"><pre><span class="k">trait</span> <span class="nc">Tree</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span><br /><span class="nc">class</span> <span class="nc">TreeItem</span><span class="o">[</span><span class="kt">A</span><span class="o">](</span> <span class="k">val</span> <span class="n">item</span> <span class="k">:</span> <span class="kt">A</span> <span class="o">)</span> <span class="k">extends</span> <span class="nc">Tree</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span><br /><span class="k">object</span> <span class="nc">TreeItem</span> <span class="o">{</span><br /><span class="k">def</span> <span class="n">apply</span><span class="o">[</span><span class="kt">A</span><span class="o">](</span> <span class="n">item</span> <span class="k">:</span> <span class="kt">A</span> <span class="o">)</span> <span class="k">=</span> <span class="o">{</span> <span class="k">new</span> <span class="nc">TreeItem</span><span class="o">(</span> <span class="n">item</span> <span class="o">)</span> <span class="o">}</span><br /><span class="k">def</span> <span class="n">unapply</span><span class="o">[</span><span class="kt">A</span><span class="o">](</span> <span class="n">tree</span> <span class="k">:</span> <span class="kt">TreeItem</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="o">)</span><br /><span class="k">:</span> <span class="kt">Option</span><span class="o">[(</span> <span class="kt">A</span> <span class="o">)]</span> <span class="k">=</span> <span class="o">{</span><br /><span class="nc">Some</span><span class="o">(</span> <span class="o">(</span> <span class="n">tree</span><span class="o">.</span><span class="n">item</span> <span class="o">)</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="k">class</span> <span class="nc">TreeSection</span><span class="o">[</span><span class="kt">A</span><span class="o">](</span><br /><span class="k">val</span> <span class="n">section</span><span class="k">:</span> <span class="kt">List</span><span class="o">[</span><span class="kt">Tree</span><span class="o">[</span><span class="kt">A</span><span class="o">]]</span><br /><span class="o">)</span> <span class="k">extends</span> <span class="nc">Tree</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span><br /><span class="k">object</span> <span class="nc">TreeSection</span> <span class="o">{</span><br /><span class="k">def</span> <span class="n">apply</span><span class="o">[</span><span class="kt">A</span><span class="o">](</span> <span class="n">section</span> <span class="k">:</span> <span class="kt">List</span><span class="o">[</span><span class="kt">Tree</span><span class="o">[</span><span class="kt">A</span><span class="o">]]</span> <span class="o">)</span> <span class="k">=</span> <span class="o">{</span> <span class="k">new</span> <span class="nc">TreeSection</span><span class="o">(</span> <span class="n">section</span> <span class="o">)</span> <span class="o">}</span><br /><span class="k">def</span> <span class="n">unapply</span><span class="o">[</span><span class="kt">A</span><span class="o">](</span> <span class="n">tree</span> <span class="k">:</span> <span class="kt">TreeSection</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="o">)</span><br /><span class="k">:</span> <span class="kt">Option</span><span class="o">[(</span> <span class="kt">List</span><span class="o">[</span><span class="kt">Tree</span><span class="o">[</span><span class="kt">A</span><span class="o">]]</span> <span class="o">)]</span> <span class="k">=</span> <span class="o">{</span><br /><span class="nc">Some</span><span class="o">(</span> <span class="o">(</span> <span class="n">tree</span><span class="o">.</span><span class="n">section</span> <span class="o">)</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="o">}</span><br /></pre></div><br /></td></tr></tbody></table></div><br /></div><br /><br /><div>Then we might model the context by hand as</div><div><br /></div><br /><div id="paste" class="lang-scala code"><br /><div class="code"><table class="syntaxtable"><tbody><tr><td class="linenos"><div class="linenodiv"><pre> 1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19</pre></div></td><td class="code"><div class="syntax"><pre><span class="k">trait</span> <span class="nc">Context</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span><br /><span class="nc">case</span> <span class="k">class</span> <span class="nc">Top</span><span class="o">[</span><span class="kt">A</span><span class="o">](</span> <span class="o">)</span> <span class="k">extends</span> <span class="nc">Context</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span><br /><span class="k">class</span> <span class="nc">TreeContext</span><span class="o">[</span><span class="kt">A</span><span class="o">](</span><br /><span class="k">val</span> <span class="n">left</span> <span class="k">:</span> <span class="kt">List</span><span class="o">[</span><span class="kt">Tree</span><span class="o">[</span><span class="kt">A</span><span class="o">]],</span><br /><span class="k">val</span> <span class="n">ctxt</span> <span class="k">:</span> <span class="kt">Context</span><span class="o">[</span><span class="kt">A</span><span class="o">],</span><br /><span class="k">val</span> <span class="n">right</span> <span class="k">:</span> <span class="kt">List</span><span class="o">[</span><span class="kt">Tree</span><span class="o">[</span><span class="kt">A</span><span class="o">]]</span><br /><span class="o">)</span> <span class="k">extends</span> <span class="nc">Context</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span><br /><span class="k">object</span> <span class="nc">TreeContext</span> <span class="o">{</span><br /><span class="k">def</span> <span class="n">apply</span><span class="o">[</span><span class="kt">A</span><span class="o">](</span><br /><span class="n">left</span> <span class="k">:</span> <span class="kt">List</span><span class="o">[</span><span class="kt">Tree</span><span class="o">[</span><span class="kt">A</span><span class="o">]],</span><br /><span class="n">ctxt</span> <span class="k">:</span> <span class="kt">Context</span><span class="o">[</span><span class="kt">A</span><span class="o">],</span><br /><span class="n">right</span> <span class="k">:</span> <span class="kt">List</span><span class="o">[</span><span class="kt">Tree</span><span class="o">[</span><span class="kt">A</span><span class="o">]]</span> <span class="o">)</span> <span class="k">=</span> <span class="o">{</span><br /><span class="k">new</span> <span class="nc">TreeContext</span><span class="o">(</span> <span class="n">left</span><span class="o">,</span> <span class="n">ctxt</span><span class="o">,</span> <span class="n">right</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="k">def</span> <span class="n">unapply</span><span class="o">[</span><span class="kt">A</span><span class="o">](</span> <span class="n">ctxt</span> <span class="k">:</span> <span class="kt">TreeContext</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="o">)</span><br /><span class="k">:</span> <span class="kt">Option</span><span class="o">[(</span> <span class="kt">List</span><span class="o">[</span><span class="kt">Tree</span><span class="o">[</span><span class="kt">A</span><span class="o">]]</span>, <span class="kt">Context</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span>, <span class="kt">List</span><span class="o">[</span><span class="kt">Tree</span><span class="o">[</span><span class="kt">A</span><span class="o">]]</span> <span class="o">)]</span> <span class="k">=</span> <span class="o">{</span><br /><span class="nc">Some</span><span class="o">(</span> <span class="o">(</span> <span class="n">ctxt</span><span class="o">.</span><span class="n">left</span><span class="o">,</span> <span class="n">ctxt</span><span class="o">.</span><span class="n">ctxt</span><span class="o">,</span> <span class="n">ctxt</span><span class="o">.</span><span class="n">right</span> <span class="o">)</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="o">}</span><br /></pre></div><br /></td></tr></tbody></table></div><br /></div><br /><div>The context is "tree to the left", "path to a place where we might put a subtree", "tree to the right". Coding the intuitive idea of location is now straightforward. It's a pair: the context together with the subtree that "plugs into it".</div><div><br /></div><div><br /><div id="paste" class="lang-scala code"><br /><div class="code"><table class="syntaxtable"><tbody><tr><td class="linenos"><div class="linenodiv"><pre> 1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13</pre></div></td><td class="code"><div class="syntax"><pre><span class="k">class</span> <span class="nc">Location</span><span class="o">[</span><span class="kt">A</span><span class="o">](</span><br /><span class="k">val</span> <span class="n">tree</span> <span class="k">:</span> <span class="kt">Tree</span><span class="o">[</span><span class="kt">A</span><span class="o">],</span><br /><span class="k">val</span> <span class="n">ctxt</span> <span class="k">:</span> <span class="kt">Context</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span><br /><span class="o">)</span><br /><span class="k">object</span> <span class="nc">Location</span> <span class="o">{</span><br /><span class="k">def</span> <span class="n">apply</span><span class="o">[</span><span class="kt">A</span><span class="o">](</span> <span class="n">tree</span> <span class="k">:</span> <span class="kt">Tree</span><span class="o">[</span><span class="kt">A</span><span class="o">],</span> <span class="n">ctxt</span> <span class="k">:</span> <span class="kt">Context</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="o">)</span> <span class="k">=</span> <span class="o">{</span><br /><span class="k">new</span> <span class="nc">Location</span><span class="o">(</span> <span class="n">tree</span><span class="o">,</span> <span class="n">ctxt</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="k">def</span> <span class="n">unapply</span><span class="o">[</span><span class="kt">A</span><span class="o">](</span> <span class="n">loc</span> <span class="k">:</span> <span class="kt">Location</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="o">)</span><br /><span class="k">:</span> <span class="kt">Option</span><span class="o">[(</span> <span class="kt">Tree</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span>, <span class="kt">Context</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="o">)]</span> <span class="k">=</span> <span class="o">{</span><br /><span class="nc">Some</span><span class="o">(</span> <span class="o">(</span> <span class="n">loc</span><span class="o">.</span><span class="n">tree</span><span class="o">,</span> <span class="n">loc</span><span class="o">.</span><span class="n">ctxt</span> <span class="o">)</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="o">}</span><br /></pre></div><br /></td></tr></tbody></table></div><br /></div><br /></div><div>This encoding allows us some generic navigation code.</div><br /><div></div><br /><div id="paste" class="lang-scala code"><br /><div class="code"><table class="syntaxtable"><tbody><tr><td class="linenos"><div class="linenodiv"><pre> 1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52</pre></div></td><td class="code"><div class="syntax"><pre><span class="k">trait</span> <span class="nc">ZipperNavigation</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="o">{</span><br /><span class="k">def</span> <span class="n">left</span><span class="o">(</span> <span class="n">location</span> <span class="k">:</span> <span class="kt">Location</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="o">)</span> <span class="k">:</span> <span class="kt">Location</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="k">=</span> <span class="o">{</span><br /><span class="n">location</span> <span class="k">match</span> <span class="o">{</span><br /><span class="k">case</span> <span class="nc">Location</span><span class="o">(</span> <span class="n">_</span><span class="o">,</span> <span class="nc">Top</span><span class="o">(</span> <span class="o">)</span> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /> <span class="k">throw</span> <span class="k">new</span> <span class="nc">Exception</span><span class="o">(</span> <span class="s">"left of top"</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="k">case</span> <span class="nc">Location</span><span class="o">(</span> <span class="n">t</span><span class="o">,</span> <span class="nc">TreeContext</span><span class="o">(</span> <span class="n">l</span> <span class="o">::</span> <span class="n">left</span><span class="o">,</span> <span class="n">up</span><span class="o">,</span> <span class="n">right</span> <span class="o">)</span> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /> <span class="nc">Location</span><span class="o">(</span> <span class="n">l</span><span class="o">,</span> <span class="nc">TreeContext</span><span class="o">(</span> <span class="n">left</span><span class="o">,</span> <span class="n">up</span><span class="o">,</span> <span class="n">t</span> <span class="o">::</span> <span class="n">right</span> <span class="o">)</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="k">case</span> <span class="nc">Location</span><span class="o">(</span> <span class="n">t</span><span class="o">,</span> <span class="nc">TreeContext</span><span class="o">(</span> <span class="nc">Nil</span><span class="o">,</span> <span class="n">up</span><span class="o">,</span> <span class="n">right</span> <span class="o">)</span> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /> <span class="k">throw</span> <span class="k">new</span> <span class="nc">Exception</span><span class="o">(</span> <span class="s">"left of first"</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="k">def</span> <span class="n">right</span><span class="o">(</span> <span class="n">location</span> <span class="k">:</span> <span class="kt">Location</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="o">)</span> <span class="k">:</span> <span class="kt">Location</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="k">=</span> <span class="o">{</span><br /><span class="n">location</span> <span class="k">match</span> <span class="o">{</span><br /><span class="k">case</span> <span class="nc">Location</span><span class="o">(</span> <span class="n">_</span><span class="o">,</span> <span class="nc">Top</span><span class="o">(</span> <span class="o">)</span> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /> <span class="k">throw</span> <span class="k">new</span> <span class="nc">Exception</span><span class="o">(</span> <span class="s">"right of top"</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="k">case</span> <span class="nc">Location</span><span class="o">(</span> <span class="n">t</span><span class="o">,</span> <span class="nc">TreeContext</span><span class="o">(</span> <span class="n">left</span><span class="o">,</span> <span class="n">up</span><span class="o">,</span> <span class="n">r</span> <span class="o">::</span> <span class="n">right</span> <span class="o">)</span> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /> <span class="nc">Location</span><span class="o">(</span> <span class="n">r</span><span class="o">,</span> <span class="nc">TreeContext</span><span class="o">(</span> <span class="n">t</span> <span class="o">::</span> <span class="n">left</span><span class="o">,</span> <span class="n">up</span><span class="o">,</span> <span class="n">right</span> <span class="o">)</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="k">case</span> <span class="nc">Location</span><span class="o">(</span> <span class="n">t</span><span class="o">,</span> <span class="k">_</span> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /> <span class="k">throw</span> <span class="k">new</span> <span class="nc">Exception</span><span class="o">(</span> <span class="s">"right of last"</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="k">def</span> <span class="n">up</span><span class="o">(</span> <span class="n">location</span> <span class="k">:</span> <span class="kt">Location</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="o">)</span> <span class="k">:</span> <span class="kt">Location</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="k">=</span> <span class="o">{</span><br /><span class="n">location</span> <span class="k">match</span> <span class="o">{</span><br /><span class="k">case</span> <span class="nc">Location</span><span class="o">(</span> <span class="n">_</span><span class="o">,</span> <span class="nc">Top</span><span class="o">(</span> <span class="o">)</span> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /> <span class="k">throw</span> <span class="k">new</span> <span class="nc">Exception</span><span class="o">(</span> <span class="s">"up of top"</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="k">case</span> <span class="nc">Location</span><span class="o">(</span> <span class="n">t</span><span class="o">,</span> <span class="nc">TreeContext</span><span class="o">(</span> <span class="n">left</span><span class="o">,</span> <span class="n">up</span><span class="o">,</span> <span class="n">right</span> <span class="o">)</span> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /> <span class="nc">Location</span><span class="o">(</span> <span class="nc">TreeSection</span><span class="o">(</span> <span class="n">left</span><span class="o">.</span><span class="n">reverse</span> <span class="o">:::</span> <span class="o">(</span> <span class="n">t</span> <span class="o">::</span> <span class="n">right</span> <span class="o">)</span> <span class="o">),</span><br /> <span class="n">up</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="k">def</span> <span class="n">down</span><span class="o">(</span> <span class="n">location</span> <span class="k">:</span> <span class="kt">Location</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="o">)</span> <span class="k">:</span> <span class="kt">Location</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="k">=</span> <span class="o">{</span><br /><span class="n">location</span> <span class="k">match</span> <span class="o">{</span><br /><span class="k">case</span> <span class="nc">Location</span><span class="o">(</span> <span class="nc">TreeItem</span><span class="o">(</span> <span class="k">_</span> <span class="o">),</span> <span class="k">_</span> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /> <span class="k">throw</span> <span class="k">new</span> <span class="nc">Exception</span><span class="o">(</span> <span class="s">"down of item"</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="k">case</span> <span class="nc">Location</span><span class="o">(</span> <span class="nc">TreeSection</span><span class="o">(</span> <span class="nc">Nil</span> <span class="o">),</span> <span class="n">ctxt</span> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /> <span class="k">throw</span> <span class="k">new</span> <span class="nc">Exception</span><span class="o">(</span> <span class="s">"down of empty"</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="k">case</span> <span class="nc">Location</span><span class="o">(</span> <span class="nc">TreeSection</span><span class="o">(</span> <span class="n">u</span> <span class="o">::</span> <span class="n">trees</span> <span class="o">),</span> <span class="n">ctxt</span> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /> <span class="nc">Location</span><span class="o">(</span> <span class="n">u</span><span class="o">,</span> <span class="nc">TreeContext</span><span class="o">(</span> <span class="nc">Nil</span><span class="o">,</span> <span class="n">ctxt</span><span class="o">,</span> <span class="n">trees</span> <span class="o">)</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="o">}</span><br /></pre></div><br /></td></tr></tbody></table></div><br /></div><br /><div>Given the ubiquity of tree-like data structures in computing we can put this to work in lots of situations. Consider, for example, a simple abstract syntax tree representation.</div><div><br /></div><br /><div></div><br /><div id="paste" class="lang-scala code"><br /><div class="code"><table class="syntaxtable"><tbody><tr><td class="linenos"><div class="linenodiv"><pre> 1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63</pre></div></td><td class="code"><div class="syntax"><pre><span class="k">case</span> <span class="k">class</span> <span class="nc">Token</span><span class="o">[</span><span class="kt">A</span><span class="o">](</span><br /><span class="k">override</span> <span class="n">item</span> <span class="k">:</span> <span class="kt">A</span><br /><span class="o">)</span> <span class="k">extends</span> <span class="nc">TreeItem</span><span class="o">[</span><span class="kt">A</span><span class="o">](</span> <span class="n">item</span> <span class="o">)</span><br /><span class="k">case</span> <span class="k">class</span> <span class="nc">AST</span><span class="o">[</span><span class="kt">A</span><span class="o">](</span><br /><span class="k">override</span> <span class="n">section</span> <span class="k">:</span> <span class="kt">List</span><span class="o">[</span><span class="kt">Tree</span><span class="o">[</span><span class="kt">A</span><span class="o">]]</span><br /><span class="o">)</span> <span class="k">extends</span> <span class="nc">TreeSection</span><span class="o">[</span><span class="kt">A</span><span class="o">](</span> <span class="n">section</span> <span class="o">)</span><br /><br /><span class="k">object</span> <span class="nc">Exercise</span> <span class="k">extends</span> <span class="nc">ZipperNavigation</span><span class="o">[</span><span class="kt">String</span><span class="o">]</span> <span class="o">{</span><br /><span class="k">val</span> <span class="n">arithmeticExpr1</span> <span class="k">=</span><br /><span class="nc">AST</span><span class="o">[</span><span class="kt">String</span><span class="o">](</span><br /><span class="nc">List</span><span class="o">(</span><br /><span class="nc">AST</span><span class="o">[</span><span class="kt">String</span><span class="o">](</span><br /> <span class="nc">List</span><span class="o">(</span><br /> <span class="nc">Token</span><span class="o">[</span><span class="kt">String</span><span class="o">](</span> <span class="s">"a"</span> <span class="o">),</span><br /> <span class="nc">Token</span><span class="o">[</span><span class="kt">String</span><span class="o">](</span> <span class="s">"*"</span> <span class="o">),</span><br /> <span class="nc">Token</span><span class="o">[</span><span class="kt">String</span><span class="o">](</span> <span class="s">"b"</span> <span class="o">)</span><br /> <span class="o">)</span><br /><span class="o">),</span><br /><span class="nc">Token</span><span class="o">[</span><span class="kt">String</span><span class="o">](</span> <span class="s">"+"</span> <span class="o">),</span><br /><span class="nc">AST</span><span class="o">[</span><span class="kt">String</span><span class="o">](</span><br /> <span class="nc">List</span><span class="o">(</span><br /> <span class="nc">Token</span><span class="o">[</span><span class="kt">String</span><span class="o">](</span> <span class="s">"c"</span> <span class="o">),</span><br /> <span class="nc">Token</span><span class="o">[</span><span class="kt">String</span><span class="o">](</span> <span class="s">"*"</span> <span class="o">),</span><br /> <span class="nc">Token</span><span class="o">[</span><span class="kt">String</span><span class="o">](</span> <span class="s">"d"</span> <span class="o">)</span><br /> <span class="o">)</span><br /><span class="o">)</span><br /><span class="o">)</span><br /><span class="o">)</span><br /><span class="k">val</span> <span class="n">locationOf2ndMult</span> <span class="k">=</span><br /><span class="nc">Location</span><span class="o">[</span><span class="kt">String</span><span class="o">](</span><br /><span class="nc">Token</span><span class="o">[</span><span class="kt">String</span><span class="o">](</span> <span class="s">"*"</span> <span class="o">),</span><br /><span class="nc">TreeContext</span><span class="o">[</span><span class="kt">String</span><span class="o">](</span><br /><span class="nc">List</span><span class="o">(</span> <span class="nc">Token</span><span class="o">[</span><span class="kt">String</span><span class="o">](</span> <span class="s">"c"</span> <span class="o">)</span> <span class="o">),</span><br /><span class="nc">TreeContext</span><span class="o">[</span><span class="kt">String</span><span class="o">](</span><br /> <span class="nc">List</span><span class="o">(</span><br /> <span class="nc">Token</span><span class="o">[</span><span class="kt">String</span><span class="o">](</span> <span class="s">"+"</span> <span class="o">),</span><br /> <span class="nc">AST</span><span class="o">[</span><span class="kt">String</span><span class="o">](</span><br /> <span class="nc">List</span><span class="o">(</span><br /><span class="nc">Token</span><span class="o">[</span><span class="kt">String</span><span class="o">](</span> <span class="s">"a"</span> <span class="o">),</span><br /><span class="nc">Token</span><span class="o">[</span><span class="kt">String</span><span class="o">](</span> <span class="s">"*"</span> <span class="o">),</span><br /><span class="nc">Token</span><span class="o">[</span><span class="kt">String</span><span class="o">](</span> <span class="s">"b"</span> <span class="o">)</span><br /> <span class="o">)</span><br /> <span class="o">)</span><br /> <span class="o">),</span><br /> <span class="nc">Top</span><span class="o">(</span> <span class="o">),</span><br /> <span class="nc">List</span><span class="o">(</span> <span class="o">)</span><br /> <span class="o">),</span><br /><span class="nc">List</span><span class="o">(</span> <span class="nc">Token</span><span class="o">[</span><span class="kt">String</span><span class="o">](</span> <span class="s">"d"</span> <span class="o">)</span> <span class="o">)</span><br /><span class="o">)</span><br /><span class="o">)</span><br /><span class="k">def</span> <span class="n">show</span><span class="o">(</span> <span class="n">depth</span> <span class="k">:</span> <span class="kt">Int</span> <span class="o">)(</span> <span class="n">tree</span> <span class="k">:</span> <span class="kt">Tree</span><span class="o">[</span><span class="kt">String</span><span class="o">]</span> <span class="o">)</span> <span class="k">:</span> <span class="kt">Unit</span> <span class="o">=</span> <span class="o">{</span><br /><span class="n">tree</span> <span class="k">match</span> <span class="o">{</span><br /><span class="k">case</span> <span class="nc">TreeItem</span><span class="o">(</span> <span class="n">item</span> <span class="k">:</span> <span class="kt">String</span> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /><span class="k">val</span> <span class="n">indent</span> <span class="k">=</span><br /><span class="o">(</span> <span class="s">""</span> <span class="o">/:</span> <span class="o">(</span><span class="mi">1</span> <span class="n">to</span> <span class="n">depth</span><span class="o">)</span> <span class="o">)(</span> <span class="o">{</span> <span class="o">(</span> <span class="n">acc</span><span class="o">,</span> <span class="n">d</span> <span class="o">)</span> <span class="k">=></span> <span class="n">acc</span> <span class="o">+</span> <span class="s">" "</span> <span class="o">}</span> <span class="o">)</span><br /><span class="n">println</span><span class="o">(</span> <span class="n">indent</span> <span class="o">+</span> <span class="s">"Leaf : "</span> <span class="o">+</span> <span class="n">item</span> <span class="o">)</span><br /><span class="o">}</span><br /><span class="k">case</span> <span class="nc">TreeSection</span><span class="o">(</span> <span class="n">section</span> <span class="k">:</span> <span class="kt">List</span><span class="o">[</span><span class="kt">Tree</span><span class="o">[</span><span class="kt">String</span><span class="o">]]</span> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /><span class="k">for</span><span class="o">(</span> <span class="n">t</span> <span class="k"><-</span> <span class="n">section</span> <span class="o">){</span> <span class="n">show</span><span class="o">(</span> <span class="n">depth</span> <span class="o">+</span> <span class="mi">2</span> <span class="o">)(</span> <span class="n">t</span> <span class="o">)</span> <span class="o">}</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="o">}</span><br /><span class="o">}</span><br /></pre></div><br /></td></tr></tbody></table></div><br /></div><br /><div>An instance of an AST for the arithmetic expression a*b + c*d would be given by the first value in the object above; and the location of the second multiplication sign, "*", is represented by the second value.</div><br /><div></div><br /><div>Now, we can navigate around this example.</div><br /><div></div><br /><div id="paste" class="lang-scala code"><br /><div class="code"><table class="syntaxtable"><tbody><tr><td class="linenos"><div class="linenodiv"><pre> 1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39</pre></div></td><td class="code"><div class="syntax"><pre><span class="n">scala</span><span class="o">></span> <span class="k">import</span> <span class="nn">Exercise._</span><br /><span class="k">import</span> <span class="nn">Exercise._</span><br /><span class="k">import</span> <span class="nn">Exercise._</span><br /><br /><span class="n">scala</span><span class="o">></span> <span class="n">show</span><span class="o">(</span> <span class="mi">0</span> <span class="o">)(</span> <span class="n">arithmeticExpr1</span> <span class="o">)</span><br /><span class="n">show</span><span class="o">(</span> <span class="mi">0</span> <span class="o">)(</span> <span class="n">arithmeticExpr1</span> <span class="o">)</span><br /><span class="nc">Leaf</span> <span class="k">:</span> <span class="kt">a</span><br /><span class="nc">Leaf</span> <span class="k">:</span> <span class="kt">*</span><br /><span class="nc">Leaf</span> <span class="k">:</span> <span class="kt">b</span><br /><span class="nc">Leaf</span> <span class="k">:</span> <span class="kt">+</span><br /><span class="nc">Leaf</span> <span class="k">:</span> <span class="kt">c</span><br /><span class="nc">Leaf</span> <span class="k">:</span> <span class="kt">*</span><br /><span class="nc">Leaf</span> <span class="k">:</span> <span class="kt">d</span><br /><br /><span class="n">scala</span><span class="o">></span> <span class="n">show</span><span class="o">(</span> <span class="mi">0</span> <span class="o">)(</span> <span class="n">locationOf2ndMult</span><span class="o">.</span><span class="n">tree</span> <span class="o">)</span><br /><span class="n">show</span><span class="o">(</span> <span class="mi">0</span> <span class="o">)(</span> <span class="n">locationOf2ndMult</span><span class="o">.</span><span class="n">tree</span> <span class="o">)</span><br /><span class="nc">Leaf</span> <span class="k">:</span> <span class="kt">*</span><br /><br /><span class="n">scala</span><span class="o">></span> <span class="n">show</span><span class="o">(</span> <span class="mi">0</span> <span class="o">)(</span> <span class="n">up</span><span class="o">(</span> <span class="n">locationOf2ndMult</span> <span class="o">).</span><span class="n">tree</span> <span class="o">)</span><br /><span class="n">show</span><span class="o">(</span> <span class="mi">0</span> <span class="o">)(</span> <span class="n">up</span><span class="o">(</span> <span class="n">locationOf2ndMult</span> <span class="o">).</span><span class="n">tree</span> <span class="o">)</span><br /><span class="nc">Leaf</span> <span class="k">:</span> <span class="kt">c</span><br /><span class="nc">Leaf</span> <span class="k">:</span> <span class="kt">*</span><br /><span class="nc">Leaf</span> <span class="k">:</span> <span class="kt">d</span><br /><br /><span class="n">scala</span><span class="o">></span> <span class="n">show</span><span class="o">(</span> <span class="mi">0</span> <span class="o">)(</span> <span class="n">up</span><span class="o">(</span> <span class="n">up</span><span class="o">(</span> <span class="n">locationOf2ndMult</span> <span class="o">)</span> <span class="o">).</span><span class="n">tree</span> <span class="o">)</span><br /><span class="n">show</span><span class="o">(</span> <span class="mi">0</span> <span class="o">)(</span> <span class="n">up</span><span class="o">(</span> <span class="n">up</span><span class="o">(</span> <span class="n">locationOf2ndMult</span> <span class="o">)</span> <span class="o">).</span><span class="n">tree</span> <span class="o">)</span><br /><span class="nc">Leaf</span> <span class="k">:</span> <span class="kt">a</span><br /><span class="nc">Leaf</span> <span class="k">:</span> <span class="kt">*</span><br /><span class="nc">Leaf</span> <span class="k">:</span> <span class="kt">b</span><br /><span class="nc">Leaf</span> <span class="k">:</span> <span class="kt">+</span><br /><span class="nc">Leaf</span> <span class="k">:</span> <span class="kt">c</span><br /><span class="nc">Leaf</span> <span class="k">:</span> <span class="kt">*</span><br /><span class="nc">Leaf</span> <span class="k">:</span> <span class="kt">d</span><br /><br /><span class="n">scala</span><span class="o">></span> <span class="n">show</span><span class="o">(</span> <span class="mi">0</span> <span class="o">)(</span> <span class="n">up</span><span class="o">(</span> <span class="n">up</span><span class="o">(</span> <span class="n">up</span><span class="o">(</span> <span class="n">locationOf2ndMult</span> <span class="o">)</span> <span class="o">)</span> <span class="o">).</span><span class="n">tree</span> <span class="o">)</span><br /><span class="n">show</span><span class="o">(</span> <span class="mi">0</span> <span class="o">)(</span> <span class="n">up</span><span class="o">(</span> <span class="n">up</span><span class="o">(</span> <span class="n">up</span><span class="o">(</span> <span class="n">locationOf2ndMult</span> <span class="o">)</span> <span class="o">)</span> <span class="o">).</span><span class="n">tree</span> <span class="o">)</span><br /><span class="n">java</span><span class="o">.</span><span class="n">lang</span><span class="o">.</span><span class="nc">Exception</span><span class="k">:</span> <span class="kt">up</span> <span class="kt">of</span> <span class="kt">top</span><br /> <span class="o">...</span><br /><span class="n">scala</span><span class="o">></span><br /></pre></div><br /></td></tr></tbody></table></div></div><div id="paste" class="lang-scala code"><br /></div><div id="paste" class="lang-scala code"><br /></div><br /><div>Of course, the real desiderata are the mutation functions.</div><br /><div id="paste" class="lang-scala code"><br /> <div class="code"><table class="syntaxtable"><tbody><tr><td class="linenos"><div class="linenodiv"><pre> 1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99</pre></div></td><td class="code"><div class="syntax"><pre><span class="k">trait</span> <span class="nc">ZipperMutation</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="o">{</span><br /> <span class="k">def</span> <span class="n">update</span><span class="o">(</span><br /> <span class="n">location</span> <span class="k">:</span> <span class="kt">Location</span><span class="o">[</span><span class="kt">A</span><span class="o">],</span><br /> <span class="n">tree</span> <span class="k">:</span> <span class="kt">Tree</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span><br /> <span class="o">)</span> <span class="k">:</span> <span class="kt">Location</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="k">=</span> <span class="o">{</span><br /> <span class="n">location</span> <span class="k">match</span> <span class="o">{</span><br /> <span class="k">case</span> <span class="nc">Location</span><span class="o">(</span> <span class="n">_</span><span class="o">,</span> <span class="n">ctxt</span> <span class="o">)</span> <span class="k">=></span><br /><span class="nc">Location</span><span class="o">(</span> <span class="n">tree</span><span class="o">,</span> <span class="n">ctxt</span> <span class="o">)</span><br /> <span class="o">}</span><br /> <span class="o">}</span><br /> <span class="k">def</span> <span class="n">insertRight</span><span class="o">(</span><br /> <span class="n">location</span> <span class="k">:</span> <span class="kt">Location</span><span class="o">[</span><span class="kt">A</span><span class="o">],</span><br /> <span class="n">tree</span> <span class="k">:</span> <span class="kt">Tree</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span><br /> <span class="o">)</span> <span class="k">:</span> <span class="kt">Location</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="k">=</span> <span class="o">{</span><br /> <span class="n">location</span> <span class="k">match</span> <span class="o">{</span><br /> <span class="k">case</span> <span class="nc">Location</span><span class="o">(</span> <span class="n">_</span><span class="o">,</span> <span class="nc">Top</span><span class="o">(</span> <span class="o">)</span> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /><span class="k">throw</span> <span class="k">new</span> <span class="nc">Exception</span><span class="o">(</span> <span class="s">"insert of top"</span> <span class="o">)</span><br /> <span class="o">}</span><br /> <span class="k">case</span> <span class="nc">Location</span><span class="o">(</span><br /><span class="n">curr</span><span class="o">,</span><br /><span class="nc">TreeContext</span><span class="o">(</span> <span class="n">left</span><span class="o">,</span> <span class="n">up</span><span class="o">,</span> <span class="n">right</span> <span class="o">)</span><br /> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /><span class="nc">Location</span><span class="o">(</span><br /> <span class="n">curr</span><span class="o">,</span><br /> <span class="nc">TreeContext</span><span class="o">(</span> <span class="n">left</span><span class="o">,</span> <span class="n">up</span><span class="o">,</span> <span class="n">tree</span> <span class="o">::</span> <span class="n">right</span> <span class="o">)</span><br /><span class="o">)</span><br /> <span class="o">}</span><br /> <span class="o">}</span> <br /> <span class="o">}</span><br /> <span class="k">def</span> <span class="n">insertLeft</span><span class="o">(</span><br /> <span class="n">location</span> <span class="k">:</span> <span class="kt">Location</span><span class="o">[</span><span class="kt">A</span><span class="o">],</span> <span class="n">tree</span> <span class="k">:</span> <span class="kt">Tree</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span><br /> <span class="o">)</span> <span class="k">:</span> <span class="kt">Location</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="k">=</span> <span class="o">{</span><br /> <span class="n">location</span> <span class="k">match</span> <span class="o">{</span><br /> <span class="k">case</span> <span class="nc">Location</span><span class="o">(</span> <span class="n">_</span><span class="o">,</span> <span class="nc">Top</span><span class="o">(</span> <span class="o">)</span> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /><span class="k">throw</span> <span class="k">new</span> <span class="nc">Exception</span><span class="o">(</span> <span class="s">"insert of top"</span> <span class="o">)</span><br /> <span class="o">}</span><br /> <span class="k">case</span> <span class="nc">Location</span><span class="o">(</span><br /><span class="n">curr</span><span class="o">,</span><br /><span class="nc">TreeContext</span><span class="o">(</span> <span class="n">left</span><span class="o">,</span> <span class="n">up</span><span class="o">,</span> <span class="n">right</span> <span class="o">)</span><br /> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /><span class="nc">Location</span><span class="o">(</span><br /> <span class="n">curr</span><span class="o">,</span><br /> <span class="nc">TreeContext</span><span class="o">(</span> <span class="n">tree</span> <span class="o">::</span> <span class="n">left</span><span class="o">,</span> <span class="n">up</span><span class="o">,</span> <span class="n">right</span> <span class="o">)</span><br /><span class="o">)</span><br /> <span class="o">}</span><br /> <span class="o">}</span> <br /> <span class="o">}</span><br /> <span class="k">def</span> <span class="n">insertDown</span><span class="o">(</span><br /> <span class="n">location</span> <span class="k">:</span> <span class="kt">Location</span><span class="o">[</span><span class="kt">A</span><span class="o">],</span> <span class="n">tree</span> <span class="k">:</span> <span class="kt">Tree</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span><br /> <span class="o">)</span> <span class="k">:</span> <span class="kt">Location</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="k">=</span> <span class="o">{</span><br /> <span class="n">location</span> <span class="k">match</span> <span class="o">{</span><br /> <span class="k">case</span> <span class="nc">Location</span><span class="o">(</span> <span class="nc">TreeItem</span><span class="o">(</span> <span class="k">_</span> <span class="o">),</span> <span class="k">_</span> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /><span class="k">throw</span> <span class="k">new</span> <span class="nc">Exception</span><span class="o">(</span> <span class="s">"down of item"</span> <span class="o">)</span><br /> <span class="o">}</span><br /> <span class="k">case</span> <span class="nc">Location</span><span class="o">(</span><br /><span class="nc">TreeSection</span><span class="o">(</span> <span class="n">progeny</span> <span class="o">),</span><br /><span class="n">ctxt</span><br /> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /><span class="nc">Location</span><span class="o">(</span><br /> <span class="n">tree</span><span class="o">,</span><br /> <span class="nc">TreeContext</span><span class="o">(</span> <span class="nc">Nil</span><span class="o">,</span> <span class="n">ctxt</span><span class="o">,</span> <span class="n">progeny</span> <span class="o">)</span><br /><span class="o">)</span><br /> <span class="o">}</span><br /> <span class="o">}</span><br /> <span class="o">}</span><br /> <span class="k">def</span> <span class="n">delete</span><span class="o">(</span><br /> <span class="n">location</span> <span class="k">:</span> <span class="kt">Location</span><span class="o">[</span><span class="kt">A</span><span class="o">],</span> <span class="n">tree</span> <span class="k">:</span> <span class="kt">Tree</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span><br /> <span class="o">)</span> <span class="k">:</span> <span class="kt">Location</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="k">=</span> <span class="o">{</span><br /> <span class="n">location</span> <span class="k">match</span> <span class="o">{</span><br /> <span class="k">case</span> <span class="nc">Location</span><span class="o">(</span> <span class="n">_</span><span class="o">,</span> <span class="nc">Top</span><span class="o">(</span> <span class="o">)</span> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /><span class="k">throw</span> <span class="k">new</span> <span class="nc">Exception</span><span class="o">(</span> <span class="s">"delete of top"</span> <span class="o">)</span><br /> <span class="o">}</span><br /> <span class="k">case</span> <span class="nc">Location</span><span class="o">(</span><br /><span class="n">_</span><span class="o">,</span><br /><span class="nc">TreeContext</span><span class="o">(</span> <span class="n">left</span><span class="o">,</span> <span class="n">up</span><span class="o">,</span> <span class="n">r</span> <span class="o">::</span> <span class="n">right</span> <span class="o">)</span><br /> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /><span class="nc">Location</span><span class="o">(</span><br /> <span class="n">r</span><span class="o">,</span><br /> <span class="nc">TreeContext</span><span class="o">(</span> <span class="n">left</span><span class="o">,</span> <span class="n">up</span><span class="o">,</span> <span class="n">right</span> <span class="o">)</span><br /><span class="o">)</span><br /> <span class="o">}</span><br /> <span class="k">case</span> <span class="nc">Location</span><span class="o">(</span><br /><span class="n">_</span><span class="o">,</span><br /><span class="nc">TreeContext</span><span class="o">(</span> <span class="n">l</span> <span class="o">::</span> <span class="n">left</span><span class="o">,</span> <span class="n">up</span><span class="o">,</span> <span class="nc">Nil</span> <span class="o">)</span><br /> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /><span class="nc">Location</span><span class="o">(</span><br /> <span class="n">l</span><span class="o">,</span><br /> <span class="nc">TreeContext</span><span class="o">(</span> <span class="n">left</span><span class="o">,</span> <span class="n">up</span><span class="o">,</span> <span class="nc">Nil</span> <span class="o">)</span><br /><span class="o">)</span><br /> <span class="o">}</span><br /> <span class="k">case</span> <span class="nc">Location</span><span class="o">(</span><br /><span class="n">_</span><span class="o">,</span><br /><span class="nc">TreeContext</span><span class="o">(</span> <span class="nc">Nil</span><span class="o">,</span> <span class="n">up</span><span class="o">,</span> <span class="nc">Nil</span> <span class="o">)</span><br /> <span class="o">)</span> <span class="k">=></span> <span class="o">{</span><br /><span class="nc">Location</span><span class="o">(</span> <span class="nc">TreeSection</span><span class="o">(</span> <span class="nc">Nil</span> <span class="o">),</span> <span class="n">up</span> <span class="o">)</span><br /> <span class="o">}</span><br /> <span class="o">}</span><br /> <span class="o">}</span><br /><span class="o">}</span><br /></pre></div><br /></td></tr></tbody></table></div><br /> </div><br /><div>In the next post we'll show how we don't have to design the <span class="Apple-style-span" style="font-family:'courier new';">Context</span> and <span class="Apple-style-span" style="font-family:'courier new';">Location</span> types by hand. They can be derived from the container type -- in this case, <span class="Apple-style-span" style="font-family:'courier new';">Tree</span>.</div>leithaushttp://www.blogger.com/profile/01069099703796397027noreply@blogger.com13tag:blogger.com,1999:blog-3049258033565653738.post-27541466984501222052009-12-29T23:11:00.000-08:002009-12-31T05:25:26.001-08:00The place for forceIn the last post we discussed a method of representing of finite geometries as terms in a computational calculus. The background aim of this endeavor is to re-situate Einstein's physical intuitions about geometry, gravity, mass and energy in a new formalism; and, the background aim of that endeavor is to construct, out of a computational formalism, a physical theory that includes both quantum mechanics and general relativity. In short, the aim is to get "it from bit" in a way that unifies gravitation with quantum mechanics.<br /><br />With that in mind, the purpose of a framework to study evolving discrete geometry should be clear, but where is the place for force in all of this? That's where the choice of the particular variant of the π-calculus becomes relevant. In a reflective higher-order calculus there is a rich structure on names, which is a place to host a rich "synchronization algebra", i.e. the algebraic structure determining when two names are triggers of a process synchronization. In the ordinary π-calculus, it is name equality that does this job. The simplest form of synchronization comes from the comm rule, such as the one for a monadic, asynchronous calculus like this one<br /><br /><div style="text-align: center;"><span style="font-family:courier new;">x?(y).P | x!(v) -> P{v/y}</span><br /></div><br />In a reflective higher-order calculus names have internal structure deriving from the structure of process terms. This gives a very rich setting to express synchronization constraints. In a previous post we described one we call annihilation.<br /><br /><div style="text-align: center;"><span style="font-family:courier new;"> s = @S, t = @T, ∀ R. S|T →* R => R →* 0</span><br /></div><div style="text-align: center;"><span style="font-family:courier new;">------------------------------------------</span><br /></div><div style="text-align: center;"><span style="font-family:courier new;"> s?(y)P | t!(Q) → P{@Q/y}</span><br /></div><span style="font-family:courier new;"><br /></span>This comm rule says that if (this is all the stuff above the horizontal line) <span style="font-family:courier new;">s</span> is the transcription (aka code) of some process, <span style="font-family:courier new;">S</span>, and <span style="font-family:courier new;">t</span> the transcription of some process <span style="font-family:courier new;">T</span> and that whenever you run <span style="font-family:courier new;">S</span> and <span style="font-family:courier new;">T</span> in parallel composition together whenever they (eventually) reduce to a state <span style="font-family:courier new;">R</span>, that state (eventually) reduces to <span style="font-family:courier new;">0</span>,<br /><br />then (this is all the stuff below the horizontal line) <span style="font-family:courier new;">s</span> and <span style="font-family:courier new;">t</span> can be used to synchronize for an interaction that results in a substitution. This basic idea can be used to provide a template for different kinds of force. Before we discuss that thought, however, the attentive reader might be wondering about something. If the "comm" rule is the most basic of the rules governing reduction, but it mentions reduction in its hypothesis, is this rule well-founded? Will it ever allow reduction to take place?<br /><br />The answer is 'yes'! Note that we require that <span style="font-family:courier new;">0</span> is the unit of the parallel composition monoid and so <span style="font-family:courier new;">0|0 = 0</span> ; similarly, and after no steps we get from termination to termination, or in symbols <span style="font-family:courier new;">0 →* 0</span>. From these two facts we have <span style="font-family:courier new;">@0</span> can be used as a channel to synchronize with itself. Taking one step further we see that <span style="font-family:courier new;">@(@0?(y)0)</span> can be used to synchronize with <span style="font-family:courier new;">@(@0!(0))</span>. More generally, the reader may verify, we have that processes that cancel each other out, matching every output with an input, (alternatively said, imposing a kind of linear discipline on i/o) can be used to provide the codes for channels that can be used to synchronize. Hence the name: annihilation.<br /><br />Returning to the topic at hand, the thought is that running the check for annihilation -- which amounts to exhaustive execution of the processes the codes of which are the subjects of guards -- provides a natural vehicle in which to express force. The intuition is that the less complex the annihilation calculation the stronger the force. An example may prove illustrative. Consider the following race condition<br /><br /><div style="text-align: center;"> <span style="font-family:courier new;">x</span><sub style="font-family: courier new;">l</sub><span style="font-family:courier new;">!( Q</span><sub style="font-family: courier new;">l</sub><span style="font-family:courier new;"> ) | x?( y )P | x</span><sub style="font-family: courier new;">r</sub><span style="font-family:courier new;">!( Q</span><sub style="font-family: courier new;">r</sub><span style="font-family:courier new;"> )</span><br /></div><br />Suppose that the check that <span style="font-family:courier new;">x</span><sub style="font-family: courier new;">l</sub> annihilated <span style="font-family:courier new;">x</span> was simply more complex than the check that <span style="font-family:courier new;">x</span><sub style="font-family: courier new;">r</sub> annihilated <span style="font-family:courier new;">x</span>. Intuition suggests that the race is more often won by the less complex check. The effect, therefore, is a certain tendency to evolve in one way over another. To an outside observer this looks like a force between <span style="font-family:courier new;">x</span> and <span style="font-family:courier new;">x</span><sub style="font-family: courier new;">r</sub>. Well, if it looks like a force and feels like a force and quacks like a force... why not investigate whether this might not be a sufficient framework to model force?<br /><br />One important aspect of the construction of this model is that the choice of synchronization algebra is nearly independent of the method of modeling the geometry. However, once we have a geometrical structure, how the geometry is likely to evolve is determined by the synchronization algebra. In other words we are building up our model of physics in a <span style="font-style: italic;">compositional</span> manner. Another important aspect of this particular modeling choice is that it has enough structure to construct many apparently different types of forces -- roughly aligned to complexity classes of the annihilation calculation -- but there is only <span style="font-style: italic;">one</span> notion of force: the complexity of annihilation.<br /><br />Again, this is starting feel like it's moving in an interesting direction, but it raises a host of very challenging questions. In this model, because of the way the structure-behavior relationship is repackaged, we do not need a "differential structure" to host an expression of dynamics. The gold standard, however, of physical theories are general relativity and quantum mechanics. The first of these (and arguably the second) is certainly dependent on a notion of derivative to express dynamics. If we are to judge the quality of this alternate approach we have to build a means of comparison. Ideally, we would like to find an interpretation mapping the standard expression of these physical theories into the new model. A question that stands out when contemplating such a mapping is how to interpret the derivative -- and in particular its relationship to dynamics -- in this alternate model?leithaushttp://www.blogger.com/profile/01069099703796397027noreply@blogger.com0tag:blogger.com,1999:blog-3049258033565653738.post-2118958700430021962009-12-28T13:31:00.000-08:002009-12-31T15:39:40.015-08:00The secret life of space<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhP2cs9DhS5UT9Tg19yPjO6Ij8FadklewV5YBsdPXQIH4-J5vaGE6XTwe6bss5qz6yUsGwHdDQX3_Psa1L8jIrBbOeQOTN7mcKkc0p0VjgdmMinkxUyr_NlIcAGIsBtTDmt3ZP3nOpMS2lu/s1600-h/Fano+plane.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 250px; height: 250px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhP2cs9DhS5UT9Tg19yPjO6Ij8FadklewV5YBsdPXQIH4-J5vaGE6XTwe6bss5qz6yUsGwHdDQX3_Psa1L8jIrBbOeQOTN7mcKkc0p0VjgdmMinkxUyr_NlIcAGIsBtTDmt3ZP3nOpMS2lu/s400/Fano+plane.png" alt="" id="BLOGGER_PHOTO_ID_5420404186648302098" border="0" /></a><br /><div><br /></div><div><br /></div><div>Over Christmas i took the time to code up a <a href="http://en.wikipedia.org/wiki/Pi_calculus">π-calculus</a> representation of the <a href="http://en.wikipedia.org/wiki/Fano_plane">Fano plane</a>. [1] <span class="Apple-style-span" style="color: rgb(51, 51, 51); line-height: 20px;"><span class="Apple-style-span" style="color: rgb(0, 0, 0);"><span class="Apple-style-span" style="font-size:small;">From a layman's point of view, you can think of this as a very specific way to write a computer program that represents the information of the Fano plane. </span></span><span class="Apple-style-span" style="color: rgb(0, 0, 0); line-height: normal;"><span class="Apple-style-span" style="line-height: 20px;"><span class="Apple-style-span" style="font-size:small;">What is novel about this is that the program can evolve. As it evolves it can turn into other <a href="http://en.wikipedia.org/wiki/Projective_geometry">projective geometries</a></span></span><span class="Apple-style-span" style="line-height: 20px;"><span class="Apple-style-span" style="font-size:small;">.</span></span><span class="Apple-style-span" style="color: rgb(51, 51, 51); line-height: 20px;"><span class="Apple-style-span" style="font-size:small;"> </span></span><span class="Apple-style-span" style="font-size:small;">This blog records some of my motivations for engaging in this kind of activity. </span></span></span></div><div><br /></div><div>Imagine that the <a href="http://en.wikipedia.org/wiki/Quantum_mechanics#Relativity_and_quantum_mechanics">issues around the reconciliation</a> of <a href="http://en.wikipedia.org/wiki/Quantum_mechanics">quantum mechanics</a> and <a href="http://en.wikipedia.org/wiki/General_relativity">general relativity</a> have to do with a sort of impedance mismatch of the devices used to capture the intuitions -- not the intuitions themselves. i've long thought that Einstein's intuitions would be better expressed in a different sort of formalism. In particular, i think certain computational formalisms in which there is a different account of the structure-behavior relationship have the promise of being better containers for Einstein's intuitions. Remember -- after all -- Mr E had to essentially invent much of the apparatus he eventually used to express his ideas. Often the first container is not the sleekest or best suited to the job. Compare the model T to the Prius or the Kittyhawk to the 787.</div><div><br /></div><div>Certain models of computation have hit on a novel combination. To understand the technical and historical novelty you need to understand that in classical approaches to modeling the relationship between structural (or even kinematic) aspects and behavioral aspects of physical phenomena there is a clear dividing line. Algebraic structure encodes structure, and maps or functions between algebraic structure encodes behavior. The classic example of this is <a href="http://en.wikipedia.org/wiki/Linear_algebra">linear algebra</a>. Vector spaces are where you encode state. Maps between vectors spaces are where you encode behavior.</div><div><br /></div><div>Now, certain families of computational calculi -- notably lambda and π-calculi -- do not endure this division of labor. Rather, behavior is "folded into" the specification of the structure. You have a 3-fold spec: an algebra (the grammar of the terms in the model), a structural equivalence (saying which "syntactic differences" can be treated as noise), and a reduction relation -- which says how terms (aka programs) behave or evolve. (See, for example, <a href="https://docs.google.com/Doc?docid=0AZI9qM5f_1cfZGc5NnM5d25fNTE5Z2RmZGJoZGg&hl=en">this specification</a> of the variant of the π-calculus i used to construct my encoding.)<br /></div><div><br /></div><div>This is a novel way to package structure and behavior. The novelty has had some interesting technical and cultural consequences, but that's beside the point. The main point is that this packaging makes these calculi intriguing candidates for encoding Einstein's intuitions about the relationship of geometry, gravity, mass and energy.</div><div><br /></div><div>Of course, one of the tricky things about these calculi is finding notions of geometry inside them. Direct (but not entirely simple-minded) <a href="http://en.wikipedia.org/wiki/Scott_continuity">interpretations of the topological structure of these formalisms</a> get you things that are not even <a href="http://en.wikipedia.org/wiki/Hausdorff_space">T-2</a> -- that is, do not even enjoy certain basic separation properties that we think must hold in models of physical space. So, how do you get geometry to show up in these types of formalisms?</div><div><br /></div><div>One approach is to encode the geometry. On one level we know this must be possible, because both the lambda calculus and the π-calculus are Turing complete. So, since we know we can encode convincing simulations of (the geometry of) physical space as ordinary programs, we know we can encode them in the lambda or π-calculus. However, the question remains whether that encoding bears any relationship to the fundamental machinery of the computational model. In other words will it be of any use to encode these notions in the model, or will it just be another formal representation -- potentially with more baggage to push around.</div><div><br /></div><div>That's where employing certain principles -- principles we have picked up from working with computation -- comes into play. Notably, when the structure of the encoding is in alignment with something called the <a href="http://en.wikipedia.org/wiki/Curry%E2%80%93Howard_correspondence">Curry-Howard isomorphism</a>, it enjoys certain properties. It's another long discussion to try to explain what those properties are and what they offer to this endeavor. Suffice it to say that encodings enjoying this discipline are more easily aligned with a whole host of other structures and so are more easily probed and more easily beaten into layers of abstraction that simplify pushing baggage around.</div><div><br /></div><div>So, i've now exhibited a very simple-minded encoding of the simplest of <a href="http://en.wikipedia.org/wiki/Projective_geometry">projective geometries</a>, the Fano plane, into one of the computational calculi, the π-calculus. The encoding aligns with the Curry-Howard isomorphism in a specific way. From a layman's point of view, you can think of this as a very specific way to write a computer program that represents the information of the Fano plane.</div><div><br /></div><div>What is novel about this is that program can evolve. As it evolves it can turn into other projective geometries. That's starting to feel more closely aligned with Einstein's program -- while being far from a full expression of his ideas. i can't begin to calculate <a href="http://en.wikipedia.org/wiki/Tests_of_general_relativity">the precession of the perihelion of Mercury</a>. On the other hand, i have a good handle on how to import the recent work by <a href="http://arxiv.org/abs/0910.3920">Abramsky and Coecke on axiomatic quantum mechanics</a> into this framework -- a pay-off of respecting Curry-Howard.</div><div><br /></div><div>The 'Doh!' moment i had over Christmas was that this sort of task was in my grasp years ago. i've already demonstrated a somewhat more challenging encoding -- encoding knots as processes in the π-calculus. But, it just never occurred to me to start with the Fano plane and work out the simplest encoding that exhibited all the desiderata. Again, this simple-minded effort raises many, many more questions than it answers, but it's still pretty cool, nonetheless.</div><div><br /></div><div>There is an intriguing connection with biology that has occurred to me ever since i began this research program. i confess the idea is not mine, but <a href="http://en.wikipedia.org/wiki/Christopher_Alexander">Christopher Alexander</a>'s. In his seminal work, <a href="http://www.natureoforder.com/">The Nature of Order</a>, this world class architect suggests that 'life' is an objective property of space. He suggests that there are objective, consensually validatable properties of space that allow us to gauge which configurations of space have more life.</div><div><br /></div><div>Since i began investigating geometry itself as an outcome of information-processing behavior i reached the startling conclusion that there might be something to his idea. Specifically, a number of folks from <a href="http://lucacardelli.name/BioComputing.htm">Cardelli to Priami</a>, have shown that biological processes -- from signal-processing to immunological behavior -- have relatively straightforward representations in the formalism i have been using to represent geometry.</div><div><br /></div><div>To reiterate, Priami, Regev, Silverman, et al, have represented biological processes as π-calculus processes. i now have in hand representations of both geometry and topological properties such as knottedness in terms of properties of π-calculus processes. This suggests the very real possibility that there might be overlap in the kinds of processes inhabiting the target of these encodings. In other words, could we find encodings of geometries that are also encodings of biological processes? Could we find encodings of biological processes that are also encodings of geometries?</div><div><br /></div><div>This leads to the startling thought: space itself might be alive!</div><div><br /></div><div>Again, this is fully in line with both credible lines of investigation and with credible methods of investigation. <a href="http://en.wikipedia.org/wiki/John_Archibald_Wheeler">Wheeler</a>, for example, coined the phrase "<a href="http://en.wikipedia.org/wiki/Digital_physics">it from bit"</a> to describe the research program of physics arising from information-processing. What is more natural, and more in alignment with a reductionist view point than that biology ought to lie wholly inside physics? So, if physics arises from information processing and life arises inside physics, then life arises from information processing.</div><div><br /></div><div>Ironically, however, this provides an intriguing escape hatch for life: abstraction. The abstract properties we use to characterize those processes that are alive allow it to climb up out of any specific physical container and inhabit any formal dynamical system of sufficient complexity. Life once again shows itself to be uncontainably resilient and robust!</div><div><span class="Apple-style-span" style="white-space: pre;"><span class="Apple-style-span" style="white-space: normal;"><br /></span></span></div><div><span class="Apple-style-span" style="white-space: pre;"><span class="Apple-style-span" style="white-space: normal;"><span style="font-size:78%;">[1] If you want me to publish the encoding, drop a comment. If i get enough requests (say 3), i will put up the encoding. Actually, <a href="https://docs.google.com/Doc?id=dg96s9wn_518f4v7dbg8">here is a more interesting artifact</a> -- the synchronization skeleton of the encoding. It has all the connectivity of the Fano plane, but what happens after interaction is yet to be specified. There are solutions for Pij, Qij that regenerate the plane, so that the artifact is static. However, there are other definitions that generate new structures.</span><br /></span></span></div><div><span class="Apple-tab-span" style="white-space: pre;"><br /></span></div>leithaushttp://www.blogger.com/profile/01069099703796397027noreply@blogger.com3