--nextPart4372678.0LJtYQEeh0 Content-Type: text/plain; charset so-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Sunday 02 March 2008, Yusuke ENDOH wrote: > By the way, I'm curious to know what purpose do people use > Proc#curry for. I know you know what currying is for; I'm just throwing some thoughts out there. It sounds as if you're looking for practical examples for documentation. A common use for me in FP has been extensible, custom printers. For example, logger = proc { |level, exception, source, message| if level_of( level ) >= LogLevel::current_level case level when :debug STDERR.puts "DEBUG [#{source}]: #{message}" when :error STDERR.puts "ERROR [#{source}]: #{message}" STDERR.puts exception.backtrace when :info STDERR.puts message end } @debug = logger.curry.call(:debug).call(nil) @error = logger.curry.call(:error) @info = logger.curry.call(:info).call(nil).call(nil) ... def some_method() ... @debug.call( "some_method", "Enter" ) ... begin ... rescue @error.call( "some_method", !$, "It didn't work" ) end ... end Another very common use for currying is for pre-creating commonly used functions that are simple compositions of other functions such as #map and #inject. Even in FP, the choice between using currying and using argument tuples is largely one of which is going to be more convenient for the common use of the function -- although there's an belief that, commonly, currying is a better choice. The logger example above could also be written: def logger( level, exception, source, message ) ... end def debug( source, message ) logger( :debug, nil, source, message ) end and so on. -- ### SER ### Deutsch|Esperanto|Francaise|Linux|XML|Java|Ruby|Haskell|Aikido|Iaido ### http://www.ser1.net, http://www.ser1.net/Security/ser_public.gpg ### Jabber: seanerussell / gmail.com (OTR enabled) --nextPart4372678.0LJtYQEeh0 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQBHzAm/P0KxygnleI8RAnXZAKC/chrmExLfA7orqhEnFyt+a+r6eACdECwD TwvM2K41CY1ZJ07lITJUC8kù×g -----END PGP SIGNATURE----- --nextPart4372678.0LJtYQEeh0--