Stuck with Validation

211 views
Skip to first unread message

Grégoire Neuville

unread,
Oct 1, 2012, 5:49:38 PM10/1/12
to functio...@googlegroups.com
Dear all,

I'm kind of struggling with fj's Validation. Here is my use case :

in the following method :

G method(A param1, B param2, C param3)

I would like to apply the following function :

F<A, Validation<E, F<B, Validation<E, F<C, Validation<E, D>>>>>> f1

using param1, 2, and 3 and accumulating possible failures in a Semigroup<E> ;
this I think would provide me a Validation<E, D> from which it would be
easy to obtain the desired G.

And there I lie, wondering how to ignite the wick...

I read Tony Morris' following article and presentation :
http://blog.tmorris.net/automated-validation-with-applicatives-and-semigroups-part-2-java/
and
http://applicative-errors-scala.googlecode.com/svn/artifacts/0.6/html/index.html
; while very instructive, I was presumably not able to fully lick the
substantial marrow out of them, unless they simply didn't addressed my
point ?
Indeed, in those examples, the validation concern seems to be separated
from the application concern (i.e the function to be eventually applied
(Person.person in the second example) does not bear any Validation in
its type signature). I could follow this path, but I like the idea of
the functions bearing in their types the possibility of their failure.

I suspect I'm missing something obvious ; a hint or two that would make
it appear would be much appreciated.

Regards,

G.N


--
Grégoire Neuville

Robin P

unread,
Oct 2, 2012, 1:50:17 AM10/2/12
to functio...@googlegroups.com
Hello,

I think your type signature is not common. It is more usual to have a function f of type A -> B -> C -> D, and have validator functions g1..g3 of type A -> Validation<E, A>, B -> Validation<E, B> etc.

Then you can do:
g1(a).accumulate(eSemigroup,
   g2(b), g3(c),
   f);

which will yield a Validation<E, D>.

BR,
Robin

Grégoire Neuville

unread,
Oct 2, 2012, 2:16:30 PM10/2/12
to functio...@googlegroups.com
Hi,

>
> I think your type signature is not common. It is more usual to have a
> function f of type A -> B -> C -> D, and have validator functions g1..g3 of
> type A -> Validation<E, A>, B -> Validation<E, B> etc.
>
> Then you can do:
> g1(a).accumulate(eSemigroup,
> g2(b), g3(c),
> f);
>
> which will yield a Validation<E, D>.

Yep. I think it amounts to the T. Morris' examples I cited earlier and
I'll probably end up doing so. However I'm still quite convinced (but
maybe is it an irrational conviction) that a manipulation from
A -> Validation<E, B -> Validation<E, C -> Validation<E, D>>> to
Validation<E, D> exists. And as to bearing the validation in the
function type signature, that is what one would do with Option or
Either, isn't it ? So why not with Validation ?

Anyway, thank you for the answer.

Regards,

G.N
> --
> You received this message because you are subscribed to the Google Groups
> "Functional Java" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/functionaljava/-/cqt9xNsP4UQJ.
> To post to this group, send email to functio...@googlegroups.com.
> To unsubscribe from this group, send email to
> functionaljav...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/functionaljava?hl=en.



--
Grégoire Neuville
Reply all
Reply to author
Forward
0 new messages