<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"
    xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>antiselfdual.net</title>
        <link>http://antiselfdual.net</link>
        <description><![CDATA[Thoughts on functional programming]]></description>
        <atom:link href="http://antiselfdual.net/rss.xml" rel="self"
                   type="application/rss+xml" />
        <lastBuildDate>Wed, 26 Jun 2024 00:00:00 UT</lastBuildDate>
        <item>
    <title>Parsing permutation phrases</title>
    <link>http://antiselfdual.net</link>
    <description><![CDATA[<p>Records in Haskell, as in many other languages, allow fields to be specified in any order, as long as they don’t appear more than once; a field may also be omitted.</p>
<p>Is there a principled way to add a corresponding feature to a parser combinator library? We’d want a combinator that took parsers for each field and returned a parser for the whole record. It’s important too that the resultant parser be reasonably efficient. We could use such a combinator also for XML, JSON, YAML, URL query parameters, and so on.</p>
<p>I’ll walk us through the implementation from the <a href="https://www.semanticscholar.org/paper/Parsing-permutation-phrases-Baars-L%C3%B6h/26f31e9c7587027e238677afc6f8aa31fd34399d">paper</a> and the modified versions existing in the Haskell ecosystem. These rely on lazy evaluation; I’ll show how the technique can be adapted for languages with strict evaluation.</p>]]></description>
    <pubDate>Wed, 26 Jun 2024 00:00:00 UT</pubDate>
    <guid>http://antiselfdual.net</guid>
    <dc:creator>Mark Hopkins</dc:creator>
</item>
<item>
    <title>Functional Pearl: Higher-kinded data</title>
    <link>http://antiselfdual.net</link>
    <description><![CDATA[<p>A trick that can give an algebraic data type extra powers is to add a parameter that’s not merely a type, but a <em>type constructor</em>.</p>
<p>What kinds of extra powers? Well, for instance, we can:</p>
<ul>
<li>create type-safe builders, where it’s <em>compilation error</em> if a field is not set — but you can customise which fields are mandatory</li>
<li>create “smart” records, that we might use to back a form on a webpage, so that we can:
<ul>
<li>make all fields empty initially, or set them to default <code>Text</code> values — even for fields holding other types, such as <code>Int</code></li>
<li>query to ask which fields were not set, or did not parse, or pass validation; we can then export (or import) that data as a map keyed by field name</li>
<li>finally convert to a record with standard, bona-fide fields of the expected types</li>
</ul></li>
<li>replace the whole family of different abstract syntax trees typically used in different passes of a compiler pipeline with a single data structure</li>
<li>add additional safety guarantees: e.g. a table-printing library where it becomes a compilation error to provide rows of different lengths</li>
<li>enable automatic diffing of data structures</li>
<li>and in general, simplify patterns of processing data with similar structures.</li>
</ul>
<p>I’ll compare and contrast several different approaches to working effectively with higher-kinded data.</p>
<p>First, I’ll build up a small library with lifted versions of
familiar type classes like <code>Functor</code>, <code>Foldable</code>, <code>Traversable</code>
that will work for our new parameterized types, along with a number of combinators and utility functions.</p>
<p>I’ll walk us through creating manual instances for these new type classes, and then discuss approaches using GHC Generics and Template Haskell.</p>
<p>Finally I’ll show a different approach based on type families, as employed in the <a href="https://hackage.haskell.org/package/higgledy">higgledy</a> package.</p>]]></description>
    <pubDate>Wed, 24 Jan 2024 00:00:00 UT</pubDate>
    <guid>http://antiselfdual.net</guid>
    <dc:creator>Mark Hopkins</dc:creator>
</item>
<item>
    <title>A monad for Set</title>
    <link>http://antiselfdual.net</link>
    <description><![CDATA[<p>Everyone knows it’s impossible to write a monad instance for <code>Set</code> in Haskell, because of the annoying <code>Ord</code> constraint that comes with <code>Set</code>, but which isn’t part of the definition of the standard <code>Monad</code> type class. But what if we ignored the naysayers, and just <em>did it anyway</em>?</p>
<p>That is to say, I’ll show you how we can write a genuine, law-abiding instance:</p>
<ul>
<li>with no unusual language extensions</li>
<li>without modifying the <code>Monad</code> class, and</li>
<li>using the standard <code>Set</code> implementation from the <code>containers</code> package.</li>
</ul>
<p>Using a set instead of another data structure such as a list can provide exponential
speed-ups for certain algorithms, so this is of more than purely theoretical interest.</p>
<p>In fact, I’ll walk us through several implementations of set monads in Haskell,
compare the potential drawbacks of each, and show how we might address these.</p>]]></description>
    <pubDate>Wed, 28 Jun 2023 00:00:00 UT</pubDate>
    <guid>http://antiselfdual.net</guid>
    <dc:creator>Mark Hopkins</dc:creator>
</item>
<item>
    <title>Languages and patterns</title>
    <link>http://antiselfdual.net</link>
    <description><![CDATA[<p>I’ll demo some tools I wrote to help myself learn German and Turkish that create example sentences from a generative grammar model along with their translations into English, segueing into a discussion on agglutinative languages and vowel harmony, and using this as an opportunity to talk about how some tricks with patterns in Haskell (<strong>and</strong> and <strong>or patterns</strong>) can help us write cleaner code.</p>
<p>Links from the talk</p>
<ul>
<li><p><a href="https://notes.backgroundsignal.com/Querying_a_Dataset_with_Scala_s_Pattern_Matching.html">Querying a Dataset with Scala’s Pattern Matching — Arnold deVos</a></p></li>
<li><p><a href="https://hackage.haskell.org/package/OrPatterns">OrPatterns on Hackage</a></p></li>
<li><p><a href="https://github.com/ghc-proposals/ghc-proposals/pull/43">The Or Patterns language proposal</a></p></li>
</ul>]]></description>
    <pubDate>Thu, 23 Sep 2021 00:00:00 UT</pubDate>
    <guid>http://antiselfdual.net</guid>
    <dc:creator>Mark Hopkins</dc:creator>
</item>
<item>
    <title>Golden round-trip testing</title>
    <link>http://antiselfdual.net</link>
    <description><![CDATA[<p>In this talk I introduce <strong>golden round-trip testing</strong>.</p>
<p><em>Golden tests</em><a href="#fn1" class="footnote-ref" id="fnref1" role="doc-noteref"><sup>1</sup></a> and <em>property-based round-trip testing</em><a href="#fn2" class="footnote-ref" id="fnref2" role="doc-noteref"><sup>2</sup></a> are two heavy-hitters that deserve to be in every programmer’s testing arsenal.</p>
<p>It turns out that a mashup of the two is even better!</p>
<section id="footnotes" class="footnotes footnotes-end-of-document" role="doc-endnotes">
<hr />
<ol>
<li id="fn1"><p><a href="https://hackage.haskell.org/package/tasty-golden">https://hackage.haskell.org/package/tasty-golden</a><a href="#fnref1" class="footnote-back" role="doc-backlink">↩︎</a></p></li>
<li id="fn2"><p><a href="https://hackage.haskell.org/package/hedgehog/docs/Hedgehog-Internal-Tripping.html">https://hackage.haskell.org/package/hedgehog/docs/Hedgehog-Internal-Tripping.html</a><a href="#fnref2" class="footnote-back" role="doc-backlink">↩︎</a></p></li>
</ol>
</section>]]></description>
    <pubDate>Thu, 23 Sep 2021 00:00:00 UT</pubDate>
    <guid>http://antiselfdual.net</guid>
    <dc:creator>Mark Hopkins</dc:creator>
</item>
<item>
    <title>A taste of topos theory</title>
    <link>http://antiselfdual.net</link>
    <description><![CDATA[<p>For a computer programmer, graphs might seem commonplace and not particularly interesting. But in fact they secretly come with a lot of extra structure. For instance:</p>
<ul>
<li>we can add and multiply graphs</li>
<li>the structure-preserving maps (graph homomorphisms) between any two graphs form another graph</li>
<li>for every graph <span class="math inline"><em>G</em></span>, there’s a “powergraph” of subgraphs of <span class="math inline"><em>G</em></span></li>
<li>subgraphs of <span class="math inline"><em>G</em></span> correspond to predicates on <span class="math inline"><em>G</em></span>, but where instead of the booleans we use for predicates on sets, there’s a special graph <span class="math inline"><em>Ω</em></span> to use instead.</li>
</ul>
<p>So where does this structure come from?
The answer is the mathematical field of <em>topos theory</em>.</p>
<p>There are many ways to approach topos theory.
One view is that the concept of “topos” allows us to extract an interface
from set theory. Now we can apply this interface to other domains — provided they also fit the definition of a topos. In other words, we can continue to use the language of sets in other, more complicated domains. Luckily, there are lots of other topoi!</p>
<p>This interface turns out to be a typed lambda calculus, and one with a lot of nice
features: it has sums and products, it’s dependently typed, it has refinement types with intersection and union i.e. we can form subtypes by applying a predicate, and very frequently it comes with other goodies like modalities.</p>
<p>By happy coincidence some of the most common constructions in discrete maths and computer science - graphs (of multiple flavours), automata - are topoi, or at least quasitopoi, a minor variation.</p>
<p>I’ll show how to derive the special graph <span class="math inline"><em>Ω</em></span> that serves as a replacement for the booleans when forming predicates on graphs.</p>]]></description>
    <pubDate>Wed, 26 Aug 2020 00:00:00 UT</pubDate>
    <guid>http://antiselfdual.net</guid>
    <dc:creator>Mark Hopkins</dc:creator>
</item>
<item>
    <title>Dependent types made difficult</title>
    <link>http://antiselfdual.net</link>
    <description><![CDATA[<p>In the spirit of
<a href="https://en.wikipedia.org/wiki/Mathematics_Made_Difficult">Mathematics Made Difficult</a>
and
<a href="https://www.stephendiehl.com/posts/monads.html">Monads Made Difficult</a>,
let’s take a deeper look at dependent types to see if we can come to understand them a little better.</p>
<p>The field of <em>categorical semantics</em> tells us that the simply typed lambda
calculus has a natural interpretation in any Cartesian closed category: it
is their “internal language”.</p>
<p>What’s an internal language good for?
On one hand, having a high-level type theory for talking about low-level properties can greatly simplify proofs.</p>
<p>On the other hand, this language can have very practical consequences.
As he describes in his paper “Compiling to Categories”<a href="#fn1" class="footnote-ref" id="fnref1" role="doc-noteref"><sup>1</sup></a>, Conal Elliott was able to put this correspondence to work in the form of a GHC plugin that allows the same program to be interpreted in multiple different CCCs — yielding applications including hardware circuits, automatic differentiation, incremental compilation and interval analysis.</p>
<p>What’s the story for <em>dependent types</em>
i.e. is there a categorical semantics for dependent types?</p>
<p>It turns out that dependent type theory is the internal logic of <em>locally</em> Cartesian closed categories: ones where the pullback functor has both left and right adjoints.</p>
<p>Pullback corresponds to <em>substitution</em> into a dependent type. These left and right adjoints are called dependent sum and product, and correspond to dependent sum and product types.</p>
<p>I’ll explore what this looks like via explicit constructions in the category of sets (with pictures!).</p>
<section id="footnotes" class="footnotes footnotes-end-of-document" role="doc-endnotes">
<hr />
<ol>
<li id="fn1"><p><a href="http://conal.net/papers/compiling-to-categories/">http://conal.net/papers/compiling-to-categories/</a><a href="#fnref1" class="footnote-back" role="doc-backlink">↩︎</a></p></li>
</ol>
</section>]]></description>
    <pubDate>Wed, 22 May 2019 00:00:00 UT</pubDate>
    <guid>http://antiselfdual.net</guid>
    <dc:creator>Mark Hopkins</dc:creator>
</item>
<item>
    <title>Compile-time parsing</title>
    <link>http://antiselfdual.net</link>
    <description><![CDATA[<p>Sometimes, rather than constructing a domain object in code, it’s clearer to specify it as YAML or JSON. But at the same time, we don’t want to give up the compile-time guarantees we get from a programming language, as this would expose us to runtime errors if we made a mistake in the YAML/JSON.</p>
<p>Can we write in another language and then check it at compile time? We can, through the power of macros!</p>
<p>I’ll show how to build useful compiler checking of arbitrary strings.</p>
<p>Key ingredients will be:</p>
<ul>
<li>macros that produce macros</li>
<li>string interpolators, and</li>
<li>compile-time evaluation.</li>
</ul>]]></description>
    <pubDate>Wed, 08 Aug 2018 00:00:00 UT</pubDate>
    <guid>http://antiselfdual.net</guid>
    <dc:creator>Mark Hopkins</dc:creator>
</item>
<item>
    <title>All of basic category theory</title>
    <link>http://antiselfdual.net</link>
    <description><![CDATA[<p>If you’ve learnt about lenses in functional programming,
you may have been puzzled by the claim that</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="kw">data</span> <span class="dt">Lens</span> s a <span class="ot">=</span> <span class="dt">Lens</span> {<span class="ot"> get ::</span> s <span class="ot">-&gt;</span> a,<span class="ot"> set ::</span> a <span class="ot">-&gt;</span> s <span class="ot">-&gt;</span> s }</span></code></pre></div>
<p>is in some sense the same as</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="kw">forall</span> f<span class="op">.</span> <span class="dt">Functor</span> f <span class="ot">=&gt;</span> (a <span class="ot">-&gt;</span> f a) <span class="ot">-&gt;</span> s <span class="ot">-&gt;</span> f s</span></code></pre></div>
<p>More to the point: how on Earth did someone ever figure this out in the first place?</p>
<p>Don’t know your Kan extensions from your co-ends, your pushouts from your presheaves?
Join me for a scenic adventure tour through the magical land of category theory, stopping off at all the major sights.</p>
<p>We’ll learn the basic notions that form the conceptual backbone of category theory,
and how they all fit together.
I’ll also explain how the above equivalence of lens representations comes about.</p>
<p>Category theory has made deep inroads into computer science theory, but in this talk we’ll be focused on computer science <em>practice</em>. We’ll explore the advantages category theory brings to programming in terms of</p>
<ul>
<li>providing alternate representations for types</li>
<li>classifying solutions</li>
<li>simply providing a clarifying viewpoint and helping to organise our thinking.</li>
</ul>
<p>In addition this should provide you with the right framework for further exploring category theory, should you so wish.</p>
<h4 id="outlinestructure-of-the-talk">Outline/Structure of the Talk</h4>
<p>I’ll cover the fundamentals of, and some applications of, the universal constructions of basic category theory:</p>
<ul>
<li>initial objects</li>
<li>universal properties (universal arrows, universal elements)</li>
<li>representable functors</li>
<li>limits</li>
<li>adjunctions</li>
<li>monads</li>
<li>ends</li>
<li>Kan extensions</li>
</ul>
<h4 id="learning-outcomes">Learning Outcomes</h4>
<p>Attendees will come away with a better idea of how the different concepts and tools of category theory fit together and how to use them.</p>
<h4 id="target-audience">Target Audience</h4>
<p>Functional programmers who are curious about category theory, but feel overwhelmed when they turn to textbooks or resources such as the <a href="https://ncatlab.org/nlab/">nLab</a> to learn more.</p>
<h4 id="prerequisites-for-attendees">Prerequisites for Attendees</h4>
<p>Ideally, participants would already have seen the definition of a category and be familiar with Haskell syntax. I’m also going to assume participants have already been exposed to monads and comonads, and to free constructions (e.g. free monoid, free monad) as I will only touch on these lightly.</p>]]></description>
    <pubDate>Tue, 22 May 2018 00:00:00 UT</pubDate>
    <guid>http://antiselfdual.net</guid>
    <dc:creator>Mark Hopkins</dc:creator>
</item>
<item>
    <title>Conditional contexts</title>
    <link>http://antiselfdual.net</link>
    <description><![CDATA[<p>Wouldn’t it be nice if Scala would let you write a parametric function that could do different things depending on whether or not the type parameter was an
instance of some type class?</p>
<p>For instance</p>
<ul>
<li>a <code>Set[A](a: A*)</code> function that creates either a <code>TreeSet</code> or a <code>HashSet</code>, depending on whether an <code>Ordering[A]</code> is in scope.</li>
<li>a numerical algorithm <code>doCalc[N : Numeric](n: Matrix[N])</code> that works for all numeric types <code>N</code>, but uses a (more expensive, but numerically stable) algorithm for floating point numbers, but not integers (which don’t need it).</li>
</ul>
<p>I’ll run through the use and implementation of a Haskell library (<a href="https://hackage.haskell.org/package/ifcxt">ifcxt</a>) which provides this functionality, then show the (surprisingly simple) Scala implementation.</p>
<p>Notably, this has to be an <em>extension to the type system</em> in Haskell,
but practically comes for free in Scala.</p>
<p>Accompanying <a href="https://github.com/mjhopkins/ifcxt-scala">Scala code</a>
allows you to play with three different implementations.</p>]]></description>
    <pubDate>Wed, 08 Nov 2017 00:00:00 UT</pubDate>
    <guid>http://antiselfdual.net</guid>
    <dc:creator>Mark Hopkins</dc:creator>
</item>
<item>
    <title>Monadic matching mishaps</title>
    <link>http://antiselfdual.net</link>
    <description><![CDATA[<p>The following Scala code fails to compile:</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode scala"><code class="sourceCode scala"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a>  <span class="co">// Search for a file by filename glob</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a>  <span class="kw">def</span> <span class="fu">find</span><span class="op">(</span>glob<span class="op">:</span> <span class="ex">String</span><span class="op">):</span> <span class="ex">Error</span> \<span class="op">/</span> <span class="ex">File</span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a>  <span class="co">// retrieve the first and last lines</span></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a>  <span class="kw">def</span> <span class="fu">firstLastLine</span><span class="op">(</span>file<span class="op">:</span> <span class="ex">File</span><span class="op">):</span> <span class="ex">Error</span> \<span class="op">/</span> <span class="op">(</span><span class="ex">String</span><span class="op">,</span> <span class="ex">String</span><span class="op">)</span></span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a>  <span class="co">// summarize the first text file</span></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a>  <span class="kw">val</span> summary <span class="op">=</span> <span class="cf">for</span> <span class="op">{</span></span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a>    file          <span class="op">&lt;-</span> <span class="fu">find</span><span class="op">(</span><span class="st">&quot;*.txt&quot;</span><span class="op">)</span></span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a>    <span class="op">(</span>first<span class="op">,</span> last<span class="op">)</span> <span class="op">&lt;-</span> <span class="fu">firstLastLine</span><span class="op">(</span>file<span class="op">)</span></span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a>  <span class="op">}</span> <span class="cf">yield</span> file <span class="op">+</span> <span class="st">&quot;: &quot;</span> <span class="op">+</span> first<span class="op">.</span><span class="fu">take</span><span class="op">(</span><span class="dv">20</span><span class="op">)</span> <span class="op">+</span> <span class="st">&quot;...&quot;</span> <span class="op">+</span> last<span class="op">.</span><span class="fu">takeRight</span><span class="op">(</span><span class="dv">20</span><span class="op">)</span></span></code></pre></div>
<p>with the error</p>
<pre class="text"><code>could not find implicit value for parameter M: scalaz.Monoid[Error]</code></pre>
<p>but it’s not immediately clear why, or why it <em>does</em> work when we replace <code>\/</code> with <code>Option</code>.</p>
<p>I’ll discuss why this occurs, a simple fix to make it work, and compare with similar situations in other languages with pattern-matching and monads (<a href="https://www.haskell.org">Haskell</a>, <a href="http://www.idris-lang.org">Idris</a>, <a href="http://www.purescript.org">Purescript</a>), ending by identifying a Scala feature that perhaps could be improved in future compiler versions.</p>]]></description>
    <pubDate>Thu, 13 Jul 2017 00:00:00 UT</pubDate>
    <guid>http://antiselfdual.net</guid>
    <dc:creator>Mark Hopkins</dc:creator>
</item>
<item>
    <title>How do functional programmers do dependency injection?</title>
    <link>http://antiselfdual.net</link>
    <description><![CDATA[<p>How should we think about dependency injection?</p>
<p>In the context of imperative languages there are many well-established frameworks for doing
dependency injection. Is there a functional programming equivalent?</p>
<p>We often hear that the FP answer is “use a Reader monad”.
However, I’ll argue this isn’t a good answer.</p>
<p>A functional programmer would instead turn the question around and ask “What operations would you do if you had these dependencies?”.
By reframing the original problem we reveal a more fundamental outlook. Namely, what are the <em>languages</em> of operations these dependencies allow us to express, and what are the <em>interpreters</em> for those languages?</p>
<p>To achieve reuse, both languages and interpreters will need to be <em>modular</em>, i.e. support good notions of composition.</p>
<p>So how do we go about doing this?</p>
<p>I’ll compare and contrast two solutions of this problem. The first, popularised in Wouter Swierstra’s Functional Pearl <em>Datatypes à la Carte</em> (and familiar to some through Rúnar Bjarnason’s talk “Compositional application architecture with reasonably priced free monads”) builds up a data structure of abstract operations, which are then run by an interpreter.</p>
<p>The second approach — popularised by Oleg Kiselyov as <em>Typed tagless final interpreters</em> — takes advantage of Scala’s support for higher-kinded types. Rather than building up and tearing down a data structure, we simply add a type class constraint to our program. “Interpretation” is now a compile-time operation: it’s just specialisation to a type that satisfies the constraints. This is both simpler and more efficient, and sufficient for almost all purposes.</p>]]></description>
    <pubDate>Wed, 08 Jun 2016 00:00:00 UT</pubDate>
    <guid>http://antiselfdual.net</guid>
    <dc:creator>Mark Hopkins</dc:creator>
</item>
<item>
    <title>Stop paying for free monads!</title>
    <link>http://antiselfdual.net</link>
    <description><![CDATA[<p>Free monads, as used in the <em>Datatypes à la carte</em> pattern, are a useful way to structure code, separating of specification from implementation and enabling modularisation.</p>
<p>But they also come with a runtime performance penalty…</p>
<p>The complementary <em>typed tagless final interpreters</em> approach
(popularised in the Haskell and OCaml worlds by Oleg Kiselyov)
offers a performance boost over free monads.</p>
<p>Yet, frustratingly, available sample code centres around simple expression languages,
and “real world” examples that you might be able to put to use in your day job
are hard to come by.</p>
<p>In this talk, we’ll compare and contrast the typed tagless approach with datatypes à la carte
and explore how the typed tagless approach can be used in real production code
— with configuration, state, side effects and error handling.</p>
<p><a href="https://github.com/mjhopkins/StopPayingForFreeMonads">Haskell code</a> for the associated LambdaJam workshop.</p>]]></description>
    <pubDate>Sun, 29 May 2016 00:00:00 UT</pubDate>
    <guid>http://antiselfdual.net</guid>
    <dc:creator>Mark Hopkins</dc:creator>
</item>
<item>
    <title>Macro-based smart constructors</title>
    <link>http://antiselfdual.net</link>
    <description><![CDATA[<p>Smart constructors are a nice pattern for building data types that need extra validation or calculation.</p>
<p>But in the case when we’re building our data type from statically known values, they leave us with two annoyances:</p>
<p>• they’re more clunky</p>
<p>• we have a <em>run-time test</em> for something that’s known at and should be checked at <em>compile time</em>.</p>
<p>We’ll investigate how Scala macros can help us address these problems and
thus achieve both additional safety and greater convenience.</p>
<p>Accompanying <a href="https://github.com/mjhopkins/macro-smart-constructors">Scala code</a>
demonstrating the techniques in action.</p>]]></description>
    <pubDate>Wed, 13 Apr 2016 00:00:00 UT</pubDate>
    <guid>http://antiselfdual.net</guid>
    <dc:creator>Mark Hopkins</dc:creator>
</item>
<item>
    <title>Seven trees in one</title>
    <link>http://antiselfdual.net</link>
    <description><![CDATA[<p>It’s a rather surprising fact that there’s an O(1) bijection between the datatype of unlabelled (planar) binary trees</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="kw">data</span> <span class="dt">Tree</span> <span class="ot">=</span> <span class="dt">Leaf</span> <span class="op">|</span> <span class="dt">Node</span> <span class="dt">Tree</span> <span class="dt">Tree</span></span></code></pre></div>
<p>and 7-tuples of these trees. This presentation explores the fascinating story of how this bijection comes about, and the interesting connections to notions of isomorphism of types and
distributive categories.</p>
<p><a href="https://github.com/mjhopkins/seven-trees">Haskell code</a> containing a <a href="https://en.wikipedia.org/wiki/QuickCheck">QuickCheck</a> test of the bijection.</p>]]></description>
    <pubDate>Fri, 22 May 2015 00:00:00 UT</pubDate>
    <guid>http://antiselfdual.net</guid>
    <dc:creator>Mark Hopkins</dc:creator>
</item>
<item>
    <title>Getting higher: Higher-kinded and higher rank types in Scala</title>
    <link>http://antiselfdual.net</link>
    <description><![CDATA[<p>Some of us may have heard the terms “higher-kinded type” or “higher rank type”
and wondered what they meant, or what the difference was.</p>
<p>In this talk I’ll attempt to demystify these terms and give a few examples of how they can be useful in practice.</p>]]></description>
    <pubDate>Wed, 09 Apr 2014 00:00:00 UT</pubDate>
    <guid>http://antiselfdual.net</guid>
    <dc:creator>Mark Hopkins</dc:creator>
</item>
<item>
    <title>Much ado about monoids</title>
    <link>http://antiselfdual.net</link>
    <description><![CDATA[<p>I’ll introduce the <code>Monoid</code> and <code>Foldable</code> type classes from Scala’s
<a href="https://github.com/scalaz/scalaz">scalaz</a> library
and show how the compositionality property they satisfy means
they can be used to do basic data analysis
in a single pass over the data.</p>]]></description>
    <pubDate>Wed, 12 Jun 2013 00:00:00 UT</pubDate>
    <guid>http://antiselfdual.net</guid>
    <dc:creator>Mark Hopkins</dc:creator>
</item>

    </channel>
</rss>
