I have a validation module copied from Railway oriented programming that performs error handling in my application:
type ErrorMessage = ErrorMessage of string
type ValidationResult<'T> =
| Success of 'T
| Error of ErrorMessage
module ValidationResult =
let doubleMap successHandler errorHandler = function
| Success x -> successHandler x
| Error e -> errorHandler e
let bind f = function
| Success x -> f x
| Error e -> Error e
let (>=>) f g = f >> bind g
I was testing the Kleisli composition by using the following test functions:
let validation1 (list: int list) =
if List.length list = 6
then Success list
else Error <| ErrorMessage "Length error"
let validation2 list =
if List.forall (fun x -> x > 6) list
then Success list
else Error <| ErrorMessage "All elements must be larger than 6"
let combined = validation1 >=> validation2
//^^^^^^^^^^^^ compile error
To my understanding, validation1 and validation2 should compose because both are of type int list -> ValidationResult<int list>. However I got a compile error
Expecting a type supporting the operator '>=>' but given a function type. You may be missing an argument to a function.
How can I solve this?
open ValidationResult? - Fyodor Soikin