[clean-list] list: atom?

RT Happe rthappe@mathematik.uni-freiburg.de
Thu, 21 Nov 2002 20:29:48 +0100 (CET)


> hello, I am new to this list, and also to Clean.....a question here: are
> there any functions like atom? or pair?  (like Scheme) to apply on a
> element of a list??

In Clean, (most) values don't carry type information with them as they do
in Scheme.  Typically, you will try to make do with the static type system
(described in the language report).  If you want to use a heterogenous
list, (0) you should ask yourself why.  Isn't there a more appropriate
algebraic data type?
      (1) you may create a container for the various kinds of elements and
homogenise the list, as in the dummyish example in the PS.
      (2) you may consider existential types, a somewhat advanced topic.
      (3) you may look into Clean 2's ``Dynamics'', but try the other
options first.

(You cannot define union types such as  atom:: Int | Char | ...)

rthappe

PS (nonsense):

module krims

import StdEnv

::Krims = Foo Int | Bar String | Baz [Krims]

w:: Krims -> Int
w (Foo x) = x
w (Bar x) = 1
w (Baz krimses) = length krimses

Start
  = w (Baz [Foo 6, Baz [], Bar "gnoe", Foo 1])