soegaard2
2020-6-28 12:52:49

Under which name is this function usually known as? (define (mapmap f xss) (for/list ([xs xss]) (map f xs)))


laurent.orseau
2020-6-28 12:58:55

No idea. First made-up name that came to my mind was mmap.


laurent.orseau
2020-6-28 13:05:58

Not all simple functions have a name. IIRC, identity was introduced very late in Racket (because you can use values, but it’s not the same contract)


soegaard2
2020-6-28 13:06:34

I sort of thought it was called deep-map, but I couldn’t find that name in the docs.


laurent.orseau
2020-6-28 13:07:08

deep-map sounds more like a tree-map to me


soegaard2
2020-6-28 13:09:15

That would be okay - but I can’t find tree-map for a standard list-based tree either.


laurent.orseau
2020-6-28 13:11:21

some srfi?


laurent.orseau
2020-6-28 13:12:04

tree-map is different though since elements that are lists are recurred through.


maueroats
2020-6-28 13:12:34

I don’t think you’d want either of these choices, but <https://hoogle.haskell.org/?hoogle=(a-%3Eb)-%3E%5B%5Ba%5D%5D-%3E%5B%5Bb%5D%5D|Hoogle says> <<$>> or <$$>. Conclusion: not as common as you would think?


laurent.orseau
2020-6-28 13:17:41

@soegaard2 I didn’t check, but it may be faster to use (define (mapmap f xss) (for/list ([xs (in-list xss)]) (for/list ([x (in-list xs)]) (f x)))) because map will check the list contract many times, whereas there’s a chance for the compiler to lift it when using for/list


laurent.orseau
2020-6-28 13:19:44

(because map is a function but for/list is a macro, so more chances to speed things up, but I don’t know for sure)


soegaard2
2020-6-28 13:21:02

Good point. I am using it on relatively small “tables” though.


laurent.orseau
2020-6-28 13:24:24

table-map also came to my mind, but I’m not sure how widespread it is to call these 2d-lists tables. I would say that a table must have the same number of rows, which is not necessarily the case for you function.


gfb
2020-6-28 16:11:49

@laurent.orseau They both involve checking the outer list once, and each inner list once, so I don’t see the check you’re thinking of. I can imagine different optimizations that might get applied to each, so it would need profiling with a particular enviroment and use case.


laurent.orseau
2020-6-28 16:29:24

I was thinking of the list? check in the inner loop, but it’s actually constant-time amortized, so that doesn’t apply here. (I had in mind a map with two lists, which checks that the lengths are equal, and this is linear time. for friends don’t check this.) +1 to profiling in any case


cyunus
2020-6-28 18:13:02

@cyunus has joined the channel


maueroats
2020-6-28 22:04:06

ben
2020-6-29 02:14:18

@samth how would you turn a type-&gt;sexp value back into a type at runtime?


ben
2020-6-29 02:20:07

I got something to work for simple types, but fails if a type uses an extra def from the #%type-decl submodule.

The simple thing is: • have a module that imports the same bindings as a type-decl submod does • define-namespace-anchor NS in this module • (eval ty-datum NS) I’ve tried changing tc-toplevel.rkt to put a copy of (make-env-init-codes) as an S-expression in the module toplevel, and eval’ing that too … but I still get unbound id errors

I also tried putting a sexp-&gt;type function inside the #%type-decl submod, using eval in its anchored namespace, and still get unbound ids