Ich lese in ein paar Tutorials, dass if a then b else c
für match a with true => b | false => c end
steht. Allerdings überprüft das erste sehr merkwürdig nicht den Typ a
, während letzteres natürlich sicherstellt, dass a
ein boolescher ist. Zum BeispielIn Coq, "wenn dann else" nicht booleschen ersten Argument erlaubt?
Coq < Check if nil then 1 else 2.
if nil then 1 else 2
: nat
where
?A : [ |- Type]
Coq < Check match nil with true => 1 | false => 2 end.
Toplevel input, characters 33-38:
> Check match nil with true => 1 | false => 2 end.
> ^^^^^
Error: Found a constructor of inductive type bool while
a constructor of list is expected.
Warum ist erlaubt if ... then ... else ...
erstes Argument nichts anderes als ein nicht-boolean zu sein? Gibt es eine Überlastung? (Locate "if".
gibt kein Ergebnis.)