Why is there “data” and “newtype” in Haskell? [duplicate]

Both newtype and the single-constructor data introduce a single value constructor, but the value constructor introduced by newtype is strict and the value constructor introduced by data is lazy. So if you have data D = D Int newtype N = N Int Then N undefined is equivalent to undefined and causes an error when … Read more

Why aren’t variables declared in “try” in scope in “catch” or “finally”?

Two things: Generally, Java has just 2 levels of scope: global and function. But, try/catch is an exception (no pun intended). When an exception is thrown and the exception object gets a variable assigned to it, that object variable is only available within the “catch” section and is destroyed as soon as the catch completes. … Read more

Why doesn’t Java allow generic subclasses of Throwable?

As mark said, the types are not reifiable, which is a problem in the following case: try { doSomeStuff(); } catch (SomeException<Integer> e) { // ignore that } catch (SomeException<String> e) { crashAndBurn() } Both SomeException<Integer> and SomeException<String> are erased to the same type, there is no way for the JVM to distinguish the exception … Read more

What does void mean in C, C++, and C#?

Basically it means “nothing” or “no type” There are 3 basic ways that void is used: Function argument: int myFunc(void) — the function takes nothing. Function return value: void myFunc(int) — the function returns nothing Generic data pointer: void* data — ‘data’ is a pointer to data of unknown type, and cannot be dereferenced Note: … Read more

When someone writes a new programming language, what do they write it IN?

It’s not a stupid question. It’s an excellent question. As already answered the short answer is, “Another language.” Well that leads to some interesting questions? What if its the very first language written for your particular piece of hardware? A very real problem for people who work on embedded devices. As already answered “a language … Read more

Why doesn’t a python dict.update() return the object?

Python’s mostly implementing a pragmatically tinged flavor of command-query separation: mutators return None (with pragmatically induced exceptions such as pop😉 so they can’t possibly be confused with accessors (and in the same vein, assignment is not an expression, the statement-expression separation is there, and so forth). That doesn’t mean there aren’t a lot of ways … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)