From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 30E82BC6B for ; Tue, 30 Oct 2007 21:44:47 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAPM0J0fAXQInh2dsb2JhbACBWo0IAgEICimBEw X-IronPort-AV: E=Sophos;i="4.21,348,1188770400"; d="scan'208";a="5295917" Received: from concorde.inria.fr ([192.93.2.39]) by mail3-smtp-sop.national.inria.fr with ESMTP; 30 Oct 2007 21:44:46 +0100 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l9UKikJ2007668 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Tue, 30 Oct 2007 21:44:46 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAPM0J0fY/EBGnmdsb2JhbACBWo0IAgEBBwQGERiBEw X-IronPort-AV: E=Sophos;i="4.21,348,1188770400"; d="scan'208";a="5295916" Received: from mail.colba.net (HELO mailhost1.enter-net.com) ([216.252.64.70]) by mail3-smtp-sop.national.inria.fr with ESMTP; 30 Oct 2007 21:44:45 +0100 Received: (qmail-ldap/ctrl 20164 invoked from network); 30 Oct 2007 20:44:44 -0000 Received: from unknown (HELO [192.168.0.100]) ([216.252.78.17]) (envelope-sender ) by mailhost1.enter-net.com (qmail-ldap-1.03) with SMTP for ; 30 Oct 2007 20:44:44 -0000 Message-ID: <4727A611.3050507@generation.net> Date: Tue, 30 Oct 2007 16:45:53 -0500 From: Eliot Handelman Reply-To: eliot@generation.net User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 To: caml Cc: Chung-chieh Shan Subject: Re: [Caml-list] Re: Which syntax to teach ? References: <1193225773.3612.27.camel@Blefuscu> <471F7F7B.9040905@fmf.uni-lj.si> <666572260710241205x19edbd4ar840811b1d7a7315f@mail.gmail.com> <5i2kv4-hmj.ln1@mantle.rutgers.edu> <47275E10.4070705@janestcapital.com> <47276500.3050501@gmail.com> In-Reply-To: <47276500.3050501@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 472797BE.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; syntax:01 functors:01 motivating:01 functors:01 compiler:01 ocaml:01 compiler:01 functor:01 wrote:01 compile:01 caml-list:01 newline:02 define:02 define:02 defined:02 > >>> 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