Version française
Home     About     Download     Resources     Contact us    
Browse thread
Which syntax to teach ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Edgar Friendly <thelema314@g...>
Subject: Re: [Caml-list] Re: Which syntax to teach ?
Brian Hurt wrote:
> Chung-chieh Shan wrote:
> 
>> Any tips on how (and perhaps how not) to teach functors?  I'm using a
>> Haskell equivalent of functors (namely constructor classes) in an AI
>> class (!) and they seem to be mysterious.  It didn't seem to work to
>> explain the Java/C# code that I would like to write (but can't, because
>> these languages have no interface _on_ generics (as opposed to generic
>> interfaces)).
>>
> Not sure how well this would work, but my idea would be to map the
> concepts onto the standard code concepts.
> 
<SNIP>
> and so on.  Functors, then, are a way to manipulate modules, in the same
> way that functions are a way to manipulate values.
> 
> Brian
> 
> 
That's more or less how I think of them.  Functions can be written with
"holes" to fill in with their parameters.  In the same way, modules can
have these "empty puzzle-spaces" that, once you fit the right kind of
puzzle piece (module of the right type), you can plug it in (apply the
functor) to get a full module.  Sort of like how you can do partial
application with functions to get exactly the function you want.  i.e.

let sum_int = fold_left (+) 0

Functors/generics fill a much bigger hole in other languages, because in
Ocaml it's possible to pass each piece of the parameter module to each
of the contained functional values, and because of polymorphic
functions, we don't need functors to abstract over types as much.  I
guess you could teach it like extra arguments to every function in your
functor, I don't know if that'd help your students.

E.