Re: Design Patterns and Functional programming
- From: Jon Harrop <jon@xxxxxxxxxxxxxxxxx>
- Date: Wed, 18 Jul 2007 08:48:00 +0100
Dmitry A. Kazakov wrote:
Ada is functional, cool.
Ada doesn't support closures. For one thing, closures require a garbage
collector that can handle cyclic heaps.
Anyway, it is no problem to add downward closures
in any OOPL. The reason why C++ does not have it is because C didn't have
local functions.
Sure.
To me, this is just a question of automation. Does the compiler automate
closures?
What do you mean under automation?
Identify free variables, encapsulate them in a closure as the environment
and make invocation transparent (so closures look like normal functions).
The function is useless so the inference is inconsequential.
Is "useless" a language term? On the language level anything legal is
"useful" and compiles. On the software design level, you cannot say if a
function is useless without knowing its purpose. For my purpose [to
illustrate the point] it is very useful.
I think that point is in question...
Statically typed OOPL solve this
problem by introducing classes with manifested properties instead of
ad-hoc chimeras like Boolean | Rubbish. What do they have in common?
Are they not exactly equivalent?
Not a all. Classes are sets of types as defined by the programmer. It is
always statically determinable if a given type is a member of the class,
because inheritance is manifested. When inheritance is inferred, it
quickly becomes undecidable as my example shows. Therefore as a "paradigm"
a substantial types inference is a non-starter.
Too much inference is bad, yes. A decideable type system is good, maybe.
SML's type system is decideable and Haskell's is not. It makes little
difference in practice.
Is the above OCaml not a counter example? The result is a recurrence
relation.
It is not checkable.
OCaml just checked it.
Consider the function Recurse jumping over 0..9
indirection levels, where this number is chosen from the figures of
decimal representation of Pi. Now it is impossible to say whether
access x n Integer is a member of the class without evaluation of Pi.
q.e.d.
Yes.
and there is no way to statically ensure that dispatch never fails at
run-time.
What dispatch?
to a member function of the class.
In a dynamically typed language you get "message not understood." This is
a price to pay to be able to have ad-hoc classes. If you have a class
Boolean
| Rubbish, the choice is between to allow operation "not" on it and fail
| at
run-time when the actual is Rubbish or to try to determine if all members
of the class indeed have "not." As the latter is undecidable, here you
are.
Yes.
The solution is to choose your definition of "type" carefully. This is
exactly what the Hindley-Milner type system does.
--
Dr Jon D Harrop, Flying Frog Consultancy
OCaml for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists/?usenet
.
- Follow-Ups:
- Re: Design Patterns and Functional programming
- From: laynor@xxxxxxxxx
- Re: Design Patterns and Functional programming
- References:
- Design Patterns and Functional programming
- From: Jon Harrop
- Re: Design Patterns and Functional programming
- From: Dmitry A. Kazakov
- Re: Design Patterns and Functional programming
- From: Jon Harrop
- Re: Design Patterns and Functional programming
- From: Dmitry A. Kazakov
- Re: Design Patterns and Functional programming
- From: Jon Harrop
- Re: Design Patterns and Functional programming
- From: Dmitry A. Kazakov
- Re: Design Patterns and Functional programming
- From: Jon Harrop
- Re: Design Patterns and Functional programming
- From: Dmitry A. Kazakov
- Re: Design Patterns and Functional programming
- From: Jon Harrop
- Re: Design Patterns and Functional programming
- From: Dmitry A. Kazakov
- Re: Design Patterns and Functional programming
- From: Dmitry A. Kazakov
- Re: Design Patterns and Functional programming
- From: Jon Harrop
- Re: Design Patterns and Functional programming
- From: Dmitry A. Kazakov
- Re: Design Patterns and Functional programming
- From: Jon Harrop
- Re: Design Patterns and Functional programming
- From: Dmitry A. Kazakov
- Re: Design Patterns and Functional programming
- From: Jon Harrop
- Re: Design Patterns and Functional programming
- From: Dmitry A. Kazakov
- Re: Design Patterns and Functional programming
- From: Jon Harrop
- Re: Design Patterns and Functional programming
- From: Dmitry A. Kazakov
- Design Patterns and Functional programming
- Prev by Date: Re: Design Patterns and Functional programming
- Next by Date: Re: Design Patterns and Functional programming
- Previous by thread: Re: Design Patterns and Functional programming
- Next by thread: Re: Design Patterns and Functional programming
- Index(es):
Relevant Pages
|