Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Recursive apply function
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-11-20 (10:45)
From: Ville-Pertti Keinonen <will@e...>
Subject: Re: [Caml-list] Recursive apply function
On Wed, Nov 19, 2003 at 08:54:08PM -0700, Peter Scott wrote:

> first element of the list. Unfortunately, I get this message when run: 
> "This expression has type 'a but is here used with type 'b -> 'a", 
> referring to the "(f arg)" part.

You can get your "apply" function to typecheck using the -rectypes option,
but it still doesn't do what you want; it only accepts functions that
return functions of the same (recursive) type.

Static typing prevents things like Lisp apply from being implemented
even for the limited case where arguments have the same type.  The type
of a partially applied function is almost never identical to the fully
applied function (except for the case of recursively typed functions that
return functions, such as your "apply").

Note that the -rectypes option is probably not something you want to use
unless you know that you need it.  An example is if you want to have a
state machine with functions representing states without resorting to
side-effects (f : event -> action * 'a as 'a).

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: