Re:Arduino-copilot makes it easy to use Haskell to program a...
by joeyh on Sunday January 26, 2020 @09:18AM
(#22152166)
It's worth looking at the C code that's generated from a simple blink example in haskell. It's not very idiomatic, but neither is it very slow. Much of the fluff should get optimised away by the C compiler. I've been generally very impressed with how readable the output is, as generated code goes, and how performant it seems.
[ Parent
| on HN ]
Re:Arduino-copilot makes it easy to use Haskell to program a...
by joeyh on Sunday January 26, 2020 @09:28AM
(#22152200)
Doing some constant folding, the C compiler would arrive at something like this:
void loop(void) {
delay(100);
digitalWrite(13, s0[s0_idx]);
s0[s0_idx] = s0[s0_idx];
s0_idx = (++s0_idx) % 2;
}
void setup()
{
pinMode(13, OUTPUT);
}
Only the s0[s0_idx] = s0[s0_idx] looks like extra work now. I don't know if a C compiler would optimise that away, but assuming it does not, one extra memory write per loop is not bad overhead.