News for hackers. Stuff that matters.
Re:Arduino-copilot makes it easy to use Haskell to program a... by kbumsik on Sunday January 26, 2020 @12:22AM (#22150527)
I'm not familiar with Haskell and functional programming in general, so I'm curious if these codes in the OP make sense to Haskell people? Every lines of the codes are full of side effects (LEDs, buttons, delay...) and completely procedural.
Re:Arduino-copilot makes it easy to use Haskell to program a... by monoideism on Sunday January 26, 2020 @12:26AM (#22150536)
Pardon the off-topic question, but I noticed you used the plural "codes" instead of "code", which has typically been used in American English. Traditionally, "codes" has been used in other dialects of English, but I've noticed an increasing number of Americans using the plural form.

Is this a thing now? Are we saying "codes" instead of "code"?

Re:Arduino-copilot makes it easy to use Haskell to program a... by kbumsik on Sunday January 26, 2020 @12:34AM (#22150559)
Interesting question. I'm Korean and actually I was asking myself if "codes" is correct English while typing. I don't know, but except for grammar "code" seems to be countable to me.

Note that Korean grammar (and maybe some other languages) doesn't have strict rules about plural forms.

Anyway "Codes" make sense to me when they refer "snippets".

edit: added some more thoughts.

Re:Arduino-copilot makes it easy to use Haskell to program a... by monoideism on Monday January 27, 2020 @10:54PM (#22166303)
Yes, I think it's something some American developers have picked up from others using "global" English. I heard the plural used a lot from devs in and from the Indian subcontinent, and now, I'm starting to hear native American devs use the plural form.
Re:Arduino-copilot makes it easy to use Haskell to program a... by Dansvidania on Sunday January 26, 2020 @04:03AM (#22151181)
Code as in 'sourcecode' is uncountable IMO.

Code as in 'password' or 'cypher' or 'set of symbols' is instead countable.

Re:Arduino-copilot makes it easy to use Haskell to program a... by one-punch on Sunday January 26, 2020 @02:44AM (#22150988)
The code is mostly pure Haskell (the do block, which most Haskellers are familiar with), with a few domain-specific elements (those led and delay “assignments” and the Stream type in this functional reactive programming framework arduino-copilot, whose meaning is specific to this Arduino application and most Haskellers have to guess).

The short answer is that I could guess what it means.

This `arduino-copilot` example really showcases one killer application of Haskell: writing eDSL (embedded domain-specific language) in Haskell.

Haskell allows really high level abstraction: in particular, you can overload the operator which combines different statements in Haskell. In C/C++, the semicolon combines subsequent statements, Haskell even allows you to overload (give a new meaning to) the semicolon “operator” (think of overloading ; instead of overloading +). That is, in Haskell we can interpret differently how to combine subsequent statements in different contexts (such as null-checking, exception handling, async/await style concurrency, looping, or procedural state passing, etc., see the example below).

However, when we “overload the semicolon operator”, we intuitively have some expectations:

1. We expect to be able to turn a value into a standalone statement (to inject a value as a single statement with that value, e.g., to turn the value “97” into the statement “97;”, and this operation is called return)

2. We expect to be able to use the result of a statement in the next statement as in

    str <- getLine;
    putStrLn str
This could be rewritten using a bind operation (denoted >>=) as getLine >>= putStrLn.

When we package up (encapsulate) the above two operations (return and bind), we expect the two operations to play nicely with each other to satisfy some intuitive laws (e.g,. if you inject a value then use the value in a subsequent functional statement, it is the same as just calling the function on the value, so the return and bind cancels out, etc.). A mathematical formalization of this idea (the two operations with some intuitive laws) is named a monad, which happens to generalize many different computational contexts of combining statements such as null-checking, exception handling, async/await style concurrency, looping, or procedural state passing [1].

[1]: https://philipnilsson.github.io/Badness10k/posts/2017-05-07-...

The ability to reinterpret statement compositions is why Haskell is so great for embedding domain-specific languages (even procedural eDSL), as the arduino article shows, and this is why some people call Haskell the finest procedural language.