From: Gauthier Nadji <gauthier@kriek.lip6.fr>
To: maulin shah <maulincs510@yahoo.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] stack
Date: Wed, 14 Feb 2001 01:29:30 +0100 (CET) [thread overview]
Message-ID: <Pine.LNX.4.21.0102140123010.13058-100000@singha.lip6.fr> (raw)
In-Reply-To: <20010213222451.40437.qmail@web12202.mail.yahoo.com>
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 = <fun>
# 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
next prev parent reply other threads:[~2001-02-14 22:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-02-13 22:24 maulin shah
2001-02-14 0:29 ` Gauthier Nadji [this message]
2001-02-14 7:30 ` Ohad Rodeh
2001-02-14 17:34 ` wester
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.21.0102140123010.13058-100000@singha.lip6.fr \
--to=gauthier@kriek.lip6.fr \
--cc=caml-list@inria.fr \
--cc=maulincs510@yahoo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).