I have a question to make the environment of if true then x else y not closed, closed but not well typed, and closed and well typed. How can I do this in OCaml?
All I know is that not closed means that there is a variable that is not bound. So x and y will not be bound in this case. Additionally, well typed means that the expression satisfies the grammar.
Im not sure how to apply that here however and I only have very wrong answers. Maybe something like:
if (x:int, y:int) then (true) else (false)
if (x:int, y: int) then (x: bool) else (y: bool)
if (true) then (x: int) else (y: int)
for the 3 conditional respectively
You're asking us to do your homework, but we're not taking the class! So we don't have much to go on.
The basic way to bind a variable in OCaml is with
let. So if you don't havelet x = ...thenxis unbound (other things being equal). If you do have something likelet x = 4 in ...thenxis bound.Update
Note that
(x : int)does not bindx, i.e., it doesn't associate it with a value. It just specifies (or ascribes) the type ofx.