Annotating a record type used in a functor


Hey folks! Looking for an assist with some functors. I want to create a module that fetches data from a server as JSON but returns it as a Reason record type. I’m doing that by creating a definition module that defines the record type (data) and provides a function for decoding the JSON into that type. Then my functor uses that to return the fetching module. I’m also using Belt’s Result.t to handle errors, and wrapping that in a state variant type to indicate loading. My problem is: once I do the data fetch and get back a result, it seems that the underlying definition of data (that is, that it’s a Reason record) has been obfuscated away by the functor somehow. No matter how I annotate it, if I try to access one of its fields I get an error. I’ve mocked up a stripped down, contrived example to show all of this:

Reason Try Example

Anyone have any idea how to do this properly so that I can access the record’s fields when I get it back as a result? Seems like it ought to be possible but I just haven’t been able to figure out how to do it. Thanks!


This version with stripped out type in the module looks to work.

module MyData: Def=


module MyData = 

I’m not 100% sure about what is happening, but probably giving a module definition a module type definition makes the compiler type inferring do something different than what you are expecting.


@gabrielrabreu thanks so much! In my actual code I’d also annotated the result of the functor with the generated type there, and I ended up having to take that off as well, but then everything worked as expected. Seems weird that fewer annotations would solve it, but I’m just happy it’s working :smile:.

Thanks for taking a look at it!