effluence2023-04-05T20:16:20-04:00https://sonnym.comTypes in Elm: Decomposition and Ad Hoc Polymorphism2018-11-19T00:00:00-05:00https://sonnym.com/2018/11/19/types-in-elm-decomposition-and-ad-hoc-polymorphism<h2>New Beginnings</h2>
<p>Since I originally learned about and tried Elm in 2013, a lot about the language
has changed. Elm and I have grown distant and close several times over the
years, each encounter being more pleasant than the last, but always ending
somewhat abruptly and falling a bit short. After our most recent reunion,
however, I feel as though the language has matured to a point where I am
empowered to really move forward with the larger projects I began several years
ago.</p>
<p>The purpose of this article is to elucidate some topics that were not abundantly
clear to me as an effectively new Elm user. It builds from real problems I have
encountered while writing real programs, and the solutions I devised to address
those issues. These techniques revolve around how we compose and decompose
types to make our programs more maintainable.</p>
<p>before we move forward with the specifics, I would like to take a detour
through my history with Elm as a way to frame the present discussion.</p>
Privacy and Exposure, Gatekeepers and Privileged Consumers2018-01-03T00:00:00-05:00https://sonnym.com/2018/01/03/privacy-and-exposure-gatekeeprs-and-privileged-consumers<h2>Encapsulation and Information Hiding</h2>
<p><span class="fancylink"> <a href="https://en.wikipedia.org/wiki/Information_hiding">Encapsulation</a> <span> <a href="https://en.wikipedia.org/wiki/Information_hiding" target="_blank" alt="Pop Out" title="Pop Out"><svg class="octicon octicon-link-external" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M11 10h1v3c0 .55-.45 1-1 1H1c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h3v1H1v10h10v-3zM6 2l2.25 2.25L5 7.5 6.5 9l3.25-3.25L12 8V2H6z"/></svg></a> </span> </span>
and
<span class="fancylink"> <a href="https://en.wikipedia.org/wiki/Information_hiding">information hiding</a> <span> <a href="https://en.wikipedia.org/wiki/Information_hiding" target="_blank" alt="Pop Out" title="Pop Out"><svg class="octicon octicon-link-external" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M11 10h1v3c0 .55-.45 1-1 1H1c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h3v1H1v10h10v-3zM6 2l2.25 2.25L5 7.5 6.5 9l3.25-3.25L12 8V2H6z"/></svg></a> </span> </span>,
are well known principles in object-oriented programming, common mechanisms for
maintaining DRY code and enforcing the
<span class="fancylink"> <a href="https://en.wikipedia.org/wiki/Single_responsibility_principle">single responsibility principle</a> <span> <a href="https://en.wikipedia.org/wiki/Single_responsibility_principle" target="_blank" alt="Pop Out" title="Pop Out"><svg class="octicon octicon-link-external" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M11 10h1v3c0 .55-.45 1-1 1H1c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h3v1H1v10h10v-3zM6 2l2.25 2.25L5 7.5 6.5 9l3.25-3.25L12 8V2H6z"/></svg></a> </span> </span>.
While these foundational elements imbue the programmer with significant
expressive power and are essential for writing software with possessing anything more than a
semblance of maintainability, they sometimes introduce restrictions that are
ultimately antithetical to those goals. We, the writers of code, should,
therefore, have a solid understanding of not only the standard use of these core
object-oriented principles, but also, and, perhaps, more importantly, where they
break down in addition to how and when to work around them.</p>
<p>We will look at the ways in which we are able to subvert typical safety nets, and
this exploration of various means for exposing otherwise private members will
also serve as an introduction to some features of the Ruby programming language
less frequently encountered in day to day practice. We will, ultimately,
introduce additional safety to objects that traditionally have little, in an
attempt to limit the use of our newfound powers for good. Let us begin by
looking at the three levels of visibility available and how they are used via a
concrete, storybook example.</p>
On Maintainability: Gold Plating the Game of Life in Elm2017-06-18T00:00:00-04:00https://sonnym.com/2017/06/18/on-maintainability-gold-plating-the-game-of-life-in-elm<h2>Launch Pad</h2>
<p>In a previous
<a href="/2017/05/22/revisiting-the-game-of-life-in-elm/">article</a>,
we explored how to write Conway's Game of Life in the Elm programming language.
This example was predicated on one from several years before and compared the
differences in Elm over the intervening period of time. Today, we will add some
entirely unnecessary features to the simple version of the program.</p>
<p>This exercise in
<span class="fancylink"> <a href="https://en.wikipedia.org/wiki/Gold_plating_(software_engineering)">gold plating</a> <span> <a href="https://en.wikipedia.org/wiki/Gold_plating_(software_engineering)" target="_blank" alt="Pop Out" title="Pop Out"><svg class="octicon octicon-link-external" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M11 10h1v3c0 .55-.45 1-1 1H1c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h3v1H1v10h10v-3zM6 2l2.25 2.25L5 7.5 6.5 9l3.25-3.25L12 8V2H6z"/></svg></a> </span> </span>
will serve as a means of probing what it feels like to add new features to an
already established Elm program; these microcosmic changes will, hopefully, be
reflective of maintaining larger applications in Elm. Throughout the course of
this article, we will consider successive diffs, starting from the original
implementation, while moving toward the final version.</p>
Common Table Expressions in ActiveRecord: A Case Study of Quantiles2017-06-05T00:00:00-04:00https://sonnym.com/2017/06/05/common-table-expressions-in-activerecord-a-case-study-of-quantiles<h2>Framing</h2>
<p>Today, we are going to look at a straightforward real-world problem, and build a
comprehensive solution. In doing so, we will start with some various naive
approaches as we increase our understanding of the underlying mechanics,
encounter some pitfalls, and, ultimately, approach a reasonable level of
sophistication and abstraction. The stack we will be using for this case study
is
<span class="fancylink"> <a href="http://rubyonrails.org/">Ruby on Rails 5.1</a> <span> <a href="http://rubyonrails.org/" target="_blank" alt="Pop Out" title="Pop Out"><svg class="octicon octicon-link-external" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M11 10h1v3c0 .55-.45 1-1 1H1c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h3v1H1v10h10v-3zM6 2l2.25 2.25L5 7.5 6.5 9l3.25-3.25L12 8V2H6z"/></svg></a> </span> </span>
with
<span class="fancylink"> <a href="https://www.postgresql.org/">PostgreSQL 9.6</a> <span> <a href="https://www.postgresql.org/" target="_blank" alt="Pop Out" title="Pop Out"><svg class="octicon octicon-link-external" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M11 10h1v3c0 .55-.45 1-1 1H1c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h3v1H1v10h10v-3zM6 2l2.25 2.25L5 7.5 6.5 9l3.25-3.25L12 8V2H6z"/></svg></a> </span> </span>
for the database.</p>
<p>Now, let me present to you the problem through which we will frame this
discussion: given a number of student records, when displaying a single
student, also display the quintile into which their grade falls.</p>
Continuations in Ruby - Part 1: First Class Objects2017-05-29T00:00:00-04:00https://sonnym.com/2017/05/29/continuations-in-ruby-part-1-first-class-objects<h2>Caveat Emptor</h2>
<p>This is the first in an ongoing part series exploring the possibilities
presented to the programmer when continuations are a first class part of a
language. These articles follow Chapter 20 of Paul Graham's venerable treatise
<span class="fancylink"> <a href="http://www.paulgraham.com/onlisp.html">On Lisp</a> <span> <a href="http://www.paulgraham.com/onlisp.html" target="_blank" alt="Pop Out" title="Pop Out"><svg class="octicon octicon-link-external" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M11 10h1v3c0 .55-.45 1-1 1H1c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h3v1H1v10h10v-3zM6 2l2.25 2.25L5 7.5 6.5 9l3.25-3.25L12 8V2H6z"/></svg></a> </span> </span>.</p>
<p>While a powerful semantic construct, there is no secret that continuations are,
for good reason,
<span class="fancylink"> <a href="http://okmij.org/ftp/continuations/against-callcc.html">thoroughly reviled</a> <span> <a href="http://okmij.org/ftp/continuations/against-callcc.html" target="_blank" alt="Pop Out" title="Pop Out"><svg class="octicon octicon-link-external" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M11 10h1v3c0 .55-.45 1-1 1H1c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h3v1H1v10h10v-3zM6 2l2.25 2.25L5 7.5 6.5 9l3.25-3.25L12 8V2H6z"/></svg></a> </span> </span>.
In short, give us the ability to store the state of a computation and return to
it at a later point in the execution of our program. This form of non-local
return (or
<span class="fancylink"> <a href="http://rosettacode.org/wiki/Jump_anywhere#Ruby">jump anywhere</a> <span> <a href="http://rosettacode.org/wiki/Jump_anywhere#Ruby" target="_blank" alt="Pop Out" title="Pop Out"><svg class="octicon octicon-link-external" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M11 10h1v3c0 .55-.45 1-1 1H1c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h3v1H1v10h10v-3zM6 2l2.25 2.25L5 7.5 6.5 9l3.25-3.25L12 8V2H6z"/></svg></a> </span> </span>)
can be compared to <code>goto</code> statements of old or <code>try</code>/<code>catch</code> semantics commonly
seen today. Both of these language features, in fact, can be implemented in
terms of continuations, and in section 5.8.3 of
<span class="fancylink"> <a href="http://shop.oreilly.com/product/9780596516178.do">The Ruby Programming Language</a> <span> <a href="http://shop.oreilly.com/product/9780596516178.do" target="_blank" alt="Pop Out" title="Pop Out"><svg class="octicon octicon-link-external" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M11 10h1v3c0 .55-.45 1-1 1H1c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h3v1H1v10h10v-3zM6 2l2.25 2.25L5 7.5 6.5 9l3.25-3.25L12 8V2H6z"/></svg></a> </span> </span>,
the authors construct a BASIC inspired <code>goto</code> function. Today, when we <code>require
'continuation'</code>, the interpreter will kindly inform us that 'warning: callcc is
obsolete; use Fiber instead'.</p>
<p>With continuations framed in this way, it should go without saying that, under
no circumstances whatsoever, should these curios be used in anything with any
degree of seriousness. Why, then, should should we even bother? Sometimes,
the simple fact that we should not is enough to make it worthwhile.</p>
Revisiting the Game of Life in Elm2017-05-22T00:00:00-04:00https://sonnym.com/2017/05/22/revisiting-the-game-of-life-in-elm<h2>Reflection</h2>
<p>Over three years ago, I wrote an
<a href="/2014/05/05/writing-game-of-life-in-elm/">article</a>
exploring how to write Conway's Game of Life in the Elm programming language.
That article was originally written for version 0.12.3 and later updated for
0.14, but during the intervening span of time, Elm has matured significantly.
In the process, Elm has
<span class="fancylink"> <a href="http://elm-lang.org/blog/farewell-to-frp">dropped its functional reactive roots</a> <span> <a href="http://elm-lang.org/blog/farewell-to-frp" target="_blank" alt="Pop Out" title="Pop Out"><svg class="octicon octicon-link-external" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M11 10h1v3c0 .55-.45 1-1 1H1c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h3v1H1v10h10v-3zM6 2l2.25 2.25L5 7.5 6.5 9l3.25-3.25L12 8V2H6z"/></svg></a> </span> </span>
in favor of subscription-based concurrency. Today, we will go through the same
exercise of writing the game of life, as a means of exploring the basics of a
simple modern Elm program.</p>
Hacking S-expressions into Ruby2015-02-26T00:00:00-05:00https://sonnym.com/2015/02/26/hacking-s-expressions-into-ruby<h2>Background</h2>
<p><span class="fancylink"> <a href="https://en.wikipedia.org/wiki/S-expression">S-expressions</a> <span> <a href="https://en.wikipedia.org/wiki/S-expression" target="_blank" alt="Pop Out" title="Pop Out"><svg class="octicon octicon-link-external" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M11 10h1v3c0 .55-.45 1-1 1H1c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h3v1H1v10h10v-3zM6 2l2.25 2.25L5 7.5 6.5 9l3.25-3.25L12 8V2H6z"/></svg></a> </span> </span>
are a classic means of storing trees of data. Part of the original Lisp
specification, they have been a part of software engineering since the very
beginning. Other languages, notably Scheme and, more recently, Clojure, have
helped maintain the relevancy of this very simple means for representing data.</p>
<p>In the spirit of
<span class="fancylink"> <a href="https://en.wikipedia.org/wiki/Greenspun%27s_tenth_rule">Greenspun's tenth rule</a> <span> <a href="https://en.wikipedia.org/wiki/Greenspun%27s_tenth_rule" target="_blank" alt="Pop Out" title="Pop Out"><svg class="octicon octicon-link-external" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M11 10h1v3c0 .55-.45 1-1 1H1c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h3v1H1v10h10v-3zM6 2l2.25 2.25L5 7.5 6.5 9l3.25-3.25L12 8V2H6z"/></svg></a> </span> </span>,
we are going to attempt make first-class s-expressions in Ruby. There is
already a
<span class="fancylink"> <a href="http://rosettacode.org/wiki/S-Expressions#Ruby">nice implementation</a> <span> <a href="http://rosettacode.org/wiki/S-Expressions#Ruby" target="_blank" alt="Pop Out" title="Pop Out"><svg class="octicon octicon-link-external" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M11 10h1v3c0 .55-.45 1-1 1H1c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h3v1H1v10h10v-3zM6 2l2.25 2.25L5 7.5 6.5 9l3.25-3.25L12 8V2H6z"/></svg></a> </span> </span>
of s-expressions in Ruby, for reference, but they are not first-class, which
makes them less than ideal. As such, we are going to to see how far we can
push (read: abuse) the dynamic nature of the Ruby language, and investigate
just how much control we have over certain elements of its syntax.</p>
<p>For anyone more interested in the result than the journey, be warned that this
attempt will not be successful, but some interesting results will be found
along the road to ultimate failure.</p>
Using Defined Properties for Better AngularJS Directives2015-01-21T00:00:00-05:00https://sonnym.com/2015/01/21/using-defined-properties-for-better-angularjs-directives<h2>On Directives</h2>
<p>Directives in AngularJS are an exemplary solution for writing reusable
components in modern web applications. They allow us to encapsulate all the
messy business logic and expose a very clean, declarative interface to consumers
of the API. As with most tools for constructing abstractions, however,
directives have certain limitations that can lead to implementation details
leaking through, resulting in code that less
<span class="fancylink"> <a href="https://en.wikipedia.org/wiki/DRY_principle">DRY</a> <span> <a href="https://en.wikipedia.org/wiki/DRY_principle" target="_blank" alt="Pop Out" title="Pop Out"><svg class="octicon octicon-link-external" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M11 10h1v3c0 .55-.45 1-1 1H1c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h3v1H1v10h10v-3zM6 2l2.25 2.25L5 7.5 6.5 9l3.25-3.25L12 8V2H6z"/></svg></a> </span> </span>
and, consequently, less maintainable.</p>
<p>There are, however, ways to work around these shortcomings and to build
simpler, more expressive interfaces to our directives. Leveraging a lesser known
feature of JavaScript, we can encapsulate additional details of our business
logic. This method is also well suited for building on top of third party
directives with a complex API by abstracting the details into a business
object. In doing so, our markup will become more in line with the ideal in
AngularJS, which
<span class="fancylink"> <a href="https://docs.angularjs.org/guide/introduction">promotes declarative code</a> <span> <a href="https://docs.angularjs.org/guide/introduction" target="_blank" alt="Pop Out" title="Pop Out"><svg class="octicon octicon-link-external" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M11 10h1v3c0 .55-.45 1-1 1H1c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h3v1H1v10h10v-3zM6 2l2.25 2.25L5 7.5 6.5 9l3.25-3.25L12 8V2H6z"/></svg></a> </span> </span>
over imperative. Without further ado, let us look at the current situation and
how we can improve our directives.</p>
Barebones Architecture in Elm2014-12-23T00:00:00-05:00https://sonnym.com/2014/12/23/barebones-architecture-in-elm<h2>Motivation and Background</h2>
<p>In the process of writing larger applications in
<span class="fancylink"> <a href="http://elm-lang.org/">Elm</a> <span> <a href="http://elm-lang.org/" target="_blank" alt="Pop Out" title="Pop Out"><svg class="octicon octicon-link-external" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M11 10h1v3c0 .55-.45 1-1 1H1c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h3v1H1v10h10v-3zM6 2l2.25 2.25L5 7.5 6.5 9l3.25-3.25L12 8V2H6z"/></svg></a> </span> </span>
I find it far too easy to initially focus on one small part of the problem
while losing perspective on the bigger picture. For instance, I will begin by
rendering a simple scene, followed by splitting out components, and finally
adding in signals. While this is generally a good approach, in my mind,
it is sometimes difficult to retrofit patterns onto the basis of the application
I have already written.</p>
<p>There are some really excellent resources covering the architecture of applications
in the Elm language. The
<span class="fancylink"> <a href="http://elm-lang.org/learn/Architecture.elm">canonical article</a> <span> <a href="http://elm-lang.org/learn/Architecture.elm" target="_blank" alt="Pop Out" title="Pop Out"><svg class="octicon octicon-link-external" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M11 10h1v3c0 .55-.45 1-1 1H1c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h3v1H1v10h10v-3zM6 2l2.25 2.25L5 7.5 6.5 9l3.25-3.25L12 8V2H6z"/></svg></a> <a href="https://web.archive.org/web/20141223/http://elm-lang.org/learn/Architecture.elm" target="_blank" alt="Open on archive.org" title="Open on archive.org"><svg class="octicon octicon-mirror" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M15.5 4.7L8.5 0l-7 4.7c-.3.19-.5.45-.5.8V16l7.5-4 7.5 4V5.5c0-.34-.2-.61-.5-.8zm-.5 9.8l-6-3.25V10H8v1.25L2 14.5v-9l6-4V6h1V1.5l6 4v9zM6 7h5V5l3 3-3 3V9H6v2L3 8l3-3v2z"/></svg></a> </span> </span>
on the subject can be found on the official Elm site and covers everything at
a high level. The best example is likely
<span class="fancylink"> <a href="https://evancz.github.io/elm-todomvc/">TodoMVC</a> <span> <a href="https://evancz.github.io/elm-todomvc/" target="_blank" alt="Pop Out" title="Pop Out"><svg class="octicon octicon-link-external" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M11 10h1v3c0 .55-.45 1-1 1H1c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h3v1H1v10h10v-3zM6 2l2.25 2.25L5 7.5 6.5 9l3.25-3.25L12 8V2H6z"/></svg></a> </span> </span>
(<span class="fancylink"> <a href="https://github.com/evancz/elm-todomvc">source</a> <span> <a href="https://github.com/evancz/elm-todomvc" target="_blank" alt="Pop Out" title="Pop Out"><svg class="octicon octicon-link-external" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M11 10h1v3c0 .55-.45 1-1 1H1c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h3v1H1v10h10v-3zM6 2l2.25 2.25L5 7.5 6.5 9l3.25-3.25L12 8V2H6z"/></svg></a> </span> </span>)
ported to Elm which uses many the concepts from the article to create a rich
and simple interface, showcasing just how powerful Elm is. Another great and
extremely polished example is
<span class="fancylink"> <a href="http://dreamwriter.io/">Dreamwriter</a> <span> <a href="http://dreamwriter.io/" target="_blank" alt="Pop Out" title="Pop Out"><svg class="octicon octicon-link-external" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M11 10h1v3c0 .55-.45 1-1 1H1c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h3v1H1v10h10v-3zM6 2l2.25 2.25L5 7.5 6.5 9l3.25-3.25L12 8V2H6z"/></svg></a> </span> </span>
(<span class="fancylink"> <a href="https://github.com/rtfeldman/dreamwriter">source</a> <span> <a href="https://github.com/rtfeldman/dreamwriter" target="_blank" alt="Pop Out" title="Pop Out"><svg class="octicon octicon-link-external" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M11 10h1v3c0 .55-.45 1-1 1H1c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h3v1H1v10h10v-3zM6 2l2.25 2.25L5 7.5 6.5 9l3.25-3.25L12 8V2H6z"/></svg></a> </span> </span>),
which also incorporates the separation of components as outlined in the original
article.</p>
Writing Game of Life in Elm2014-05-05T00:00:00-04:00https://sonnym.com/2014/05/05/writing-game-of-life-in-elm<h2>Introduction</h2>
<p>In this article, we will walk through the steps for writing an implementation
of
<span class="fancylink"> <a href="https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life">Conway's Game of Life</a> <span> <a href="https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life" target="_blank" alt="Pop Out" title="Pop Out"><svg class="octicon octicon-link-external" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M11 10h1v3c0 .55-.45 1-1 1H1c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h3v1H1v10h10v-3zM6 2l2.25 2.25L5 7.5 6.5 9l3.25-3.25L12 8V2H6z"/></svg></a> </span> </span>
in the
<span class="fancylink"> <a href="http://elm-lang.org/">Elm</a> <span> <a href="http://elm-lang.org/" target="_blank" alt="Pop Out" title="Pop Out"><svg class="octicon octicon-link-external" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M11 10h1v3c0 .55-.45 1-1 1H1c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h3v1H1v10h10v-3zM6 2l2.25 2.25L5 7.5 6.5 9l3.25-3.25L12 8V2H6z"/></svg></a> </span> </span>
programming language.</p>
<p>In doing so, we will learn about the basic principles involved with writing
programs in Elm, while grounding them in a concrete problem. We will be
building a single program in steps, so much of the source will be repeated
between the examples, but it will be more clear to present each step in its
entirety.</p>
<p>I first became interested in Elm after seeing Evan Czaplicki's
<span class="fancylink"> <a href="http://lanyrd.com/2013/mlocjs/sccwrp/">talk</a> <span> <a href="http://lanyrd.com/2013/mlocjs/sccwrp/" target="_blank" alt="Pop Out" title="Pop Out"><svg class="octicon octicon-link-external" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M11 10h1v3c0 .55-.45 1-1 1H1c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h3v1H1v10h10v-3zM6 2l2.25 2.25L5 7.5 6.5 9l3.25-3.25L12 8V2H6z"/></svg></a> </span> </span>
from mloc.js 2013, where he presented an overview of Elm and the compelling example
of how one would write a simple side-scroller in an extremely straight forward
fashion as a consequence of the core concept in Elm: signals.</p>
Lazy Ruby2014-04-05T00:00:00-04:00https://sonnym.com/2014/04/05/lazy-ruby<h2>Lazy Evaluation and Recursive Lists</h2>
<p>In Haskell, it is possible to construct infinite lists via recursive
definition. This is only possible because Haskell uses
<span class="fancylink"> <a href="https://en.wikipedia.org/wiki/Lazy_evaluation">lazy evaluation</a> <span> <a href="https://en.wikipedia.org/wiki/Lazy_evaluation" target="_blank" alt="Pop Out" title="Pop Out"><svg class="octicon octicon-link-external" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M11 10h1v3c0 .55-.45 1-1 1H1c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h3v1H1v10h10v-3zM6 2l2.25 2.25L5 7.5 6.5 9l3.25-3.25L12 8V2H6z"/></svg></a> </span> </span>
rather than eager evaluation. Otherwise, the entire list would need to be
calculated and the program would never terminate.</p>
<p>Because Haskell makes it easy to define lists and is lazy, the code for
defining an infinite series is very simple. The following list represents
the fibonacci sequence.</p>
Hooks in AngularJS Controllers2014-02-05T00:00:00-05:00https://sonnym.com/2014/02/05/hooks-in-angularjs-controllers<h2>The Situation</h2>
<p>Sometimes when working with nested scopes, you may encounter a situation in
which some scope action depends on the status of some arbitrarily nested
controller. This could be a multi-part form built from reusable components,
preventing the user from proceeding until complete, for example.</p>
<p>An architecture that allows scopes nested within another scope to influence the
life cycle of the latter has one primary advantage, namely, greater separation
of concerns. A nested controller can supply functions for data validation and
formatting, while the parent controller defines functions for navigation and
accumulation of results. This leads to better modularity, as the parent
controller is isolated from the implementation of nested controllers, while the
latter are able to be used modularly in more contexts.</p>