What this error means and how can i solve it? I am trying to generate types based on the CSS spec at styled-ppx and got stuck at this error that i dont know how to it fix neither what that means exactly.
I tried to get OCaml inference from the target file with dune using (ocamlc_flags -i :standard) because my suspect is that infered types and generated types are crashing since both are polymorphic variants, but had problems generating targets.
You can check the pull request with the problem being reproducible here
In your ppx code,
it is unlikely that the meaning of
typesmatches your expectation.In this context, the list of type
typesrepresents an intersection (aka a conjunction) of types. For instance, inthe
typeslist would contain the ast nodes for the typeintandfloat. (You can have a look at the latest version of OCaml manual https://ocaml.org/api/compilerlibref/Parsetree.html#TYPErow_field_desc to have more detailed description of those AST nodes.)You probably meant to box the list of types in a product type
Indeed, polymorphic variant constructors always have arity one. Otherwise,
`A _ * _would not be unifiable with`A of _.Concerning your exact error message, the conjunctive type error that you are half-describing is likely related to the fact that conjunctive (like
int & float) are only allowed as argument of polymorphic variant constructors in the upper bound of a polymorphic variant type. In other words,is fine because we are on the right-hand side of
<. But bothand
yields an error
because the conjunction of types appears in the lower bound of the type which lists the constructors that were explicitly present.
EDIT: Why are conjunctive types sometimes allowed?
Having conjunctive types makes it possible to use functions that have incoherent interpretation of some constructors. For instance, I could have a function that works on either
`A of intor`B of floatand another function that expects both
`Aand`Bto have a float argumentIf I try to apply
fandgon the same argumentI end up in a situation where
hcan be applied to`B 0.without troublebut trying to use
hon`A _for any_cannot workThis is the kind of situation where conjunctive types arise:
hhas type[< `B of float | `A of int & float ] -> float. Moreover, we can wait to get a concrete argument of the form`A of xto check if the constructor argumentxfit in the conjunction of typesint&float. In this specific case, we know that there are no types that are bothintandfloat, but more complex cases can happen, and delaying the check is a simple way to handle all cases.Contrarily, when we have a concrete value of type
[> `A of 'x ], there is no reason to delay this check. Thus it is not possible to construct a positive value that has a conjunctive type in OCaml. Consequently, it forbids the possibility to write types with conjunctive types in a positive position.