Dhall 具有返回类型的函数:
let f = \(b : Bool) -> Natural -- ok
它有if
表达式:
let f = \(b: Bool) -> if b == True then 1 else 0 -- ok
但是这两个功能不能一起使用:
-- Error: ❰if❱ branch is not a term
let f= \(b : Bool) -> if b == True then Natural else Integer
in 3
为什么?
起初我认为这是一个避免依赖类型的技巧,但似乎 Dhall 在使用联合时确实允许类型真正依赖于值。以下编译良好:
let MyBool = <T | F>
let myIf: MyBool -> Type = \(b: MyBool) ->
merge
{ T = Bool
, F = Natural
}
b
in 3
更新
dhall标准现在支持这样的 if 表达式,dhall-haskell也是如此,感谢@gabriel-gonzales