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
[Caml-list] Problem with polymorphic letrec
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-09-19 (19:06)
From: Chris Quinn <cq@h...>
Subject: Re: [Caml-list] Problem with polymorphic letrec
> let rec polymul mul p q =
>    polymul (polymul mul) (fun _ -> p) (fun _ -> q)
> This expression does not typecheck in ocaml 2 because polymul is used
> polymorphically within its own body.
> I could not come up with any hack to code polymul without changing the
> representation of polynomials, which I'd rather not change for other
> reasons.
> Any suggestion on how to work around this problem?

You can certainly get the polymorphism back by abstracting out
the main functionality:

let rec polymul_aux f mul p q =
   f (f mul) (fun _ -> p) (fun _ -> q)

then :
let polymul = polymul_aux polymul_f

But maybe, ultimately, that will not be the problem!

I don't know if it has any relevance at all but the -rectypes
flag can sometimes help.
For instance:

type key
type 'data map = (key * ('data * 'data map)) list

This is a type which will not typecheck without -rectypes
but it is definitely meaningful and useful to me!

Chris Q.
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr