caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Newbie question concerning type definitions
@ 2001-10-11  6:43 Thomas Link
  2001-10-11  7:11 ` Remi VANICAT
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Link @ 2001-10-11  6:43 UTC (permalink / raw)
  To: caml-list

Hello, 

I have hesitated to send this question to this mailing list as I 
suspect it to be rather stupid. What am I trying to do? I would like to 
implement a simple stack based language in OCaml in order to get a 
feeling for OCaml and also to test some ideas. Well, I didn't get far 
as I wasn't even able to define the basic data structures. I guess this 
is plain wrong:

type returnState = Succeeded | Failed | Error of int
and proc = (stack -> dictionary -> returnState) 
and procs = proc list 
and element = 
	Int of int 
  | String of string
  | Float of float
  | Word of proc 
and stack = element Stack.t 
and dictionary = (string, procs) Hashtbl.t;; 

When compiling this, the compiler tells me that proc's definition is 
cyclic. How can I circumvent this in OCaml? 

My apologies if this is too simple-minded for being asked in this 
forum, but could somebody tell me please how the correct definition of 
these types could possibly look like? 

Cheers, Thomas. 


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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] Newbie question concerning type definitions
  2001-10-11  6:43 [Caml-list] Newbie question concerning type definitions Thomas Link
@ 2001-10-11  7:11 ` Remi VANICAT
  0 siblings, 0 replies; 2+ messages in thread
From: Remi VANICAT @ 2001-10-11  7:11 UTC (permalink / raw)
  To: caml-list

"Thomas Link" <t.link.tmp200101@gmx.net> writes:

> Hello, 
> 
> I have hesitated to send this question to this mailing list as I 
> suspect it to be rather stupid. What am I trying to do? I would like to 
> implement a simple stack based language in OCaml in order to get a 
> feeling for OCaml and also to test some ideas. Well, I didn't get far 
> as I wasn't even able to define the basic data structures. I guess this 
> is plain wrong:
> 
> type returnState = Succeeded | Failed | Error of int
> and proc = (stack -> dictionary -> returnState) 
> and procs = proc list 
> and element = 
> 	Int of int 
>   | String of string
>   | Float of float
>   | Word of proc 
> and stack = element Stack.t 
> and dictionary = (string, procs) Hashtbl.t;; 
> 
> When compiling this, the compiler tells me that proc's definition is 
> cyclic. How can I circumvent this in OCaml? 

this is a FAQ (is this FAQ in the FAQ ?)
There is two possible answer :
First add the -rectype option to the compiler to allow such recursive
type, 

Secondly, put the proc type into a constructor :

type returnState = Succeeded | Failed | Error of int
and proc = Proc of (stack -> dictionary -> returnState) 
and procs = proc list 
and element = 
	Int of int 
  | String of string
  | Float of float
  | Word of proc 
and stack = element Stack.t 
and dictionary = (string, procs) Hashtbl.t;; 

-- 
Rémi Vanicat
vanicat@labri.u-bordeaux.fr
http://dept-info.labri.u-bordeaux.fr/~vanicat
-------------------
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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-10-11  7:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-11  6:43 [Caml-list] Newbie question concerning type definitions Thomas Link
2001-10-11  7:11 ` Remi VANICAT

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).