[Caml-list] [ANN] pfff_visual, a fancy code visualizer/navigator for OCaml, and more

2010-09-23 Thread Yoann Padioleau
Hi list,

It is my pleasure to announce pfff_visual, a code visualizer/navigator
for OCaml. Note that this is not a replacement for Emacs or vi, but more a
companion that works with Emacs/Vi.

A demo is available here:
part1: http://www.youtube.com/watch?v=HRZjBGD3osw
part2: http://www.youtube.com/watch?v=993pmNLY_VU

pfff_visual is using pfff, which is mainly an OCaml API to write
static analysis, dynamic analysis, code visualizations, code
navigations, or style-preserving source-to-source transformations such
as refactorings on source code. For now the effort is focused on PHP
but there is preliminary support for Javascript, and C++ code.
There is also preliminary support for OCaml code so that the infrastructure
can be used on the code of pfff itself.

You can get the source of pfff and pfff_visual here:
http://github.com/facebook/pfff

Here is how to install it:
$ git clone g...@github.com:facebook/pfff.git
$ ./configure
$ make depend; make; make opt
$ ./pfff_visual /path/to/project/using/supported/languages

pfff has been tested on MacOS and Linux and is licensed under the LGPL.

Thanks to 
- Lex Stein for ocamlbdb
- Olivier Andrieu for ocamlcairo
- Jacques Garrigue for ocamlgtk
- Martin Jambon, Mika Illouz and Gert Stolpmann for lib-json
- Nicolas Canasse for lib-xml
- Jane Street for lib-sexp
- Thomas Gazagnaire for dynType
- Maas-Maarten Zeeman for OUnit.ml
- Thorsten Ohl for xHTML.ml
- Sylvain Conchon, Jean-Christophe Filliâtre and Julien Signoles for 
  ocamlgraph
- Xavier Leroy for ocamlmpi
- Markus Mottl for ocamlpcre
- Iain Proctor for ocamlthrift
- Guillaume Cottenceau for pleac


Enjoy.
___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


[Caml-list] [ANN] pfff_visual, a fancy code visualizer/navigator for OCaml, and more

2010-09-23 Thread Yoann Padioleau
Hi list,

It is my pleasure to announce pfff_visual, a code visualizer/navigator
for OCaml. Note that this is not a replacement for Emacs or vi, but more a
companion that works with Emacs/Vi.

A demo is available here:
 part1: http://www.youtube.com/watch?v=HRZjBGD3osw
 part2: http://www.youtube.com/watch?v=993pmNLY_VU

pfff_visual is using pfff, which is mainly an OCaml API to write
static analysis, dynamic analysis, code visualizations, code
navigations, or style-preserving source-to-source transformations such
as refactorings on source code. For now the effort is focused on PHP
but there is preliminary support for Javascript, and C++ code.
There is also preliminary support for OCaml code so that the infrastructure
can be used on the code of pfff itself.

You can get the source of pfff and pfff_visual here:
 http://github.com/facebook/pfff

Here is how to install it:
 $ git clone g...@github.com:facebook/pfff.git
 $ ./configure
 $ make depend; make; make opt
 $ ./pfff_visual /path/to/project/using/supported/languages

pfff has been tested on MacOS and Linux and is licensed under the LGPL.

Thanks to 
 - Lex Stein for ocamlbdb
 - Olivier Andrieu for ocamlcairo
 - Jacques Garrigue for ocamlgtk
 - Martin Jambon, Mika Illouz and Gert Stolpmann for lib-json
 - Nicolas Canasse for lib-xml
 - Jane Street for lib-sexp
 - Thomas Gazagnaire for dynType
 - Maas-Maarten Zeeman for OUnit.ml
 - Thorsten Ohl for xHTML.ml
 - Sylvain Conchon, Jean-Christophe Filliâtre and Julien Signoles for 
   ocamlgraph
 - Xavier Leroy for ocamlmpi
 - Markus Mottl for ocamlpcre
 - Iain Proctor for ocamlthrift
 - Guillaume Cottenceau for pleac


Enjoy.

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


Re: [Caml-list] Optional arguments "between" non-optional ones

2010-09-23 Thread Jacques Garrigue
On 2010/09/24, at 0:05, Adrien wrote:
> On 23/09/2010, bluestorm  wrote:
>> (sorry for any double-posting)
>> 
>> The problem is that in your declaration of h, the inferred type for f
>> is of the form (unit -> unit -> ...), and you use it with the
>> different type (unit -> ?a:'a -> unit -> ...).
>> 
>> Changing ?a to be the first parameter of f change f's type to (?a:'a
>> -> unit -> unit -> ...). OCaml knows that it can implicitly coerce
>> functions when the optional parameters appear in the first position.
> 
> I actually expected types (?a:'a -> unit -> unit -> ...) and (unit ->
> ?a:'a -> unit -> ...) to work alike. I'm wondering why the arguments
> are "dropped" from the first case but not the second.

The answer is that this way of coercing functions by applying optional
arguments when they are passed is a kind of hack. The formal semantics
defines optional argument discarding as happening only when a function
is applied. However, one often wants this discarding to occur when
the function is passed as argument, to avoid manual eta-expansion.
This is actually done through an eta-expansion (i.e., (fun x -> f x) gets
passed to the function instead of f, to be sure that side-effects happen at
the right time). Since only cases with a single eta-expansion are considered,
optional arguments should come first.

Of course we are very careful of not breaking the formal semantics
(where there is no eta-expansion, and discarding will only occur when
the function is applied). Whenever the eta-expansion approach might
introduce a discrepancy, you will get a type error.

Jacques Garrigue

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


Re: [Caml-list] what do I need to know to understand camlp4

2010-09-23 Thread Elias Gabriel Amaral da Silva
2010/9/23 ben kuin :

>> [1] Compared to other programming languages. I know the syntax is > the way 
>> it is for precise reasons (currying, closer to mathematical
>> notation, ...).
> Would you mind to list a few mathematical subjects that help me to
> understand OCamls syntax?

I suppose one is lambda calculus. Function application is
left-associative in ML. That is, if $ is an operator such as a $ b
means "a applied to b", then it is more natural to interpret a $ b $ c
as (a $ b) $ c[1]. The apply "operator" is simply not written in
OCaml, so we write just a b c, and it means (a b) c.

This is due to the fact that a N parameter function is just a
single-parameter function that return a new "curried" function that
gets N-1 parameters - just like lambda calculus. So one could write
let f = a b in f c to make this explicit as well. (This gets a bit
more complicated with optional parameters)

In fact, you want some mathematical background on functional
programming aesthetics (and whatnot),
http://en.wikipedia.org/wiki/Lambda_calculus may be a good
introduction.

[1] Pervasives should define it. In fact, even though ** is
right-associative, it looks like any user-defined operator is
left-associative by default. So it works like Haskell:

# let ($) a b = a b;;
val ( $ ) : ('a -> 'b) -> 'a -> 'b = 
# fun x y z -> x $ y $ z;;
- : ('a -> 'b -> 'c) -> 'a -> 'b -> 'c = 
# let q = fun x y z -> x $ y $ z;;
val q : ('a -> 'b -> 'c) -> 'a -> 'b -> 'c = 
# let q' = fun x y z -> (x $ y) $ z;;
val q' : ('a -> 'b -> 'c) -> 'a -> 'b -> 'c = 
# let q'' = fun x y z -> x $ (y $ z);;
val q'' : ('a -> 'b) -> ('c -> 'a) -> 'c -> 'b = 
# let q''' = fun x y z -> x $ y z;;
val q''' : ('a -> 'b) -> ('c -> 'a) -> 'c -> 'b = 

-- 
Elias Gabriel Amaral da Silva 

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


Re: [Caml-list] what do I need to know to understand camlp4

2010-09-23 Thread ben kuin
> If you are new to OCaml,
I'm not actually new to OCaml, but although  I've read every notable
book about OCaml and a lot of good code of other OCaml programs, OCaml
is still very foreign and counter-intuitive too me.

I know what you're might thinking now: why the hell does he still bother?

The 'problem' is that every time I read something in Python or worse
in Java/C++ I instantly miss the lightweight types/pattern matching
facility the ability to easily pass functions around. Then I read
functional Ruby or Scala code, and I begin to hate fp because in these
context it only makes the code harder to read.

So why does the whole world tries to hammer some functional features
into his imperative language? Why not maximize the imperative features
of a functional language? I know only one big project where the
explicitely use an imperative style in ocaml? But this code looks
(syntax wise) still too much functional for my taste.

> with its syntax (somewhat quirky[1], I admit).
For me it's worse, the syntax doesn't look quirky, but rather random
too me. It's not like cpp where the syntax is utterly pragmatic,
without any aesthetic claim. In OCaml it feels like someone
deliberately neglected the syntax.

> [1] Compared to other programming languages. I know the syntax is > the way 
> it is for precise reasons (currying, closer to mathematical
> notation, ...).
Would you mind to list a few mathematical subjects that help me to
understand OCamls syntax?

thanks a lot
ben

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


Re: [Caml-list] what do I need to know to understand camlp4

2010-09-23 Thread Yoann Padioleau

On Sep 23, 2010, at 11:49 AM, ben kuin wrote:

> thanks Jake, after browsing through those articles I came to the
> conclusion that for understanding and using camlp4 the notion of
> quotations and antiquotations is fundamental. My absolute lack of
> knowledge in this area might be a reason why I can't figure out how
> camlp4 works.

Do you know how macros work in other languages ?
You could have a look at Lisp macros which are simpler than OCaml macros:
 http://cl-cookbook.sourceforge.net/macros.html
Understanding lisp macros could be a good step towards understanding ocaml 
macros.

> 
> 
> 
> On Thu, Sep 23, 2010 at 6:23 PM, Jake Donham  wrote:
>> On Thu, Sep 23, 2010 at 8:25 AM, bluestorm  wrote:
>>> For an accessible introduction to modern (>= 3.10) Camlp4, you may be
>>> interested in Jake Donham's blog post series "Reading Camlp4" :
>>> http://ambassadortothecomputers.blogspot.com/search/label/camlp4
>> 
>> You can also see the articles in sequence at
>> 
>>  http://ambassadortothecomputers.blogspot.com/p/reading-camlp4.html
>> 
>> which I recommend since later articles depend on earlier material.
>> 
>> Jake
>> 
>> ___
>> Caml-list mailing list. Subscription management:
>> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
>> Archives: http://caml.inria.fr
>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>> Bug reports: http://caml.inria.fr/bin/caml-bugs
>> 
> 
> ___
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs



___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


Re: [Caml-list] what do I need to know to understand camlp4

2010-09-23 Thread Jake Donham
On Thu, Sep 23, 2010 at 11:49 AM, ben kuin  wrote:
> thanks Jake, after browsing through those articles I came to the
> conclusion that for understanding and using camlp4 the notion of
> quotations and antiquotations is fundamental. My absolute lack of
> knowledge in this area might be a reason why I can't figure out how
> camlp4 works.

Unfortunately quotations are a rather leaky abstraction. You need to
understand what is happening at the AST level to do anything
complicated, and to understand what's wrong when you get an error.
Anything you can do with quotations you can of course do directly with
the AST, since quotations are just syntactic sugar for the AST. But to
make the code readable quotations are essential.

Jake

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


Re: [Caml-list] what do I need to know to understand camlp4

2010-09-23 Thread ben kuin
thanks Jake, after browsing through those articles I came to the
conclusion that for understanding and using camlp4 the notion of
quotations and antiquotations is fundamental. My absolute lack of
knowledge in this area might be a reason why I can't figure out how
camlp4 works.



On Thu, Sep 23, 2010 at 6:23 PM, Jake Donham  wrote:
> On Thu, Sep 23, 2010 at 8:25 AM, bluestorm  wrote:
>> For an accessible introduction to modern (>= 3.10) Camlp4, you may be
>> interested in Jake Donham's blog post series "Reading Camlp4" :
>> http://ambassadortothecomputers.blogspot.com/search/label/camlp4
>
> You can also see the articles in sequence at
>
>  http://ambassadortothecomputers.blogspot.com/p/reading-camlp4.html
>
> which I recommend since later articles depend on earlier material.
>
> Jake
>
> ___
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


Re: [Caml-list] what do I need to know to understand camlp4

2010-09-23 Thread ben kuin
thanks a lot for this information and the links, this is very helpful

On Thu, Sep 23, 2010 at 6:26 PM, Michael Ekstrand  wrote:
> On Thu, 2010-09-23 at 16:56 +0200, ben kuin wrote:
>> Could someone give any idea how I can begin to understand how to write
>> simple camlp4 extensions?
>
> Shameless self-plug, but I wrote a blog post this summer about my
> experience figuring out how to do it.  I provide a walk-through and
> explanation of a minimal syntax extension which adds lazy list pattern
> matching support based on Batteries.  The URL:
>
> http://www.elehack.net/michael/blog/2010/06/ocaml-syntax-extension
>
> I do assume a basic knowledge of parsing context-free grammars, but a
> generic tutorial on parsing with a tool such as Yacc can fill in that
> gap.  The Wikipedia article[1] may also be helpful.
>
> Once you've lept the hurdle of figuring out what pieces you need to
> write and build a syntax extension, the remaining tricky part is to
> figure out what pieces of the grammar you need to extend to accomplish
> your objective.  For that, I consult the definition of the OCaml parser
> in Camlp4OCamlParser.ml in the OCaml source tree.
>
> - Michael
>
> 1. http://en.wikipedia.org/wiki/Context-free_grammar
>
> --
> Web/blog: http://elehack.net/michael
> Jabber/Google Talk: this e-mail address
> Twitter: http://twitter.com/elehack
> mouse, n: a device for pointing at the xterm in which you want to type
>
>

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


[Caml-list] Re: what do I need to know to understand camlp4

2010-09-23 Thread Sylvain Le Gall
On 23-09-2010, ben kuin  wrote:
>
> Could someone give any idea how I can begin to understand how to write
> simple camlp4 extensions?
>

If you consider yourself as a n00b, don't start by camlp4. This is
probably the most difficult part of OCaml -- and to program camlp4 you
need to use OCaml standard syntax (or revised syntax, it depends if you
use antiquotations). 

If you still want to follow the hard path, as suggested elsewhere, Jake
Donham's blog posts are very good:

 http://ambassadortothecomputers.blogspot.com/p/reading-camlp4.html

Or if you are around, there is a tutorial session at CUFP:
http://cufp.org/conference/sessions/2010/camlp4-and-template-haskell
(but you need to subscribe).

Regards,
Sylvain Le Gall


___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


Re: [Caml-list] what do I need to know to understand camlp4

2010-09-23 Thread Michael Ekstrand
On Thu, 2010-09-23 at 16:56 +0200, ben kuin wrote:
> Could someone give any idea how I can begin to understand how to write
> simple camlp4 extensions?

Shameless self-plug, but I wrote a blog post this summer about my
experience figuring out how to do it.  I provide a walk-through and
explanation of a minimal syntax extension which adds lazy list pattern
matching support based on Batteries.  The URL:

http://www.elehack.net/michael/blog/2010/06/ocaml-syntax-extension

I do assume a basic knowledge of parsing context-free grammars, but a
generic tutorial on parsing with a tool such as Yacc can fill in that
gap.  The Wikipedia article[1] may also be helpful.

Once you've lept the hurdle of figuring out what pieces you need to
write and build a syntax extension, the remaining tricky part is to
figure out what pieces of the grammar you need to extend to accomplish
your objective.  For that, I consult the definition of the OCaml parser
in Camlp4OCamlParser.ml in the OCaml source tree.

- Michael

1. http://en.wikipedia.org/wiki/Context-free_grammar

-- 
Web/blog: http://elehack.net/michael
Jabber/Google Talk: this e-mail address
Twitter: http://twitter.com/elehack
mouse, n: a device for pointing at the xterm in which you want to type


___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


Re: [Caml-list] what do I need to know to understand camlp4

2010-09-23 Thread Jake Donham
On Thu, Sep 23, 2010 at 8:25 AM, bluestorm  wrote:
> For an accessible introduction to modern (>= 3.10) Camlp4, you may be
> interested in Jake Donham's blog post series "Reading Camlp4" :
> http://ambassadortothecomputers.blogspot.com/search/label/camlp4

You can also see the articles in sequence at

  http://ambassadortothecomputers.blogspot.com/p/reading-camlp4.html

which I recommend since later articles depend on earlier material.

Jake

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


Re: [Caml-list] what do I need to know to understand camlp4

2010-09-23 Thread bluestorm
> Could someone give any idea how I can begin to understand how to write
> simple camlp4 extensions?

For an accessible introduction to modern (>= 3.10) Camlp4, you may be
interested in Jake Donham's blog post series "Reading Camlp4" :
http://ambassadortothecomputers.blogspot.com/search/label/camlp4
You will also find valuable (though incomplete) information on the
camlp4 wiki : http://brion.inria.fr/gallium/index.php/Camlp4

The older version of camlp4 (< 3.10, now called camlp5) also provides
a documentation
http://caml.inria.fr/pub/docs/tutorial-camlp4/index.html , and you can
also use to Martin Jambon's tutorial
http://martin.jambon.free.fr/extend-ocaml-syntax.html (for the older
camlp4).

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


Re: [Caml-list] what do I need to know to understand camlp4

2010-09-23 Thread David MENTRE
Hello,

2010/9/23 ben kuin :
> I'm a Ocaml n00b (without any degree). Therefore I have a faible for
> everything that makes Ocamls syntax more algol/imperative like [1].

If you are new to OCaml, I strongly advise you to learn it the way it
is, with its syntax (somewhat quirky[1], I admit). You are going to
learn a *lot* more than trying to fit it in your current imperative
knowledge.

Sincerely yours,
david

[1] Compared to other programming languages. I know the syntax is the
way it is for precise reasons (currying, closer to mathematical
notation, ...).

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


Re: [Caml-list] Optional arguments "between" non-optional ones

2010-09-23 Thread Adrien
On 23/09/2010, bluestorm  wrote:
> (sorry for any double-posting)
>
> The problem is that in your declaration of h, the inferred type for f
> is of the form (unit -> unit -> ...), and you use it with the
> different type (unit -> ?a:'a -> unit -> ...).
>
> Changing ?a to be the first parameter of f change f's type to (?a:'a
> -> unit -> unit -> ...). OCaml knows that it can implicitly coerce
> functions when the optional parameters appear in the first position.

I actually expected types (?a:'a -> unit -> unit -> ...) and (unit ->
?a:'a -> unit -> ...) to work alike. I'm wondering why the arguments
are "dropped" from the first case but not the second.

Also, that's what I've done: I've simply swapped two parameters in a
function and it's working well now.

> This is explained in the manual :
> http://caml.inria.fr/pub/docs/manual-ocaml/manual006.html#htoc39
>
>> However, in the specific case where the expected type
>> is a non-labeled function type, and the argument is
>> a function expecting optional parameters, the compiler
>> will attempt to transform the argument to have it match
>> the expected type, by passing None for all optional parameters.

Well spotted. I had gone a bit through the documentation but hadn't seen that.

> A fix is to add an annotation when defining h :
>
> let h (f : _ -> ?a:_ -> _) =
>  f () ()
>
> # let () = h f;;
> bouh!
> bouh!
>

I had tried to add an annotation too but (unit -> unit -> unit). Now,
thinking again about it and with your explanation, I understand better
why it had failed. I was trying to coerce f into a more restrictive
(or simply different?) type but the solution was keep the type of h's
argument broader.
Thanks.

--

Adrien Nader

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


[Caml-list] what do I need to know to understand camlp4

2010-09-23 Thread ben kuin
hi
I'm a Ocaml n00b (without any degree). Therefore I have a faible for
everything that makes Ocamls syntax more algol/imperative like [1]. An
example would be an extension like 'newref'
(http://bitbucket.org/johannes/newref/wiki/Home), which turns:

print_int !i   into   print_int $i(* newref *)

so I fiercely try to also perlify the declaration that turns

 let i = ref 3 intolet $i = 3 (* my idea ... *)

but camlp4 makes my head spin. The syntax is very difficult and in a
lot of camlp4 documentation there is AST modification involved, which
is a subject I don't get although I made several attempts. And simple
program transformation with camlp4 (using concrete syntax) is nowhere
documented.

Could someone give any idea how I can begin to understand how to write
simple camlp4 extensions?

thanks
ben

[1] please don't kill me

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


Re: [Caml-list] Optional arguments "between" non-optional ones

2010-09-23 Thread bluestorm
(sorry for any double-posting)

The problem is that in your declaration of h, the inferred type for f
is of the form (unit -> unit -> ...), and you use it with the
different type (unit -> ?a:'a -> unit -> ...).

Changing ?a to be the first parameter of f change f's type to (?a:'a
-> unit -> unit -> ...). OCaml knows that it can implicitly coerce
functions when the optional parameters appear in the first position.

This is explained in the manual :
http://caml.inria.fr/pub/docs/manual-ocaml/manual006.html#htoc39

> However, in the specific case where the expected type
> is a non-labeled function type, and the argument is
> a function expecting optional parameters, the compiler
> will attempt to transform the argument to have it match
> the expected type, by passing None for all optional parameters.

A fix is to add an annotation when defining h :

let h (f : _ -> ?a:_ -> _) =
 f () ()

# let () = h f;;
bouh!
bouh!

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


[Caml-list] Optional arguments "between" non-optional ones

2010-09-23 Thread Adrien
Hi,

I was refactoring code today and hit a typing error that I couldn't
explain. I eventually tracked it down to the following:

  let f () ?a () =
print_endline "bouh!"

  let h f =
f () ()

  let () = h f;;  (* error is for "f" here *)

  Error: This expression has type unit -> ?a:'a -> unit -> unit
 but an expression was expected of type unit -> unit -> 'b


If I remove the first unit argument of f, then it works as expected.
There also seems to be variations around that.

Is there any explanation for that difference? And any chance of it
getting improved?

Thanks.


-- 

Adrien Nader

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs