With static intro all of this is a macro, while loop, and a switch statement. A fraction of the complexity and you get editor help and typed holes. https://willcrichton.net/notes/type-safe-printf/ … https://github.com/deech/LambdaWorldCadiz2019-WhatFPCanLearnFromStaticIntrospection/blob/master/printf.nim …
-
Show this thread
-
Replying to @deech
I wouldn't say this is a meaningful comparison. The nim strategy is the same as Rust's (see: https://github.com/rust-lang/rust/blob/8e5a27766ff14af36448a4b4c0a8bff84090168f/src/librustc_builtin_macros/format.rs …). The blog post is showing how a format safety property can be captured without macros.
1 reply 0 retweets 0 likes -
Replying to @wcrichton @deech
That said, I agree that the trait-encoding is gnarly. I think there are ways to make these kinds of programs easier to write, in terms of distance from mental model to code. See:https://github.com/willcrichton/tyrade …
1 reply 0 retweets 0 likes -
Replying to @wcrichton
But doesn't the rust built-in have access to type information that rust users do not have? With static intro any user of the language can run the type checker on an arbitrary expression at compile time.
1 reply 0 retweets 2 likes -
Replying to @deech
Oh I see -- you're right, Rust doesn't give user-space macros access to type information. I've wanted this for a while though (see: https://willcrichton.net/notes/type-directed-metaprogramming-in-rust/ …).
1 reply 0 retweets 0 likes -
Replying to @wcrichton @deech
However, with traits you can get a lot of mileage out of syntax-directed transformations. Rust's println impl doesn't introspect types. format!("{:?}", 3) expands to Arg(3, fmt::Debug) which then only type-checks if 3 implements Debug.
1 reply 0 retweets 0 likes -
Replying to @wcrichton @deech
That's why Rust doesn't have %d or %s, just {} and {:?}. The Debug/Format traits take care of checking whether an object is convertible to a string.
1 reply 0 retweets 0 likes
To see an example, go to this playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=07ad6d44dd855455c1e444d21357df18 … Then click "Tools > Expand Macros".
-
-
Replying to @wcrichton
This is quite similar to how Haskell does it so the pattern is familiar.
0 replies 0 retweets 1 likeThanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
cognitive psychology. PhD