<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;">Hi Oleg,</div><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br><div><div>On 9 Mar 2010, at 17:52, <a href="mailto:oleg@okmij.org">oleg@okmij.org</a> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><br>Stephen Tetley wrote:<br><blockquote type="cite">The finally tagless style is an implementation of the TypeCase pattern<br></blockquote><blockquote type="cite">(Bruno C. d. S. Oliveira and Jeremy Gibbons):<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><a href="http://www.comlab.ox.ac.uk/jeremy.gibbons/publications/typecase.pdf">http://www.comlab.ox.ac.uk/jeremy.gibbons/publications/typecase.pdf</a> <br></blockquote><br>The finally tagless style is slightly more general.<br><br>The TypeCase paper emphasizes that TypeCase is a pattern to define a<br>_closed_ type-indexed function -- the indexed family is fixed but the<br>collection of functions is extensible. This is in contrast to type<br>classes, where the collection of functions is fixed (by the class<br>declaration) but the indexed family is extensible (more type class<br>instances can be defined at any time).<br><font class="Apple-style-span"><font class="Apple-style-span" color="#144FAE"><br></font></font></div></blockquote><blockquote type="cite"><div>The tagless final approach permits the definition of an extensible<br>family of open type-indexed functions. For example, we can define a<br>`data type' of expressions and extend it at any time with more<br>expression forms *and* more processing functions (e.g., a new way to<br>print or compile an expression). &nbsp;With the tagless final approach, we<br>have the extensibility in both dimensions.<br><br></div></blockquote><div><br></div><div><div>It is true that "Typecase" is aimed at closed type-indexed functions, although in Section 4.2 I note, in passing, that you can achieve extensibility too for the *explicit* representations variation of the typecase pattern (which is the same that is used by tagless final):&nbsp;</div><div><br></div><div>"<font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><i>The smart datatype solution in this section is fully closed to extension. That is, in order to add another case in the formatting list, such as a constructor&nbsp;Chr&nbsp;that handles characters, we would need to modify the GADT itself. On the other hand, the solution in the previous section using the explicit version of the design pattern allows some form of extensibility. Adding a&nbsp;new case for&nbsp;printf&nbsp;that handles characters corresponds to adding a new function, which could even be in a different module.</i></span></font>"</div><div><br></div><div>Fortunately, there is a whole paper devoted to the issue of extensibility for an application of the typecase pattern using *explict* representations:</div><div><br></div><div><strong>Extensible and Modular Generics for the Masses</strong><br>Bruno C. d. S. Oliveira, Ralf Hinze and Andres Loeh<br><em>In Henrik Nilsson, editor, Trends in Functional Programming (TFP).</em></div><div><i><br></i></div><div><i>Link:&nbsp;<a href="http://ropas.snu.ac.kr/%7Ebruno/papers/ExtensibleGM.pdf">http://ropas.snu.ac.kr/%7Ebruno/papers/ExtensibleGM.pdf</a></i></div><div><i><br></i></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;">And the relation to the expression problem is pointed out there. Perhaps you'd like to have a look at the paper if you haven't seen it already.</span></font></div></div></div><br></div><div>Bruno</div></div></div><br></body></html>