Hey,
The type of sequence
is 'a t list -> 'a list t
(where t
is Validation.Make(Semantic_error).t
).
You are applying check_fun_def_body_in_block : ('a,'b) stmt list option -> unit t
to each element of the list giving you a unit t list
. When you then sequence the effects, you get back unit list t
.
However, in the first case of your match statement, you are returning unit t
. Since unit t
does not equal unit list t
(!) it will not type check.
There are two ways to fix this:
- return
ok []
from the first branch and addValidation.map ~f:List.concat
aftersequence
on the second branch; - add
Validation.map ~f:(fun _ -> ())
aftersequence
on the second branch.
(EDIT: it turns out I can’t code without a type checker… you will still have to flatten the list of lists for the first option, above)
The semantic check code isn’t quite where I want it to be at the moment so it probably doesn’t matter which you use (Semantic_check
currently performs type checking which requires a monadic interface - see below) but I would usually prefer the first option. It might be worth taking a look at the docs I added explaining apply
works here.
If the computations are independent (i.e. checking the validity of one statement does not depend on the result of a previously checked statement) you only require the Applicative
interface. Validation
should not really support the Monad
interface since the implementation violates the monad laws and, more practically, doing so means it doesn’t actually accumulate errors through monadic bind!.
NB In the PR I submitted yesterday for semantic warnings I actually changed the interface to validation to match the standard Core_kernel
signatures so sequence
is called all
there.