12 ms·
Hey, I am one of the authors. To clarify when you ask about multiple concurrent validations I assume you do not mean parallel. In that case I believe the syste
by belevy 5y ago
Hey, I am one of the authors.
To clarify when you ask about multiple concurrent validations I assume you do not mean parallel. In that case I believe the system presented is the concurrent solution.
The final paragraph in which we use a `ValidationResult` will indeed collect all the failed validation errors from every leaf node (specifying which leaf node the error is for is not defined in the article but was implemented in the production system). Parallelism would require IO and is not used here though it would be fairly simple to add.
What we could do is when we run the validations on both sides an `and_` or an `or_` we can run them in parallel and combine the results. This approach should then run all of the leaves in parallel and then combine them together, I am not sure that it would speed anything up though and might even slow it down(unless the validations are effectful).
I hope that was clear, but if not let me know.
- lalaithion 5y agoParallelism doesn't require IO, merely https://hackage.haskell.org/package/parallel-3.2.2.0/docs/Control-Parallel.html https://hackage.haskell.org/package/parallel-3.2.2.0/docs/Co... or https://hackage.haskell.org/package/monad-par-0.3.5/docs/Control-Monad-Par.html https://hackage.haskell.org/package/monad-par-0.3.5/docs/Con...
- shepmaster 5y agoA concrete example would be the input (in JSON to pick a format) { "alpha": "3", "beta": "5" } Here, the fields `alpha` and `beta` are serialized as strings but should be treated as numbers. If the input were malformed: { "alpha": "dog", "beta": "cat" } Then I'd like to get two validation errors for a single validation attempt. For example: { "alpha": ["must be a number"], "beta": ["must be a number"] } > I believe the system presented is the concurrent solution. It sounds like you are saying that I'd be able to get something isomorphic to the above, so that's good. In addition to the above, I'd like to be able to say that once the values have been validated (a.k.a. parsed) as numbers, then `beta` must always be greater than `alpha`. This is a type of validation across fields that also depends on earlier validations (parsing, transformation, etc.) succeeding.
- belevy 5y agoSo you want something like `eitherContramap :: (b -> Either ErrMsg a) -> ValidationRule a -> ValidationRule b` we could define this as follows eitherContramap f rule = ValidationRule $ \b -> either failure (validate rule) (f b)