caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] newbie problem with splitting code into files
@ 2003-05-23 12:48 g.o.d
  2003-05-23 14:21 ` Xavier Leroy
  2003-05-23 14:38 ` [Caml-list] newbie problem with splitting code into files Ken Rose
  0 siblings, 2 replies; 4+ messages in thread
From: g.o.d @ 2003-05-23 12:48 UTC (permalink / raw)
  To: caml-list

Hello,

i am a bloody ocaml newbie. i have big problems with learning
ocaml as my brain refuses to thing functional... is get better slowly.

i studied several documentation sources but i was not able to find
a solution for the following problem:

i want to split code like for example the following into
several files:

-------------------- 8< --------------------
class type test_type = object
	val mutable x:int
	method get_x:int
end;;

class test : test_type = object
	val mutable x = 0
	method get_x = x
end;;

let main() =
	let t=new test in
	printf "X: %d\n" t#get_x;;

let _ = main()

-------------------- 8< --------------------

as long as i keep this in one file it works.
so what i did now is splitting it up, putting
class type declaration into test.mli, putting
class declaration into test.ml and putting
let main()... into main.ml

when i now compile test.mli followed by test.ml,
i get error messages like:

The implementation test.ml does not match the interface test.cmi:
The field `#test_type' is required but not provided
The field `test_type' is required but not provided

So what am i doing wrong?

thank you
-> Heiko Irrgang

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] newbie problem with splitting code into files
  2003-05-23 12:48 [Caml-list] newbie problem with splitting code into files g.o.d
@ 2003-05-23 14:21 ` Xavier Leroy
  2003-05-23 21:17   ` [Caml-list] Camlp4 for newbies TBraibant
  2003-05-23 14:38 ` [Caml-list] newbie problem with splitting code into files Ken Rose
  1 sibling, 1 reply; 4+ messages in thread
From: Xavier Leroy @ 2003-05-23 14:21 UTC (permalink / raw)
  To: g.o.d; +Cc: caml-list

> i want to split code like for example the following into
> several files:

The following seems to do what you want:

----------- file test.mli -------------

class type test_type = object
        val mutable x:int
        method get_x:int
end
 
class test : test_type

----------- file test.ml --------------

class type test_type = object
        val mutable x:int
        method get_x:int
end
 
class test : test_type = object
        val mutable x = 0
        method get_x = x
end

----------- file main.ml --------------

open Test
open Printf

let main() = 
        let t=new test in
        printf "X: %d\n" t#get_x;; 
 
let _ = main()

---------------------------------------

Hope this helps,

- Xavier Leroy

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] newbie problem with splitting code into files
  2003-05-23 12:48 [Caml-list] newbie problem with splitting code into files g.o.d
  2003-05-23 14:21 ` Xavier Leroy
@ 2003-05-23 14:38 ` Ken Rose
  1 sibling, 0 replies; 4+ messages in thread
From: Ken Rose @ 2003-05-23 14:38 UTC (permalink / raw)
  To: g.o.d; +Cc: caml-list

g.o.d@zefix.tv wrote:
> 
> Hello,
> 
> i am a bloody ocaml newbie. i have big problems with learning
> ocaml as my brain refuses to thing functional... is get better slowly.

It took me a while, too.

> i studied several documentation sources but i was not able to find
> a solution for the following problem:

<snipped example>

> as long as i keep this in one file it works.
> so what i did now is splitting it up, putting
> class type declaration into test.mli, putting
> class declaration into test.ml and putting
> let main()... into main.ml
> 
> when i now compile test.mli followed by test.ml,
> i get error messages like:
> 
> The implementation test.ml does not match the interface test.cmi:
> The field `#test_type' is required but not provided
> The field `test_type' is required but not provided
> 
> So what am i doing wrong?

I haven't done anything with objects in ocaml, but when I see errors of
that sort, it means that the cmi file is stale and I need to do "make
clean; make".

That usually clears it up for me.

Good luck

 - ken

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* [Caml-list] Camlp4 for newbies
  2003-05-23 14:21 ` Xavier Leroy
@ 2003-05-23 21:17   ` TBraibant
  0 siblings, 0 replies; 4+ messages in thread
From: TBraibant @ 2003-05-23 21:17 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 812 bytes --]

This is a set of very basic questions about CamlP4.

Fisrt of all, is CAMLP4 really compatible with OCaml, because the Stream don't work the same way, in Ocaml, and particulary, the [<>] constructor don't work ...

Secondary, what are the main differences between CAMLP4, LEX, YACC? and where can i find a small tutorial about those ones?

Third of all, my own problem, is what is the efficientest and easiest way to implement a small compilator of a language of my own, under OCaml. I 'm currently using CamlP4, with a lot of evaluations formulas, like 

let instruction = parser | [< 'KEYWORD "Foo" >] -> Foo
;;

let operande = parser...;;
let modifier = parser...;;

Does someone know where i can find some examples of thing like that?

Thank you very much

Thomas Braibant









[-- Attachment #2: Type: text/html, Size: 2365 bytes --]

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

end of thread, other threads:[~2003-05-23 21:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-23 12:48 [Caml-list] newbie problem with splitting code into files g.o.d
2003-05-23 14:21 ` Xavier Leroy
2003-05-23 21:17   ` [Caml-list] Camlp4 for newbies TBraibant
2003-05-23 14:38 ` [Caml-list] newbie problem with splitting code into files Ken Rose

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