M lib/dhall/as_dhall.rb => lib/dhall/as_dhall.rb +6 -0
@@ 220,5 220,11 @@ module Dhall
)
end
end
+
+ refine ::Proc do
+ def as_dhall
+ FunctionProxy.new(self)
+ end
+ end
end
end
M lib/dhall/ast.rb => lib/dhall/ast.rb +22 -0
@@ 188,6 188,28 @@ module Dhall
end
end
+ class FunctionProxy < Function
+ def initialize(callable, curry: true)
+ @callable = if !curry
+ callable
+ elsif callable.respond_to?(:curry)
+ callable.curry
+ elsif callable.respond_to?(:to_proc)
+ callable.to_proc.curry
+ else
+ callable.method(:call).to_proc.curry
+ end
+ end
+
+ def call(*args, &block)
+ @callable.call(*args.map { |arg| arg&.as_dhall }, &block).as_dhall
+ end
+
+ def as_json
+ raise "Cannot serialize #{self}"
+ end
+ end
+
class Bool < Expression
include(ValueSemantics.for_attributes do
value Bool()
M lib/dhall/normalize.rb => lib/dhall/normalize.rb +11 -2
@@ 120,9 120,18 @@ module Dhall
end
end
- class Forall; end
+ class FunctionProxy
+ def shift(*)
+ self
+ end
+
+ def substitute(*)
+ raise "Cannot substitute #{self}"
+ end
- class Bool
+ def normalize
+ self
+ end
end
class Variable