caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* (no subject)
@ 2003-02-07  5:23 Nikolaj Bjorner
  2003-02-07 13:10 ` [Caml-list] Re: your mail Mike Potanin
  0 siblings, 1 reply; 8+ messages in thread
From: Nikolaj Bjorner @ 2003-02-07  5:23 UTC (permalink / raw)
  To: checker; +Cc: caml-list

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

I am pretty sure this is not related to references, but to let-rec.

Try:

let rec f x = x and g y = f y + 1;;

you will see that the type inferred is:

val f : int -> int
val g : int -> int

Now try:

let f x = x and g y = f y + 1;;

this time:

val f : 'a -> 'a
val g : int -> int

You may still be wondering why, of course.
The basic answer (I hope I am not too rusty in this)  
is that type inference for polymorphic let-rec is not decidable
(you have to solve a semi-unification problem).
Hence, the "solution" is not to abstract type variables  
until all type inference for all  
let-rec-and clauses have been analyzed.

So:

let rec f x = x and g y = f y + 1 and h z = not (h z);;

does not type check at all, but again:  
let f x = x and g y = f y + 1 and h z = not (h z);;
does work.


Nikolaj




From: Chris Hecker [mailto:checker@d6.com]
Sent: Thu 2/6/2003 5:31 PM
To: caml-list@inria.fr
Subject: [Caml-list] streams and value restriction




I assume I'm running into the polymorphism restriction thing here, but
I'm not sure why (I kind of understand it when references are in play,
but this is baffling me).

Here's a simple version of some stream parser code.  I'd like
parse_opt_comma_list to be polymorphic so I can use it to parse lists
of any of my values.  It works fine as a separate let rec, but if I
put it in the overall let rec of the main parser (with and) it won't
generalize and gets tagged as string-only since that's the first way
it's used.

Can somebody explain why this is a problem?  Sorry for being dense.

Thanks,
Chris


type t =
    Int of int
  | String of string

(* this works: *)
let rec parse_opt_comma_list parse list = parser
    [< 'Genlex.Kwd ",";
       a = parse ;
       optlist = parse_opt_comma_list parse (a::list) >] -> optlist
  | [< >] -> list

let rec parse_values = parser
    [< 'Genlex.String s;
       optlist = parse_opt_comma_list (parser [< 'Genlex.String s >] -> s) [] >] ->
         (String s) :: List.map (fun s -> String s) optlist
  | [< 'Genlex.Int i;
       optlist = parse_opt_comma_list (parser [< 'Genlex.Int i >] -> i) [] >] ->
         (Int i) :: List.map (fun i -> Int i) optlist

(* this doesn't: *)
let rec parse_values = parser
    [< 'Genlex.String s;
       optlist = parse_opt_comma_list (parser [< 'Genlex.String s >] -> s) [] >] ->
         (String s) :: List.map (fun s -> String s) optlist
  | [< 'Genlex.Int i;
       optlist = parse_opt_comma_list (parser [< 'Genlex.Int i >] -> i) [] >] ->
         (Int i) :: List.map (fun i -> Int i) optlist

and parse_opt_comma_list parse list = parser
    [< 'Genlex.Kwd ",";
       a = parse ;
       optlist = parse_opt_comma_list parse (a::list) >] -> optlist
  | [< >] -> list


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

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

^ permalink raw reply	[flat|nested] 8+ messages in thread
* (no subject)
@ 2002-01-21 23:27 cgillot
  2002-01-21 22:43 ` [Caml-list] Re: your mail Markus Mottl
  0 siblings, 1 reply; 8+ messages in thread
From: cgillot @ 2002-01-21 23:27 UTC (permalink / raw)
  To: markus; +Cc: caml-list

Hi,

  Sorry I'm still new to Ocaml and sorry if the question is dumb,
but I did looked thoroughly and didn't got it... 
  I don't know whether this is a ocaml problem or a pcre-ocaml
problem, but the point is that although I manage to generate a 
toplevel with pcre-ocaml linked by doing :

ocamlmktop -o ocamlunx -I +camlp4 -I +contrib unix.cma str.cma pcre.cma camlp4o.cma

When I try to do a :
#open Pcre;;
or to use a function with its full-qualified name a "Unbound module" message.

BTW the machine is a x86 debian woody but using the sid ocaml packages,
ocaml 3.04-2 and pcre_ocaml-4.12-1

Any help is greatly appreciated.
-------------------
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] 8+ messages in thread
* (no subject)
@ 2001-08-03 10:58 Johann Spies
  2001-08-03 13:26 ` [Caml-list] Re: your mail Francois Pottier
  2001-08-03 17:42 ` Vitaly Lugovsky
  0 siblings, 2 replies; 8+ messages in thread
From: Johann Spies @ 2001-08-03 10:58 UTC (permalink / raw)
  To: ocaml mailing list
  Cc: Sylvain Pogodalla, Francois.Thomasset, Brian Rogoff, Dave Berry, luther

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: multipart/mixed; boundary="Frank Atanassow <franka@cs.uu.nl>, Francois.Pottier@inria.fr,", Size: 5553 bytes --]

Frank Atanassow <franka@cs.uu.nl>, Francois.Pottier@inria.fr,
    Basile.Starynkevitch@cea.fr, Benedikt.Rosenau@dlr.de,
    Wolfgang Lux <lux@wi.uni-muenster.de>,
    Stefano Lanzavecchia <stf@apl.it>,
    Sebastien Briais <sbriais@ens-lyon.fr
Subject: Re: [Caml-list] Please help a newbie
References: <87lml2a896.fsf@#maties.sun.ac.za> <3B6949D5.784BAC9F@xrce.xerox.com>
From: Johann Spies <jspies@maties.sun.ac.za>
Date: 03 Aug 2001 10:58:03 +0000
In-Reply-To: Sylvain Pogodalla's message of "Thu, 02 Aug 2001 14:38:45 +0200"
Message-ID: <87g0b98l6s.fsf@#maties.sun.ac.za>
Lines: 132
User-Agent: Gnus/5.0803 (Gnus v5.8.3) Emacs/20.7
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii

Thank you to everyone that replied. I have realized now that it is not
that easy to start programming in ocaml (or a functional language)
when you are an amateur and coming from a procedural/imperative
programming background.

My knowledge of the theory of programming is not good.  I started
programming as a hobby using Basic, Pascal, Dbase III, a little bit of
Prolog and for the past few years, Python.

Maybe Sylvain summarized my problems with his questions:

> There are many different things in your code. Answering to some
> questions might help you:
> + what is the type of lys?
> + what is the type of the elements of lys?

I am not sure about the difference between these two questions.  I
realised my mistake that lys was a char list and I expected wys_dit to
print strings.

> + what is the type of wys_dit?

As I understand it wys_dit is a function.  I always thought of
functions as using types not necessarily having types.

> + do you think wys_dit is able to print one element of lys?

Answered above.

> + how many parameters do you want for wys_die_lys?

I thought it needed one, originally, but it did not work, so I tried a
second.  At least the interpreter did not complain.  Another response
to my question, explained why I did not see an interpreter complaint.

> + do you see the interpreter answers that it "expects" two
>   parameters?

No, I did not see that.  I do not always understand the messages of
the interpreter.

> + can you compare the function f1 and f2 such that:
> let f1 x = match x with
> | [] -> print_string "empty list";print_newline()
> | h::t -> print_string "not empty list";print_newline();;
> let f2 = function 
> | [] -> print_string "empty list";print_newline()
> | h::t -> print_string "not empty list";print_newline();;
> + how many parameters do they need?

Maybe this is what I am struggling to understand.  I can not see how
f2 can work.  What data does it use?

Related to this is what Benedikt referred to:

> But the easiest way is:
> 
> let wys_die_lys = List.iter print_string;;

In this function, there is no explicit parameter.  Where is this
behaviour documented?

Francois Thomasset's remark on the same topic also underlines my lack
of understanding of the handling of arguments a function:

> 2/ your wys_die_lys has 2 arguments, as can be seen from the
> signature val wys_die_lys : 'a -> string list -> unit list = <fun>
> (the system deduced the string list type for the type of the second
> argument from the call to print_string in wys_dit).



> + do you expect wys_dit to return a result?
I did.
> + what type for that result?
A printed string.
> + what is the exact meaning of the :: operator?

I am not sure.  I could not find an explanation for it.  I have just
now searched the "operator" section of the ocaml-manual for :: again
and could only find :

     type 'a list = [] | :: of 'a * 'a list

>From that I suspect that :: is an alternative for [] - telling the
compiler that the tipe is a list?

I tried to figure out what it does by reading examples of it's use.


> + do you really want to build a unit list, as the type of wys_die_lys
> describes ?

No.  I am do not see the of what use a "unit list" can be. 

Some of you also helped me to see the necessity of flushing the
output:

> You need to flush stdout or print_newline; also the function
> wys_die_lys does not need to return a unit list but just a unit;

Someone wrote:

> I would recommend not to use print_string as long as
> you're not comfortable with the language; writing purely
> functional code (no side effects) will be easier.

I have always used print statements in programs to help me with
debugging and to see what is going on (that is besides the necessity
to get some output from the program).  A program with no side effects
does not make sense to me.  What is the use of it?

As you can see, these questions revealed my lack of understanding of
some of the basics.  I suspect the only way to get to understand it is
by reading, asking and trying.

I have not responded to everything. I appreciate all the help, remarks
and code sent to me and I will probably ask some more questions in the
future.

Johann
-- 
Johann Spies          Telefoon: 021-808 4036
Informasietegnologie, Universiteit van Stellenbosch

     "Love is patient, love is kind. It does not envy, it
      does not boast, it is not proud. It is not rude, it is
      not self seeking, it is not easily angered, it keeps
      no record of wrongs. Love does not delight in evil but
      rejoices with the truth. It always protects, always
      trusts, always hopes, always perseveres." 
                                I Corinthians 13:4-7 
-------------------
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] 8+ messages in thread
* (no subject)
@ 2001-03-06 20:25 rakesh malhotra
  2001-03-07 16:53 ` [Caml-list] Re: your mail Brian Rogoff
  0 siblings, 1 reply; 8+ messages in thread
From: rakesh malhotra @ 2001-03-06 20:25 UTC (permalink / raw)
  To: caml-list

hi:
	I get the following error when trying to install OCaml on a sun
sparc station.

	Please help.

thanks

rakesh


Options for linking with X11: -cclib -lX11
NDBM found (in /usr/include)
Configuring LablTk...
tcl.h not found.
Configuration failed, LablTk will not be built.

** Configuration summary **

Directories where Objective Caml will be installed:
        binaries.................. /usr/local/bin
        standard library.......... /usr/local/lib/ocaml
        manual pages.............. /usr/local/man/man1 (with extension .1)
Configuration for the bytecode compiler:
        C compiler used........... gcc
        options for compiling..... -fno-defer-pop -Wall -Wno-unused
        options for linking.......  -lcurses -lnsl -lsocket -lm
Configuration for the native-code compiler:
        hardware architecture..... sparc
        OS variant................ solaris
        C compiler used........... gcc
        options for compiling..... -Wall -Wno-unused
        options for linking.......  -lcurses -lnsl -lsocket -lm
        assembler ................ $(AS) 
        preprocessed assembler ... gcc -c -DSYS_$(SYSTEM)
        profiling with gprof ..... not supported
Source-level replay debugger: supported
Configuration for the external libraries:
        libraries supported ...... unix str num dynlink bigarray threads
graph dbm
The "num" library:
        target architecture ...... supersparc-solaris
The "graph" library:
        options for compiling .... 
        options for linking ...... -cclib -lX11
The "labltk" library: configuration failed
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


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

end of thread, other threads:[~2003-02-07 12:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-07  5:23 Nikolaj Bjorner
2003-02-07 13:10 ` [Caml-list] Re: your mail Mike Potanin
  -- strict thread matches above, loose matches on Subject: below --
2002-01-21 23:27 cgillot
2002-01-21 22:43 ` [Caml-list] Re: your mail Markus Mottl
2002-01-22  9:00   ` Daniel de Rauglaudre
2002-01-22 13:12     ` Markus Mottl
2001-08-03 10:58 Johann Spies
2001-08-03 13:26 ` [Caml-list] Re: your mail Francois Pottier
2001-08-03 17:42 ` Vitaly Lugovsky
2001-03-06 20:25 rakesh malhotra
2001-03-07 16:53 ` [Caml-list] Re: your mail Brian Rogoff

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