Tag Info

Hot answers tagged

14

Wrt abstraction, I see that repeat(square, 2) returns implementation detail in the form of apply_n_times(n - 1)(f(x)) multiple times before providing the actual result. The function returned by repeat(square, 2) is not an implementation detail; it's the whole point of calling repeat. An implementation detail is something that the caller doesn't need to ...


6

The benefit of abstraction is that the caller doesn't have to know about implementation details. If I understand correctly, you're questioning this python construct because the caller can find about about implementation details. That's not the same thing. Not having to know about how a method does its job is useful. It aids the software developer in their ...


5

You already said in your question how you can tell whether your program is referentially transparent or not: if you can replace a expression with its value, without changing the meaning of the program, it is referentially transparent. If you cannot do that, it is not. So, let's just try and replace some expressions with their values! in your summation ...


5

In the situations similar to the one you've described you should always use the third option, or, better yet, just let add' = (+) (but beware of Monomorhism Restriction). I see no sense in the other two definitions you have provided. However, it's common to use nested functions in a way similar to your second example if the nested function takes auxiliary ...


4

The caller doesn't so much need to know the implementation details of repeat(f, n) as he needs to know its return value. In this case, the return value is a little more complicated than most, because it returns a function. In a static language like Haskell, this is easily documented in the function signature like: repeat :: (a -> a) -> Int -> (a ...


2

State + move = new state Both old state and new state are immutable. Move doesn't mutate board state, but creates a copy of the old state with move added. Imagine an inefficient implementation where board state is just a linked list of moves taken and each new move just adds another head to the linked list. For instance if I am holding a reference to a ...


2

The most common pattern I see in these types of situations is to use a CompletableFuture, which most FP languages just call a plain Future. It allows you to execute something long-running like a query, then specify actions to take later. If the query succeeds, the result is passed to the next action in the chain. If it fails, all the subsequent actions ...


2

What inconsistency? In the first case, you have a function. In the second case, you have a lambda expression, that is a function which has no name. Python could have chosen one of those three approaches: Returning None, Returning an arbitrary string, such as <lambda>, Raising an exception. All three options are valid, given that the third one ...


2

Is there still any functional programming language that doesn't rely on C runtime? The answer to this exact question is yes: C is not the only low-level language which is suitable as a compilation target (although definitely the most popular one). For example, the Embedded ML described in Functional Programming for Embedded Flight Software ...


1

In principle? Yes. C is a programming language like all others. What C can do, other languages can be made to do. In practice? Rarely. C is near-ubiquitous as a systems programming language (there are exceptions, but they will be provided in the outraged comments, so I don't bother listing them), and it is almost always a better idea to use what is already ...


1

I would say it is functional! The only half way iffy thing would be the fact that computeSequence actually mutates the array passed into it, however you only use it as a local function and thus it really doesn't matter because it still never changes anything outside of it's local scope and thus always yields the same results. to answer your second question ...



Only top voted, non community-wiki answers of a minimum length are eligible