<div>I think you might find the RemoteData solution here relevant to your problem: <a href="http://blog.jenkster.com/2016/06/how-elm-slays-a-ui-antipattern.html">http://blog.jenkster.com/2016/06/how-elm-slays-a-ui-antipattern.html</a></div><div><br></div><div>I've been using it successfully for a lot of UI work. Even if you have a default handler function that gives a sane-ish default value for the context you'll be using it in (I.e "Loading..." in UI), I've found it helps keep interfaces sane even when you "forget" you actually care about the empty state.</div><div><br></div><div><br><div class="gmail_quote"><div>On Sun, 16 Apr 2017 at 15:07, MarLinn <<a href="mailto:monkleyon@gmail.com">monkleyon@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 2017-04-16 13:51, Saurabh Nanda wrote:<br>
> Can we use the type-system (or anything else) to enforce the dev to at<br>
> least _think_ about the blank state?<br>
<br>
That is an interesting problem. But I'd say the solution depends highly<br>
on your architecture. Tomas' suggestion to use NonEmpty could be one<br>
solution, and one you could try to build upon to track more details in<br>
the types. Alternatively, you could add a typeclass that just handles<br>
the zero-element-case. That way your constraints remind the developer to<br>
at least copy-paste a default implementation.<br>
<br>
        showItemTable :: (HasZeroItemPresentation (presenter item)) => presenter item -> [item] -> Table item<br>
<br>
But maybe there's a much simpler solution: Create a datatype that stores<br>
the normal presentation function, a zero-case presentation function, and<br>
optionally a one-item presentation function. Now whenever someone<br>
creates a new type of item, they need a new presentation adapter.<br>
<br>
        data TablePresenter item = TablePresenter { showZeroItems :: Widget; showItem :: item -> Widget; showSingleItem :: Maybe (item -> Widget) }<br>
<br>
        showItemTable :: TablePresenter item -> [item] -> Table item<br>
<br>
This should offer safety and code reuse, and it should be easy to<br>
integrate because you don't even have to start with types. Why be fancy<br>
when the simple solutions work?<br>
<br>
Cheers,<br>
MarLinn<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr">- Mario</div></div>