Wed 29 Mar 17 − 19:45, Danylo Hlynskyi(abcz2.upr...@gmail.com) a écrit:
> But I'm too interested on how to specify type for `if` without introducing
> local lambda (e.g., will there be special syntax for this).

I'll add some type annotations of course (To be honnest, I doubt the
second example could ever be typed that precisely without any
annotation ; in the best case, it would probably have a type like
`(bool|int) -> (string|bool)`). I don't know what the actual syntax
would be (I hope I'll be able to make may case for introducing them
directly into the language, if not they will be included into comments).

But if your question was "what's the type of `if isInt x then x+1 else
!x`, then the answer is "it depends on the type of x in the context".
Depending on the type `τ` of x, it could have several types, like

- If `τ` is a subtype of `int`: `int`
- If `τ` is a subtype of `bool`: `bool`
- If `τ` is a subtype of `int|bool`: `int|bool`

(or even more precise: If `τ` is a subtype of `true`, then the `if`
can be given the type `false` because `!` has type
`(true -> false)&(false -> true)`)

-- 
Théophane Hufschmitt

Attachment: signature.asc
Description: PGP signature

_______________________________________________
nix-dev mailing list
nix-dev@lists.science.uu.nl
http://lists.science.uu.nl/mailman/listinfo/nix-dev

Reply via email to