Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: wester@ilt.fhg.de
To: maulin shah <maulincs510@yahoo.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] stack
Date: Wed, 14 Feb 2001 18:34:05 +0100	[thread overview]
Message-ID: <200102141734.SAA08358@ilt.fhg.de> (raw)
In-Reply-To: <20010213222451.40437.qmail@web12202.mail.yahoo.com>


> 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???
> 

I'm an OCaml beginner too but I hope this is what you wanted.
(Any other solutions?) 

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)::[]
	| Opn (e1,Add,e2)  -> List.append (List.append (compile e1) (compile e2)) (IADD::[]);
	| Opn (e1,Sub,e2)  -> List.append (List.append (compile e1) (compile e2)) (ISUB::[]);;

let m = Opn (Opn (Num 2.0, Sub, Num 3.0), Add, Num 2.0);;
let stackn = compile m;;

Rolf Wester


-------------------------------------
Rolf Wester
wester@ilt.fhg.de
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


      parent reply	other threads:[~2001-02-14 17:34 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
2001-02-14  7:30 ` Ohad Rodeh
2001-02-14 17:34 ` wester [this message]

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=200102141734.SAA08358@ilt.fhg.de \
    --to=wester@ilt.fhg.de \
    --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