Version française
Home     About     Download     Resources     Contact us    
Browse thread
Converting variants with only constant constructors to integers
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: bluestorm <bluestorm.dylc@g...>
Subject: Re: [Caml-list] Converting variants with only constant constructors to integers
You're right : that's true in the "int" case and I hadn't considered it.

But if you use the same trick for ('a -> float) or other types you can get a
segfault :

# external floatify : 'a -> float = "%identity";;
external floatify : 'a -> float = "%identity"
# floatify 0;;
Segmentation fault

Also there are other problems with "intify" that may be worse than segfaults
: your application running with nonsense data and failing at an arbitrary
later point. Though ocaml doesn't fail (in the current implementation, it
would be unwise to assume that the GC/runtime will never check this), you
get strange behavior with those integers-wich-are-not-integers :

# let x = intify (1,2);;
val x : int = 70246988845964
# x * 1 - x;;
- : int = 1