<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Lumi - Medium]]></title>
        <description><![CDATA[Find us at https://www.lumi.com/blog - Medium]]></description>
        <link>https://medium.com/fuzzy-sharp?source=rss----d57e27362b5---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Lumi - Medium</title>
            <link>https://medium.com/fuzzy-sharp?source=rss----d57e27362b5---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 09:27:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/fuzzy-sharp" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[Using PureScript to create a domain-specific language for building forms with validation]]></title>
            <link>https://medium.com/fuzzy-sharp/building-a-type-safe-embedded-dsl-for-form-components-with-validation-e7ffaaf537e4?source=rss----d57e27362b5---4</link>
            <guid isPermaLink="false">https://medium.com/p/e7ffaaf537e4</guid>
            <category><![CDATA[haskell]]></category>
            <category><![CDATA[dsl]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[forms]]></category>
            <category><![CDATA[purescript]]></category>
            <dc:creator><![CDATA[Arthur Xavier]]></dc:creator>
            <pubDate>Thu, 08 Nov 2018 14:58:08 GMT</pubDate>
            <atom:updated>2019-05-23T17:25:00.399Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Note: </strong><a href="https://www.lumi.dev/blog/using-purescript-to-create-a-dsl-for-building-forms">This post</a> and our new engineering blog can be found at <a href="https://www.lumi.dev">lumi.dev</a></p><p>In a <a href="https://medium.com/fuzzy-sharp/purescript-and-haskell-at-lumi-7e8e2b16fb13">previous post</a> we have shown how we use PureScript and Haskell at <a href="https://www.lumi.com/">Lumi</a> to improve the correctness of our code. Using languages with such powerful type systems does not only help us write more correct code, but also help us think about domains and behavior, increasing our creativity and efficiency. However, the expressiveness of these languages is not only to be observed in their type system, but also in their syntax, what allows us to write — and use — embedded domain-specific languages with ease.</p><p>In this post, we will go through the process of creating a small type-safe embedded domain-specific language for specifying form components with validation in PureScript, explaining all the whys and hows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sj_-deIo6g_i7PbVc4Hpjg.jpeg" /></figure><h3>Embedded domain-specific languages</h3><p>Ever wished you could use a new language perfectly tailored to solve the specific problem at hand? These are called <em>domain-specific languages</em> (DSLs), computer languages specialized to a particular application domain. Some examples of DSLs are: HTML, CSS, Elm, SQL, GLSL, LaTeX, and Markdown — used to write this very article.</p><p>Creating a language for specific domains is, however, highly unpractical in modern software engineering. That’s why a common practice is to use <em>embedded</em> domain-specific languages (EDSLs), that is, domain-specific languages that are implemented as libraries for a general-purpose “host language”, allowing the EDSL to exploit the host language’s infrastructure, including its syntax, type system, modularity, etc., while enabling programmers to work on a much higher level of abstraction.</p><p>Languages like Haskell and PureScript, have such a rich syntax that using an EDSL in these languages can feel like writing in a different one. An example of this is what we will have by the end of this tutorial, an embedded domain-specific language for specifying form components with validation. Here is what a form written in this EDSL can look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*EDsxO_dCgBpr5Y65fnIyDQ.png" /></figure><p>To write this form, we start with simple form fields like textbox, passwordBox, numericInput or array, then add some focus to better see the parts of the complex data structure the form edits. We, then, add some syntactic sugar to the mixture with ado, sprinkle in some labels, section separators and validation with the validated combinator, and, voilà, we have a form! Here is the code that generates the form in the picture above:</p><pre>userForm :: Form UserFormData User<br>userForm = ado<br>  section &quot;User data&quot;<br>  username &lt;-<br>    label &quot;Username&quot; Required<br>    $ focus (prop (SProxy :: SProxy &quot;username&quot;))<br>    $ validated (nonEmpty &quot;Username&quot;)<br>    $ textbox<br><br>  password &lt;- wizard do<br>    password &lt;- step<br>      $ label &quot;Password&quot; Required<br>      $ focus (prop (SProxy :: SProxy &quot;password&quot;))<br>      $ validated (nonEmpty &quot;Password&quot;)<br>      $ passwordBox<br>    passwordConfirmation &lt;- step<br>      $ label &quot;Password confirmation&quot; Required<br>      $ focus (prop (SProxy :: SProxy &quot;passwordConfirmation&quot;))<br>      $ validated<br>          (mustEqual &quot;Passwords must match&quot; (toString password))<br>      $ passwordBox<br>    pure password<br><br>  section &quot;Personal data&quot;<br>  age &lt;-<br>    label &quot;Age&quot; Optional<br>    $ focus (prop (SProxy :: SProxy &quot;age&quot;))<br>    $ numericInput<br><br>  addresses &lt;-<br>    label &quot;Addresses&quot; Neither<br>    $ focus (prop (SProxy :: SProxy &quot;addresses&quot;))<br>    $ array defaultAddress addressForm<br><br>  in User { username, password, age, addresses }</pre><p>The reader is encouraged to return to this code snippet by the end of every section to understand how the developed concepts are used in a real example.</p><p>From reading the code above, one can already spot some advantages of using this approach (frequently called <a href="https://en.wikipedia.org/wiki/Language-oriented_programming">language-oriented programming</a>). The most significant one, however, is that it allows us to exploit the host language’s syntax — in this case PureScript — to write form specifications in a clear, type-safe, and <em>composable</em> way. This is why EDSLs are also often called <em>combinator libraries</em>, as we can use them to build complex structures out of simpler, composable ones.</p><h3>A language for specifying forms</h3><p>In a strict sense, a form is a user interface capable of modifying a data structure. It has an input and an output (or result). A translation of this definition to a PureScript type is:</p><pre>newtype Form a = Form (a -&gt; (a -&gt; Effect Unit) -&gt; UI)</pre><p>Here, a is the type of the data structure which is manipulated by the form, a -&gt; Effect Unit is a callback for when the input value gets changed in the user interface (henceforth called the &quot;change callback&quot;), and UI is a visual representation of the interface (can be a Virtual DOM, React&#39;s JSX, GTK widgets, or even text).</p><p>A better definition of Form, however, must include a differentiation between input and output. One reason for this is that different UI representations might yield different input types; for example, some user interface library might use a specific data type of a checkbox&#39;s <em>checked</em> state instead of a Boolean, the desired output for such an input field. Some larger forms might also have a more condensed output than there are fields in them. For these reasons, we can rewrite our definition of the Form type as:</p><pre>newtype Form i a =<br>  Form (i -&gt; { ui :: (i -&gt; Effect Unit) -&gt; UI, result :: a })</pre><p>The reason for including the change callback in the ui field of the result record is that it is considered a part of the user interface, and should not be a requirement for obtaining an output from the form.</p><h4>Combining forms</h4><p>According to the definition of Form i a, a form can be <em>any</em> user interface capable of manipulating a data structure of type i and yielding a result of type a. In particular, single input fields such as text boxes and check boxes may be treated like simple forms themselves.</p><p>In order to build larger forms from many fields, we might try to build a Form by hand each time. However, we would prefer to find a way of combining these single-input forms into larger, more useful forms. In order to do this, we can make use of a few PureScript type classes, notably the Applicative type class.</p><p>In order to instantiate the Applicative type class for Form, we must also have instances of the Functor and Apply type classes. When instantiated to Form, these three classes provide us the following three functions:</p><ul><li>Functor: map :: (a -&gt; b) -&gt; Form i a -&gt; Form i b</li><li>Apply: apply :: Form i (a -&gt; b) -&gt; Form i a -&gt; Form i b</li><li>Applicative: pure :: a -&gt; Form i a.</li></ul><p>The map function from the Functor type class allows us to change the result type of a form, while the pure function from Applicative allows us to create an empty form that produces a specific, pre-defined result.</p><p>In this case, however, the most important of the three functions is apply, from the Apply type class. When used together with map, the apply function allows us to combine multiple forms (both their UIs and their result types), so that we can create a larger form out of multiple, individual ones.</p><p>This type class is often associated with side effects, and in this context, we can think of the combination of form UIs as being a side effect of composing forms and their results, as with the Writer monad, which accumulates a monoid on the side.</p><p>Considering that &lt;$&gt; is the infix operator for map, and &lt;*&gt; is the one for apply, an example of this is:</p><pre>personForm =<br>  (\firstName lastName { address, city } -&gt; firstName &lt;&gt; &quot; &quot; &lt;&gt; lastName &lt;&gt; &quot; lives at &quot; &lt;&gt; address &lt;&gt; &quot;, &quot; &lt;&gt; city)<br>  &lt;$&gt; firstNameForm<br>  &lt;*&gt; lastNameForm<br>  &lt;*&gt; addressForm</pre><p>Or using PureScript’s ado-notation, a syntactic sugar that translates expressions written in <em>applicative syntax</em> (such as the example above) to a do-notation inspired syntax, such as below:</p><pre>personForm = ado<br>  firstName &lt;- firstNameForm<br>  lastName &lt;- lastNameForm<br>  { address, city } &lt;- addressForm<br>  in firstName &lt;&gt; &quot; &quot; &lt;&gt; lastName &lt;&gt; &quot; lives at &quot; &lt;&gt; address &lt;&gt; &quot;, &quot; &lt;&gt; city</pre><p>This is the basis of our DSL for specifying form components: a Form data type with input and output types, a current value, and a user interface (comprised of a change callback and a UI representation); and (polymorphic) functions that let us combine multiple Forms.</p><h4>Editing a data structure with a form</h4><p>The goal of this DSL is to combine multiple small forms (as single input fields are also forms) to obtain a more complex one that can be used to edit a large data structure. Consider the case of the previous example, where we could have the following data structure:</p><pre>type PersonFormData =<br>  { firstName :: String<br>  , lastName :: String<br>  , address ::<br>      { address :: String<br>      , city :: String<br>      }<br>  }</pre><p>In this case, each single form field (a Form value itself) must have PersonFormData as its input type, and this means that we wouldn&#39;t be able to, for example, use a general text box for the firstName field, as this text box would have the type:</p><pre>textbox :: Form String String</pre><p>Fortunately, it’s possible to fix this problem by using <em>lenses</em>.</p><p>Also called <em>functional references</em>, lenses are composable functions that let us edit some part of a data structure. Lenses are a natural fit for forms, whose purpose is to visually edit a large structure in terms of its smaller parts.</p><p>The <a href="https://pursuit.purescript.org/packages/purescript-profunctor-lenses/">purescript-profunctor-lenses</a> library provides a comprehensive set of types and composable functions for updating, viewing and setting values within nested data structures. Given that the type Lens&#39; s a describes a way of viewing or transforming a value of type a that always exists somewhere inside a structure of type s, a function that changes a form to focus on a small part of a larger structure would have type:</p><pre>focus :: forall i j a. Lens&#39; i j -&gt; Form j a -&gt; Form i a</pre><p>Knowing that the functions view and set (from the <a href="https://pursuit.purescript.org/packages/purescript-profunctor-lenses/">purescript-profunctor-lenses</a> library) allow us to, respectively, view and set a value to which the specified lens points, we can implement the focus function as:</p><pre>focus :: forall i j a. Lens&#39; i j -&gt; Form j a -&gt; Form i a<br>focus l (Form f) =<br>  Form \i -&gt;<br>    let<br>      { ui, result } = f (view l i)<br>    in<br>      { ui: \onChange -&gt; ui (onChange &lt;&lt;&lt; flip (set l) i)<br>      , result<br>      }</pre><p>With focus, now we are able to edit complex data structures with Form. An example is the implementation of personForm below. Note that the prop function creates a lens that focuses on a specific field of a record (given an SProxy to the field&#39;s label):</p><pre>personForm :: Form PersonFormData String<br>personForm = ado<br>  firstName &lt;- focus (prop (SProxy :: SProxy &quot;firstName&quot;)) textbox<br>  lastName &lt;- focus (prop (SProxy :: SProxy &quot;lastName&quot;)) textbox<br>  { address, city } &lt;- focus (prop (SProxy :: SProxy &quot;address&quot;)) addressForm<br>  in firstName &lt;&gt; &quot; &quot; &lt;&gt; lastName &lt;&gt; &quot; lives at &quot; &lt;&gt; address &lt;&gt; &quot;, &quot; &lt;&gt; city</pre><pre>addressForm :: Form { address :: String, city :: String } String<br>addressForm = ado<br>  address &lt;- focus (prop (SProxy :: SProxy &quot;address&quot;)) textbox<br>  city &lt;- focus (prop (SProxy :: SProxy &quot;city&quot;)) textbox<br>  in { address, city }</pre><p>Notice how the lenses used in the definition of addressForm compose with the one used in personForm when applying focus to addressForm. This is the power of composable lenses, and how they allow us to edit a large, complex data structure with our (so far) simple DSL.</p><h3>Adding validation to the language</h3><p>Validated forms are nothing more than forms whose output depends on some validation criteria. Let’s recall the definition of our Form type:</p><pre>newtype Form i a = Form (i -&gt; { ui :: (i -&gt; Effect Unit) -&gt; UI, result :: a })</pre><p>In this definition we can see that, if we provide a (unvalidated) input value to the form, we will <em>always</em> get back a user interface and an <em>output value</em>.</p><p>In order to have a validated form, then, we must simply change the return type of the function wrapped in the Form constructor. If a validated form does not <em>always</em> return a valid output, then it&#39;s natural to change this definition to:</p><pre>newtype Form i a =<br>  Form (i -&gt; { ui :: (i -&gt; Effect Unit) -&gt; UI, result :: Maybe a })</pre><p>Note that, with this change, the Functor, Apply and Applicative instances of Form must also be changed to take the optional return value into account. If a form yields its return value as Nothing, this means it&#39;s invalid, as we will not be able to retrieve a value of type a by running the form. If it yields a Just a case, however, then it&#39;s valid.</p><p>This, in turn, changes the way the forms behave. That is, although all the form UIs get concatenated in an applicative chain (with ado-notation or with &lt;$&gt; and &lt;*&gt;), the final result is only available if all the intermediary forms yield a valid result.</p><h4>Handling validation errors</h4><p>The choice of the type constructor used to wrap the form’s output value may be contested. Maybe was chosen because we don&#39;t want to handle validation errors outside the form. Other valid choices for this type constructor could be Eitheror the V type, from the <a href="https://pursuit.purescript.org/packages/purescript-validation/4.0.0/docs/Data.Validation.Semigroup#t:V">purescript-validation</a> library. The latter would allow us to accumulate validation errors if more than one form field is invalid.</p><p>With Maybe, however, we chose to encapsulate the handling of validation errors in the user interface itself. In this sense, we need a way of transforming a form in order to display validation errors. But first we must define what <em>validation</em> actually is.</p><p>In the context of validated forms, a value can be either valid or invalid. If invalid, we would like to know what happened, that is, we would like to have a <em>validation error</em>. If it is valid, however, we would probably like to transform it into an output value of a different type. For example, a required text field might have its input encoded as a String, whereas its output value should be a NonEmptyString.</p><p>Thus, we define a <em>validator</em> as:</p><pre>type Validator i a = i -&gt; Either String a</pre><p>Some examples of validators are:</p><pre>nonNull :: String -&gt; Validator (Maybe a) a<br>nonNull name = maybe (Left (name &lt;&gt; &quot; is required.&quot;)) Right</pre><pre>nonEmpty :: String -&gt; Validator String NonEmptyString<br>nonEmpty name s =<br>  case NonEmptyString.fromString s of<br>    Just nes -&gt; Right nes<br>    Nothing -&gt; Left (name &lt;&gt; &quot; is required.&quot;)</pre><pre>mustEqual :: forall a. Eq a =&gt; a -&gt; String -&gt; Validator a a<br>mustEqual value1 error value2 =<br>  if value1 == value2<br>    then Right value1<br>    else Left error</pre><p>The one thing left to properly integrate validation into our DSL is a <em>combinator</em> that uses a Validator. Given a Validator, this combinator must change a Form to display validation errors if its result is invalid, and change the result type:</p><pre>validated :: forall i a b. Validator i b -&gt; Form i a -&gt; Form i b<br>validated validator (Form f) =<br>  Form \v -&gt;<br>    let<br>      { ui } = f v.value<br>      err = validator v.value<br>    in<br>      { ui: \onChange -&gt; displayValidationError err (ui onChange)<br>      , result: hush err<br>      }</pre><p>That’s it! Given a function displayValidationError that appends a validation error to the form, we can use a function as simple validated to validate our forms and display errors.</p><p>The validated function as defined above doesn&#39;t take into account, however, the state of the form fields in order to display the validation errors. That is, if a form field is unmodified, but is validated as a non empty string, the error message will be displayed anyway. This is not a good user experience, and, to fix it, we must track the state of a form field when it is being validated.</p><h4>Tracking form field state for validation messages</h4><p>Consider a simple change to the behavior of our form: validation errors should only be displayed if a form field has been modified.</p><p>As with all other combinators in our DSL, if we want to change the behavior of a form based on its input, we should create a new combinator that acts on it, possibly changing the input type. This is exactly what we want in this case, that is, to embellish the input of a form field with an additional state: whether or not it has been modified. This can be achieved with a simple type:</p><pre>type Validated a = { value :: a, modified :: Boolean }</pre><p>The Validated type defines the state of a form field on which validation is performed. It contains a value and can be either a fresh or a modified field. Another possibility for this is to change the definition of Form to encapsulate the input type in Validated, but we chose the first option for the sake of simplicity.</p><p>The only change left now is to effectively track this state on validated fields. For this, we need to change the result of the validated function to be a Form whose input is of type Validated i. Notice, also, how modified is set to true when building the resulting user interface:</p><pre>validated<br>  :: forall i a b<br>   . Validator i b<br>  -&gt; Form i a<br>  -&gt; Form (Validated i) b<br>validated validator (Form f) =<br>  Form \v -&gt;<br>    let<br>      { ui } = f v.value<br>      err = validator v.value<br>    in<br>      { ui: \onChange -&gt;<br>          displayValidationError<br>            err<br>            (ui (onChange &lt;&lt;&lt; { value: _, modified: true }))<br>      , result: hush err<br>      }</pre><p>With this simple change, every time the value of a form field is changed, its modified flag is set to true. As a consequence, in order for this mechanism to work as expected, we must initialize all form fields of type Validated i with the modified flag set to false.</p><p>It’s noticeable that we can include all sorts of different states in the Validated type, some interesting possibilities include: asynchronous validation, debouncing, validation based on the focus state and much more.</p><h4>Monadic validation and wizards</h4><p>One interesting fact about the DSL we have so far, is that it admits a Monad instance. This is another advantage of choosing Maybe for the form&#39;s output value (over V, for example), as it has a lawful Monad instance.</p><p>What this means in terms of behavior, is that, in a monadic chain, subsequent form fields are only displayed if all the previous ones produce valid results, just as in a <a href="https://en.wikipedia.org/wiki/Wizard_(software)">wizard</a>.</p><p>The problem, however, is that this Monad instance is incompatible with the Apply instance of Form. In order to remedy this situation, we can define a newtype that simply encapsulates a Form and adds this wizard-like behavior in a compatible way:</p><pre>newtype Wizard i a = Wizard (Form i a)</pre><pre>wizard :: forall i. Wizard i ~&gt; Form i<br>wizard (Wizard form) = form</pre><pre>step :: forall i. Form i ~&gt; Wizard i<br>step = Wizard</pre><p>The Functor and Applicative instances for Wizard can be newtype-derived. The Apply instance, however, must be defined in terms ofap, so that it is compatible with the Monad instance, which is left as an exercise for the reader.</p><p>Besides providing us the wizard-like behavior, the greatest advantage of having a Monad instance, is that we&#39;re now able to have sequential dependencies on validated values.</p><p>One good illustration of this is a form containing fields for password and password confirmation, where the password confirmation is validated with mustEqual over the valid password:</p><pre>passwordForm :: Form _ NonEmptyString<br>passwordForm = wizard do<br>  password &lt;- step<br>    $ focus (prop (SProxy :: SProxy &quot;password&quot;))<br>    $ validated (nonEmpty &quot;Password&quot;)<br>    $ passwordBox</pre><pre>  passwordConfirmation &lt;- step<br>    $ focus (prop (SProxy :: SProxy &quot;passwordConfirmation&quot;))<br>    $ validated<br>        (mustEqual &quot;Passwords must match&quot; (toString password))<br>    $ passwordBox</pre><pre>  pure password</pre><p>Here’s what it looks like in action (the field labels are a different combinator, not defined here as it depends on the choice for UI):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/0*0q49GPjlXCyEL7Ba.gif" /></figure><h4>Fetching remote data with Wizard</h4><p>The convenience introduced by the Monad instance of Wizard begets its exploitation. For example, if the UI representation allows for side-effects to be performed when it is rendered, then it is possible to have a dummy form field that fetches some remote data that is used within the form:</p><pre>fetch :: Aff a -&gt; Form (Maybe a) a<br>fetch = ...</pre><pre>countryStateForm :: Form _ Address<br>countryStateForm = wizard do<br>  countries &lt;- step<br>    $ focus (prop (SProxy :: SProxy &quot;countries&quot;))<br>    $ fetch loadAllCountries<br><br>  country &lt;- step<br>    $ focus (prop (SProxy :: SProxy &quot;country&quot;))<br>    $ validated (nonNull &quot;Country&quot;)<br>    $ select countries<br><br>  states &lt;- step<br>    $ focus (prop (SProxy :: SProxy &quot;states&quot;))<br>    $ fetch (loadStatesForCountry country)<br><br>  step ado<br>    state &lt;-<br>      focus (prop (SProxy :: SProxy &quot;state&quot;))<br>      $ validated (nonNull &quot;State&quot;)<br>      $ select states<br>    postalCode &lt;-<br>      focus (prop (SProxy :: SProxy &quot;postalCode&quot;))<br>      $ validated (nonEmpty &quot;Postal code&quot;)<br>      $ textbox<br>    in Address { country, state, postalCode }</pre><p>The step combinator transforms a Form into a Wizard, and, due to Wizard&#39;s Monad instance, steps that follow each other in a monadic chain are sequential, that is, the next step is only available if all the previous steps are valid and have produced an output value. This happens because Monad introduces sequential dependency on values. One can notice this sequential dependency in the example above, as the country field depends on the value countries produced by the first form field.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*zUBAf_oh7zRGQvIAor9ZwA.gif" /><figcaption>The code above generates this simple, yet interesting form.</figcaption></figure><h3>Conclusion</h3><p>The embedded domain-specific language described in this post to specify and generate type-safe form UIs with validation has proven itself a successful experiment at Lumi. It has allowed us to, not only build our forms in a type-safe way, avoiding errors and enforcing constraints on the data structures and on the behavior of the forms, but has also enabled the team to build new forms much faster and more consistently with a small language that can produce complex and reusable forms that are yet easy to understand and maintain.</p><p>The types and functions described here are also a simplification of what we actually use at Lumi. Since we use <a href="https://github.com/lumihq/purescript-react-basic">purescript-react-basic</a> to render our user interfaces, the UI type used throughout this post is different. Based on our UI guidelines for forms, we have also decided to use a more specific UI type that takes into account the input fields&#39; labels, validation errors and nested fields. Other improvements worth mentioning are: the inclusion of a props parameter to the Form type, which is used as an argument to the function wrapped by form (besides the input value of type i); and a type class that generates default data for empty forms.</p><p>Some alternative approaches to the problem are worth mentioning, most notably David Peter’s <a href="https://github.com/sharkdp/purescript-flare">purescript-flare</a>, and <em>Formlets</em>, as described in the paper <a href="http://homepages.inf.ed.ac.uk/slindley/papers/formlets-essence.pdf"><em>The Essence of Form Abstraction</em></a> by Cooper et al., which served as inspiration for the approach presented here.</p><p>If you have any questions, ideas, or any other kind of feedback, please leave a comment below.</p><p>And if you’re interested in using PureScript to solve real-world problems like this one, then get in touch — <a href="https://www.lumi.com/jobs">we’re hiring at Lumi</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7ffaaf537e4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fuzzy-sharp/building-a-type-safe-embedded-dsl-for-form-components-with-validation-e7ffaaf537e4">Using PureScript to create a domain-specific language for building forms with validation</a> was originally published in <a href="https://medium.com/fuzzy-sharp">Lumi</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PureScript and Haskell at Lumi]]></title>
            <link>https://medium.com/fuzzy-sharp/purescript-and-haskell-at-lumi-7e8e2b16fb13?source=rss----d57e27362b5---4</link>
            <guid isPermaLink="false">https://medium.com/p/7e8e2b16fb13</guid>
            <category><![CDATA[haskell]]></category>
            <category><![CDATA[purescript]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming-languages]]></category>
            <dc:creator><![CDATA[Phil Freeman]]></dc:creator>
            <pubDate>Mon, 06 Aug 2018 20:19:26 GMT</pubDate>
            <atom:updated>2019-05-23T17:25:48.517Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IQkteOcQYDxrMz-i3Wxzeg.png" /><figcaption>The PureScript logo by Gareth Hughes is licensed under the <a href="https://creativecommons.org/licenses/by/4.0/">CC-BY 4.0 license</a></figcaption></figure><p><strong>Note: </strong><a href="https://www.lumi.dev/blog/purescript-and-haskell-at-lumi">This post</a> and our new engineering blog can be found at <a href="https://www.lumi.dev">lumi.dev</a></p><p>At <a href="https://www.lumi.com/">Lumi</a>, we take the correctness of our code seriously. “Code correctness” is a tricky thing to define fully, but we can begin by trying to eradicate things like type errors and unhandled exceptions. This sort of correctness is important for understanding and communicating data confidently and accurately, especially when that data is related to large financial transactions or the manufacture of large numbers of physical goods.</p><p><a href="https://medium.com/fuzzy-sharp/migrating-to-postgres-2dc1519a6dc7">Previously</a>, I talked about how we were able to ensure correctness while successfully migrating our database from RethinkDB to Postgres by leaning heavily on Haskell. That was almost one year ago, and since then we’ve been able to build on the work done there, to develop a large and stable backend application.</p><p>In this blog post, I’m going to tell a similar story about how we’re improving correctness on the front-end by moving from JavaScript to <a href="http://purescript.org">PureScript</a>.</p><h3>The need for types on the front-end</h3><p>We get a lot of benefit from using Haskell on the backend at Lumi. All of our API servers and clients are written in Haskell using <a href="http://haskell-servant.readthedocs.io/en/stable/">Servant</a>, and we use <a href="https://hackage.haskell.org/package/esqueleto">esqueleto</a> and <a href="http://hackage.haskell.org/package/persistent">persistent</a> (with a generous helping of custom DSLs) to write our SQL queries. It is extremely rare for us to encounter a runtime error in production on our servers, and when we do, it is usually of the “business logic error” variety. It’s hard to overstate the value of having types everywhere on the backend.</p><p>Our front-end is a large web application written using React, with plenty of logic of its own. So why then, if types are so useful to us, were we using untyped JavaScript with React on the front-end, when JavaScript offers comparatively few guarantees? There are a few answers:</p><ol><li>When our product was new, there were fewer options available, and the options we might have chosen were immature.</li><li>Everyone on the team was able to write JavaScript effectively, but not everyone was familiar with compile-to-JavaScript languages. Now we have enough developers that we don’t need to worry about that, but originally, it was useful for everyone to be able to contribute easily.</li><li>JavaScript was a suitable choice for a small application initially, allowing us to iterate quickly, but is less suitable now that the project has grown in scope. It is not particularly difficult to build new code in JavaScript, but it is difficult to maintain a large JavaScript application, requiring extensive tests for things which could be covered by types.</li></ol><p>Of course, types are not just a tool for guaranteeing correctness. A common complaint is that a type system might decrease developer productivity by requiring the user to add type annotations to provide any guarantee of correctness, but a sufficiently expressive type system like the one in GHC is able to actually <em>increase</em> developer productivity by providing tools like <a href="https://en.wikipedia.org/wiki/Parametric_polymorphism">parametric polymorphism</a>, <a href="https://en.wikipedia.org/wiki/Type_class">type classes</a>, <a href="https://wiki.haskell.org/Category:Type-level_programming">type-level programming</a> and <a href="https://wiki.haskell.org/Generics">datatype generic programming</a>.</p><p>Finally, types are also a wonderfully succinct language for expressing ideas and processes, and we wanted that language to be available on the front-end as well.</p><h3>The decision to use PureScript</h3><p>I had personally used typed front-end languages (<a href="https://www.typescriptlang.org/">TypeScript</a> and PureScript) extensively, and other team members had similar experience with other options like <a href="https://flow.org/">Flow</a> and <a href="http://elm-lang.org/">Elm</a>. As the original developer of the PureScript compiler, I had an obvious interest in seeing it adopted at Lumi, but I was also aware that it might not be the optimal choice of front-end language for a few reasons:</p><ul><li>Other team members might not enjoy using it as much as I do, or might find themselves to be less productive.</li><li>Using a relatively uncommon programming language might make it more difficult to hire developers.</li><li>Without language-level support for things like JSX and CSS, we would need to find some other way to work with our design team, who previously were able to modify our React components directly if necessary.</li><li>The library ecosystem is relatively small, and we would need to build some things of our own in order to be productive.</li></ul><p>As a team, we were in agreement that JavaScript was causing a lot of problems for us, but we weren’t sure about the best approach to fix them. To my pleasant surprise, a majority of the team were enthusiastic about trying PureScript as the first option, because it fits our needs well.</p><p>You might be asking how we chose PureScript out of the many available options for typed front-end development. Aside from the in-house experience and my own preference for demonstrating its use on a large real-world application, there are a few technical reasons. It is simplest to just say that PureScript was the unique solution to the following set of constraints:</p><ul><li>The setup process should be simple and unintrusive. It should be trivial to set up an environment to quickly test out ideas.</li><li>The language should integrate smoothly with JavaScript, its libraries and its build tools.</li><li>The type system should be expressive, supporting things like sum types, row polymorphism, type classes and higher-kinded types.</li><li>It should be easy to build simple solutions, but still possible to experiment with more advanced ideas. As Justin Woo <a href="https://speakerdeck.com/justinwoo/type-safe-type-level-type-driven-solutions-with-purescript?slide=7">puts it</a>, the language should have a culture of “the sky is the limit” and should not limit your creativity.</li><li>The development of the language itself should be open enough that we would be able to modify any part of the toolchain if it became necessary.</li></ul><h3>Getting started</h3><p>Eventually, we decided to jump in and try out PureScript by replacing one of our existing JSX-based React components. We chose a simple, pure component with no side-effects or API calls. After setting up the PureScript compiler in our existing Webpack-based build, we were off to a good start.</p><p>I was a little concerned about the suitability of the existing React bindings for our purposes (they were a little too complicated, as they tried to support the full React API, which we didn’t need), so I cobbled together a simplified set of React bindings for us to use. We’ve since polished and released those bindings as a separate library called <a href="https://github.com/lumihq/purescript-react-basic">purescript-react-basic</a>.</p><p>Now that we had proven that the approach could work, we started porting more and more of our pure components over to react-basic. We knew, however, that we wanted to be able to replace our API calls and page-level components as well. For this, we decided to use code generation, since our API is large and changes reasonably frequently, and we wanted to ensure as much correctness as we could.</p><h3>Generating types</h3><p>The first step was to generate a complete set of PureScript types to correspond to the types we used in our Haskell API. To solve this problem, we turned to GHC Haskell’s support for datatype-generic programming. We created a simplified representation of PureScript data types (PursTypeConstructor), and a type class for Haskell record types which would be converted into PureScript types (ToPursType):</p><pre>data PursRecord = PursRecord<br>  { recordFields :: [(Maybe Text, PursType)]<br>  }</pre><pre>data PursTypeConstructor = PursTypeConstructor<br>  { name      :: Text<br>  , dataCtors :: [(Text, PursRecord)]<br>  }</pre><pre>class ToPursType a where<br>  toPursType :: Tagged a PursTypeConstructor</pre><pre>  default toPursType <br>    :: ( Generic a<br>       , GenericToPursType (Rep a)<br>       )<br>    =&gt; Tagged a PursTypeConstructor<br>  toPursType = retag $ genericToPursType @(Rep a) id</pre><p>The toPursType member of the type class creates a representation of the type class, tagged with the original Haskell type it originated from.</p><p>It would be tedious and error-prone to write these instances out by hand, so we provide a default implementation of the type class for record types which implement the Generic interface. Luckily, GHC will derive Generic instances for us if we turn on the -XDeriveGeneric extension, so generating these representations of our Haskell types is practically free.</p><p>Once we have a list of PursTypeConstructor structures, we can turn them into PureScript code fairly easily — nothing fancy needed here, just simple string templating. For convenience, we also emit a little extra code to make our generated types usable on the PureScript side: serialization boilerplate (itself derived using PureScript’s own version of datatype-generic programming!), Lenses and Isos for all fields and data constructors, functions for debugging, and so on.</p><h3>Generating API clients</h3><p>The next step was to turn our Haskell API definitions into usable, safe PureScript clients. Fortunately, Servant is perfect for this task — since our API definitions are represented at the type-level, we can turn those definitions into PureScript code and know for sure that the resulting code will be compatible with the server implementation.</p><p>The <a href="http://hackage.haskell.org/package/servant-foreign">servant-foreign</a> library was perfect for solving this problem, since it generates the data structures we need, including lists of API endpoints with reasonable names and all of the types of query parameters, request bodies and response bodies. From there, it’s just a question of assembling the PureScript code from those data structures.</p><p>The only tricky bit is providing the necessary HasForeignType instances which are necessary in order to convert names of Haskell types into names of PureScript types. We chose to reuse the same names, and then a dash of Template Haskell magic is all that’s needed to traverse the graph of types and generate all of the necessary instances, thanks to the incredibly useful <a href="http://hackage.haskell.org/package/th-reify-many">th-reify-many</a> library:</p><pre>$(do names &lt;- reifyManyWithoutInstances &#39;&#39;HasForeignType<br>       [ &#39;&#39;Order<br>       , -- ... a list of other top-level types goes here<br>       ] (const True)<br>     let toInstance nm =<br>           let tyCon = TH.ConT nm<br>               nmLit = TH.LitE (TH.StringL (TH.nameBase nm))<br>           in [d| instance HasForeignType<br>                             Purs<br>                             PursType<br>                             $(pure tyCon)<br>                    where<br>                      typeFor _ _ _ = PursTyCon $(pure nmLit)<br>                |]<br>     concat &lt;$&gt; mapM toInstance names<br> )</pre><p>This needs a little explanation:</p><ul><li>reifyManyWithoutInstances traverses the type graph looking for types without HasForeignType instances</li><li>For each type it finds, the toInstance function turns its name into a HasForeign type instance using a Template Haskell splice. The tyCon and nmLit nodes are in scope, so we can use anti-quotation $(...) to use them in the splice.</li></ul><h3>Types as a tool</h3><p>As I mentioned earlier, a good type system should increase productivity by reducing busywork. In addition to making our API clients free from boilerplate, we’ve been able to increase productivity in a number of other areas since implementing PureScript. I hope to be able to write about each of these in some detail in future:</p><ul><li>We have built a collection of completely generic UI components on top of our typed API clients. For example, we have one table component which is parameterized by the API which provides its data and search capabilities. If we change the API, the compiler reminds us to update the table!</li><li>We have built a combinator library for assembling forms which are compatible with our API types. By using lenses and a handful of basic functions, we are able to build type-safe forms in a fraction of the time it would take by hand.</li><li>We have also built a type-level DSL in the style of Servant for deriving forms from types for certain data collection tasks. Just as Servant allows us to repurpose our type-level API definitions for the generation of API clients and documentation, we can reuse our type-level form descriptions for all sorts of things like storage in the database, indexing and querying.</li></ul><p>We have plans to implement more type-directed tools in the future:</p><ul><li>As I described in my blog post about our migration to Postgres, we have implemented a completely generic backend solution on top of our Postgres database, including filtering, search, and computed fields. We are working towards implementing the same level of reusability on the front-end, by abstracting over common API client patterns.</li><li>Now that our API clients are represented on the front-end, we would like to find new ways of representing our API calls, and find ways to implement features like batching and caching in a generic way.</li></ul><p>If this sort of work sounds appealing, <a href="https://lumi.com/jobs">we are hiring</a>!</p><h3>Conclusion</h3><p>While we still have a way to go, our experience with PureScript so far has been very positive. Instead of touting its benefits myself, I’ll leave you with a few quotes from the team:</p><blockquote>The main thing I notice is that it’s easier to expand abstractions. You can take something really specific and incrementally make it more general.</blockquote><blockquote>— Brady</blockquote><blockquote>[I’ve had] such a positive experience, with little mental overhead, and total trust in the compiler. I implemented an entire page with a list of data, filters, search, and pagination which worked first time.</blockquote><blockquote>— Brandon</blockquote><blockquote>I’ve been a fan of Javascript’s “loose” style; but as the applications I’ve worked on got larger, fear of the “<strong>null”</strong> or “undefined” began to take over. Using PureScript ensures any incorrect logic is caught or contained. I can feel more confident in the code I push out.</blockquote><blockquote>— Kimi</blockquote><blockquote>After a few months in PureScript, having to edit the occasional JavaScript file fills me with anxiety — a typo or incorrect assumption anywhere could break half the site! In PureScript, even if I’ve gotten the business logic wrong somewhere, the problem is always contained.</blockquote><blockquote>— Madeline</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e8e2b16fb13" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fuzzy-sharp/purescript-and-haskell-at-lumi-7e8e2b16fb13">PureScript and Haskell at Lumi</a> was originally published in <a href="https://medium.com/fuzzy-sharp">Lumi</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Custom manufacturing should be as scalable as the web]]></title>
            <link>https://medium.com/fuzzy-sharp/custom-manufacturing-should-be-as-scalable-as-the-web-964aaa6f5a37?source=rss----d57e27362b5---4</link>
            <guid isPermaLink="false">https://medium.com/p/964aaa6f5a37</guid>
            <category><![CDATA[announcements]]></category>
            <dc:creator><![CDATA[Steph Ango]]></dc:creator>
            <pubDate>Wed, 14 Feb 2018 16:57:54 GMT</pubDate>
            <atom:updated>2018-07-13T20:07:13.696Z</atom:updated>
            <content:encoded><![CDATA[<h4>Announcing Lumi’s Series A, led by Spark Capital, Forerunner Ventures and Homebrew.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kFEWmLWDMSoN_t3tivZ_VA.jpeg" /></figure><p>Three years ago we launched <a href="https://www.lumi.com">Lumi.com</a> to help e-commerce companies produce custom packaging. Today, <a href="https://twitter.com/jessegenet">Jesse Genet</a> and I are thrilled to announce we’ve raised a $9M Series A.</p><p>In 2017, tens of millions of packaging items were produced using the Lumi platform. If you bought something on the internet recently, chances are high that it came in box or an envelope made with Lumi.</p><p>Online brands use Lumi packaging to ship everything from clothing to food, books, electronics, games, mattresses, cosmetics and medicine.</p><p>Many of our customers bring a new perspective to how business can be reinvented for the 21st century. They’re making commerce more inclusive, more sustainable, more accessible, more personal. They are challenging the status quo and are enabled by the internet to flourish more freely than ever before. We think Lumi can break down a few of the logistical barriers that still stand in their way.</p><p>Historically, the packaging supply chain was designed for companies that developed slowly and regionally, but today businesses are able to develop rapidly and globally. In the past three years, we’ve helped companies grow from branding their packaging with a simple rubber stamp, to producing hundreds of truckloads of <a href="https://www.lumi.com/products/corrugated-mailer-boxes">printed boxes</a>. We’re designing that flexibility into Lumi because your supply chain should be as scalable as your online store.</p><p>Eighteen months ago <a href="https://medium.com/fuzzy-sharp/vertical-commerce-and-how-the-next-generation-of-retail-will-be-built-1ef35f2fc695">I wrote about vertical commerce brands</a> (aka VCBs, or <a href="https://medium.com/@dunn/digitally-native-vertical-brands-b26a26f2cf83">DNVBs</a>) and how their supply chain will evolve:</p><blockquote>VCBs sell physical things, atoms. But when it comes to making and moving them, VCBs want these physical things to behave more digitally, like bits. They want their physical infrastructure to scale as easily as their AWS-powered site.</blockquote><p>The magic behind Lumi is networked manufacturing, i.e. bringing factories online. Instead of managing communications with individual suppliers for each item, the Lumi Dashboard centralizes this process. Each item is abstracted into specifications and the best factory for each job is picked based on criteria for cost, quality and lead time. Our extensive network of factories allows us to locate manufacturing within 50 miles of almost any distribution center in the United States. If fulfillment moves to a different part of the country, production can be quickly re-located near the new distribution center.</p><p>As we learn a company’s usage patterns, individual optimizations can be made to improve sustainability, reliability and costs. As the entire system gets more efficient, major reductions in waste and carbon emissions can be achieved.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*votTk0Jq4f4_gdjk6WFvIw.png" /><figcaption>Items in the Lumi Dashboard</figcaption></figure><p>We’re often asked if our customers eventually outgrow Lumi — some might! But conceptually, we don’t see a limitation. Take the example of Netflix, which accounts for over a third of internet traffic in the US. In <a href="https://medium.com/netflix-techblog/four-reasons-we-choose-amazons-cloud-as-our-computing-platform-4aceb692afec">an excellent blog post</a>, Netflix explained the four reasons why they rely on Amazon Web Services to host and stream their content. These closely match the reasons even big brands are switching to Lumi:</p><blockquote>1. We needed to re-architect, which allowed us to question everything, including whether to keep building out our own data center solution.<br>2. Letting Amazon focus on data center infrastructure allows our engineers to focus on building and improving our business.<br>3. We’re not very good at predicting customer growth or device engagement.<br>4. We think cloud computing is the future.</blockquote><p>Since publishing this article in 2010, Netflix has experimented with its own data centers but consistently returned to AWS for these reasons. Rolling your own hosting, much like building your own payment processor, checkout or email delivery system, is not only unnecessary, it has become less cost-effective and potentially detrimental compared to using a dedicated service — even at large scale.</p><p>Up until now, this level of flexibility was only available in the digital world. But the same challenges hold true for manufacturing and logistics. Lumi is all about proving that those constraints can be lifted in the physical world. That’s the idea we’re building upon every day.</p><p>To help accomplish this goal we set out to find people who could finance the next phase of Lumi. At the very top of that list were two names: <a href="http://sparkcapital.com/">Spark Capital</a> and <a href="http://forerunnerventures.com/">Forerunner Ventures</a>. We couldn’t be more excited that they agreed. Kevin Thau of Spark led our $9M Series A, with Kirsten Green of Forerunner Ventures, and Satya Patel continued <a href="http://homebrew.co/">Homebrew</a>’s amazing support.</p><p>📦 Need help with your packaging? <a href="https://www.lumi.com/">Let us know.</a><br>👋 Want to build the supply chain of the future? <a href="https://www.lumi.com/jobs">We’re hiring!</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=964aaa6f5a37" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fuzzy-sharp/custom-manufacturing-should-be-as-scalable-as-the-web-964aaa6f5a37">Custom manufacturing should be as scalable as the web</a> was originally published in <a href="https://medium.com/fuzzy-sharp">Lumi</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Migrating from RethinkDB to Postgres — An Experience Report]]></title>
            <link>https://medium.com/fuzzy-sharp/migrating-to-postgres-2dc1519a6dc7?source=rss----d57e27362b5---4</link>
            <guid isPermaLink="false">https://medium.com/p/2dc1519a6dc7</guid>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[rethinkdb]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[haskell]]></category>
            <dc:creator><![CDATA[Phil Freeman]]></dc:creator>
            <pubDate>Wed, 13 Sep 2017 17:36:03 GMT</pubDate>
            <atom:updated>2019-05-23T17:26:15.361Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Note: </strong><a href="https://www.lumi.dev/blog/migrating-from-rethinkdb-to-postgres-an-experience-report">This post</a> and our new engineering blog can be found at <a href="https://www.lumi.dev">lumi.dev</a></p><p><em>TL;DR</em>: we switched from RethinkDB and ElasticSearch to Postgres, leaning heavily on Haskell in order to fill in some of the gaps quickly. The project was a success, and we’re very happy with the switch. Haskell has been invaluable for refactoring safely and confidently.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3zADeX-f3kiPritXGxEFgw.png" /></figure><h3>Motivation</h3><p>At <a href="https://www.lumi.com">Lumi</a>, our backend stack has historically used <a href="https://rethinkdb.com/">RethinkDB</a> for the primary database and <a href="https://www.elastic.co/products/elasticsearch">ElasticSearch</a> for indexing and search. This has worked well for the most part, but it has recently started to show its limitations.</p><p>In this post, I’ll talk about some of the more interesting problems we faced while migrating from RethinkDB and ElasticSearch to <a href="https://www.postgresql.org/">Postgres</a>.</p><p>In order to understand why we decided to switch, I need to explain a bit about our data architecture. RethinkDB was used as the primary source of data, but in order to implement searches on computed fields (for example, statistics), we would previously precompute these fields and store them in ElasticSearch, updating them as necessary. This gave good search performance, but obviously came with its own set of issues. Specifically, it was tricky to ensure that the computed fields were always up to date, and it was difficult to be sure that this property would hold by considering the code.</p><p>Now, this is obviously an issue with how we used RethinkDB and ElasticSearch, not an issue with the tools themselves. But in the absence of some more sophisticated approach, we decided to go with a low-tech solution and simply compute these fields on the fly, as functions in the database. This was something that we could implement easily in Postgres, and our experiments suggested that the performance would be on par with our RethinkDB/ElasticSearch setup.</p><p>Here are some other concerns we had:</p><p>RethinkDB:</p><ul><li><em>Performance</em> — Joins can be slow or even crash the database. Computing certain statistics on the fly in Rethink didn’t seem to be an option.</li><li><em>Correctness</em> — The query language is untyped, which can make it difficult to compose large queries if you’re used to working with types.</li><li><em>Support</em> — Rethink is <a href="https://rethinkdb.com/blog/rethinkdb-shutdown/">no longer commercially maintained</a>.</li></ul><p>ElasticSearch:</p><ul><li><em>Correctness</em> — There are many types of indexes, and the same operations can give different results based on the exact type of index you picked. That said, the <a href="http://hackage.haskell.org/package/bloodhound">bloodhound</a> library does a great job of presenting a sensible API to ElasticSearch.</li></ul><p>Postgres also had its own appealing characteristics:</p><ul><li><em>Features</em> — Full SQL with many useful extensions. ACID guarantees. Schemas make sure we don’t invalidate existing data.</li><li><em>Performance</em> — Postgres can handle complex queries easily. If we have performance issues, we can always EXPLAIN a query and debug.</li><li><em>Correctness</em> — SQL isn’t a perfect language when it comes to correctness (NULL handling jumps to mind), but it&#39;s pretty good, and relational algebra provides a good foundation for reasoning about correctness. There are also excellent Haskell libraries which wrap Postgres in order to provide additional type-safety.</li><li><em>Support</em> — Postgres is basically going to be around forever, and it has an excellent, active community.</li></ul><h3>Getting Started</h3><p>First of all, we decided that all access to the database would go through our Haskell web services instead of being spread between various Node and Haskell services. This should have several advantages, but primarily, it means that every read and write gets type-checked. We can’t put any data into the database which is incorrectly formatted.</p><p>Next, we decided that we’d use <a href="http://hackage.haskell.org/package/persistent">persistent</a> to describe the database schema. persistent has some support for building queries, but we decided to use <a href="http://hackage.haskell.org/package/esqueleto">esqueleto</a> to build our queries since its query language is much richer. Anything we can&#39;t write with esqueleto is written in a SQL function and imported by name on the Haskell side. This gives us a nice split between type-checked Haskell and the full power of SQL with Postgres extensions.</p><p>persistent has the ability to generate migrations for any schema changes, so we use persistent to generate all of our schema update scripts.</p><h3>Migrating Data</h3><p>Migrating all data from our existing production database into a shiny new Postgres RDS instance was an interesting challenge.</p><p>We approached it like this:</p><ul><li>Run the persistent migration script and drop all constraints temporarily.</li><li>Use <a href="http://hackage.haskell.org/package/servant">servant</a> to generate a simple web service with one method for each of our persistent entities to insert data into the database.</li><li>Run a Python script to pull data from Rethink and push it to our new API, reporting any errors (which usually amounted to schema discrepancies, and which we were able to fix over the course of a few days).</li><li>Fix up any bad data in place in the database using a collection of ad hoc scripts. This step was necessary since data in RethinkDB had become bad over time due to the lack of an enforced schema and presumably bugs in our code.</li><li>Add back any constraints we dropped and create indexes.</li></ul><h3>Replacing RethinkDB and ElasticSearch</h3><p>We were using ElasticSearch in three ways:</p><ul><li>To store computed statistics, and to make those searchable,</li><li>To perform simple searches against string and numeric values, and to perform the occasional full-text search.</li><li>To parse simple query strings to support more interesting searches.</li></ul><h3>Computing Statistics</h3><p>Instead of pre-computing statistics and storing them in ElasticSearch, we decided to compute all statistics on demand. This was something we previously tried in RethinkDB, but the results were not good. When joins were involved, queries were often way too slow and in some cases caused the database to crash.</p><p>When we tried implementing statistics as SQL queries in Postgres, we were amazed by the performance. We could implement complex statistics involving data from many tables, and with some help from the query analyzer, we were even able to beat our previous query performance in most cases. Note that we were simply retrieving stored results previously, but now we were computing all information on the fly. This is a great improvement for correctness, but it’s also a testament to the fantastic performance of Postgres.</p><p>There is the possibility that this approach will not scale to larger datasets. However, there are many options if that becomes a problem. Aside from simply throwing more hardware at the problem, we could consider things like materialized views, or a separate data warehouse entirely, trading liveness of our data for improved average query speed. Another option might be to compute statistics incrementally, which is an area where I think Haskell would really shine.</p><p>For now, in order to implement our stats queries in esqueleto, we designed a type class:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9982341fd684a047149e163444af8d3b/href">https://medium.com/media/9982341fd684a047149e163444af8d3b/href</a></iframe><p>Here, the functional dependency is implementing a function from entity types to types of selected computed fields (internal to esqueleto) and the result type (public in our exposed API).</p><p>The HasStats class is a wrapper, providing a value of the SomeStats helper data type for the appropriate entity. SomeStats packages up the functions we need in order to compute statistics.</p><p>First, it packages a function which turns our entity type into a collection of selected fields. The SqlSelect constraint ensures that we can actually turn these queries into SELECT statements using esqueleto.</p><p>SomeStats also packages up a function rep -&gt; result which can turn esqueleto&#39;s representation of this data into an actual result.</p><p>These two functions give us everything we need in order to select, filter, and sort by our selected statistics in our API.</p><h3>Simple Searches</h3><p>Simple searches were by far our biggest use case, so we decided to focus on that. For now, we are not going to worry about full-text search since we didn’t use it very much or in any crucial ways (even though, arguably, this is the real reason to use ElasticSearch in the first place). Thankfully, Postgres provides functionality for full-text search (what can’t it do?), which we will probably look into if we find we need to restore this functionality.</p><p>Our simple search functionality varied from entity to entity, so we created a new type class to capture the mapping from entity types to search functions, which are implemented as esqueleto queries:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6bc99bcaaa6087b0d88647b7739aa6f7/href">https://medium.com/media/6bc99bcaaa6087b0d88647b7739aa6f7/href</a></iframe><p>This looks complicated, but the complication just arises from the need to support searches which involve joins between multiple tables. The SearchData type family captures all of the entity information we need to pull in order to perform a query against a single row. The createTextQuery applies a search term to that structure to form a predicate which we can pass to the database.</p><h3>Replacing ElasticSearch Query Strings</h3><p>In order to replace ElasticSearch’s simple query string parser, we needed to implement our own small search DSL and parser. With Haskell’s parsec library, this was very simple. We designed a small language of search terms:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bac016bc575526bdb8213c0226c23681/href">https://medium.com/media/bac016bc575526bdb8213c0226c23681/href</a></iframe><p>and a parser for these terms using <a href="http://hackage.haskell.org/package/parsec">parsec</a>. For the most part, this expression language is self-explanatory, but the SpecificMatch constructor requires some explanation.</p><p>We would like to support query strings like firstName:John which matches a specific field. In order to turn this into a typed query which can be passed to esqueleto, we need to actually check that the firstName field has the right type — a string, in this case. Note that this is a type-changing operation — we go from untyped queries to typed queries.</p><p>That operation can fail, so we implement it using an error tracking monad. But we need to perform that operation against every SpecificMatch appearing in a Query. By deriving Traversable, we can simply use traverse to perform this operation globally, for free!</p><h3>Notes on Dynamic Types</h3><p>When we were using RethinkDB and ElasticSearch, everything was untyped, and we could pass names of fields directly to the database without type checking. If the types didn’t match, we would either not find out, or find out by catching an exception from the database driver. This was obviously not ideal from a debugging point of view, but it certainly made implementation easier.</p><p>In order to keep the same search functionality, we had to find a way to use untyped field names with the typed fields exposed by persistent and esqueleto. This problem also shows up when performing other operations such as filtering and sorting rows.</p><p>To solve this problem, we implemented a new type class in order to map our entity types to lists of acceptable field names:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e8c52e75db468f93593402d4e1b58189/href">https://medium.com/media/e8c52e75db468f93593402d4e1b58189/href</a></iframe><p>Here, selectRows is simply an association list of field names to column data.</p><p>What is SomeColumn?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e755bfc2d0498450c481f7f855a6c5e5/href">https://medium.com/media/e755bfc2d0498450c481f7f855a6c5e5/href</a></iframe><p>In order to produce a value of type SomeColumn entity, we must have a type typ of SQL expressions in mind (and instances for the required constraints on typ), along with a function of type entity -&gt; E.SqlExpr (E.Value typ) which can pull the appropriate field out of our entity type. In this way, SomeColumn captures both the type of the column, and how it’s read from the database.</p><p>The KnownPersistField constraint here is key. It provides a way to check the inferred type of a field against the type of filter provided by the user at runtime:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ecdb9cc0f3959904efb10d08c9d32a4/href">https://medium.com/media/7ecdb9cc0f3959904efb10d08c9d32a4/href</a></iframe><p>PersistFieldProxy is a value level representative for a column type. It reflects all of the possible types of database columns we care about, at the value level. The KnownPersistField class simply says that we know the column type, and can provide a PersistFieldProxy.</p><p>Unlike the type-level representation of column types, we can case on a PersistFieldProxy to implement different behavior for different column types.</p><p>Pattern matching a PersistFieldProxy can also bring type information into scope. For example, we can check if a column type is a string, in which case we can bring a SqlString instance into scope. This allows us to use string queries in esqueleto:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/94e1d78ef0a136cba0edba9a1dedcd8e/href">https://medium.com/media/94e1d78ef0a136cba0edba9a1dedcd8e/href</a></iframe><p>Combining the SomeColumn data type and the KnownPersistField class, we have enough information to turn runtime strings into typed expressions, and to verify the type of any associated data provided by the user.</p><p>This was quite a lot of work in order to recover functionality which we got “for free” from RethinkDB using dynamic types, but I think it is worth it. Now we are able to turn any untyped query from our API into a typed query and we are able to inspect type information at runtime and act on it in various ways. Since we are able to catch type errors before they hit the database, our errors are better and we even catch some errors that the database driver would not report.</p><h3>JSON Support</h3><p>RethinkDB allowed us to store arbitrary JSON documents in columns, and perform quite expressive queries against fields in those documents. We were initially concerned that we might lose that functionality in moving to Postgres, and that we might have to store more data in columns.</p><p>However, we were pleasantly surprised to discover that the JSON support in Postgres was <a href="https://www.postgresql.org/docs/9.6/static/datatype-json.html">sufficiently advanced</a> in order to implement all of the functionality we were using in RethinkDB.</p><p>We can pull nested data out of JSON documents and filter and sort based on those values. We can even join with an array of data stored in JSON format, and then aggregate those values in various ways.</p><p>We don’t store many JSON documents in the database, but for some cases, it is definitely preferable to storing flattened data over many columns. To support these cases, we write custom SQL functions which are then imported into Haskell as typed functions on esqueleto expressions.</p><p>One downside is that Postgres does not support JSON schemas, so it is possible to get into invalid states over time. We rely on Haskell to type-check our data on the way in to the database, but we have to be careful that migrations don’t invalidate existing data. We could look into using something like <a href="https://github.com/gavinwahl/postgres-json-schema">postgres-json-schema</a> to solve this problem eventually.</p><h3>Conclusion</h3><p>The migration to Postgres was a success and it improved the performance, correctness, and maintainability of our code. There are still plenty of interesting ways we could improve things, and new Postgres features to explore.</p><p>It’s been an interesting challenge to recover all of the functionality and flexibility that we had with RethinkDB and ElasticSearch, but I hope I’ve shown that Postgres handled the job well, and that Haskell turned out to be crucial for such a large refactoring.</p><p>If you’re interested in using Haskell to solve real-world problems like these, then get in touch — <a href="https://www.lumi.com/jobs">we’re hiring at Lumi!</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2dc1519a6dc7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fuzzy-sharp/migrating-to-postgres-2dc1519a6dc7">Migrating from RethinkDB to Postgres — An Experience Report</a> was originally published in <a href="https://medium.com/fuzzy-sharp">Lumi</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Running a business with boobs: the things I never say]]></title>
            <link>https://medium.com/fuzzy-sharp/running-a-business-with-boobs-the-things-i-never-say-ac58a48c674?source=rss----d57e27362b5---4</link>
            <guid isPermaLink="false">https://medium.com/p/ac58a48c674</guid>
            <category><![CDATA[entrepreneurship]]></category>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[humor]]></category>
            <category><![CDATA[women-in-tech]]></category>
            <category><![CDATA[international-womens-day]]></category>
            <dc:creator><![CDATA[Jesse Genet]]></dc:creator>
            <pubDate>Wed, 08 Mar 2017 21:22:06 GMT</pubDate>
            <atom:updated>2017-04-13T22:53:53.083Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>I’ve never published anything about what it’s like to be a woman in business, but today is International Women’s Day and I decided to use my incredibly keen wit and personal experiences to speak some truths ;)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*quWPuU5Kf0OBWFRCYctgiw.jpeg" /><figcaption>Credit: Life Magazine (From photo shoot of the Monokini designed by Rudy Gernreich)</figcaption></figure><p>I have boobs. They are small boobs but they are still boobs. I also run a business. It’s bigger and more important to me than my boobs. These are just facts, but I’m sure I’ve already offended someone… so let’s just keep this rolling.</p><p>I started my first business at 16 and have been a CEO with employees for the past seven years of my life. I’m 29 now. I started out life as a baby and then a little girl in Detroit and now I live in LA and run <a href="http://lumi.com">Lumi</a>. Yep, these facts make me a Female CEO. Similarly, a person who starts life out as a baby that turns into a little boy who then devotes the better part of a decade to building businesses might end up as a Male CEO.</p><p>For anyone in the business community who interacts with people with boobs (cough, cough, 100% of the business community), these are five things I’ve never said about the things you shouldn’t say either. All of them are from personal experience.</p><h3>1. Don’t invite me to your event and admit it’s because you want women there.</h3><p>I fully understand and support efforts to make business events more diverse and inclusive, but inviting me to an event and in the same breath admitting that you’re doing it because you want women to be there is sort of like inviting a black guy to your birthday party and admitting it’s because you don’t want your other friends to think you’re racist. It feels icky and makes the invitee feel like the invitation isn’t genuine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MLrmYq3BVMBXVKx5Ybv-4w.jpeg" /><figcaption>This is me, holding a box.</figcaption></figure><h3>2. Don’t ask me if my dad helped me draft a document.</h3><p>Yes, someone asked me this about a contract I sent them. This is just one example of the blatant questions and comments older men wittingly or unwittingly ask young females in business without understanding the gravity of the sexism involved. Would you ask a mid-20s self-made male businessperson if their father helped them with something?</p><p>Yes, my dad was a lawyer, but he is also dead. The last document he helped me draft was a middle school English paper.</p><h3>3. Don’t demean me while asking for a job.</h3><p>In the past three months I’ve interviewed over 60 candidates for sales, operations and financial roles as I work to build out my team at Lumi. The frequency that male job candidates ask demeaning questions is fascinating, and always shocking.</p><p>Here’s an example: while interviewing a man for a comptroller position, he asked me if I was familiar with financial statements, like a balance sheet. This person knew I had been an entrepreneur for years. When I simply replied y<em>es</em>, because I found the question so mystifying, I was met with laughter and a five minute lecture on why balance sheets matter. A lecture that would have been more fitting for a high school level finance class than an interview with a CEO who carved out a precious 30 minute slot to speak with a candidate.</p><p>Assume women know things. Provide real intelligence and value when you speak with them, or get out of the way so they can find a different colleague.</p><h3>4. Don’t act surprised that I am the CEO.</h3><p>I’m a five foot tall woman weighing in at about 118 pounds. Even though I spell my name <em>Jesse</em>, the male spelling, most people I meet use the internet and already know I am a female. Other people learn about Lumi just by experiencing our company or products online and then find out that I am the CEO. It’s often those people who react with some expression of shock, like, “Whoa! Lumi is actually a really cool company. You’re the CEO?” <em>Actually</em>, I really am.</p><p>Another cringeworthy reaction I get is surprise, if not skepticism, that I’m not in an female-focused industry. Female CEOs are making extraordinary progress with female-specific products in industries that were all but totally neglected, but just like with male founders, we have the capacity to focus on passions beyond our anatomy.</p><p>Both of these expressions of surprise suck. I can run any type of company I want. I could start a company around male mental health if I wanted to, and the more comments I get like this, the more I consider it.</p><h3>5. Don’t question my level of ambition.</h3><p>If I told you about a sub 30-year-old guy who raised over $270k on Kickstarter during college, personally sold a product they invented into 1,500 retail stores, built a company into seven figure sales without venture investment, turned down a deal on <em>Shark Tank</em>, got into Y Combinator, raised venture capital from top tier investors, and has been an active CEO without a single break or sabbatical for seven years, would you question their level of ambition?</p><p>Nope. So don’t question mine.</p><p>I’ve seen dudes being hailed as ambitious simply for quitting their cushy day jobs, yet it’s surprisingly common for women to be questioned on whether they are ambitious “enough.” Stop questioning the ambition level of women in business.</p><h4>Having boobs and running a business is exactly the same as having a penis and running a business, except boobs are more aesthetically pleasing. I hope, at minimum, we can all agree on that.</h4><p>Added Note: For anyone concerned about penis-shaming please note that I think penises are great (I favor those attached to people I already like). For anyone concerned that this neglects trans individuals, please note how I used language around the baby portion up top to allude to the fact that a baby might choose to be whatever gender it identifies with.</p><p>I respect penises and trans folk. I also respect my own sense of humor enough not to make rash edits to this article, which I hope you can respect.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac58a48c674" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fuzzy-sharp/running-a-business-with-boobs-the-things-i-never-say-ac58a48c674">Running a business with boobs: the things I never say</a> was originally published in <a href="https://medium.com/fuzzy-sharp">Lumi</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vertical commerce and how the next generation of retail will be built]]></title>
            <link>https://medium.com/fuzzy-sharp/vertical-commerce-and-how-the-next-generation-of-retail-will-be-built-1ef35f2fc695?source=rss----d57e27362b5---4</link>
            <guid isPermaLink="false">https://medium.com/p/1ef35f2fc695</guid>
            <category><![CDATA[ecommerce]]></category>
            <category><![CDATA[retail]]></category>
            <dc:creator><![CDATA[Steph Ango]]></dc:creator>
            <pubDate>Mon, 22 Aug 2016 01:00:40 GMT</pubDate>
            <atom:updated>2023-09-20T21:36:17.047Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Originally published at </em><a href="http://stephanango.com/vertical-commerce"><em>http://stephango.com/vertical-commerce</em></a></p><p>“Digitally native vertical brand” (or DNVB for short) is a new term <a href="https://medium.com/@dunn/digitally-native-vertical-brands-b26a26f2cf83">picking up steam</a> to describe a kind of company we’ve all become familiar with — think Warby Parker, Dollar Shave Club, Everlane, MeUndies, Casper and Primary, to name a few from this <a href="https://medium.com/@dunn/the-emerging-encyclopedia-of-digitally-native-vertical-brands-dnvbs-74bfd0e581bb#.apupv9wk4">rapidly growing list</a>. DNVBs point to an important trend that is “<a href="http://www.nytimes.com/2016/07/28/technology/these-stores-didnt-develop-websites-they-started-there.html?rref=collection%2Fbyline%2Ffarhad-manjoo&amp;action=click&amp;contentCollection=undefined&amp;region=stream&amp;module=stream_unit&amp;version=latest&amp;contentPlacement=6&amp;pgtype=collection">reshaping the retail landscape</a>”.</p><p>DNVBs are companies that are born online. They’re taking a fresh look at commoditized products (like <a href="https://www.harrys.com/">razors</a> and <a href="https://www.tuftandneedle.com/">mattresses</a>), neglected demographics (like <a href="http://www.shethinx.com/">women</a> and <a href="http://walkerandcompany.com/">people of color</a>), and taking out the pretension behind luxury goods (like <a href="http://benchmademodern.com/">furniture</a> and <a href="https://www.winc.com/">wine</a>). They’re typically bypassing retailers, preferring a direct-to-consumer relationship which improves their margins while reducing prices. Most importantly, they’re able to do this because of new technology and consumer behavior that has emerged in the past ten years.</p><p>I find it helpful to map out the landscape of retail along two axes: offline-native versus online-native companies, and brands versus retailers. DNVBs fall squarely in the upper right quadrant:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mm-nfBC0lGxEF9YUpD420g.png" /></figure><p>A notable fact is that DNVBs are relatively new. Most of them are less than five years old. But DNVBs are a growing concern for companies that operate in the other three quadrants. A few weeks ago, Dollar Shave Club, founded in 2011, <a href="http://www.wsj.com/articles/unilever-buys-dollar-shave-club-1468987836">was acquired</a> by Unilever for one billion dollars. Procter &amp; Gamble, Gillette’s parent company, has litigated against all three of the big shaving DNVBs (Dollar Shave Club, Harry’s and Bevel). And recently, in a move to gain more web-savvy, Walmart acquired Jet.com. These are only the first signs of the impending sea-change.</p><p>As new vertical commerce brands emerge for every industry and every demographic, I’ve been asking myself “Why now?” What are the enabling forces that led to the first generation of DNVBs, and what will the next ten years look like? These are four of my ideas.</p><h3><strong>1. Online sales will continue to grow</strong></h3><p>It’s impossible to talk about e-commerce without mentioning Amazon. In 2015, Amazon captured nearly <a href="http://www.bloomberg.com/news/articles/2015-12-16/amazon-is-capturing-bigger-slice-of-u-s-online-holiday-spending">40% of all online spending</a> during the holiday season. To give credit where credit’s due, Amazon has changed people’s habits.</p><p>Most of Amazon’s 22-year history has been about helping consumers get comfortable typing their credit card number into a website. One barrier at a time, Amazon has reduced skepticism by defining what e-commerce should look like, securely saving your credit card information, creating the expectation of free shipping, simplifying returns — all the things we now expect from any online store. With <a href="https://www.youtube.com/watch?v=EHMXXOB6qPA">Dash buttons</a> and <a href="https://www.youtube.com/watch?v=KkOCeAtKHIc">Echo</a>, Amazon continues to push the boundaries of what consumers are willing to trust when it comes to the online buying experience. This benefits DNVBs because consumers are more likely than ever to take a risk buying from a website they’ve never been to before.</p><p>To keep things in perspective, e-commerce still only accounts for about 10% of all retail sales in the US. According to <a href="http://www.census.gov/retail/index.html">data from the US Commerce Department</a>, the past six years have seen a consistent average of 15% year-over-year growth in e-commerce sales, growing to $341.7B in 2015. For comparison, <a href="http://corporate.walmart.com/_news_/news-archive/investors/2015/02/19/walmart-announces-q4-underlying-eps-of-161-and-additional-strategic-investments-in-people-e-commerce-walmart-us-comp-sales-increased-15-percent">Walmart’s offline sales</a> alone were around $300B (US). Only in the past five years has there been enough consumer demand online to make this many DNVBs viable. There is still a lot of room to grow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fa7MKjkgXgs4ulQphH25ug.png" /><figcaption>Online sales over the past 10 years in the US</figcaption></figure><p>Over the past 10 years the overall size of the e-commerce pie has grown about 4X. It’s also worth noting that during this time, <a href="http://www.pewinternet.org/2015/12/21/home-broadband-2015/">broadband adoption grew</a> from 30% to 70% and millennials entered the workforce. Not only are millennials avid customers of DNVBs, many of the companies were founded by millennial entrepreneurs who applied their digital-native perspective to retail. What will Gen Z’s idea of retail look like?</p><h3><strong>2. Software will continue to reduce barriers</strong></h3><p>Ten years ago, many of the services that enabled DNVBs didn’t exist or were just barely getting off the ground. Here are a some services (and their launch dates) that come to mind:</p><ul><li><strong>Hosting</strong>: AWS (2006), Heroku (2007), DigitalOcean (2011)</li><li><strong>Web stores</strong>: Shopify (2006), Spree (2007), BigCommerce (2009)</li><li><strong>Crowdfunding</strong>: Kickstarter (2009), Indiegogo (2010)</li><li><strong>Fulfillment</strong>: Shipstation (2011), Easypost (2012), Shippo (2014)</li><li><strong>Payments</strong>: Square (2009), Braintree (2007), Stripe (2011)</li><li><strong>Newsletters</strong>: Mailchimp (2001), Campaign Monitor (2004)</li><li><strong>Customer service</strong>: Zendesk (2007), Desk (2009)</li><li><strong>Social networks:</strong> Instagram (2010), Pinterest (2010), Snapchat (2011)</li></ul><p>This list barely scratches the surface of the hundreds of tools and platforms that make up the backend of DNVBs. These tools have helped companies keep their staff small and focus on what they do best: making a great product and sharing their story.</p><p>Before payment platforms like Stripe, e-commerce companies had to apply with their bank for a merchant account (remember those?) and build an entire payments solution. That process now takes less than a day. Every one of these services has a similar story behind it. Software has reduced the time, capital, and staff required to get DNVBs off the ground.</p><p>Going forward, these tools will continue to improve and new ones will emerge. Falling in line with the adage that “<a href="http://www.wsj.com/articles/SB10001424053111903480904576512250915629460">software is eating the world</a>”, new software tools will continue to spread into even more areas of business. Bringing me to my next point…</p><h3><strong>3. Modern logistics will help them scale</strong></h3><p>A defining aspect of DNVBs is what Andy Dunn, CEO of Bonobos, calls a “<a href="https://medium.com/@dunn/digitally-native-vertical-brands-b26a26f2cf83#.l3dhc9z31">maniacal focus on customer experience</a>”. To that end, DNVBs are looking to create a cohesive link throughout the entire experience — from the marketing, to the branding, the buying experience, the delivery, the product itself, and even to the final stage of its lifecycle through recycling programs.</p><p>As software tools continue to streamline the digital side of DNVBs, we are beginning to see possible improvements to the physical supply chain as well.</p><p>On the product side one can point to lower entry points in prototyping tools such as 3D printing and laser cutting tools which have helped <a href="http://www.wired.com/2016/03/studio-neat-kickstarter-kings-taught-world-how-to-crowdfund/">even tiny companies</a> design production-ready parts that can be turned into industrial-grade tooling. Likewise, affordable prototyping and manufacturing services are becoming more accessible thanks to marketplaces like <a href="https://makersrow.com/">Maker’s Row</a> and <a href="https://www.etsy.com/manufacturing">Etsy Manufacturing</a>.</p><p>As you may know from the (<a href="https://www.kickstarter.com/fulfillment">sometimes undeserved</a>) reputation that Kickstarter projects deliver behind schedule, manufacturing and shipping is challenging — especially if you’ve never done it before. We are now seeing companies that have learned this the hard way turning into services to help the next generation of DNVBs. This certainly applies to my company, <a href="https://www.lumi.com/">Lumi</a>, where <a href="https://www.lumi.com/showcase">we help DNVBs with packaging and fulfillment supplies</a>, but also to companies like <a href="https://cardsagainsthumanity.com/">Cards Against Humanity</a>, a Kickstarter success story which is now launching a fulfillment service called <a href="http://www.blackbox.cool/">Blackbox</a>. Other fulfillment services such as <a href="http://shipbob.com/">Shipbob</a> and <a href="https://amplifier.com/">Amplifier</a> come from similar origin stories, solving a problem they experienced first-hand.</p><p>As you continue to move through the supply chain stack, you find young companies bringing a fresh pair of eyes to problems such as freight (<a href="http://flexport.com/">Flexport</a>) and enterprise resource planning (<a href="https://erpnext.com/">ERPNext</a>) — areas that have historically been the domain of ossified giants.</p><p>DNVBs sell physical things, atoms. But when it comes to making and moving them, DNVBs want these physical things to behave more digitally, like bits. They want their physical infrastructure to scale as easily as their AWS-powered site. That’s coming soon, and it will allow DNVBs to compete head to head with some of the reigning analog players like H&amp;M or IKEA.</p><h3><strong>4. Old-school strategies will come back</strong></h3><p>Finally, strategies that have worked since the dawn of commerce will continue to be explored by DNVBs, namely physical sales and portfolios of brands.</p><p>Many DNVBs are already experimenting with physical sales to help their customers experience products first-hand. Whether it’s through a <a href="http://la.racked.com/2015/7/28/9051081/parachute-venice-pop-up">pop-up</a>, <a href="http://nymag.com/thecut/2013/10/first-look-olivia-kims-french-fling-pop-in.html">pop-in</a>, <a href="https://casper.com/nyc">showroom</a>, <a href="http://www.geekwire.com/2014/hands-amazon-tests-physical-retail-kindle-kiosk-vending-machines/">kiosk</a>, <a href="http://la.racked.com/2014/4/30/7603169/cool-warby-parker-showroom-headed-to-dtlas-alchemy-works">store-within-a-store</a>, <a href="http://www.fastcompany.com/3008182/where-are-they-now/take-look-inside-warby-parkers-new-nyc-flagship-store">flagship</a>, or simply a <a href="http://www.recode.net/2015/9/28/11618946/bevel-parent-company-raises-24-million-will-sell-razors-in-target">retail partner</a>, the move has already earned the obnoxiously catchy buzzword “<a href="http://www.geekwire.com/2016/clicks-bricks-online-retailers-setting-shop/">clicks-to-bricks</a>”.</p><p>Retailers are beginning to catch on by offering space for rent inside their stores. New retail experiments such as <a href="https://www.washingtonpost.com/news/business/wp/2015/12/17/b8ta-the-new-gadget-store-that-is-a-bet-by-a-silicon-valley-company-on-brick-and-mortar-shopping/">B8ta</a> in Palo Alto, may further suggest that renting space in a store is a more appealing business proposition to new brands than traditional retail sales.</p><p>As more DNVBs emerge, we are likely to see the kind of consolidation that made <a href="https://en.wikipedia.org/wiki/Procter_%26_Gamble">P&amp;G</a>, <a href="https://en.wikipedia.org/wiki/VF_Corporation">VF</a>, <a href="https://en.wikipedia.org/wiki/LVMH">LVMH</a>, <a href="https://en.wikipedia.org/wiki/PVH_(company)">PVH</a> and other acronymed conglomerates successful. With its sister brand <a href="https://www.ayr.com/">Ayr</a>, we’ve already seen Bonobos move in that direction. Labels such as Matt Alexander’s <a href="http://editioncollective.com/">Edition Collective</a> suggest that a portfolio of small brands <a href="http://blog.lumi.com/wellmade/4-matt-alexander">may be more effective in today’s climate</a> than one big brand, and DNVBs are the perfect vehicle for that idea.</p><p>The Cambrian explosion of vertical commerce is still in its early stages, and Dollar Shave Club’s acquisition is only the first bit of evidence. At root, it’s the idea that there can be a brand for everyone. Consumers demand it, technology enables it, and incumbents will feel it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ef35f2fc695" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fuzzy-sharp/vertical-commerce-and-how-the-next-generation-of-retail-will-be-built-1ef35f2fc695">Vertical commerce and how the next generation of retail will be built</a> was originally published in <a href="https://medium.com/fuzzy-sharp">Lumi</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[14 Questions to Ask Your Team]]></title>
            <link>https://medium.com/fuzzy-sharp/14-questions-to-ask-your-team-b31d3046a4a2?source=rss----d57e27362b5---4</link>
            <guid isPermaLink="false">https://medium.com/p/b31d3046a4a2</guid>
            <category><![CDATA[personal-development]]></category>
            <category><![CDATA[business]]></category>
            <dc:creator><![CDATA[Steph Ango]]></dc:creator>
            <pubDate>Tue, 12 Jul 2016 05:00:38 GMT</pubDate>
            <atom:updated>2016-07-12T05:09:58.289Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a questionnaire I created because the <a href="https://www.lumi.com">Lumi</a> team was becoming big enough that people didn’t always have a chance to learn about each other on a deeper level.</p><p>We created an online form, and everyone on the team received the answers as they came in. It was a fun and insightful exercise, so I thought I’d share these questions, if you’d like to try them with your team. Feel free to expand or edit!</p><ol><li>What is your full name?</li><li>What city were you born in?</li><li>What city do you currently live in and how long have you lived there?</li><li>What are/were your parents’ occupations?</li><li>What are 2–5 hobbies/skills/activities that you enjoy the most? Can be work, personal, anything.</li><li>What are 2–5 things you would like to learn or get better at?</li><li>What is one thing you are strangely good at?</li><li>Who is one person that has significantly inspired you or affected your life in a meaningful way? How so?</li><li>What is one place that has significantly inspired you or affected your life in a meaningful way? How so?</li><li>What is one thing that makes you feel anxious or nervous?</li><li>What is one thing that makes you feel relaxed, calm, at peace?</li><li>What is one thing that makes you feel excited or fired up — in a good way?</li><li>Who are 5–10 people (alive or dead, fictional or real) that you admire?</li><li>What was one of your favorite creations you experienced in the past year, and why? Could be anything from music, tv, movie, restaurant, museum, book, article, podcast, theater, etc</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b31d3046a4a2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fuzzy-sharp/14-questions-to-ask-your-team-b31d3046a4a2">14 Questions to Ask Your Team</a> was originally published in <a href="https://medium.com/fuzzy-sharp">Lumi</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Trademarking the Dictionary]]></title>
            <link>https://medium.com/fuzzy-sharp/trademarking-the-dictionary-57289011b884?source=rss----d57e27362b5---4</link>
            <guid isPermaLink="false">https://medium.com/p/57289011b884</guid>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[branding]]></category>
            <dc:creator><![CDATA[Steph Ango]]></dc:creator>
            <pubDate>Mon, 21 Dec 2015 22:22:22 GMT</pubDate>
            <atom:updated>2015-12-21T22:49:33.991Z</atom:updated>
            <content:encoded><![CDATA[<h4>If there’s a branding trend that hit critical mass in 2015, it’s using common words to name products.</h4><p>Music, Paper, Watch, TV, Sketch, Pencil. Which companies make a product with one of those names? The answer is… Every major tech company you’ve heard of, from Apple to Microsoft, Google, Adobe, Dropbox, Facebook and up-and-comers such as FiftyThree and Bohemian Coding.</p><p>It’s part of an ambitious effort for technology companies to make their products synonymous with the basic activities in your life.</p><p>For decades gadgets have often been named by their model number — which occasionally earned notoriety — such as the HP-12C or the TR-808. Over time companies found it more appealing to use memorable trademarks such as Walkman or Game Boy.</p><p>In recent years, however, we’ve seen the rise of common words being used to brand products. A poignant example is Apple’s recent shift away from the “i” prefix introduced with the iMac, to simply using the names Apple Watch, Apple Pencil and Apple Music for its newest products.</p><p>There are four main reasons for this shift.</p><h4>1. Redefining words for the digital age</h4><p>As we continue our trajectory from analog to digital technology, an opportunity has emerged to re-define the meaning of words like “pencil” and “watch”. It conveys the desire to make technology less futuristic, and more like an evolution of the things you already know. Naming a product Pencil or Watch makes it feel more familiar and approachable.</p><h4>2. Reducing the burden of memorization</h4><p>The word “Watch” in Apple Watch is so commonplace and intuitively descriptive of the product that all you really need to remember is the word “Apple”. When you walk by an Apple Watch billboard on the street, you don’t need to remember a product name, just “Apple” and the fact that they make a watch. When you walk into the Apple store all you need to ask is “Can I see the watch?”</p><h4>3. Reducing the burden of choice</h4><p>When Steve Jobs returned to Apple in 1997 he notoriously slashed the convoluted matrix of product lines from twenty down to four. Apple would focus on making just four computers: consumer desktop, professional desktop, consumer laptop and professional laptop. This simple structure still defines the Mac product lines today: iMac and Mac Pro, MacBook and MacBook Pro.</p><p>This change allowed the engineering teams to put more wood behind fewer arrows, but also made purchasing decisions much clearer for customers. Simplifying the product names implies simplifying the product offerings and reducing the burden of choice for your customers.</p><h4>4. Taking ownership of the concept</h4><p>The most cynical take on this trend is that companies want to own ideas. The opportunity to re-define words for the digital age has also become a battleground for brands to take ownership over the definition of those words.</p><p>By calling it “Apple Music”, there is an implied message that Apple can satisfy all your musical needs—that the concept of music itself belongs to Apple, and that when you think music, you think Apple. Similarly, by co-opting the word “like”, Facebook has created a brand association with the mere act of enjoying something.</p><p>This is where the strategy can fall short, particularly when multiple companies set their sights on the same word.</p><p>Owning common words is not easy, for both legal and linguistic reasons. When FiftyThree launched its app <a href="http://www.fiftythree.com/paper">Paper</a>, it could have never foreseen that both Facebook and Dropbox would eventually make apps by the <a href="https://www.facebook.com/paper">same</a> <a href="https://www.dropbox.com/paper">name</a>. Unfortunately, it’s a legal fight FiftyThree can’t afford to have. Not only do Facebook and Dropbox have much deeper pockets, but the use of such a common term puts their defense on shaky ground to begin with. Consumers are left prefixing the capital “p” Paper with the appropriate company name. To make matters worse FiftyThree was burned again with <a href="http://www.fiftythree.com/pencil">Pencil</a>, a word which Apple recently <a href="http://www.apple.com/apple-pencil/">commandeered</a>.</p><p>With the proliferation of this trend, ambiguity is a recurring concern. If you’re a designer who enjoys working in Sketch, you may be referring to Adobe’s <a href="http://www.adobe.com/products/sketch.html">drawing app</a> or Bohemian Coding’s popular <a href="https://www.sketchapp.com/">UI design app</a>. I shouldn’t have to mention that ambiguity is the antithesis of branding.</p><p>The danger I see for companies like FiftyThree and Bohemian Coding is that they’ve put more effort in marketing their product names than their company names. As words like “Paper” and “Sketch” become commoditized by well-known brands, there is a potential for those smaller companies to lose the memorable edge they had created.</p><p>While the pendulum may swing back towards unique trademarks — especially for smaller companies — I think this strategy will continue to be popular with companies large enough to jostle for valuable words. In fact seeing which of them are capable of staking out common words is a good proxy for measuring their weight in the industry. Remember Microsoft Office?</p><p>Ultimately I don’t adhere to the cynic’s view of this strategy because it has already lost its novelty. My optimistic perspective is that language is quick to react. People have adapted to using the brand name in conjunction with the product name, thus defusing any corporate ownership of our vocabulary. What companies are left with is the responsibility to match the simplicity of their product lines with the simplicity of their branding. And that’s a good thing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57289011b884" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fuzzy-sharp/trademarking-the-dictionary-57289011b884">Trademarking the Dictionary</a> was originally published in <a href="https://medium.com/fuzzy-sharp">Lumi</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>