English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Immediate recursive functions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-02-17 (18:20)
From: Marcin 'Qrczak' Kowalczyk <qrczak@k...>
Subject: Re: [Caml-list] Immediate recursive functions
Alex Baretta <alex@barettadeit.com> writes:

> I sometimes feel the need for a mu operator. I'm thinking of something
> like the following:
>
> # (rec f x -> if x <= 0 then 1 else x * (f (pred x))) 5
> - : int = 120
>
> as opposed to
>
> (let rec f x = if x <= 0 then 1 else x * (f (pred x)) in f) 5
> - : int = 120

Here it is immediately applied to arguments. For such cases my
language Kogut provides a syntax:

   loop 5 [
      x {if (x <= 0) {1} else {x * again (x - 1)}}
   ]

or with pattern matching:

   loop 5 [
      (<= 0) {1}
      x      {x * again (x - 1)}
   ]

This is related to 'case' (OCaml's 'match') like in Scheme "named let"
is related to ordinary 'let', except that the name 'again' is implicit.
There can be more arguments than one.

-- 
   __("<         Marcin Kowalczyk
   \__/       qrczak@knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/