Pointers in Haskell??

Hamilton Richards ham@cs.utexas.edu
Fri, 7 Dec 2001 10:46:11 -0600


At 9:30 AM -0600 12/7/01, Bryan Hayes (Hayes Technologies) wrote:
> I am totally new to Haskell, so maybe this is a stupid question.
> Various languages have pointers (or references), for good reason.
> Haskell can at least partly do without them (they are only existing
> internally somehow).
> My question is: Does Haskell principally not need pointers (i.e. in case
> of 2 data structures needing to reference an other very
> large data structure) or is this a design flaw or have a overlooked
>something?

In Haskell, you can arrange for a large data structure to be shared by
giving it a name, and then using the name wherever you'd use a pointer in
some other language.

For example, in

>  t = [0..]  -- could be quite large

>  b = 3 : t

>  c = 5 : t

the lists b and c share list t. Of course, these lists' implementations are
full of pointers, but there's never a need for them to appear explicitly in
Haskell programs.



------------------------------------------------------------------
Hamilton Richards, PhD           Department of Computer Sciences
Senior Lecturer                  Mail Code C0500
512-471-9525                     The University of Texas at Austin
Taylor Hall 5.138                Austin, Texas 78712-1188
ham@cs.utexas.edu                hrichrds@swbell.net
------------------------------------------------------------------