[Nix-dev] Typing nix − funding campaign
Théophane Hufschmitt
rg_nixos at regnat.ovh
Thu Mar 30 09:52:24 CEST 2017
Wed 29 Mar 17 − 19:45, Danylo Hlynskyi(abcz2.uprola at 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.science.uu.nl/pipermail/nix-dev/attachments/20170330/fd3416bd/attachment.sig>
More information about the nix-dev
mailing list