>
>>> Chung-chieh Shan wrote:
>>>
>>>
>>>> Any tips on how (and perhaps how not) to teach functors?
>>>>
>
>
Here's a way of motivating functors that I found useful when trying to
understand them.
In some languages, eg scheme, we can write something like:
(define (solve) (oracle))
(define (oracle) (display "this is the oracle speaking.") (newline))
where solve in defined before its component, oracle. We only get an
error if we try to call solve before
oracle has been defined; otherwise the compiler is happy. But in ocaml
we can't even get that far, because the compiler
needs to know what oracle is before it can compile solve.
This leads to the problem of having to know all of the components of a
thing before we can define it.
But this can lead to inflexibility, because we may wish to describe some
top-level behavior
before getting into the particulars. What we can do is to describe the
parts we need as a signature.
The signature is input to a functor. We can then refer to the missing
parts through the signature. A further
benefit is that the definition of oracle is left to an awaited moment of
inspiration
-- eliot