Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abstract type support? #6

Closed
wpcarro opened this issue Jul 23, 2019 · 5 comments
Closed

Abstract type support? #6

wpcarro opened this issue Jul 23, 2019 · 5 comments

Comments

@wpcarro
Copy link
Contributor

wpcarro commented Jul 23, 2019

First of all - thank you for making this and open sourcing it. I'm loving it so far. I'm new to Reason and OCaml so forgive me if the way I phrase this question is vague.

I added a new field to my record that I'm encoding of type StringMap.t(list(string)). When I run milk, I get this error:

Fatal error: exception Failure("Abstract type found, but no 'helpers' module specified for this engine")
Raised at file "stdlib.ml", line 33, characters 17-33
Called from file "src/serde/MakeDeserializer.re", line 131, characters 16-98
Called from file "src/serde/MakeDeserializer.re", line 206, characters 10-20
Called from file "src/serde/MakeDeserializer.re", line 302, characters 16-82
Called from file "belt/belt_List.ml", line 172, characters 29-34
Called from file "src/SerdeFile.re", line 232, characters 12-94
Called from file "src/Milk.re", line 190, characters 12-271
Called from file "src/Milk.re", line 212, characters 4-11
Called from file "src/Milk.re", line 241, characters 10-44
Called from file "bin/Main.re", line 104, characters 4-47

This error goes away when I remove the StringMap.t(..). I'm inferring from the error that the "abstract type" is the StringMap.t and that I need to provide my own serialize and deserialize functions. I think this makes sense. Can you point me to a place in the documentation where I can learn more about doing this? If there isn't any, I'd be happy to write some if you give me a hand.

Thanks!

@wpcarro
Copy link
Contributor Author

wpcarro commented Jul 23, 2019

By the way, the StringMap.t was created using what I understand to be OCaml's "module functors":

module StringMap = Map.Make(String);

This is my attempt at getting a general purpose dictionary. I suppose I could also model it as:

type KeywordList('a) = list(("string", 'a))

but I'd rather not since I'll get O(n) performance instead of the log n offered by Map.

@jaredly
Copy link
Owner

jaredly commented Jul 24, 2019

abstract types are definitely supported, but I imagine the error message could be better. Here's an example types.json where "helpers" is provided
https://github.com/jaredly/veoluz/blob/master/types.json#L6
and the TypeHelpers.re that provides serialization and deserialization for the abstract type https://github.com/jaredly/veoluz/blob/master/ui/TypeHelpers.re

@wpcarro
Copy link
Contributor Author

wpcarro commented Jul 24, 2019

Thanks for sharing this. So is the advice to add "TypeHelpers" to my types.json file?

@jaredly
Copy link
Owner

jaredly commented Jul 24, 2019

yup! And for the abstract type that you want to support, add manual serialization & deserialization functions. (the example there is for Belt's String Set and String Map)

@wpcarro
Copy link
Contributor Author

wpcarro commented Jul 24, 2019

Excellent! Thanks, @jaredly! And thanks for such a great library. As I get more comfortable in this ecosystem, I'd love to contribute.

wpcarro added a commit to wpcarro/milk that referenced this issue Jul 25, 2019
I had some difficulty understanding the following error message:
"Abstract type found, but no 'helpers' module specified for this engine"

I received this error because I had an Abstract Type in the object that I wanted
to serialize and deserialize but I didn't provide any implementations for Milk
to serialize or deserialize it.

I'm adding a section on "Abstract Types" to the Readme.md to document what I
learned from the issue and to hopefully help others and my future self.

See this thread for more information: jaredly#6
@jaredly jaredly closed this as completed Aug 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants