#-- # 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 library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This library 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 # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #++ # # $Id: prelude.rb 34 2007-10-23 21:38:09Z prelude $ $:.unshift(File.dirname(__FILE__)) require 'prelude/util' require 'prelude/array_list' # WARNING: Somehow rdoc breaks on multiline constants and does not # generate a full list of constants below. Please see the sources for # all defined functions and functors, there are plenty and they are all # defined as constants. # # The implementation of frequently used functors is based on the code # from Ben Yu's rparsec library, see http://rubyforge.org/frs/?group_id=2326 module Prelude VERSION = '0.0.5' LIST_IMPLEMENTATION = Prelude::ArrayList # Thrown if an illegal operation is performed on an empty list. class EmptyListError < RuntimeError; end # Thrown if a needed method is not available class MissingMethodError < RuntimeError; end # Thrown if no function was supplied class MissingFunctionError < RuntimeError; end # Thrown if something wrong with the functions' arguments class ArgumentError < RuntimeError; end # Thrown if bad list is encountered class ImproperListError < RuntimeError; end # A helper method to create an empty list of a given list type. Has to be a proper list. def Prelude.new_list(list=nil) res = LIST_IMPLEMENTATION.new(list) #p "new_list #{res.inspect}" raise ImproperListError unless res.kind_of?(Prelude::ProperList) res end # A helper method to generate a new lambda that uses native implementation if available def Prelude.use_native(meth) list = Prelude.new_list if list.kind_of?(Prelude::ProperList) and list.respond_to?(meth) Lambda.new { |l, *args| l.method(meth)[*args] } else nil end end end # Prelude require 'prelude/lambda' require 'prelude/functors' require 'prelude/functions' require 'prelude/monad'