Short answer: I made a package because I wanted to release as soon as possible & encourage feedback / new ideas.
Longer answer: I don't think there's any reason TR couldn't integrate these "smarter" operators (specifically, macros that inspect their arguments before calling a core TR function). That's part of why I used the colon notation. But they should be opt-in rather than default features because the extra analysis fails in potentially-confusing ways. (let ([n 2]) (ann (-: n n) Zero)) ;; Type error These operators can also introduce type errors. (regexp-match #rx"hello" #"world") ;; Type error, generated by inferring the result type String from the regexp pattern That example is a bug in my implementation, but it shows how easily things can go strange. It's also possible that a user type error triggers a series of type errors in the expanded code. On Tue, Dec 15, 2015 at 9:27 AM, Matthias Felleisen <matth...@ccs.neu.edu> wrote: > > On Dec 15, 2015, at 2:14 AM, Alexis King <lexi.lam...@gmail.com> wrote: > > > This is pretty neat. Without looking too much into the documentation or > implementation, could you briefly elaborate on why these changes are in a > separate package rather than improvements to TR itself? > > > +1 > > > > > > At a quick glance, you mention doing some sort of static analysis on > arguments in the normal macro expansion phase: is there any practical > reason why TR couldn’t export these? Are there any hidden incompatibilities > with the core Racket forms? Or is this just a philosophical division, > deciding that TR shouldn’t unnecessarily re-implement forms to perform > “magic” typechecking? > > > > Anyway, my curiosity aside, this is a cool idea. I’ll definitely > consider playing with this a bit if I can get some free time. > > > > Alexis > > > >> On Dec 14, 2015, at 21:40, Benjamin Greenman < > benjaminlgreen...@gmail.com> wrote: > >> > >> Have you or someone you know [1] ever thought: > >> > >> "Gee, I wish Typed Racket could figure out that ___ has type ___. > >> It's pretty obvious to me." > >> > >> Then the new "trivial" [2] library is here to help. If you're using > basic arithmetic (+, -, *, /), format strings, or regexp-match, just add a > colon to the end of your favorite operator. > >> > >> When a strong type really is obvious, you win! > >> > >> (require trivial/regexp) > >> (cond > >> [(regexp-match: #rx"f(o*)" "foobar") > >> => > >> (lambda ([m : (List String String)]) (cadr m))] > >> [else > >> "no match"]) > >> > >> Please send bugs & feature requests to the issue tracker [3]. The > tracker's also a good place to complain about the choice of the name > "trivial" or the colon notation. > >> > >> [1] https://groups.google.com/forum/#!topic/racket-users/BfA0jsXrioo > >> [2] http://pkg-build.racket-lang.org/doc/trivial/index.html > >> [3] https://github.com/bennn/trivial/issues > >> > >> > >> ;; --- More Examples > >> > >> Before: > >> (+ 1 (if (= 0 (- 2 2)) 1 "x")) > >> ;; expected: Number, given: (U String One) > >> > >> (printf "hello ~a") > >> ;; raises runtime error > >> > >> (ann (regexp-match "f(o*)" "foobar") > >> (U #f (List String String))) > >> ;; Type Error, got type > >> ;; (U #f (Pairof String (Listof (U False String)))) > >> > >> > >> After adding (require trivial): > >> > >> (+ 1 (if (= 0 (-: 2 2)) 1 "x")) > >> ;; Success! > >> > >> (printf: "hello ~a") > >> ;; Compile-time error > >> > >> (ann (regexp-match "f(o*)" "foobar") > >> (U #f (List String String))) > >> ;; Success! > >> > >> > >> If a strong type isn't clear from the call site, you get standard Typed > Racket types. > >> > >> (let ([n 2]) (-: n 2)) > >> ;; Type: Integer > >> > >> ((lambda ([f : (-> String Void)]) (f "~b" 'NaN)) > >> printf:) > >> ;; Runtime error > >> > >> (regexp-match: "f(o*)|bar" "foo") > >> ;; Type: (U #f (Pairof String (Listof (U #f String)))) > >> > >> > >> One more thing: there's a special form for compiling regular expression > patterns: > >> > >> (define-regexp: my-pat #rx"f(o*)") > >> ;; Also supports pregexp, byte-regexp, byte-pregexp > >> > >> (ann (regexp-match: my-pat "") > >> (U #f (List String String))) > >> ;; Success! > >> > >> > >> -- > >> You received this message because you are subscribed to the Google > Groups "Racket Users" group. > >> To unsubscribe from this group and stop receiving emails from it, send > an email to racket-users+unsubscr...@googlegroups.com. > >> For more options, visit https://groups.google.com/d/optout. > > > > -- > > You received this message because you are subscribed to the Google > Groups "Racket Users" group. > > To unsubscribe from this group and stop receiving emails from it, send > an email to racket-users+unsubscr...@googlegroups.com. > > For more options, visit https://groups.google.com/d/optout. > > -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.