class Dhall::Function
Public Class Methods
decode(var_or_type, type_or_body, body_or_nil=nil)
click to toggle source
# File lib/dhall/binary.rb, line 63 def self.decode(var_or_type, type_or_body, body_or_nil=nil) type_or_body = Dhall.decode(type_or_body) if body_or_nil.nil? of_arguments(Dhall.decode(var_or_type), body: type_or_body) else raise ArgumentError, "explicit var named _" if var_or_type == "_" body_or_nil = Dhall.decode(body_or_nil) new(var: var_or_type, type: type_or_body, body: body_or_nil) end end
disable_alpha_normalization!()
click to toggle source
# File lib/dhall/normalize.rb, line 87 def self.disable_alpha_normalization! @@alpha_normalization = false end
enable_alpha_normalization!()
click to toggle source
# File lib/dhall/normalize.rb, line 91 def self.enable_alpha_normalization! @@alpha_normalization = true end
of_arguments(*types, body:)
click to toggle source
# File lib/dhall/ast.rb, line 160 def self.of_arguments(*types, body:) types.reverse.reduce(body) do |inner, type| new( var: "_", type: type, body: inner ) end end
Public Instance Methods
<<(other)
click to toggle source
# File lib/dhall/ast.rb, line 184 def <<(other) FunctionProxy.new( ->(*args, &block) { call(other.call(*args, &block)) }, curry: false ) end
>>(other)
click to toggle source
# File lib/dhall/ast.rb, line 191 def >>(other) FunctionProxy.new( ->(*args, &block) { other.call(call(*args, &block)) }, curry: false ) end
as_json()
click to toggle source
# File lib/dhall/ast.rb, line 206 def as_json if var == "_" [1, type.as_json, body.as_json] else [1, var, type.as_json, body.as_json] end end
binding()
click to toggle source
# File lib/dhall/ast.rb, line 198 def binding to_proc.binding end
call(*args, &block)
click to toggle source
Calls superclass method
Dhall::Expression#call
# File lib/dhall/ast.rb, line 170 def call(*args, &block) args += [block] if block args.map! { |arg| arg&.as_dhall } return super if args.length > 1 body.substitute( Variable.new(name: var), args.first.shift(1, var, 0) ).shift(-1, var, 0).normalize end
curry()
click to toggle source
# File lib/dhall/ast.rb, line 202 def curry self end
normalize()
click to toggle source
Calls superclass method
Dhall::Expression#normalize
# File lib/dhall/normalize.rb, line 114 def normalize return super unless alpha_normalize? with( var: "_", type: type&.normalize, body: body .shift(1, "_", 0) .substitute(Variable[var], Variable["_"]) .shift(-1, var, 0) .normalize ) end
shift(amount, name, min_index)
click to toggle source
Calls superclass method
Dhall::Expression#shift
# File lib/dhall/normalize.rb, line 95 def shift(amount, name, min_index) return super unless var == name with( type: type.shift(amount, name, min_index), body: body.shift(amount, name, min_index + 1) ) end
substitute(svar, with_expr)
click to toggle source
# File lib/dhall/normalize.rb, line 104 def substitute(svar, with_expr) with( type: type&.substitute(svar, with_expr), body: body.substitute( var == svar.name ? svar.with(index: svar.index + 1) : svar, with_expr.shift(1, var, 0) ) ) end
Protected Instance Methods
alpha_normalize?()
click to toggle source
# File lib/dhall/normalize.rb, line 129 def alpha_normalize? var != "_" && @@alpha_normalization end