
On Sat, Feb 09, 2002 at 12:01:02PM -0500, glasgow-haskell-users-request@haskell.org wrote:
I'd say that's because in the second case you also got to apply the (,), besides the (+)/(-) constructor during the transversing... Am I right?
opss... I meant to write: the (,) constructor besides the (+)/(-)... J.A.
I'd guess that it's not just that you have to apply the (,) constructor -- it also has to do with the fact that the tuples it's constructing here are boxed. -- Kirsten Chevalier * krc@cs.berkeley.edu * Often in error, never in doubt "When nothing remains of me, / Not a particle, / I shall sparkle in the footnote of an article." -- Daniel Aaron http://www.cs.berkeley.edu/~krc/

On Sunday 10 February 2002 18:48, Kirsten Chevalier wrote:
I'd guess that it's not just that you have to apply the (,) constructor -- it also has to do with the fact that the tuples it's constructing here are boxed.
could you elaborate a little more on that (boxed / unboxed) or provide a link on the subject? thanks J.A.

I don't know of a reference, but here's the basic idea: if you have a polymorphic type (like [a]), and it's instantiated to [Int] (or whatever), instead of storing in memory a standard linked list representation like [1,2] = 1:2:[] = [1 x] /--> [2 x] /--> Nil \---/ \---/ (which would be standard), it stores it as: [x x] /--> [x x] /--> Nil | \---/ | \---/ 1 2 So instaed of storing 1 and 2 in the list, it stores pointers to them. The reason it does this is so that it makes it easy to generate code for polymorhpic functions. (,) being boxed means that instead of storing a pair of element, you're storing a pair of pointers. That means you get worse performance because you have to chase more pointers. (at least that's my impression) - hal -- Hal Daume III "Computer science is no more about computers | hdaume@isi.edu than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume On Sun, 10 Feb 2002, Jorge Adriano wrote:
On Sunday 10 February 2002 18:48, Kirsten Chevalier wrote:
I'd guess that it's not just that you have to apply the (,) constructor -- it also has to do with the fact that the tuples it's constructing here are boxed.
could you elaborate a little more on that (boxed / unboxed) or provide a link on the subject?
thanks J.A. _______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

On Monday 11 February 2002 02:10, Hal Daume III wrote:
So instaed of storing 1 and 2 in the list, it stores pointers to them. The reason it does this is so that it makes it easy to generate code for polymorhpic functions. (,) being boxed means that instead of storing a pair of element, you're storing a pair of pointers. That means you get worse performance because you have to chase more pointers.
(at least that's my impression) Thanks, I knew the concept but not the name.
On Sunday 10 February 2002 18:48, Kirsten Chevalier wrote:
I'd guess that it's not just that you have to apply the (,) constructor -- it also has to do with the fact that the tuples it's constructing here are boxed. This brings another question to my mind, isn't it toupling a standard technique used in functional programming? I'm pretty sure I've seen it focused in some papers/text books. I for one would not expect that folding the list twice would be more efficient...
J.A.

Hal Daume III
So instaed of storing 1 and 2 in the list, it stores pointers to them. The reason it does this is so that it makes it easy to generate code for polymorhpic functions. (,) being boxed means that instead of storing a pair of element, you're storing a pair of pointers. That means you get worse performance because you have to chase more pointers.
Not quite: (,) being boxed means that the *tuple* is boxed, not that
its elements are boxed. Only boxed things can live on the heap.
Unboxed things cannot live on the heap, but can live in registers.
Ints are represented in GHC by the data type
data Int = I# Int#
where Int# is the type of *unboxed integers*. The I# constructor forms
the box that allows the Int# to live on the heap (since it can't live
on the heap on its own, only in a register):
+----+----+
| I# | 42 | is a heap object of (boxed) type Int.
+----+----+
Now the representation you want for lists is something like:
data MyList = Nil | Cons Int# MyList
which would have elements like this:
+------+---+---+ +------+---+---+ +------+---+---+ +-----+
| Cons | 1 | *--->| Cons | 1 | *--->| Cons | 1 | *--->| Nil |
+------+---+---+ +------+---+---+ +------+---+---+ +-----+
like you want.
You can't have an unboxed list, since things of unbounded size must
live on the heap and unboxed lists can't live on the heap.
I hope this helps, and isn't just more confusing.
In summary: (,) being boxed means that *it lives on the heap*, in its
own box. If you want the *elements* to be stored directly in their
cells, without a box, then you should make the elements have unboxed
type, not the container.
HTH.
--KW 8-)
--
Keith Wansbrough
participants (4)
-
Hal Daume III
-
Jorge Adriano
-
Keith Wansbrough
-
Kirsten Chevalier