Re: Design Patterns and Functional programming



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
.



Relevant Pages

  • Re: Function minimization and random numbers
    ... minor point, but surely the CLR spec defines the type system, not the ... it doesn't actually impose anything on your type system. ... You look at a member invocation: ... be second-class closures because you cannot manipulate all functions in the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Theory X.
    ... Axiom schema of Comprehension: for every formula Q in which x is ... I only want to clarify the idea of maximal element. ... In this theory a set of type i should have a member of type j ...
    (sci.logic)
  • Re: Function minimization and random numbers
    ... Well, .NET's type system makes the distinction, allowing conversions ... Groovy supports overloaded method groups as closures, ... Consider a language that support integers but imposes a compile time ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Design Patterns and Functional programming
    ... If you mean a programming style heavily relying on closures, then yes, ... This is why OOP can be integrated into functional languages. ... Yet a consistent type system would be able to describe either. ...
    (comp.object)
  • Re: Function minimization and random numbers
    ... Well, .NET's type system makes the distinction, allowing conversions ... lacks closures. ... design but it culminated in F# rather than delegates. ... Are you claiming that the C# support for closures is useless? ...
    (microsoft.public.dotnet.languages.csharp)