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 XAA31323; Wed, 14 Feb 2001 23:24:12 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id XAA31319 for caml-list@pauillac.inria.fr; Wed, 14 Feb 2001 23:24:12 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id BAA11757 for ; Wed, 14 Feb 2001 01:29:33 +0100 (MET) Received: from singha.lip6.fr (singha.lip6.fr [132.227.204.18]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f1E0TWn17798 for ; Wed, 14 Feb 2001 01:29:32 +0100 (MET) Received: from localhost (gauthier@localhost) by singha.lip6.fr (8.9.3/8.9.3/SuSE Linux 8.9.3-0.1) with ESMTP id BAA13727; Wed, 14 Feb 2001 01:29:30 +0100 Date: Wed, 14 Feb 2001 01:29:30 +0100 (CET) From: Gauthier Nadji To: maulin shah cc: caml-list@inria.fr Subject: Re: [Caml-list] stack In-Reply-To: <20010213222451.40437.qmail@web12202.mail.yahoo.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk you define stack as a type and use it in "compile" as a variable. in the function "compile", the variable "stack" was not declared. you probably meant this: #let rec compile e = match e with Num x -> [PUSH x] |Opn (e1, o, e2) -> (compile e1) @ (compile e2) @ [match o with Add -> IADD | Sub -> ISUB];; -: val compile : exp -> ins list = # compile (Opn (Num 5., Add, Num 2.));; - : ins list = [PUSH 5.000000; PUSH 2.000000; IADD] the problem is that this function is O(n^3). this could be done in O(n), which is left as an exercise to the student :) hope this helps despite my obvious lack of pedagogy On Tue, 13 Feb 2001, maulin shah wrote: > hi all, > I am a student and learning ocaml. need help for one > problem of Unbound value stack > here is my code. > > type ins =PUSH of float| IADD|ISUB;; > type stack = ins list;; > type opn = Add|Sub;; > type exp = Num of float | Opn of exp* opn *exp;; > > let rec compile exp= > match exp with > Num x-> (PUSH x)::stack > |Opn e1,Add,e2 -> compile e2, > compile e1, > (IADD)::stack;; > > gives error : unbound value stack???? > could any one clrify this??? > > thanks > maulin > > > > > __________________________________________________ > Do You Yahoo!? > Get personalized email addresses from Yahoo! Mail - only $35 > a year! http://personal.mail.yahoo.com/ > ------------------- > To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr > ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr