Live data from Hacker News

What Is Type-Level Programming?

blog.sulami.xyz

81–90 of 96 posts

Re: What Is Type-Level Programming?

#81
post #73

Earlier quoted context omitted.

> Yeah, and it's trivial in C++, what's your point? I see lots of assertions of that fact, but no examples. Care to link some actual code? > Why the hell would you want to change the direction of a pin anyway? Just declare it as Pin or Pin . i2c uses the same pin for sending and receiving and changes the mode of the pin for the purposes of communication with peripherals.

Ok, but then the pin is always both Input/Ouput, so still static; and the example is still as contrived as ever.

Well no, its output when writing and input when reading. I2C isn't full-duplex.

Re: What Is Type-Level Programming?

#82

I do not believe that the rust solution can be exactly encoded in C++ as the C++ type system itself can't statically guarantee linear typing. You have to use move semantics with a runtime guard... ... except that it might be possible to also "shift left" in C++, by running the pin-using code a compile-time (possibly instantiating it on mock objects) and validate the "runtime guard". This is a rough example https://gc…

Can rust do linear types? I thought it was limited to affine by the exception machinery

Re: What Is Type-Level Programming?

#83

I do not believe that the rust solution can be exactly encoded in C++ as the C++ type system itself can't statically guarantee linear typing. You have to use move semantics with a runtime guard... ... except that it might be possible to also "shift left" in C++, by running the pin-using code a compile-time (possibly instantiating it on mock objects) and validate the "runtime guard". This is a rough example https://gc…

Can rust do linear types? I thought it was limited to affine by the exception machinery

It is probably close enough for this use.

Re: What Is Type-Level Programming?

#84
post #32

"C++ to the RISCue! A Practical Guide for Embedded C++20 - CppCon 2021" https://www.youtube.com/watch?v=2Bi8SiVwyQA Basically how to use the C++ type system to create state machines for embedded systems. Including examples for Arduino.

Correct me if I'm wrong, but...the example from the talk still wouldn't prevent the error in the article example at compile time? You can happily write INPUT instead of OUTPUT and it would compile without error?

Re: What Is Type-Level Programming?

#85
post #75
post #74

Earlier quoted context omitted.

> C like code was presented as C++ Blame Arduino for their stdlib. > was presented as something not available in C++ You are putting things in the author's mouth, they never said that; only that it was not available in Arduino's stdlib.

What about blame the author for their lack of C++ skills while selling Rust, and pretending otherwise?

Once again, you're reading a language war where there is none.

Read the bloody article, it's all about the type system, not the language.

Do you really expect the author to rewrite the Arduino stdlib for the sake of pjmlp's sensibility?

Re: What Is Type-Level Programming?

#86
post #85
post #75

Earlier quoted context omitted.

What about blame the author for their lack of C++ skills while selling Rust, and pretending otherwise?

Once again, you're reading a language war where there is none. Read the bloody article, it's all about the type system, not the language. Do you really expect the author to rewrite the Arduino stdlib for the sake of pjmlp's sensibility?

I expect the author to actually learn C++ to start with.

I survived the Usenet flamewars, there is no sensibility to hurt.

Looking at the fellow comments the crowd shares a similar opinion on the article.

Some food for thought.

Re: What Is Type-Level Programming?

#87
post #28
post #8

Correct me if I'm wrong, but I see nothing in the Rust example that couldn't just as well be implemented in C++. A comparison to C would have made more sense.

Yeah, many posts from Rust Evangelism Strike Force fail to gain appreciation from the target audience, when they clearly show a lack of understanding of C++ capabilities.

I swear: if it wasn't for the eerie woke mob mentality surrounding the language, I might actually give it a second glance; but there's no chance in hell I'll put my energy into something this fundamentalistic.

Re: What Is Type-Level Programming?

#88
post #68
post #65

Earlier quoted context omitted.

Then they should have presented the case that way, instead of showing C like code and assuming there is no way to do that in C++.

> Then they should have presented the case that way That's exactly what they did. > assuming there is no way to do that in C++ You are extrapolating things that are nowhere to be found in the article.

> > Then they should have presented the case that way

> That's exactly what they did.

You have read the article, right? It starts with showing how it looks like in C++ and then goes on with the revelation "In Rust on the other hand ...". Literally. This strongly suggests that what they are getting at is a language feature that sets Rust apart from C++.

Re: What Is Type-Level Programming?

#89
post #6
post #4

>"This looks fine, but what happens if you do not get the pin mode right, for any of many possible reasons?" This is such a contrived and pathetic example. None of it has anything to do with C++ or Rust. It was a decision of whomever wrote pin access libraries. In either of the languages mentioned there is absolutely no problem creating an interface that would return particular pin in "right" state ready to be operat…

But a strongly typed language allows you to check for that error in compile time . As someone who programs embedded I can assure you that you constantly run into that type of error and I could really live without it. So if people could also do that in C/C++ they are apparently not doing it.

C++ has reinterpet_cast or whatever. But in reality the huge majority of C++ code works on safely typechecked code with no escape hatches.

Re: What Is Type-Level Programming?

#90
post #84
post #32

"C++ to the RISCue! A Practical Guide for Embedded C++20 - CppCon 2021" https://www.youtube.com/watch?v=2Bi8SiVwyQA Basically how to use the C++ type system to create state machines for embedded systems. Including examples for Arduino.

Correct me if I'm wrong, but...the example from the talk still wouldn't prevent the error in the article example at compile time? You can happily write INPUT instead of OUTPUT and it would compile without error?

There are a lot of people in this thread eager to brag about their C++ bona fides without giving fair consideration to the problem the article is really discussing. The video is interesting for several reasons but it doesn't go towards the main question.

(Thanks, btw, to gpderetta for being the only one to take a real shot.)

Post reply on HN