Haris Bogdanovic wrote: > I know Ruby programming well but I wanted to add funtional paradigm in > my > programming as it is very usefull. If you know Ruby well - and you obviously understand functional programming, because you know it is "usefull" (sic) - then just start writing functional programs. To do this, make sure that: 1. you don't modify any objects. Only use methods which return new objects. 2. once a local variable is assigned, you don't reassign it. However Ruby won't enforce (1) unless you litter your code with 'freeze' statements, and it can't enforce (2) at all. a = "hello" a << " world" # wrong: modifies the string a += " world" # wrong: new string, but assigned to same variable b = a + " world" # right # Example: convert all hash keys to strings src = {:one=>1, :two=>2} # Imperative out = src.inject({}) { |h,(k,v)| h[k.to_s] = v; h } # Functional out = src.inject({}) { |h,(k,v)| h.merge(k.to_s => v) } > If you don't know and are not interested in it you don't have to insult > me. > And Haskell looks pretty useless to me because it is functional paradigm > only language. Who's being insulting now? What are you saying about all Haskell programmers, and all the language designers? Do you genuinely believe that useful systems cannot be written in Haskell? Go and look at Erlang. Massive real-world systems are built out of this, with incredible reliability, using only functional programming and CSP. It's also very straightforward to pick up and use, and has a very comprehensive standard library. Remember also that functional languages allow all sorts of compile-time optimisations which are impossible in Ruby, so there is the potential for much higher performance. For example, OCaml generates code which is reputedly only half the speed of the equivalent C code. -- Posted via http://www.ruby-forum.com/.