Pointers in Haskell??

Ch. A. Herrmann herrmann@infosun.fmi.uni-passau.de
Fri, 7 Dec 2001 17:04:03 +0100


Hello,

>>>>> "Bryan" == Bryan Hayes <(Hayes Technologies)" <bryan.hayes@hayestechnologies.com>> writes:

    Bryan> My question is:
    Bryan> Does Haskell principally not need pointers (i.e. in case of 2
    Bryan> data structures needing to reference an other very large data
    Bryan> structure) or is this a design flaw or have a overlooked
    Bryan> something?

if you hold two variables to a data structure, the structure is
represented only once. This is established by a graph structure of data,
instead of just a tree structure. If you modify one copy, only the
reachable parts between the handle (variable) and the position where the
change has been made, are copied. All common substructures that are not
affected by the change remain shared. Memory is allocated and released
automatically.

However, if you prefer a more state-based way of programming, you can
deal with pointers in a so-called "monad", but if you need pointers for
no other reason than efficiency, you should first try to use efficient
programming techniques and data structures in Haskell. Programming in
Haskell is completely different from imperative programming but it'll
be worth it from the perspective of programming productivity.
Just finding a way to fit imperative style in the syntax of Haskell
will not give you the benefit you may expect from Haskell. 
Have a look at the book by Simon Thompson: "Haskell: The Craft of
Functional Programming". It explains the methodology of programming
in Haskell very well.

Cheers
-- 
 Christoph Herrmann