From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA22656; Tue, 7 Aug 2001 11:16:06 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA22720 for ; Tue, 7 Aug 2001 11:16:05 +0200 (MET DST) Received: from drazi.auctionwatch.ro (nat-192.auctionwatch.ro [193.226.187.192]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f779G4928674 for ; Tue, 7 Aug 2001 11:16:04 +0200 (MET DST) Received: from auctionwatch.ro (IDENT:costins@scostin.auctionwatch.ro [172.16.0.87]) by drazi.auctionwatch.ro (8.9.3/8.9.3) with ESMTP id MAA17559 for ; Tue, 7 Aug 2001 12:16:03 +0300 Message-ID: <3B6FB7E3.8FD8903@auctionwatch.ro> Date: Tue, 07 Aug 2001 12:41:55 +0300 From: Costin Stefan Organization: AuctionWatch Romania X-Mailer: Mozilla 4.72 [en] (X11; U; Linux 2.2.14-5.0 i686) X-Accept-Language: en MIME-Version: 1.0 To: caml-list@inria.fr Subject: [Caml-list] list in functional style Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Excuse my ignorance, I have the following problem : want to define lists but using only functions : But the type inference make problems, and I don't get it. Here is the code : let cons x l=fun a-> a x l;; let hd l= let _hd=fun x _->x in l _hd;; let tl l= let _tl=fun _ l->l in l _tl;; Load into the toplevel system give the followings signatures : val cons : 'a -> 'b -> ('a -> 'b -> 'c) -> 'c = val hd : (('a -> 'b -> 'a) -> 'c) -> 'c = val tl : (('a -> 'b -> 'b) -> 'c) -> 'c = Now : # let l=cons 1 2;; val l : (int -> int -> '_a) -> '_a = # hd l;; - : int = 1 # tl l;; - : int = 2 # l;; - : (int -> int -> int) -> int = This type inference mess up all the construction :-( It infers that the type of hd may be the same as the type of tl. But this works only for this example. A usual list is like : # let l=cons 1 (cons 2 3);; val l : (int -> ((int -> int -> '_a) -> '_a) -> '_b) -> '_b = # hd l;; - : int = 1 Now l has the following type : # l;; - : (int -> ((int -> int -> '_a) -> '_a) -> int) -> int = So the tl will miserably fail : # tl l;; This expression has type (int -> ((int -> int -> 'a) -> 'a) -> int) -> int but is here used with type (int -> ((int -> int -> 'a) -> 'a) -> (int -> int -> 'a) -> 'a) -> 'b So why the type of the result of hd may be the same of the type of the result of tl ! Why the type of the result of a cons isn't a polymorphic function ? Any suggestion ? ------------------- 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