by babel17 · 15y ago · 0 comments
Would you mind show me some code in pure functional language?
I mean, in Haskell or Clean. Those are pure enough.
My Ocaml code is not pure, but we can easy remove any occurrence of `ref`, and restricting oneself to pure methods, which produce a new fresh object instead of modifying `this` in place.
I am experiencing limitations of pure objects and message passing almost right now. In my spare time I am currently developing dynamic data flow CPU which is based on immutable "objects" and message sending. It is quite unusual style of programming, very unlike anything else, including Smalltalk, Erlang and everything.
(* Ocaml *) --Haskell
let foo = 42 foo = 42 -- top level declaration
type bar = data bar = -- type declaration
Also, records in Ocaml are a separate kind of type, more like C structs: type bar = { x:int; (* defination *)
y:float;
}
bar.x (* "member" acces *)
"Message passing" and "Method calling" are strictly equivalent, at least when everything is synchronous.