Module: Haskell

Defined in:
lib/haskell.rb,
lib/haskell/version.rb,
ext/haskell/haskell.c

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.assert_arg_type(meth, args, klasses) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/haskell.rb', line 31

def assert_arg_type(meth, args, klasses)
  args.each_with_index do |arg, i|
    if wrong_type?(arg, klasses[i])
      raise ArgumentError, "Wrong type of argument, type of #{arg.inspect} should be #{klasses[i]}"
    end
  end
end

.assert_trn_type(meth, rtn, klass) ⇒ Object



39
40
41
42
43
# File 'lib/haskell.rb', line 39

def assert_trn_type(meth, rtn, klass)
  if wrong_type?(rtn, klass)
    raise TypeError, "Expected #{meth} to return #{klass} but got #{rtn.inspect} instead"
  end
end

.wrong_type?(obj, klass) ⇒ Boolean

Returns:



45
46
47
# File 'lib/haskell.rb', line 45

def wrong_type?(obj, klass)
  !(obj.is_a?(klass) || klass == Any)
end