Live data from Hacker News

Corrode: C to Rust translator written in Haskell

github.com

61–70 of 127 posts

Re: Corrode: C to Rust translator written in Haskell

#61
post #60
post #55

Earlier quoted context omitted.

Well, it's just building off the same (negative) connotations of "Rust", which I think was itself a questionable name, trivial though it might seem. I've been looking at newer languages recently, and I see a lot of promise in Nim -- which renamed itself from Nimrod after users warned about what it connotes. Rust could take a cue.

Well, Rust isn't actually named after iron oxide. It's actually named after the fungus ( https://en.wikipedia.org/wiki/Rust_(fungus) ). Most people just don't know about the fungus.

When it comes to connotations, "what people know about" is more important than the intent.

Re: Corrode: C to Rust translator written in Haskell

#62

Earlier quoted context omitted.

That's an incredibly brilliant idea, there's some serious craftsmanship going on in that source file. Kinda taking Rust's doc unit tests format to a whole new level.

Rust should have a literate source format - with how much the community focuses on documentation, this would be an excellent addition.

There'a crate for that ;) https://github.com/pnkfelix/tango

Re: Corrode: C to Rust translator written in Haskell

#63
post #35

Earlier quoted context omitted.

Here you go. It didn't like my stdio.h. Apparently enums and unions aren't supported, but: extern int printf(char *, ...); int main(int argc, char argv[]) { printf("Hello, world!\n"); return 0; } Was turned into: extern { fn printf(arg1 : *mut u8, ...) -> i32; } #[no_mangle] pub unsafe fn main(mut argc : i32, mut argv : *mut u8) -> i32 { printf(b"Hello, world!\n\0".as_ptr() as (*mut u8)); 0i32 } edit: Also worth noti…

Shouldn't a C `int` be converted to Rust's `isize`. I think that captures the spirit better.

Not to look a gift horse in the mouth, but it seems like Corrode misses some other chances to use idiomatic Rust:

1. Rust fn:main doesn't need to return something.

2. The arguments to main aren't mutated, so Rust doesn't need to declare them as mutable.

3. Ditto for the argument to printf.

Anyone know how easy it is to recognize and code for such cases in the transpiler?

Edit: It looks like they might have opposite design goals [1]: "Corrode aims to produce Rust source code which behaves exactly the same way that the original C source behaved, if the input is free of undefined and implementation-defined behavior. ... If a programmer went to the trouble to put something in, I want it in the translated output; if it's not necessary, we can let the Rust compiler warn about it." (Edit2: cleaned up and numbered)

[1] https://github.com/jameysharp/corrode#design-principles

Re: Corrode: C to Rust translator written in Haskell

#64

Earlier quoted context omitted.

Sorry, I am not understanding what you're implying here. I am well aware of the definition of literate programming. (And what you've said isn't actually enough to be considered literate programming under Knuth's definition: that's just tangle, still missing weave. Though notably, a lot of people argue that weave isn't needed with today's programming languages...)

I mentioned it because I didn't see it in my scanning of the issue you linked to. Edit: I should have looked more closely, sorry.

Ah, no worries! I agree the issue is slightly down in the weeds, but don't worry, it's tracking the right thing :)

Re: Corrode: C to Rust translator written in Haskell

#65
post #63
post #35

Earlier quoted context omitted.

Shouldn't a C `int` be converted to Rust's `isize`. I think that captures the spirit better.

Not to look a gift horse in the mouth, but it seems like Corrode misses some other chances to use idiomatic Rust: 1. Rust fn:main doesn't need to return something. 2. The arguments to main aren't mutated, so Rust doesn't need to declare them as mutable. 3. Ditto for the argument to printf. Anyone know how easy it is to recognize and code for such cases in the transpiler? Edit: It looks like they might have opposite d…

1. A special case could be added for `main`, but it's no big deal.

2. This seems difficult as the C arguments were mutable; the algorithm would have to start doing analysis rather than direct translation.

3. Quite difficult to "know" that this printf doesn't write to its arguments, especially since the printf is manually declared.

Re: Corrode: C to Rust translator written in Haskell

#66
post #32

I was curious about how this worked so I looked into the source a little (even though Haskell isn't exactly my cup of tea), and WOW... This is just amazing. The most important part of the source is highly educative literate haskell: https://github.com/jameysharp/corrode/blob/master/src/Langua...

As someone who knows zero haskell, and little markdown, can someone explain how this works?

haskell.org [1] says there is "bird style" and "LaTeX style" ways of marking off code vs documentation, and I see neither in the linked file. Is it the "```haskell" blocks?

[1] https://wiki.haskell.org/Literate_programming#Haskell_and_li...

Re: Corrode: C to Rust translator written in Haskell

#68

Earlier quoted context omitted.

I guess you could say its ironic in terms of how I think of it anyway.

> ironic I don't even know what is and what isn't a pun anymore.

Yeah, let's not tarnish this thread any further.

Re: Corrode: C to Rust translator written in Haskell

#69
post #66
post #32

I was curious about how this worked so I looked into the source a little (even though Haskell isn't exactly my cup of tea), and WOW... This is just amazing. The most important part of the source is highly educative literate haskell: https://github.com/jameysharp/corrode/blob/master/src/Langua...

As someone who knows zero haskell, and little markdown, can someone explain how this works? haskell.org [1] says there is "bird style" and "LaTeX style" ways of marking off code vs documentation, and I see neither in the linked file. Is it the "```haskell" blocks? [1] https://wiki.haskell.org/Literate_programming#Haskell_and_li...

Yes, that seems to be the syntax used by literate markdown https://ghc.haskell.org/trac/ghc/wiki/LiterateMarkdown

Re: Corrode: C to Rust translator written in Haskell

#70
post #4

Earlier quoted context omitted.

Rust is a type of corrosion.

Ah very true. I interpret it as (from Googles define) "destroy or weaken (something) gradually." i.e. destroy/weaken the C code into Rust... Maybe it's just me, though.

They probably should've used a more specific term; like "Oxidant".
Post reply on HN