* [Caml-list] Invalid_argument("equal: abstract value")?
@ 2003-12-31 21:55 Tom Hawkins
2003-12-31 22:21 ` Tom Hawkins
0 siblings, 1 reply; 4+ messages in thread
From: Tom Hawkins @ 2003-12-31 21:55 UTC (permalink / raw)
To: caml-list
I haven't seen this error before. Can someone provide an explanation?
I've traced the problem down to a structural comparison (=) between
two large data structures. I know functional comparisons are a
no-no, but what is an "abstract value"?
The problem occurred when I added big integers (Big_int.big_int) to
the data structures under comparison. Suspecting big ints can't be
structurally compared, I tried the following, but the compiler
printed "false" as I would normally expect:
let a = Big_int.zero_big_int = Big_int.unit_big_int in
if a then print_string "true\n" else print_string "false\n";
Regards,
Tom
--
Tom Hawkins
Launchbird Design Systems, Inc.
952-200-3790
http://www.launchbird.com/
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Invalid_argument("equal: abstract value")?
2003-12-31 21:55 [Caml-list] Invalid_argument("equal: abstract value")? Tom Hawkins
@ 2003-12-31 22:21 ` Tom Hawkins
2004-01-01 3:10 ` skaller
0 siblings, 1 reply; 4+ messages in thread
From: Tom Hawkins @ 2003-12-31 22:21 UTC (permalink / raw)
To: caml-list
On Wednesday 31 December 2003 03:55 pm, Tom Hawkins wrote:
> I haven't seen this error before. Can someone provide an
> explanation?
>
> I've traced the problem down to a structural comparison (=) between
> two large data structures. I know functional comparisons are a
> no-no, but what is an "abstract value"?
>
> The problem occurred when I added big integers (Big_int.big_int) to
> the data structures under comparison. Suspecting big ints can't be
> structurally compared, I tried the following, but the compiler
> printed "false" as I would normally expect:
>
> let a = Big_int.zero_big_int = Big_int.unit_big_int in
> if a then print_string "true\n" else print_string "false\n";
Further suspecting Big_int.zero_big_int and Big_int.unit_big_int are
special cases, I tried:
Big_int.big_int_of_string "123" = Big_int.big_int_of_string "456"
Sure enough, 'Invalid_argument("equal: abstract value")'. So what's
the reasoning? (It's no big deal. I've already built a structural
comparison function for my problem as a work-around.)
-Tom
--
Tom Hawkins
Launchbird Design Systems, Inc.
952-200-3790
http://www.launchbird.com/
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Invalid_argument("equal: abstract value")?
2003-12-31 22:21 ` Tom Hawkins
@ 2004-01-01 3:10 ` skaller
2004-01-01 13:36 ` Damien Doligez
0 siblings, 1 reply; 4+ messages in thread
From: skaller @ 2004-01-01 3:10 UTC (permalink / raw)
To: Tom Hawkins; +Cc: caml-list
On Thu, 2004-01-01 at 09:21, Tom Hawkins wrote:
> On Wednesday 31 December 2003 03:55 pm, Tom Hawkins wrote:
> Big_int.big_int_of_string "123" = Big_int.big_int_of_string "456"
>
> Sure enough, 'Invalid_argument("equal: abstract value")'. So what's
> the reasoning?
A bigint is (well, at least contains) an abstract
primitive defined in C, not an algebraic data type.
The compiler doesn't know how to compare bigints.
This could be fixed the same way as for finalisers ..
provide a table of hooks for custom blocks.
Another candidate other than comparison is obviously
serialisation to extend Marshal for abstract/opaque types.
The problem is .. there's no limit to where you'd like
dynamic polymorphism.. you'd end up with Python not Ocaml.
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Invalid_argument("equal: abstract value")?
2004-01-01 3:10 ` skaller
@ 2004-01-01 13:36 ` Damien Doligez
0 siblings, 0 replies; 4+ messages in thread
From: Damien Doligez @ 2004-01-01 13:36 UTC (permalink / raw)
To: caml-list
On Thursday, January 1, 2004, at 04:10 AM, skaller wrote:
> A bigint is (well, at least contains) an abstract
> primitive defined in C, not an algebraic data type.
> The compiler doesn't know how to compare bigints.
This is only half the story.
> This could be fixed the same way as for finalisers ..
> provide a table of hooks for custom blocks.
> Another candidate other than comparison is obviously
> serialisation to extend Marshal for abstract/opaque types.
We already have a hook for comparison (and serialisation) in
custom blocks.
We don't want to use it for the type "nat" for the following
reason. "nat"s are used in "big_int"s and "ratio"s, which are
numeric types, but without canonical representation. For example,
the rational number 3 can be represented by:
{numerator = {sign = 1; abs_value = 3}
denominator = {sign = 1; abs_value = 1}
normalized = true}
or
{numerator = {sign = 1; abs_value = 6}
denominator = {sign = 1; abs_value = 2}
normalized = false}
If we use the hook for comparison on nat, and your program
tries to compare these two numbers, then the generic equality
function will return "not equal", which is the wrong result. We
think it's better to stop the program than to let the bug go
unnoticed.
-- Damien
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-01-01 13:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-31 21:55 [Caml-list] Invalid_argument("equal: abstract value")? Tom Hawkins
2003-12-31 22:21 ` Tom Hawkins
2004-01-01 3:10 ` skaller
2004-01-01 13:36 ` Damien Doligez
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox