DEV Community

Discussion on: Functional programming and pure functions

 
pentacular profile image
pentacular

A procedure is never a function, but it can implement a function - we call this an algorithm.

If map were a pure function you would not be able to compose it with a procedure in the first place.

Thread Thread
 
macsikora profile image
Pragmatic Maciej

If function is not a part of language then we can only make it from procedure by making it referencial transparent. If procedure is referencially transparent then it can be called a function. If not then we cannot name anything a function outside of pure FP languages. But this is more about naming, I have no problem to name everything a procedure as it would be at least better than naming everything a function , what is in a most false in imperative languages.

The thing is that map usage is referencially transparent if we pass to it another referencially transparent function. If we don't the composition is a procedure as you have stated, but IMO if function itself doesn't make side effects we can name it a function, it is fully ok and should not be confusing. As I stated before your opinion makes every HOF not pure even though it's implementation has nothing impure.

Thread Thread
 
pentacular profile image
pentacular

A procedure can never be called a function.

However, as I've said, you can use a procedure as a way to implement a function.

It's important to understand that it's still a procedure, and it's still executing a series of operations over time, as opposed to being a time-invariant relationship.

HOP (higher order procedures) can implement functions, while not being functions -- but the distinction remains.

I don't think we're particularly disagreeing, except on your use of "is" vs "implements".

Thread Thread
 
macsikora profile image
Pragmatic Maciej

Ok, yes I think your way of stating that is correct. Function can be implement by procedure. And .map can be co considered as HOF implementation if we use another transparently referencial procedure as an argument.