rokitna
2019-12-29 09:01:17

It looks like a mix. The top-level directory is a multi-collection package with collections “polyglot-doc,” “polyglot-lib,” and “polyglot-test”; the “polyglot-doc” directory (besides being a collection) doubles as a multi-collection package with collections “guide,” “how-tos,” “reference,” and “tutorials”; the “polyglot-test” directory doubles as a multi-collection package containing only the single “tests” collection; and the “polyglot-lib” directory doubles as a single-collection package.


rokitna
2019-12-29 09:10:54

Packages are things that can be installed. Collections are things that appear before a slash in a module name, like a namespace.

A multi-collection package is a single installable package that uses the multi option, which means it uses a slightly deeper directory structure to establish the modules’ full collection paths, rather than treating every module in the package as sharing the same root collection.


rokitna
2019-12-29 09:15:10

Installing a multi-collection package is the same as installing a single-collection package. If you’re running into trouble, I bet you’re trying to require the modules using a certain collection path when they’re actually available under a different one. Is there a specific scenario that shows the kind of trouble you’re running into?


rokitna
2019-12-29 09:23:37

Another take on it: If you’re trying to install a bunch of modules, it’s a package. If you’re trying to require one module from a bunch of modules that start with the same slashy name parts, it’s a collection. Single-collection packages cater to the common convention that these two kinds of bunches correspond to each other. Multi-collection packages are for a more general kind of module bundle which can be installed to gain access to a bunch of modules with unrelated-looking names.


p.kushwaha97
2019-12-29 10:54:59

I’m serializing a set to a string, and then using eval to convert it from a string to set again. Eval evilness aside (I trust source of input), how do I handle this in typed racket?


p.kushwaha97
2019-12-29 10:56:47

This is what my implementation is:

(string->set (-> String (Setof Symbol))) (define (string->set s) (eval (read (open-input-string s))))


p.kushwaha97
2019-12-29 10:58:01

And this is the error that type checker throws at me: Type Checker: type mismatch; ; mismatch in number of values ; expected: 1 value ; given: unknown number ; in: (eval (read (open-input-string s))) ; [Due to errors, REPL is just module language, requires, and stub definitions]


p.kushwaha97
2019-12-29 10:59:53

I essentially need to have the typechecker (1) not try to typecheck this method, and (2) trust the type signature that it returns a set when it’s given a string argument, and continue typechecking rest of the code.


p.kushwaha97
2019-12-29 14:33:40

I think this problem essentially reduces to finding a way to get the first value from the AnyValues type (return type of eval), and also making that code typecheck


samdphillips
2019-12-29 18:26:20

A trick (that I don’t know if it is recommended by TR devs) is to require/typed the identifier you want with the type you want. So something like this will type-check: (require/typed racket/base [(eval eval-set) (-> Any (Setof Symbol))]) (: string->set (-> String (Setof Symbol))) (define (string->set s) (eval-set (read (open-input-string s))))


samth
2019-12-29 19:12:19

That works fine, other ways of doing it are going to end up pretty similar.


p.kushwaha97
2019-12-29 19:34:07

I received another answer to this which I haven’t tested out but I think would work, specially to circumvent the unknown number of values issue: https://stackoverflow.com/a/59521222/1412255 . It uses a lambda to collect values into a list and get the first from the list, and casts it to the required type.


samth
2019-12-29 19:40:23

That will have the same behavior but slightly different error messages when it doesn’t work