Singly-linked list/Element definition: Difference between revisions

Haskell solution
(Add itertion support to node)
(Haskell solution)
Line 112:
 
Due to Forth's lack of typechecking, 'b' in the above examples does not have to be an actual cell, but can instead be the head pointer of the list.
 
=={{header|Haskell}}==
 
This task is not idiomatic for Haskell. Usually, all data
in pure functional programming is immutable, and deconstructed through [[Pattern Matching]]. The Prelude already contains a parametrically polymorphic list type that can take any data member type, including numeric values. These lists are then used very frequently. Because of this, lists have additional special syntactic sugar.
 
An equivalent declaration for such a list type without the special syntax would look like this:
 
data List a = Nil | Cons a (List a)
 
A declaration like the one required in the task, with an integer as element type and a mutable link, would be
 
data IntList s = Nil | Cons Integer (STRef s (IntList s))
 
but that would be really awkward to use.
 
==[[Perl]]==
Anonymous user