@@ 1599,6 1599,19 @@ module Dhall
body Expression
end)
+ def lets
+ [let]
+ end
+
+ def flatten
+ flattened = body.is_a?(LetIn) ? body.flatten : body
+ if flattened.is_a?(LetIn) || flattened.is_a?(LetBlock)
+ LetBlock.for(lets: [let] + flattened.lets, body: flattened.body)
+ else
+ self
+ end
+ end
+
def desugar
Application.new(
function: Function.new(
@@ 1636,6 1649,10 @@ module Dhall
end
end
+ def flatten
+ unflatten.flatten
+ end
+
def unflatten
lets.reverse.reduce(body) do |inside, let|
letin = LetIn.new(let: let, body: inside)