Earlier quoted context omitted.
Recursing can build up very long promise chains if you aren't careful and also just isn't a natural way for many programmers to express many kinds of code. Even simple branching gets nasty in many cases if, for example, one branch does something async while the other does not. You also lose try/catch.
Yeah, agreed. It's functional, but technically weak. This might be a place to introduce functional pipelines like Haskell's Pipes, Machines, Conduits. They solve the effectfull iteration and streaming problem, but the mechanism is heavily transformer based.
What Color Is Your Function?
131–140 of 153 posts
Re: What Color Is Your Function?
#132Earlier quoted context omitted.
You can write very safe code by using structs (even 1-element structs) for everything. But there's no generics system and very little in the way of safe tools for making one; writing a safe "generics runtime" and macros to use it puts you halfway to writing a new language.
>structs (even 1-element structs) for everything. Are there any large C projects written in this style?
It does add a bit of boilerplate. For the indexes in particular, foo_lookup(foo, idx) is substantially safer than foo[idx.value] - but then you've gotta write the lookup functions (which may just be a macro but is still a bit of cruft). Locally, if using var.value everywhere in math is getting ugly, you can of course pull things out into temporary primitive variables - enforcing things at the boundaries between functions provides almost all of the benefit.
Re: What Color Is Your Function?
#133Earlier quoted context omitted.
It's a good type system. Many programming languages don't support this kind of type information, notably C.
I'm always curious how far a sufficiently motivated masochist could go with C... I guess it's just C++ ;)
Re: What Color Is Your Function?
#134Earlier quoted context omitted.
Effect Typing and Monads are yet another colour for the lipstick you put on the pig. You still have non-composability (i.e. the async monad spreads through your code), you still have the complexity, you still don't have proper tracebacks without special runtime support, and you still have the inefficiency that Bob didn't actually mention (unwinding all those stacks all the time). Languages with threads (Java, C#) don…
Go's "good, pragmatic engineering" solution to the problem - lightweight threads, channels, and the communicating sequential processes model - is built on the back of decades of academic research, including programming languages research. And now for some computer language geekery: Go solves one "code color" problem (concurrency/asynchrony), by hard-coding the solution into the language. Go programs are written in a…
True, but you missed the major disadvantage of doing everything in a monad: there may be horrible side-effect demons lurking in every line of code!
In my experience, the most egregious offenders are shared mutable state (AKA multithreading) and exceptions. Introducing multithreading or exceptions into an application which previously shunned them feels like switching to a whole different language; one where all our intuitions and guarantees can be undermined at any time.
Re: What Color Is Your Function?
#135Re: What Color Is Your Function?
#136Funny. I thought he was talking about Java 8 for a while. We (eventually, when the rest of the stack catches up) get functors / lambdas, but: * red = instance methods. * blue = static methods, which cannot call an instance method.
Re: What Color Is Your Function?
#137Earlier quoted context omitted.
It's a good type system. Many programming languages don't support this kind of type information, notably C.
I'm always curious how far a sufficiently motivated masochist could go with C... I guess it's just C++ ;)
Re: What Color Is Your Function?
#138Funny. I thought he was talking about Java 8 for a while. We (eventually, when the rest of the stack catches up) get functors / lambdas, but: * red = instance methods. * blue = static methods, which cannot call an instance method.
That's not true. You can call an instance method from anywhere given an object. There's just no implicit 'this' in a static method.
Once you go functional, instance methods start to look like a special klugery for currying the first argument to a function. Go and Nim (for instance) hint at this more than a little, as well, with their OOP syntax.
Bundling two kinds of methods within a "class" starts to feel weird when you start using individual functions.
Re: What Color Is Your Function?
#139Earlier quoted context omitted.
It helps syntactically but does nothing about the main problem: composability. Each of your functions has to know which function to call next, instead of just having one function that invokes n other functions in order. That's what next() is meant for.
For composability in JS I use small utility modules like "inOrder": function beforeWifeComesHome() { takeTheTrashOut(); function takeTheTrashOut() { inOrder([openDoor, goOut, emptyTrash, goIn, closeDoor]); } } But it would be easier to let the compiler take care of the async calls and insert callbacks automatically so that you can think synchronously while the program works asynchronously. And if you want to run stuf…
Re: What Color Is Your Function?
#140Earlier quoted context omitted.
Also, what about Koka ? http://koka.codeplex.com/ and http://research.microsoft.com/en-us/projects/koka/ From the latter: > The Koka project tries to see if effect inference can be used on larger scale programming. The language is strict (as in ML), but seperates pure values from side effecting computations (as in Haskell). Through the effect types, there is also a strong connection to its denotational semantics, whe…
I just wanted to say that I've finally taken a look at Koka after hearing you mention in on HN many times. It's very nice! I appreciate how it provides most of the bang of effect types much more conveniently than one might expect with the explicit monadic structuring going on in Haskell. Have you looked at Frank [0] by any chance? It has a very similar row-effect type (I guess these were both first explored in Eff?)…