Class: Dhall::TypeChecker::If::AnnotatedIf

Inherits:
Object
  • Object
show all
Defined in:
lib/dhall/typecheck.rb

Instance Method Summary collapse

Constructor Details

#initialize(expr, apred, athen, aelse, context:) ⇒ AnnotatedIf

Returns a new instance of AnnotatedIf.



177
178
179
180
181
182
183
184
185
186
# File 'lib/dhall/typecheck.rb', line 177

def initialize(expr, apred, athen, aelse, context:)
  TypeChecker.assert apred.type, Builtins[:Bool],
                     "If must have a predicate of type Bool"
  TypeChecker.assert_type athen.type, Builtins[:Type],
                          "If branches must have types of type Type",
                          context: context
  TypeChecker.assert aelse.type, athen.type,
                     "If branches have mismatched types"
  @expr = expr.with(predicate: apred, then: athen, else: aelse)
end

Instance Method Details

#annotationObject



188
189
190
191
192
193
# File 'lib/dhall/typecheck.rb', line 188

def annotation
  Dhall::TypeAnnotation.new(
    value: @expr,
    type:  @expr.then.type
  )
end