This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Opinions on 3 state validation

3 replies
Naftoli Gugenheim
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
I have an implementation of formlets for reactive-web that I've been working on lately. I'm wondering as follows: Most implementations of validation that I've seen, whether Scalaz's, Websharper's, or Lift's Box, either hold a value or an error, not both. To me however it seems that a common scenario is a warning: There's an error message that has to be displayed, perhaps the user has to go through an extra confirmation step to proceed, but you don't actually want to prevent the user from proceeding if he knows what he's doing, so it definitely holds a value too. It seems like I need my own sealed trait with three case classes. Any thoughts?
richard emberson
Joined: 2010-03-22,
User offline. Last seen 42 years 45 weeks ago.
Re: Opinions on 3 state validation

Much like a compiler will allow one to see more than one error
message per compilation attempt, I've got a Recorder class
that collects information, warnings and errors as well as
results. Additionally, one can specify how many errors can
occur prior to punting. If one or more errors occur, then there
are no results; but results will be returned regardless of how
much information and/or warnings are added to the Recorder.

If your application allows for more than one error to
be detected and possibly addressed by the user at a time,
you might consider a similar approach.

Richard

On 02/20/2012 04:14 PM, Naftoli Gugenheim wrote:
> I have an implementation of formlets for reactive-web that I've been
> working on lately. I'm wondering as follows: Most implementations of
> validation that I've seen, whether Scalaz's, Websharper's, or Lift's
> Box, either hold a value or an error, not both. To me however it seems
> that a common scenario is a warning: There's an error message that has
> to be displayed, perhaps the user has to go through an extra
> confirmation step to proceed, but you don't actually want to prevent the
> user from proceeding if he knows what he's doing, so it definitely holds
> a value too. It seems like I need my own sealed trait with three case
> classes. Any thoughts?
>

ichoran
Joined: 2009-08-14,
User offline. Last seen 2 years 3 weeks ago.
Re: Opinions on 3 state validation
I use an (Option[Success], Option[Exception]) in cases like that.  (Or List[Exception] if I want to accumulate them.)  If you enrich a fold method onto Option (which I do anyway), and use match liberally, building custom classes doesn't really make things much easier.  (So far, not enough easier that I want to build the custom set of classes.)

  --Rex

On Mon, Feb 20, 2012 at 7:14 PM, Naftoli Gugenheim <naftoligug@gmail.com> wrote:
I have an implementation of formlets for reactive-web that I've been working on lately. I'm wondering as follows: Most implementations of validation that I've seen, whether Scalaz's, Websharper's, or Lift's Box, either hold a value or an error, not both. To me however it seems that a common scenario is a warning: There's an error message that has to be displayed, perhaps the user has to go through an extra confirmation step to proceed, but you don't actually want to prevent the user from proceeding if he knows what he's doing, so it definitely holds a value too. It seems like I need my own sealed trait with three case classes. Any thoughts?

Tony Morris
Joined: 2008-12-19,
User offline. Last seen 30 weeks 4 days ago.
Re: Opinions on 3 state validation

The purpose of the applicative functor for Validation is to allow computation to continue after failure. That is, the very existence of Validation is for the purpose tipi describe. Note that there is no possible corresponding monad for this (though there is one that fails and stops computing).

I have code, slides, examples and all that if you're interested enough.

On Feb 21, 2012 10:14 AM, "Naftoli Gugenheim" <naftoligug@gmail.com> wrote:
I have an implementation of formlets for reactive-web that I've been working on lately. I'm wondering as follows: Most implementations of validation that I've seen, whether Scalaz's, Websharper's, or Lift's Box, either hold a value or an error, not both. To me however it seems that a common scenario is a warning: There's an error message that has to be displayed, perhaps the user has to go through an extra confirmation step to proceed, but you don't actually want to prevent the user from proceeding if he knows what he's doing, so it definitely holds a value too. It seems like I need my own sealed trait with three case classes. Any thoughts?

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland