Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this OCaml signature possible?

Tags:

ocaml

Is an OCaml function of signature:

'a -> 'b

possible?

I think it might be possible, however, I would not know the underlying logic behind the answer, so having it explained would be great :)

EDIT: It cannot recursively loop forever

like image 997
pkiller162 Avatar asked Mar 18 '23 19:03

pkiller162


1 Answers

There are several "legitimate" answers. One is to loop forever, which you ruled out:

let rec f x = f x

Another is to diverge by raising an exception or terminating the program:

let f x = exit 0

let f x = assert false

let f x = failwith "die"
like image 78
gsg Avatar answered Mar 23 '23 23:03

gsg