Hacker News new | ask | show | jobs
by cmallen 5979 days ago
>Pointers are absolutely part of the average Haskell and Python work environment -- it's impossible to get reasonable performance without them.

I think that making calls to functions implemented in C via the FFI would be more productive. I've never heard of anyone using pointers in Python for anything.

>This sentence makes no sense, and makes me think you've never (or seldom) used Haskell before.

Sure it does, performing an arbitrary mutation on an already known variable (location in memory) in Haskell is very intentionally non-trivial due to striving for purity as a functional language. (Copy rather than overwrite behavior as a default.)

>That's because C is used in code where performance is absolutely critical, which demands having control over memory layout and management. Pointers aren't a symptom of using C -- using C is a result of needing pointers.

Uh, the whole, "C only uses pointers for speed" thing is completely incorrect. All the experienced C programmers I know use pointers simply because they're the most direct and portable means of writing terse code that is still performant in spite of the brevity. I mentioned functors for a reason.

This is more pedantic than some of the conversations I've witnessed in ##C on Freenode, come on.

You're missing the point by a greater distance than Christopher Columbus missed the West Indies in the late 15th century.

1 comments

> Sure it does, performing an arbitrary mutation on an already known variable (location in memory) in Haskell is very intentionally non-trivial due to striving for purity as a functional language. (Copy rather than overwrite behavior as a default.)

This paragraph 1) has nothing to do with monads and 2) is incorrect. Monads exist to enforce in which order computations are performed. And there's nothing difficult about mutating memory in Haskell; aside from a lack of built-in syntax, it's a close equivalent to C.

  import Foreign

  main = do
  	p <- malloc      -- p = malloc(sizeof(char))
  	poke p 'a'       -- *p = 'a'
  	peek p >>= print -- printf("'%c'\n", *p)
  	poke p 'b'       -- *p = 'b'
  	peek p >>= print -- printf("'%c'\n", *p)
  	free p           -- free(p)