Is there a Haskell idiom for updating a nested data structure?

Record update syntax comes standard with the compiler: addManStk team = team { manager = (manager team) { diet = (diet (manager team)) { steaks = steaks (diet (manager team)) + 1 } } } Terrible! But there’s a better way. There are several packages on Hackage that implement functional references and lenses, which is … Read more

Are there any statically typed, embeddable scripting languages? [closed]

I’d suggest you check out Angelscript. We used it on Warsow and it’s pretty good. It has all the features you’d expect like classes, memory management, etc. Since it’s statically typed, it can make better optimizations for you, and so the bytecode ends up faster than other scripting languages. However, AS is not as easy … Read more

Disadvantages of Scala type system versus Haskell?

The big difference is that Scala doesn’t have Hindley-Milner global type inference and instead uses a form of local type inference, requiring you to specify types for method parameters and the return type for overloaded or recursive functions. This isn’t driven by type erasure or by other requirements of the JVM. All possible difficulties here … Read more

Why isn’t there an endianness modifier in C++ like there is for signedness?

What the standard says [intro.abstract]/1: The semantic descriptions in this document define a parameterized nondeterministic abstract machine. This document places no requirement on the structure of conforming implementations. In particular, they need not copy or emulate the structure of the abstract machine. Rather, conforming implementations are required to emulate (only) the observable behavior of the … Read more

Python 3 and static typing

Thanks for reading my code! Indeed, it’s not hard to create a generic annotation enforcer in Python. Here’s my take: ”’Very simple enforcer of type annotations. This toy super-decorator can decorate all functions in a given module that have annotations so that the type of input and output is enforced; an AssertionError is raised on … Read more

Python equivalent of Typescript interface

For the code completion and type hinting in IDEs, just add static typing for the Person and Address classes and you are already good to go. Assuming you use the latest python3.6, here’s a rough equivalent of the typescript classes from your example: # spam.py from typing import Optional, Sequence class Address: street: str housenumber: … Read more

Proper type annotation of Python functions with yield

I figured out the answer on my own. I searched, but found no documentation for the 3 type parameters of Generator in the official typing documentation for Python 3.5.2 – beyond a truly cryptic mention of… class typing.Generator(Iterator[T_co], Generic[T_co, T_contra, V_co]) Luckily, the original PEP484 (that started all this) was far more helpful: “The return … Read more

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