Live data from Hacker News

Are arrays functions?

futhark-lang.org

141–145 of 145 posts

Re: Are arrays functions?

#141

Earlier quoted context omitted.

It sounds like like you're conflating pure and impure functions. No I'm not, this applies to both in different ways. If we're talking about pure functions, then due to referential transparency, arrays are in fact equivalent to functions Never ever. You're talking about a function that generates data from an index, which is trivial to make. Just because it is possible to disguise it as an array in haskell, C++ or anyt…

Notice that I never once in this discussion claimed that it was a "good idea". This is about research and experimentation. The blog post has the title because of the Haskell documentation. Also, claiming that the lack of an argument is evidence to the contrary is argument from silence, a logical fallacy. The good idea surrounding this isn't about treating functions as data, but maintaining the purity of the type syst…

This is about research and experimentation.

Haskell is 36 years old. It isn't research and experimentation any more, it is ideas that everyone with experience has had a look at. Some people might be learning haskell for the first time, but that doesn't mean it's still research, that all happened decades ago.

The good idea surrounding this isn't about treating functions as data, but maintaining the purity of the type system allowing the implications of the type system to run their course.

And what are the benefits here? How do they help the things I talked about? How do they avoid the pitfalls?

Also, claiming that the lack of an argument is evidence to the contrary is argument from silence, a logical fallacy.

Not really, because if you could contradict what I've said you would have.

within the framework of type theory and functional programming.

People can gather in a room and tell each other how great they are and how they have all the answers, but in 36 years there is a single email filtering program that was made with haskell.

you're using reasoning that applies only to procedural programming to attempt to prove why an idea in functional programming is bad.

I explained why this is a bad idea from fundamental and universally agreed upon ideas about the best ways to write software.

Functional programing languages had lots of ideas and features that turned out to work well. That doesn't mean that conflating two completely separate concepts is a good idea, no matter what 'type theory' someone comes up with to support it.

Saying something is good because haskell says it is good is circular religious thinking. These two things aren't the same, they are literally two different things and trying to unify them doesn't make life easier for anyone. It's just programming cleverness, like the 'goes to operator --> '

Re: Are arrays functions?

#142
post #73

Earlier quoted context omitted.

> However the big difference (in most languages) is that functions can take arbitrarily long. Array access either succeeds or fails quickly. For some definition of quick. Modern CPUs are usually bottlenecked by memory bandwidth and cache size. So a function that recomputes the value can often be quicker than a look up table, at least outside of microbenchmarks (since in microbenchmarks you won't have to compete with…

I've been watching those Kaze Emanuar videos on his N64 development, and it's always so weird to me when "doing the expensive computation again" is cheaper than "using the precomputed value". I'm not disputing it, he seems to have done a lot of research and testing confirming the results and I have no reason to think he's lying, but it's so utterly counter-intuitive to me.

I used to develop for the N64 and I can confirm that it is true. It is crazy how much faster the CPU is compared with not-in-cache RAM access.

Optimizing for RAM access instead of CPU instruction speed can make your code magnitudes faster.

Re: Are arrays functions?

#143
post #99

Earlier quoted context omitted.

This particular case is unique to Clojure, I believe. You definitely can’t do that in Common Lisp , and Scheme I am not so sure. It was one of the main motivations for Rich Hickey to make the language more uniform so that a few functions work on any number of data structures.

> This particular case is unique to Clojure, I believe. It also works in pure lambda calculus (assuming you define a vector type). But in lambda calculus, literally every value is a function.

is pure lambda calculus something i can install and use to host a web server?

Re: Are arrays functions?

#144
post #143

Earlier quoted context omitted.

> This particular case is unique to Clojure, I believe. It also works in pure lambda calculus (assuming you define a vector type). But in lambda calculus, literally every value is a function.

is pure lambda calculus something i can install and use to host a web server?

No reason why not, in principle. Using Church-encoded numerals and so on might be a little inefficient. Probably not as bad as Python though.

Re: Are arrays functions?

#145
post #110
post #91

Earlier quoted context omitted.

One case where a function is often not substitutable for an array is equality testing. In a language where any two arrays with the same elements in the same order are equal ([1,2] == [1,2]), the same cannot always be true of two equivalent functions. That is because extensionally equality is undecidable for arbitrary functions. Arrays and functions may be mathematically equivalent but on a programming language level…

I don’t understand this argument. Just because functional extensionality is undecidable for arbitrary functions doesn’t mean that it is undecidable for every class of functions. In the specific situation, let’s say that by an array we mean a finite, ordered list whose entries are indexed by the numbers 0, 1, …, n - 1 for some natural number n . Let’s also say that two arrays are equal if they have the same length and…

Right, so for a subset of functions, a language could implement an extensional equality test operator `==` for two functions by calling the functions for every possible input. It would be prohibitively slow for some functions, but correct.

But for other functions, even that won't be possible.

The point is that functions and arrays may be practically different. You can always do an `==` test on the contents of two arrays, but you can't do the same for two arbitrary functions.

Post reply on HN