|
|
|
|
|
by jmillikin
5978 days ago
|
|
> 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)
|
|