From: Jon Harrop Date: 2007-05-30T20:30:13+09:00 Subject: Re: Ruby & OCaml (was Re: Underscore) Mauricio Fernandez wrote: > Indeed; I was just illustrating a part of Ruby's object model (mixins) > with OCaml code. Right. > BTW, is {1.. n} a F# range comprehension or have you written some camlp4 > extension that looks like that (or is it only pseudocode)? Both. Native to F# and I think someone implemented it as a camlp4 macro for OCaml. However, containers are not derived from sequences in OCaml as they are in F#. You'd have to wrap them in objects yourself and people aren't likely to do that. For one thing, lists are slower in F# as a consequence. > On a rather old box, ocaml runs that in 0.28s (vs. Ruby's 0.61s with > #each, > #1.8s with inject), and an imperative expansion (with for and a ref) in > #0.17s, > so the ratios are > fold_left/inject 6.4X > imperative 3.6X > HOFs in Ruby are often more expensive than they would be in OCaml because > method and especially block (anonymous function) calls are quite slow. > > However, on Ruby 1.9, still under development and expected to be released > by xmas 2007: > > $ ruby19 -v bm.rb > ruby 1.9.0 (2007-02-07 patchlevel 0) [i686-linux] > user system total real > each 0.230000 0.000000 0.230000 ( 0.228493) > inject 0.310000 0.000000 0.310000 ( 0.313735) > > making it comparable to OCaml's bytecode, which is hardly surprising since > they are both stack machines with threaded code/computed gotos. Yes. Is there a native-code compiler for Ruby in the works? Does the .NET implementation give much better performance? -- Dr Jon D Harrop, Flying Frog Consultancy OCaml for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/?usenet