Re: Glasgow haskell vs. Lispworks
- From: development-2006-8ecbb5cc8aREMOVETHIS@xxxxxxxxxxxxxxxxxxxxx (Markus E.L. 2)
- Date: Thu, 16 Aug 2007 08:37:45 +0200
Jon Harrop wrote:
Markus E.L. 2 wrote:
Jon Harrop wrote:
Paul Rubin wrote:
Well, these like identity and equality are only meaningful within the
language semantics. In a pure FPL, two expressions have the same
identity if the denote the same value. Memory locations may be part
of the implementation but aren't in the language semantics.
Does that not have a grave cost in terms of memory consumption?
Why do you suspect so? Because one cannot mutate structures?
No, I use physical equality (identity) even in purely functional settings.
I do not understand you reply. The grave cost in the pure case is
probably not memory consumption, but that any comparison has actually
to be recursive and can't take the shortcut of physical equality. But
I think that perhaps the compiler is smart enough to know when it can
take the shortcut.
Or is there any other reason? Personally I see it as a further step
down the same path that started with abandoning malloc/free style
memory management and introducing garbage collection. It leaves all
decisions on actual copying to the compiler or run time environment
and actually buys them a lot of freedom as far as caching is
concerned (only think SMP and what it implies if there are no
mutable memory locations).
I use physical equality in OCaml as an optimization, to test for unaltered
results.
Ah, I understand. This is a very special case, though: It won't work
with mutable structures, would it?
For example, an 'a -> 'a map that avoids all allocation is no rewrites are
done:
let id_map f a =
if a = [||] then a else
let b = ref a in
try
for i = 0 to length a - 1 do
let e = f a.(i) in
if e != a.(i) then begin
b := Array.copy a;
(!b).(i) <- e;
raise (Start (i+1))
end
done;
a
with Start start ->
let b = !b in
for i = start to length a - 1 do
let e = f a.(i) in
if e != a.(i) then b.(i) <- e;
done;
b
or a sort that can return the input list without copying it:
# let rec sort = function
| [] -> []
| h1::t as list -> match sort t with
| h2::t when h1>h2 -> h2::sort(h1::t)
| t' -> if t==t' then list else h1::t';;
val sort : 'a list -> 'a list = <fun>
When handling symbols, I hash cons strings and compare them for physical
equality knowing that it represents semantic equality.
This is indeed a good idea.
I appreciate that this can all be done without using physical equality, but
can that be done efficiently (particularly without allocation)?
The only hope one can entertain here is that the compiler is smart
enough. But probably you're right: This is one of the effects that
make Haskell slower.
Regards -- Markus
.
- Follow-Ups:
- Re: Glasgow haskell vs. Lispworks
- From: Neelakantan Krishnaswami
- Re: Glasgow haskell vs. Lispworks
- From: Jon Harrop
- Re: Glasgow haskell vs. Lispworks
- References:
- Glasgow haskell vs. Lispworks
- From: Rene de Visser
- Re: Glasgow haskell vs. Lispworks
- From: Rainer Joswig
- Re: Glasgow haskell vs. Lispworks
- From: Stuart Cook
- Re: Glasgow haskell vs. Lispworks
- From: Rainer Joswig
- Re: Glasgow haskell vs. Lispworks
- From: rossberg
- Re: Glasgow haskell vs. Lispworks
- From: Rainer Joswig
- Re: Glasgow haskell vs. Lispworks
- From: Joachim Durchholz
- Re: Glasgow haskell vs. Lispworks
- From: Jon Harrop
- Re: Glasgow haskell vs. Lispworks
- From: Paul Rubin
- Re: Glasgow haskell vs. Lispworks
- From: Jon Harrop
- Re: Glasgow haskell vs. Lispworks
- From: Markus E.L. 2
- Re: Glasgow haskell vs. Lispworks
- From: Jon Harrop
- Glasgow haskell vs. Lispworks
- Prev by Date: Re: category theory: brouwer's fixed point theorem
- Next by Date: Re: Glasgow haskell vs. Lispworks
- Previous by thread: Re: Glasgow haskell vs. Lispworks
- Next by thread: Re: Glasgow haskell vs. Lispworks
- Index(es):
Relevant Pages
|