Hacker News new | past | comments | ask | show | jobs | submit login

You should know it at least a tiny bit though, or else you lump perfectly "idiomatic" functions in with low level functions that aren't often used and pretend they're a problem. How is a indexing an array without a bounds check somehow counter to lazy evaluation or functional programming? It is the exact same thing as indexing it normally, just without checking the length.



How is indexing an array OK with functional programming of the level of purity Haskell strives for (not to mention without bounds checking)?

In "Real World Haskell" they advise you to forgo of arrays, and even has a chapter "Life without arrays", saying "arrays and hash tables are often used as collections indexed by key, and in Haskell we use trees for that purpose".


>How is it not? That is a complete non-sequitur and makes no sense. What sort of definition of functional programming are you using that you think it restricts what data types you are allowed to use?

The normal definition of functional programming, in which not all data structures used in imperative programming are idiomatic (or even considered "functional").

For starters, mutable data structures would be considered not purely functional. E.g:

"Most books on data structures assume an imperative language such as C or C++. However, data structures for these languages do not always translate well to functional languages such as Standard ML, Haskell, or Scheme. This book describes data structures from the point of view of functional languages, with examples, and presents design techniques that allow programmers to develop their own functional data structures" [1]

[1] http://www.cambridge.org/us/academic/subjects/computer-scien...


>The normal definition of functional programming, in which not all data structures used in imperative programming are idiomatic

I can't find any reference anywhere to any sort of definition like that. Or even one that mentions restricting data structures or memory layout at all. The only "normal" definitions I can find are: "functions are first class" which is a pretty weak definition and doesn't really exclude much these days, and: "the return values of functions depend only on the functions arguments" which is what everyone in the haskell world thinks of as "functional programming". Neither of these definitions exclude arrays.

>For starters, mutable data structures would be considered not purely functional

A data structure can not be functional or imperative. Only what you do with it. Mutation is perfectly fine if it is localized (remember the function's return value needs to only depend on its arguments, nothing more).


If you look at the context you can see that they are saying that using immutable arrays has a performance hit compared to mutable ones. That doesn't mean you shouldn't use arrays if they suit your purpose.


>How is indexing an array OK with functional programming of the level of purity Haskell strives for (not to mention without bounds checking)?

How is it not? That is a complete non-sequitur and makes no sense. What sort of definition of functional programming are you using that you think it restricts what data types you are allowed to use? Do you think you aren't allowed to use lists in C?

>In "Real World Haskell" they advise you to forgo of arrays

You might want to read it instead of misrepresenting something out of context. You might also wish to consider that many of the haskell shootout submissions came from the authors of RWH.


The point is that is unsafe. You don't need to do that in idiomatic Rust code, because the bounds-check-free indexing is encapsulated inside the iterator library. So to re-frame it: fast, idiomatic Rust code is safer and easier to write than fast, idiomatic Haskell code.


>The point is that is unsafe

No, the point was that it is "far from idiomatic". Did you read the post I was replying to?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: