Who's minister of propaganda this week?

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Mon Mar 19 04:01:22 EST 2001


Mon, 19 Mar 2001 07:53:13 +0100, Alex Martelli <aleaxit at yahoo.com> pisze:

> But if the container has a list of typed references, they have to
> be typed to SOMETHING (which can be either a leaf of any
> kind or another nested container).

In Haskell's and Clean's syntax:
    type Container a = [Something a]
    data Something a = Leaf a | Nested (Container a)

In OCaml's syntax:
    type 'a container = 'a something list
    and  'a something = Leaf of 'a | Nested of 'a container

> The classic Design Pattern uses just such a 'certain interface'
> as I just described.

Design patterns designed for C++ and Java are not applicable to
languages which use algebraic types and don't use subtyping. C++
and Java don't have a convenient way to express "either this or that
or these" (wrapping each case in a class is not convenient enough).
OTOH Haskell and OCaml don't work by implicit coercion of elements
to a common supertype.

Note that in these languages it's meaningless to mix all types of
objects together in a container. If they are unrelated, you can't
apply any operation to an unspecified member of them.

Tell what do you really want to archieve. The whole thing looks like
a poor fit to the style of these languages. You don't want to have a
net of containers of everything. For example if they are registered
to let somebody do something with them, you would rather register
"do something with them" actions instead of objects themselves.
Objects are rarely mutable so even this looks very suspicious.

> So what (single) type do you make your container's references?

"Something a", where a is the type of objects in leafs.

-- 
 __("<  Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTĘPCZA
QRCZAK



More information about the Python-list mailing list