#-- # This file is part of the Prelude library that provides tools to # enable Haskell style functional programming in Ruby. # # http://prelude.rubyforge.org # # Copyright (C) 2006 APP Design, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #++ # # $Id: prelude.rb 2 2006-08-25 00:11:17Z prelude $ $:.unshift(File.dirname(__FILE__)) require 'prelude/list' require 'prelude/tuple' require 'prelude/monad' module Prelude VERSION='0.0.1' end # Prelude class Symbol # See http://blogs.pragprog.com/cgi-bin/pragdave.cgi/Tech/Ruby/ToProc.rdoc for the detailed discussion def to_proc proc { |obj, *args| obj.send(self, *args) } end def curry(one, *args) proc { |*args| self.to_proc.call(one, *args) } end end # Symbol class Proc # See also http://rubyforge.org/projects/rubymurray/ for an # elaborate port of Perl's Sub::Curry library def curry(one, *args) proc{ |*args| self.call(one, *args)} end # This is will serve as an infix composition operator def <<(*args) if (1==args.length) && args[0].is_a?(Proc) proc {|*a| self.call(args[0].call(*a)) } else self.call(*args.flatten) end end end # Proc