Re: [Caml-list] camlp4 and generating class definitions

2012-05-12 Thread Philippe Veber
Hi Joel,

You can have a look at Martin Jambon's col syntax extension :

https://github.com/pveber/col

Have a look at pa_col.ml, starting line 400.

Cheers,
  Philippe.


2012/5/11 Joel Reymont 

> I would like to auto-generate an object with a couple of mutable
> fields and some methods.
>
> I would then like to pretty-print the code into a file.
>
> Are there any examples showing how to do this with camlp4?
>
>Thanks in advace, Joel
>
> --
> AlgoKit: EasyLanguage trading strategies, on the server, w/ Rithmic R|API
> -++---
> http://wagerlabs.com | @wagerlabs | http://www.linkedin.com/in/joelreymont
> -++---
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> 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 and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] [ANN] findlib-1.3.0

2012-05-07 Thread Philippe Veber
Hi Gerd, and many thanks for this new release!

There was a strange response of findlib when missing some camlp4 package:

http://www.mail-archive.com/caml-list@inria.fr/msg00759.html

Did you also have some time to look at it? Just curious, it's not
particularly bothering me now.
Thanks again,
  Philippe.


2012/5/7 Gerd Stolpmann 

> Hi,
>
> I just released findlib-1.3.0, featuring:
>
>  - Fixes for ocaml-4.00 (especially topfind)
>  - Emitting an error if the configuration file does not exist.
>  - Emitting a warning if the selected toolchain does not exist.
>  - camlp4 is referenced by "+camlp4" in META.
>  - including the sources for the documentation in the tarball.
>  - License change (simplification) for num_top_printers.mli.
>  - Fix ocamlmklib wrapper: processing contracted args (like -L/dir)
>   correctly.
>  - Many wrappers get a new option -passrest instructing to pass all
>   remaining options on the command-line unchanged to the invoked tool.
>  - Prettified -help output.
>
> It covers a lot of bugs or suggestions I got from users, thanks for this
> (even if I sometimes don't find time for a response).
>
> Download, manual, and more information at
> http://projects.camlcity.org/projects/findlib.html.
>
> Gerd
> --
> Gerd Stolpmann, Darmstadt, Germanyg...@gerd-stolpmann.de
> Creator of GODI and camlcity.org.
> Contact details:http://www.camlcity.org/contact.html
> Company homepage:   http://www.gerd-stolpmann.de
> *** Searching for new projects! Need consulting for system
> *** programming in Ocaml? Gerd Stolpmann can help you.
>
>
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> 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 and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] extending user-defined polymorphic variant types

2012-05-07 Thread Philippe Veber
Hi Dan,

I'm afraid you can't. If you want to write unions of polymorphic variant
types, they have to be concrete and not abstract. See Romain Bardou's work
on this:

http://romain.bardou.fr/papers/stage2006p.pdf

Or, if you can read french:

www.math.nagoya-u.ac.jp/~garrigue/papers/index.html

(see Unions de variants polymorphes abstraits).

Cheers,
  Philippe.



2012/5/7 Dan Bensen 

>
> I'm trying to write a functor that extends a user-supplied polymorphic
> variant type (PVT).  How do you declare the user's type in the signature
> for the argument to the functor without locking in the individual variant
> definitions?
> The code below (in revised syntax) generates an error message that says
> the type isn't a PVT.
>
> code:
>
> > module type Reader = sig type ast; end;
> >
> > module Make (Read: Reader) = struct
> >   type ast = [= Read.ast | `Lid of string];
> > end;
>
> message:
>
> > Error: The type Read.ast is not a polymorphic variant type
>
> How do you make ast a PVT while allowing the user to
> specify the variants?
>

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] [ANN] ocamlopen 1.0.2

2012-04-17 Thread Philippe Veber
2012/4/12 Alain Frisch 

> On 04/12/2012 04:16 PM, Philippe Veber wrote:
>
>> Isn't this a good use case for polymorphic variants too ?
>>
>
> I don't see how to use polymorphic variants here.  The message bus itself
> need to provide functions like:
>
>  val dispatch: message -> unit
>  val register_listener: (message -> unit) -> unit
>
>
> How do you define the message type without having access to all possible
> message constructors?

I reckon you can't, but I mistakenly thought you could at least define the
bus without writing the full message type:

module Bus : sig
  type 'a t
  val create : unit -> 'a t
  val dispatch : 'a t -> 'a -> unit
  val register : 'a t -> ('a -> unit) -> unit
end
=
struct
  type 'a t = ('a -> unit) list ref
  let create () = ref []
  let dispatch bus msg =
List.iter (fun f -> f msg) !bus
  let register bus f =
bus := f :: !bus
end


let bus = Bus.create ()

let () = Bus.register bus (function `a -> print_char 'a')
let () = Bus.register bus (function `b n -> print_int n)

However this is not a legal program:

  let () = Bus.register bus (function `b n -> print_int n);;
  
Error: This pattern matches values of type [< `b of 'a ]
   but a pattern was expected which matches values of type [< `a ]
   These two variant types have no intersection

Well, I mentionned polymorphic variants because you can at least define
listeners without knowing the full message type and even reuse them for
buses with different message types. So you have a certain flexibility,
compared to monomorphic types.

But ok, maybe the remark wasn't even worth 2 cents :o).

Cheers,
ph.

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] Current SVN head and findlib.

2012-04-12 Thread Philippe Veber
2012/4/12 Stéphane Glondu 

> Le 12/04/2012 14:30, Philippe Veber a écrit :
> > While playing with the upcoming features of our favorite compiler, I
> > found that the current trunk and version/4.00 branch do not work well
> > with findlib (version 1.2.8). I report it here so others might confirm
> > (or not) what I say.
> >
> > OCaml version 4.01.0+dev1_2012-03-31
> >
> > # #use "topfind";;
> > - : unit = ()
> > File "/home/pveber/usr/ocamlbrew/ocaml-svn/trunk/lib/ocaml/topfind",
> > line 37, characters 0-22:
> > Error: Unbound module Topfind
> >
> > What is really surprising is that the toplevel doesn't complain if I
> > copy/paste the contents of topfind directly in the compiler:
> > [...]
>
> It works if you execute (replace /usr/lib/ocaml by `ocamlc -where`)
>
>  #directory "/usr/lib/ocaml/findlib";;
>
> before calling
>
>  #use "topfind";;
>
Indeed, it works fine with that trick. Thanks !


>
> The #directory is present in /usr/lib/ocaml/topfind, but it seems that
> now, they don't have immediate effect.
>
Yes, that is a really surprising issue for me.

Thanks again,
  ph.

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] Current SVN head and findlib.

2012-04-12 Thread Philippe Veber
Thanks for your answer !

2012/4/12 Jonathan Protzenko 

> I also have this problem, and I've reported it to Gerd.

Good.


> What I usually do is edit the topfind file, remove the "new" stuff, and
> uncomment the lines marked as "old". This has been working fine so far for
> me.
>
I tried to uncomment the "old" lines (didn't see the "new") but it still
does not work. However Stéphane's trick did it so I'll be safe until the
problem's fixed.

Thanks again,
ph.


> Cheers,
>
> jonathan
>

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] [ANN] ocamlopen 1.0.2

2012-04-12 Thread Philippe Veber
>
> 4. When would you say that one should use polymorphic variants rather
>> than your open datatypes? (I know how to argue in the other direction:
>> unique constructors make for better error messages.)
>>
>
> I've wanted such open datatypes several times.  One example is a message
> bus across an application: some components can yield messages to be
> dispatched to all registered components.  Messages can hold data, and the
> set of possible messages (with the type of their associated data) is
> extensible (say, because components can be loaded dynamically, or just to
> make the application's architecture more modular).  It makes sense to use
> an extensible datatype to represent messages.  Components can react to
> messages with pattern-matching and two components can interact if their
> share a common constructor definition.  This is simpler than encoding open
> datatypes with a "universal" type (with injections/projections).  Of
> course, one can use the existing "exn" type, but then we don't distinguish
> between exceptions and messages at all.
>

Isn't this a good use case for polymorphic variants too ? Compared to open
datatypes, you could suffer from the weaker type checks though: if two
components are supposed to communicate through a constructor, which is
mispelled in one of the component, the error would not be noticed by the
compiler.

my own 2 cent ...
philippe.

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



[Caml-list] Current SVN head and findlib.

2012-04-12 Thread Philippe Veber
Dear camlers,

While playing with the upcoming features of our favorite compiler, I found
that the current trunk and version/4.00 branch do not work well with
findlib (version 1.2.8). I report it here so others might confirm (or not)
what I say.

OCaml version 4.01.0+dev1_2012-03-31

# #use "topfind";;
- : unit = ()
File "/home/pveber/usr/ocamlbrew/ocaml-svn/trunk/lib/ocaml/topfind", line
37, characters 0-22:
Error: Unbound module Topfind

What is really surprising is that the toplevel doesn't complain if I
copy/paste the contents of topfind directly in the compiler:

[gesundheit:~ 14:23]$ocaml <
/home/pveber/usr/ocamlbrew/ocaml-svn/trunk/lib/ocaml/topfind
OCaml version 4.01.0+dev1_2012-03-31

# * *   * * * - : unit = ()
# * * # Findlib has been successfully loaded.
Additional directives:
  #require "package";;  to load a package
  #list;;   to list the available packages
  #camlp4o;;to load camlp4 (standard syntax)
  #camlp4r;;to load camlp4 (revised syntax)
  #predicates "p,q,...";;   to set these predicates
  Topfind.reset();; to force that packages will be reloaded
  #thread;; to enable threads

- : unit = ()

As you can notice, the install was done using ocamlbrew, but I could
reproduce the same problem directly installing ocaml and findlib. As I'd
rather not dump some foolishness of mine in mantis, I'd be glad somebody
could check this. Using ocamlbrew, this can be as simple as:

export OCAMLBREW_FLAGS="-t -a"
export OCAMLBREW_BASE=/home/joe/ocamlbrew
curl -kL https://raw.github.com/hcarty/ocamlbrew/master/ocamlbrew-install |
bash

The problem is present if ocamlbrew stops before installing utop.

Cheers,
  Philippe.

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] Explicitely named type variable and type constraints.

2012-03-21 Thread Philippe Veber
Thanks for your answer Jacques!

>  ([> `quit ] as 'a) screen = (module Screen with type message =
> 'a)
> >but an expression was expected of type (module Screen)
>
> Indeed, this is clearly wrong: these two module types are not equivalent.
>
Right, that one was obvious.


> > New attempt:
> >
> > # let f (screen : 'a screen) =
> > let module Screen = (val screen : Screen with type message = 'a) in
> > match Screen.(emit init) with
> >   | Some `quit -> 1
> >   | _ -> 0
> >
> >   ;;
> > Error: Unbound type parameter 'a
>
> Wrong again, as subtyping between module signatures does not
> allow free type variables.
>
At some point, I remember having a message saying that indeed type
variables are not allowed while unpacking the module, at least something
closer to what you say and more specific than "unbound type parameter 'a".
So I'd say it would be more convenient to have a specific message (just
like there is for unbound type variables in class definitions for
instance). If you don't consider it too futile, I can test it on the SVN
head and file a bug report if appropriate.


>
> > Though here I'm not sure the error is right. New attempt:
> >
> >
> > # let f (type s) (screen : s screen) =
> > let module Screen = (val screen : Screen with type message = s) in
> > match Screen.(emit init) with
> >   | Some `quit -> 1
> >   | _ -> 0
> >
> >   ;;
> > Error: This type s should be an instance of type [> `quit ]
> >
> > Which makes sense. So here is my question: is there a way to impose a
> constraint on the "newtype" introduced in argument? Let me say that I'm
> aware I should write this more simply. For instance in the module type
> Screen, emit could have type state -> [`quit | `message of message]. So my
> question is only a matter of curiosity. Still, I'd be happy to know :o).
>
> No, currently there is no way to do that.
> One can only create locally abstract types, not locally private types.
>
Ok.


> In theory I see no problem doing that, but with the current approach this
> would require new syntax,
> and be rather heavy.
>
>  let f (type s = private [> `quit]) (screen : s screen) = ...
>
> And to be fully general, recursion between those types should be allowed
> too...
>
Probably not worth the trouble. I'm just not used to writing a type and not
being able to write a function using values of this type afterwards :o).


>
> As a side note, writing
>type message = private [> unit]
> makes the problem clearer.
> And solves it in some cases:
>
> module type Screen =
>  sig
>type state
> type message = private [> `quit ]
>val init : state
> val emit : state -> message option
>  end
> # let f (module Screen : Screen) =
> match Screen.(emit init) with
>| Some `quit -> 1
>| _ -> 0
>  ;;
> val f : (module Screen) -> int = 
>
Indeed that works! (with appropriate 3.12 syntax).

# module type Screen
=

 sig

   type
state

   type message = private [> `quit
]

   val init :
state

   val emit : state -> message
option

 end;;

module type Screen
=


sig

type
state

type message = private [> `quit ]
val init : state
val emit : state -> message option
  end
# let f screen = let module Screen = (val screen : Screen) in match
Screen.emit Screen.init with Some `quit -> 1 | _ ->
0;;
val f : (module Screen) -> int =


# module Screen1 : Screen = struct type state = unit type message = [`a |
`quit] let init = () let emit () = Some `a
end;;
module Screen1 :
Screen

# module Screen2 : Screen = struct type state = int type message = [`a |
`quit] let init = 0 let emit _ = Some `quit
end;;
module Screen2 :
Screen

# [ (module Screen1 : Screen) ; (module Screen2 : Screen)
];;

- : (module Screen) list = [;
]


This nearly solves my problem: there will be several Screen modules, and
those should share a common message type, so that they can communicate.
That's why I introduced the 'a screen type. However, it seems that I can't
define it anymore:

# type 'a screen = (module Screen with type message = 'a) constraint 'a =
[>
`quit];;

Error: In this `with' constraint, the new definition of
message

   does not match its original definition in the constrained
signature:

   Type declarations do not
match:

 type message
   is not included in
 type message = private [> `quit ]

# type 'a screen = (module Screen with type message = 'a constraint 'a = [>
`quit]);;

Error: Syntax
error


It's only logical the first attempt fails. The second, however, seems more
reasonable to me (but I guess if type constraints are only allowed in type
definition there must be a good reason). Is there a workaround? In the end,
I'd want to define a list of Screen modules that share a common message
type containing the `quit tag. That said, I remember the work by Romain
Bardou and yourself on unions of private polymorphic variants, and I guess
we might face difficult problems here. In any case, I have a backup
solution, so it's no

[Caml-list] Explicitely named type variable and type constraints.

2012-03-21 Thread Philippe Veber
Hi,

I found myself defining a type that would both contain a module type and a
type constraint:

  module type Screen = sig
type state
type message
val init : state
[...]
   val emit : state -> message option
  end
  type 'a screen = (module Screen with type message = 'a) constraint 'a =
[> `quit]

That is supposed to express that screens emit messages, and that one of the
messages can be "quit". Now I've got some trouble when using the 'a screen
type in a function that unpack the module it contains:

  let f (screen : 'a screen) =
let module Screen = (val *screen* : Screen) in
match Screen.(emit init) with
  | Some `quit -> 1
  | _ -> 0

  ;;
Error: This expression has type
 ([> `quit ] as 'a) screen = (module Screen with type message = 'a)
   but an expression was expected of type (module Screen)

New attempt:

# let f (screen : 'a screen) =
let module Screen = (val screen : Screen with type message = 'a) in
match Screen.(emit init) with
  | Some `quit -> 1
  | _ -> 0

  ;;
Error: Unbound type parameter 'a

Though here I'm not sure the error is right. New attempt:


# let f (type s) (screen : s screen) =
let module Screen = (val screen : Screen with type message = s) in
match Screen.(emit init) with
  | Some `quit -> 1
  | _ -> 0

  ;;
Error: This type s should be an instance of type [> `quit ]

Which makes sense. So here is my question: is there a way to impose a
constraint on the "newtype" introduced in argument? Let me say that I'm
aware I should write this more simply. For instance in the module type
Screen, emit could have type state -> [`quit | `message of message]. So my
question is only a matter of curiosity. Still, I'd be happy to know :o).

Cheers,
  Philippe.

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] Efficient scanning of large strings from files

2012-03-21 Thread Philippe Veber
2012/3/19 Edgar Friendly 

> On 03/19/2012 05:08 AM, Philippe Veber wrote:
>
>> Thanks Edgar and Jérémie, this indeed seems to be the right track. I
>> just hope that a repeated use of input_char is not 10-100X slower than
>> input_line :o).
>> ph.
>>
>>  Quite true - instead of giving the matcher just a single byte at a time,
> it is more efficient to give it blocks of data, as long as it can keep its
> state from one block to the next.  But its matching internally will be on
> one byte at a time, normally.

Thanks for the confirmation, I now see more clearly what to do.


> I guess with DNA, because of the reduced character set, it'd be possible
> to get each symbol down to 2 bits (if you're really just using ACGT), in
> which case, the matcher could run 4 basepairs at a time, but there's a lot
> of corner issues doing things that way.  A lot depends on how much time and
> effort you're willing to spend engineering something.
>
Maybe not that far yet, but this is something we've mentionned for biocaml.
I guess I could take some inspiration from the bitset module in Batteries.
Anyway thanks everybody for your help!
ph.


>
> E.
>
>  2012/3/16 Edgar Friendly > <mailto:thelema...@gmail.com>>
>>
>>
>>So given a large file and a line number, you want to:
>>1) extract that line from the file
>>2) produce an enum of all k-length slices of that line?
>>3) match each slice against your regexp set to produce a list/enum
>>of substrings that match the regexps?
>>Without reading the whole line into memory at once.
>>
>>I'm with Dimino on the right solution - just use a matcher that that
>>works incrementally, feed it one byte at a time, and have it return
>>a list of match offsets.  Then work backwards from these endpoints
>>to figure out which substrings you want.
>>
>>There shouldn't be a reason to use substrings (0,k-1) and (1,k) - it
>>should suffice to use (0,k-1) and (k,2k-1) with an incremental
>>matching routine.
>>
>>E.
>>
>>
>>
>>On Fri, Mar 16, 2012 at 10:48 AM, Philippe Veber
>>> <mailto:philippe.veber@gmail.**com>>
>> wrote:
>>
>>Thank you Edgar for your answer (and also Christophe). It seems
>>my question was a bit misleading: actually I target a subset of
>>regexps whose matching is really trivial, so this is no worry
>>for me. I was more interested in how accessing a large line in a
>>file by chunks of fixed length k. For instance how to build a
>>[Substring.t Enum.t] from some line in a file, without building
>>the whole line in memory. This enum would yield the substrings
>>(0,k-1), (1,k), (2,k+1), etc ... without doing too many string
>>copy/concat operations. I think I can do it myself but I'm not
>>too confident regarding good practices on buffered reads of
>>files. Maybe there are some good examples in Batteries?
>>
>>Thanks again,
>>   ph.
>>
>>
>>
>>
>>
>

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] Efficient scanning of large strings from files

2012-03-19 Thread Philippe Veber
Thanks Edwin and Oliver, I wasn't aware of these libraries. I'll definitely
have a look.
Thanks again everybody for your help on this!
ph.

2012/3/18 Török Edwin 

> On 03/16/2012 04:49 PM, Jérémie Dimino wrote:
> > Le Fri, 16 Mar 2012 14:03:38 +0100,
> > Philippe Veber  a écrit :
> >
> >> Say that you'd like to search a regexp on a file with lines so long
> >> that you'd rather not load them entirely at once. If you can bound
> >> the size of a match by k << length of a line, then you know that you
> >> can only keep a small portion of the line in memory to search the
> >> regexp. Typically you'd like to access substrings of size k from left
> >> to right. I guess such a thing should involve buffered inputs and
> >> avoid copying strings as much as possible. My question is as follows:
> >> has anybody written a library to access these substrings gracefully
> >> and with decent performance? Cheers,
> >
> > You can use a non-backtracking regexp library to find offsets of the
> > substrings, then seek in the file to extract them. You can use for
> > example the libre library from Jérôme Vouillon [1]. It only accept
> > strings as input but it would be really easy to make it work on input
> > channels (just replace "s.[pos]" by "input_char ic").
> >
> >   [1] http://sourceforge.net/projects/libre/
> >   https://github.com/avsm/ocaml-re.git
> >
>
> A nice library for regular expression matching is LibTRE (BSD licensed),
> and it has a way to parse arbitrary data with callbacks:
> http://laurikari.net/tre/documentation/reguexec/
>
> According to the paper it is also good at finding substring matches
> with its tagged NFA:
> http://laurikari.net/ville/regex-submatch.pdf
>
> If you don't use back-references (!tre_have_backrefs) then it guarantees
> linear-time matching.
>
> I couldn't find an OCaml wrapper for it, but should be simple enough to
> write one.
>
> Best regards,
> --Edwin
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> 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 and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: Re: [Caml-list] Efficient scanning of large strings from files

2012-03-19 Thread Philippe Veber
Yes indeed!

2012/3/16 FrancoisCharles MatthieuBerenger 

> hi philippe,
>
> i am curious, is your string a dna sequenceso that s why it is so long?
>
> regards,f
>
>
> On Fri, 16 Mar 2012 10:14:41 -0400
> Edgar Friendly  wrote:
>
> > On 03/16/2012 09:03 AM, Philippe Veber wrote:
> > > Dear camlers,
> > >
> > > Say that you'd like to search a regexp on a file with lines so long
> that
> > > you'd rather not load them entirely at once. If you can bound the size
> > > of a match by k << length of a line, then you know that you can only
> > > keep a small portion of the line in memory to search the regexp.
> > > Typically you'd like to access substrings of size k from left to right.
> > > I guess such a thing should involve buffered inputs and avoid copying
> > > strings as much as possible. My question is as follows: has anybody
> > > written a library to access these substrings gracefully and with decent
> > > performance?
> > > Cheers,
> > >Philippe.
> > >
> > This is tricky to do, as incremental matching implies DFA-based
> > matching, but returning matching substrings implies backtrack-based
> > matching.  The re2 library returns matching substrings by matching
> > forward to find the end of patterns, and then matching backwards on the
> > reversed regex from that point to find their beginning.  I don't know if
> > even it supports this on incremental input.
> >
> > Subject to the assumption that starting to match implies either
> > finishing or aborting a match (i.e. once you've started to match your
> > regex, no other match will start before either this match attempt
> > finishes successful or not), this is not unreasonable to do.  Without
> > this assumption, it requires tracking many match start locations and
> > somehow knowing which of them match or fail to match.  I'm not sure this
> > has been done before.
> >
> > E.
> >
> > --
> > Caml-list mailing list.  Subscription management and archives:
> > https://sympa-roc.inria.fr/wws/info/caml-list
> > 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 and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] Efficient scanning of large strings from files

2012-03-19 Thread Philippe Veber
Thanks Edgar and Jérémie, this indeed seems to be the right track. I just
hope that a repeated use of input_char is not 10-100X slower than
input_line :o).
ph.

2012/3/16 Edgar Friendly 

> So given a large file and a line number, you want to:
> 1) extract that line from the file
> 2) produce an enum of all k-length slices of that line?
> 3) match each slice against your regexp set to produce a list/enum of
> substrings that match the regexps?
> Without reading the whole line into memory at once.
>
> I'm with Dimino on the right solution - just use a matcher that that works
> incrementally, feed it one byte at a time, and have it return a list of
> match offsets.  Then work backwards from these endpoints to figure out
> which substrings you want.
>
> There shouldn't be a reason to use substrings (0,k-1) and (1,k) - it
> should suffice to use (0,k-1) and (k,2k-1) with an incremental matching
> routine.
>
> E.
>
>
>
> On Fri, Mar 16, 2012 at 10:48 AM, Philippe Veber  > wrote:
>
>> Thank you Edgar for your answer (and also Christophe). It seems my
>> question was a bit misleading: actually I target a subset of regexps whose
>> matching is really trivial, so this is no worry for me. I was more
>> interested in how accessing a large line in a file by chunks of fixed
>> length k. For instance how to build a [Substring.t Enum.t] from some line
>> in a file, without building the whole line in memory. This enum would yield
>> the substrings (0,k-1), (1,k), (2,k+1), etc ... without doing too many
>> string copy/concat operations. I think I can do it myself but I'm not too
>> confident regarding good practices on buffered reads of files. Maybe there
>> are some good examples in Batteries?
>>
>> Thanks again,
>>   ph.
>>
>>
>>
>

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] Efficient scanning of large strings from files

2012-03-16 Thread Philippe Veber
2012/3/16 Edgar Friendly 

> On 03/16/2012 09:03 AM, Philippe Veber wrote:
>
>> Dear camlers,
>>
>> Say that you'd like to search a regexp on a file with lines so long that
>> you'd rather not load them entirely at once. If you can bound the size
>> of a match by k << length of a line, then you know that you can only
>> keep a small portion of the line in memory to search the regexp.
>> Typically you'd like to access substrings of size k from left to right.
>> I guess such a thing should involve buffered inputs and avoid copying
>> strings as much as possible. My question is as follows: has anybody
>> written a library to access these substrings gracefully and with decent
>> performance?
>> Cheers,
>>   Philippe.
>>
>>  This is tricky to do, as incremental matching implies DFA-based
> matching, but returning matching substrings implies backtrack-based
> matching.  The re2 library returns matching substrings by matching forward
> to find the end of patterns, and then matching backwards on the reversed
> regex from that point to find their beginning.  I don't know if even it
> supports this on incremental input.
>
> Subject to the assumption that starting to match implies either finishing
> or aborting a match (i.e. once you've started to match your regex, no other
> match will start before either this match attempt finishes successful or
> not), this is not unreasonable to do.  Without this assumption, it requires
> tracking many match start locations and somehow knowing which of them match
> or fail to match.  I'm not sure this has been done before.
>
> E.
>
Thank you Edgar for your answer (and also Christophe). It seems my question
was a bit misleading: actually I target a subset of regexps whose matching
is really trivial, so this is no worry for me. I was more interested in how
accessing a large line in a file by chunks of fixed length k. For instance
how to build a [Substring.t Enum.t] from some line in a file, without
building the whole line in memory. This enum would yield the substrings
(0,k-1), (1,k), (2,k+1), etc ... without doing too many string copy/concat
operations. I think I can do it myself but I'm not too confident regarding
good practices on buffered reads of files. Maybe there are some good
examples in Batteries?

Thanks again,
  ph.

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



[Caml-list] Efficient scanning of large strings from files

2012-03-16 Thread Philippe Veber
Dear camlers,

Say that you'd like to search a regexp on a file with lines so long that
you'd rather not load them entirely at once. If you can bound the size of a
match by k << length of a line, then you know that you can only keep a
small portion of the line in memory to search the regexp. Typically you'd
like to access substrings of size k from left to right. I guess such a
thing should involve buffered inputs and avoid copying strings as much as
possible. My question is as follows: has anybody written a library to
access these substrings gracefully and with decent performance?
Cheers,
  Philippe.

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] Re: [oss-security] CVE request: Hash DoS vulnerability (ocert-2011-003)

2012-03-13 Thread Philippe Veber
The best compromise to me is to leave the default for Hashtbl, but properly
document this aspect in the manual (with succint explanation and one
relevant pointer). That way:
- you don't break compatibility
- you keep default reproducibility (which is a real feature)
- you teach beginners like myself on tough aspects related to the use of a
datastructure in some frequent use cases.

Having a default randomisation seems much too intrusive to me
(notwithstanding the importance of web programming for ocaml's future ;o))
and for those changes that modify the semantic of a program, you have to be
in control. So I second Paolo's opinion.

However, assuming ocaml users will be "aware of attacks", at least more
than users of other languages, is not only controversial but also non
relevant: there are beginners in ocaml too (who may also be beginners in
programming), and these should be taken care of. A small note in the doc on
the DOS vulnerability that may arise from the use of Hashtbl in a web
application context is enough to protect the users I think, and is of
interest for the casual Hashtbl reader. This note could appear in a
different font/color than the main description of [Hashtbl.create], to
preserve the readability of the docs.

my 2 cent
ph.

2012/3/13 Paolo Donadeo 

> In my humble opinion, here we have two different vision of what
> computer programming is, or should be. Your statement "maybe it's
> better to assume that the programmer will not be aware of attacks" may
> be true for the average Java programmer (please, no flame, no insult
> intended to Java programmers reading this list!) but not for an OCaml
> programmer. I want to be perfectly aware of attacks, and I want to be
> in control of the data structure I use, and not "be unaware"...
>
> In Python, the other language I use every day, dictionaries are
> implemented as hash tables and not having reproducibility is a PITA.
>
>
> --
> Paolo
>
>
> On Tue, Mar 13, 2012 at 10:54, Romain Bardou 
> wrote:
> > Hi,
> >
> >
> >> As you and Gerd said, the new Hashtbl implementation in the upcoming
> >> major release has everything needed to randomize hash tables by
> >> seeding.  The question at this point is whether randomization should
> >> be the default or not: some of our big users who don't do Web stuff
> >> value reproducibility highly...  We (OCaml core developers) will take
> >> a decision soon.
> >
> >
> > FWIW, as a developer I do not expect reproducibility from Hash tables
> (nor
> > from the Random module actually) but I do expect some way to control
> > reproducibility (i.e. read the current seed, give my own seed). Maybe
> it's
> > better to assume that the programmer will not be aware of attacks, and
> > provide him with a safer environment.
> >
> > On the other hand, when you find a bug and need reproducibility, it's too
> > late if you have used a random seed without recording it. And could it
> break
> > some existing applications?
> >
> > I guess you('re) already had(having) this discussion though.
> >
> > Cheers,
> >
> > --
> > Romain
>
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> 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 and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] A js_of_ocaml equivalent for the JVM?

2012-03-12 Thread Philippe Veber
Thank you Xavier and Johan for the replies.

2012/3/9 fo...@x9c.fr 

>
> Le 9 mars 2012 à 18:45, Johan Grande a écrit :
>
> > Le 09/03/2012 18:12, Philippe Veber a écrit :
> >> Dear camlers,
> >> I used js_of_ocaml several times and was really stunned of how clever
> >> (notably because writing interfaces boils down to writing types) and
> >> efficient this approach is. Would a similar thing work for the JVM, that
> >> is a compiler from ocaml bytecode to java bytecode?
>
> It is not easy to envision such a tool on the JVM, because of the current
> restrictions imposed on Java bytecode. As an example, the size of a method
> is currently limited to 64Ko, which is clearly way too small for non
> trivial
> programs.

I see the point. It sure is a problem to reuse the same compilation scheme
than in js_of_ocaml.



>
>
> >> I guess it wouldn't
> >> provide a full interoperability with java, in the sense that creating or
> >> extending classes may not be possible (well, why not after all?).
> >> However, being able to run an ocaml program on the JVM reusing existing
> >> java libraries would be so useful already!
>
> I am currently working on this for OCaml-Java (see below).
>
I must admit one of the most exciting feature of js_of_ocaml (beside
efficiency) is the way ocaml interfaces with javascript. I remember the
procedure was much heavier with nickel. In another thread (
http://www.mail-archive.com/caml-list@inria.fr/msg02094.html) you said that
this has changed in the version you're currently developing. I look forward
to see how it works (I'm in if you need alpha testers).


>
>
> >> Are there known obstacles to this? Has anyone tried something in this
> >> direction?
>
> Well, no real obstacle as OCaml-Java showed.
> However, OCaml-Java 1.x is still a bare proof of concept due to both
> poor design choices and JVM limitations. But then came Java 1.7 and
> some limitations were removed (e. g. a garbage collector better suited
> to functional languages, and an implementation of method handles).
> OCaml-Java has been largely rewritten and now exhibit acceptable
> performances.
>
This is really great.


>
>
> >> Would there be a chance to support multicore programming that
> >> way?
>
> Yes, it is actually working. But not released yet.
> Starting from vanilla OCaml, you "only" need two things:
>  1/ have a reentrant runtime;
>  2/ have a parallel garbage collector.
> OCaml-Java implements the former, while all modern JVMs provide the latter.
> So, basically, it just works.

itou


> The great difficulty is then to provide the good
> abstractions to make the life of the programmer as easy as possible.
> I mean: who would like to program with locks?
>
Well I'm not much into multicore programming myself, but at least for
advertisement purposes, it cannot hurt ;o).



>
>
> >> I hope these are not silly questions (sorry if they are!)
> >
> > http://ocamljava.x9c.fr
>
> Thanks for the plug. However, OCaml-Java is quite different and provides
> two tools:
>  - an equivalent of ocamlrun written in Java (meaning you can interpret
>OCaml bytecode inside a JVM);
>  - an equivalent of ocamlc/ocamlopt for Java (meaning you can compile
>OCaml sources to Java jar files to be executed by a JVM).
>

Thanks for the news and clarifications!


>
>
> Kind regards,
>
> Xavier Clerc
>
>
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> 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 and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



[Caml-list] A js_of_ocaml equivalent for the JVM?

2012-03-09 Thread Philippe Veber
Dear camlers,
I used js_of_ocaml several times and was really stunned of how clever
(notably because writing interfaces boils down to writing types) and
efficient this approach is. Would a similar thing work for the JVM, that is
a compiler from ocaml bytecode to java bytecode? I guess it wouldn't
provide a full interoperability with java, in the sense that creating or
extending classes may not be possible (well, why not after all?). However,
being able to run an ocaml program on the JVM reusing existing java
libraries would be so useful already!

Are there known obstacles to this? Has anyone tried something in this
direction? Would there be a chance to support multicore programming that
way? I hope these are not silly questions (sorry if they are!)

Best,
  Philippe.

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] Functional GUI programming: looking for good practices

2012-02-22 Thread Philippe Veber
(fun k ->
>> fn k;
>> abort level () )
>>
>> "shift" and "abort" are delimcc. This runs the given function "fn" with a
>> continuation 'k'... so this continuation is the "return" function passed to
>> menu_of_list, and therefore bound to each menu-button. The abort exits the
>> "ui coroutine", resuming the mainline, hence the name: yield.
>>
>> The continuation 'k' comes from the shift... the continuation is the code
>> "outside" of the shift call... so when it's called (by the mainline's
>> gui_react), it resume at the end of 'yield' and keep on going... in this
>> example, handling the returned action!
>>
>> I hope this conveys at least the gist of what's going on... I read a lot
>> of papers over-and-over, not understanding... although none were
>> specifically GUI. Delimited continuations have numerous applications and a
>> surprising number of configurations for just a pair of functions! (Abort is
>> really a special case of "reset"... so it's shift and reset, in ump-teen
>> configurations.)
>>
>> I'll try to explain if you have any further questions! However, I'm still
>> trying to sort out how best to write my GUI code -- there is a lot of room
>> for improvement. :)
>>
>>  -Tony
>>
>> PS. I'd like to blame X. Leroy ;)... for a post some 10 years ago
>> replying to someone's attempt to do a GUI in OCaml... Xavier casually
>> replied something like "oh, you can use coroutines". That was a wild goose
>> chase (or Dahu?)! Delimcc didn't exist at the time, and it's native-code
>> implementation came about just a few years ago (thank-you Oleg!). Even
>> then, I had no idea how I was supposed to use a coroutine to write GUI
>> code! Oh well, it was an adventure, and I still don't know if this is a
>> good thing, but I like it a lot more than "signals and slots" -- the usual
>> scattered GUI code which is connected by messages/events.
>>
>>
>> On Tue, Feb 14, 2012 at 3:17 AM, Philippe Veber > > wrote:
>>
>>> Hi Anthony,
>>>
>>> This looks interesting, however as I'm not very familiar with delimcc
>>> (that's a shame, I admit), I fail to understand the flow of the program.
>>> Would you mind giving a snippet of the update loop you mentionned?
>>>
>>>
>>>> So far, I'm not sure how well this works out for a complete project. I
>>>> like it so far, but I have complexity growing in some "update loop" stuff,
>>>> which are little closures I add to be run each frame-update for reacting to
>>>> mouse-over/hover.
>>>>
>>>>
>>>
>>> Good luck in the hunt for elegant UI (code)!
>>>>
>>>
>>> Let's hope I'm not just Dahu hunting!
>>> (http://en.wikipedia.org/wiki/Dahu)
>>>
>>>
>>>
>>>>
>>>>  Tony
>>>>
>>>>
>>>
>>
>

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] Functional GUI programming: looking for good practices

2012-02-14 Thread Philippe Veber
Hi Daniel,

2012/2/14 Daniel Bünzli 

> Le mardi, 14 février 2012 à 11:02, Philippe Veber a écrit :
>
> > In other words, am I allowed to call a primitive in a lifted function?
> No. This is documented here [1].

Well I did read the paragraph, but thought the described limitation might
be about updating a signal from different threads. Of course it makes sense
that even in a single-threaded code, an update cycle should not be
interrupted by another if there are shared dependencies. May I nevertheless
humbly suggest to add the "not calling a primitive inside a lifted
function" rule more explicitely, as it is a tempting sin for a beginner?


> One way to side-step the issue is to put these updates in a queue and
> execute them after the update cycle ended.
>
 That seems a good work-around, to gather all side-effects in one place,
namely a (unit -> unit) Queue.t where to defer all calls to the primitives.
That do help, thanks !
ph.


> Best,
>
> Daniel
>
> [1] http://erratique.ch/software/react/doc/React#update
>

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] Functional GUI programming: looking for good practices

2012-02-14 Thread Philippe Veber
Hi Anthony,

This looks interesting, however as I'm not very familiar with delimcc
(that's a shame, I admit), I fail to understand the flow of the program.
Would you mind giving a snippet of the update loop you mentionned?


> So far, I'm not sure how well this works out for a complete project. I
> like it so far, but I have complexity growing in some "update loop" stuff,
> which are little closures I add to be run each frame-update for reacting to
> mouse-over/hover.
>
>

Good luck in the hunt for elegant UI (code)!
>

Let's hope I'm not just Dahu hunting!
(http://en.wikipedia.org/wiki/Dahu)



>
>  Tony
>
>

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] Functional GUI programming: looking for good practices

2012-02-14 Thread Philippe Veber
2012/2/13 Adrien 

> On 13/02/2012, Philippe Veber  wrote:
> > Dear camlers,
> >
> > I'm looking for advanced examples of GUI programming in functional style.
> > As I'm aware there is no definitive answer on this topic, I'll gladly
> read
> > about pragmatic approaches which may fail to be fully declarative, but do
> > work well in practice. Lately I've been trying to write a little GUI API,
> > replacing all mutable values by React signals (
> > http://erratique.ch/software/react), but it turns out to be more
> difficult
> > than expected, for example with layout management. In order to compute a
> > layout for the widgets, some information has to travel bottom up the
> widget
> > hierarchy, and some goes top down. While there is a well-founded order
> for
> > defining all signals, it's more difficult to group them in their
> respective
> > widget and still avoid mutually recursive definitions. More generally I'd
> > interested in good (and pragmatic !) techniques for GUI programming, with
> > some real life code.
> > Cheers,
> >   Philippe.
>
> Since FRP is quite "new" and not well understood, I'm going to try to
> summarize how I understan it: it makes it possible to use functional code
> for a task that has typically relied on mutability, with all the benefits
> we're used to.
>
With, I think, an additional benefit: making things difficult to write when
we would have done something fishy with mutable references. It's just that
sometimes it's difficult to avoid fishy stufff :o).


>
>
> I've created a lablgtk branch named "adrien/react" to get react signals out
> of gtk properties and react events out of gtk signals (they match quite
> well). Support isn't perfect but enough to test and experiment.
>
> The issue was to write the application itself: it was way too complicated
> and it involved many many react values which had to be somehow kept alive.
> It was also not very useful. The reason was that the very first thing I
> would do with all the events was React.E.select: I would create distinct
> signals only to merge them!
>
> What I've started doing instead is to have one "object" with a
> corresponding
> event: callbacks only send a message to that event and look like "send
> (`Foo
> bar)" and from then I can use match over the message in a different
> location
> in the code, typically in an FRP context.
>
I did that too, and it does seem a good practice: a central bus for
information that is relevant to the whole application. I have a question on
this particular aspect: suppose this bus is updated through the primitive
(broadcast : message -> unit), and that I have a bool event ev that
(indirectly) depends on the bus. Am I allowed to define the following event:

let action = React.E.map (fun b -> if b then broadcast `action ; not b) ev

In other words, am I allowed to call a primitive in a lifted function?


>
>
> (* Warning: this is about work in-progress; it might not always make sense,
> might have some weird things and I might not be able to explain everything
> properly. *)
>
> My current application is a web browser which I want to make much more
> intelligent than the browsers available today.

Just curious: in what way?


> For this reason, I store
> web pages in a data structure which is of course purely functional. I can
> have several layers of data structures containing objects in the same way.
>
> My objects start with a default state and evolve (in a functional way)
> through a fold according to the messages they receive. Each time the state
> changes, two sets of callbacks are triggered: first, to change the UI;
> second, to update the data structure containing the object which is needed
> because of functional updates. I also use that last mechanism to propagate
> messages from the inner objects to the outter ones.
>
> One last characteristic is that I have a UI side besides the functional
> one.
> It contains a handful of things which are needed to work with GTK.I also
> use
> it to propagate messages from the outter objects to the inner ones.
>
> This is work-in-progress and some details could be improved but I think
> that
> the big picture is there. As far as I can tell, the UI and functional sides
> are properly separated, constraints aren't heavy and I seem to be able to
> get the usual qualities of ocaml in GUIs.
>
What module would you recommend reading to get a taste of it?



>
>
> Generally speaking, FRP is not the silver bullet for GUIs. Maybe for
> Haskell
> but definitely not for OCaml. The main reason is probably that most C
> libraries have a sp

[Caml-list] Functional GUI programming: looking for good practices

2012-02-13 Thread Philippe Veber
Dear camlers,

I'm looking for advanced examples of GUI programming in functional style.
As I'm aware there is no definitive answer on this topic, I'll gladly read
about pragmatic approaches which may fail to be fully declarative, but do
work well in practice. Lately I've been trying to write a little GUI API,
replacing all mutable values by React signals (
http://erratique.ch/software/react), but it turns out to be more difficult
than expected, for example with layout management. In order to compute a
layout for the widgets, some information has to travel bottom up the widget
hierarchy, and some goes top down. While there is a well-founded order for
defining all signals, it's more difficult to group them in their respective
widget and still avoid mutually recursive definitions. More generally I'd
interested in good (and pragmatic !) techniques for GUI programming, with
some real life code.
Cheers,
  Philippe.

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] Fwd: interval trees

2012-02-12 Thread Philippe Veber
2012/2/11 Edgar Friendly 

> On 02/11/2012 12:38 PM, Goswin von Brederlow wrote:
>
>> On Fri, Feb 10, 2012 at 10:07:05AM +0900, Francois Berenger wrote:
>>>
 I need to use an interval tree.

 Biocaml has one, batteries have imap/iset, nice!

  Anyone have something like this but for non-overlapping intervals and
>> allowing interval insertion and removal with merging and spliting of the
>> internaly used intervals?
>>
>
> Yes, IMap / ISet (borrowed from camomile and improved) do this.  I assume
> biocaml's is the same.

Actually no, biocaml_intervalTree keeps the inserted intervals untouched,
it is in fact pretty similar to an interval multimap, with some specialized
operations. In cases when we want to describe a set of integers (vs a set
of intervals), we use ISet from Batteries. With these two structures we can
describe an interesting range of genome annotations.



>
>
> E.
>
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/**wws/info/caml-list
> 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 and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] Fwd: interval trees

2012-02-11 Thread Philippe Veber
Hi François,

The Biocaml_intervalTree module is merely a specialization of Set in the
standard library. It should be fairly easy to functorize it over a type
with a total order relation. I think you might even sed -e 's/int/float/g'
the current implementation (with a couple of additional and minor
modifications).

ph.

2012/2/10 Francois Berenger 

>  Original Message 
> Subject: interval trees
> Date: Thu, 09 Feb 2012 17:30:21 +0900
> From: Francois Berenger
> To: 
> batteries-discuss@lists.forge.**ocamlcore.org
> CC: bioc...@googlegroups.com
>
> Hello,
>
> I need to use an interval tree.
>
> Biocaml has one, batteries have imap/iset, nice!
>
> However, I have intervals of reals, not integers. :(
>
> I want to build the tree (once), then query it with a real number
> (many times) like in: which intervals contain the query real number?
>
> Should I convert my floats to ints (by sorting them then ranking) before
> inserting them into some existing interval tree for integers?
> I am not so concerned about the pre-processing time.
>
> Should I write from scratch?
>
> Thanks for any suggestion,
> F.
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/**wws/info/caml-list
> 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 and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] ocamldoc option with oasis

2012-01-14 Thread Philippe Veber
2012/1/14 Török Edwin 

> On 01/14/2012 11:01 PM, Philippe Veber wrote:
>
>> 2012/1/14 Christophe 
>> TROESTLER
>> >
>>
>>  On Sat, 14 Jan 2012 20:47:17 +0100, Philippe Veber wrote:
>>>
>>>>
>>>> Is there a way to pass an option (in my case -charset utf8) to ocamldoc
>>>> when using oasis? Said differently, I'd like to customize the command
>>>>
>>> used
>>>
>>>> by oasis to generate the target of a Document section.
>>>>
>>>
>>> This was discussed some time ago but I am not sure whether it was
>>> implemented.  You can use a custom generator to achieve the same thing
>>> however.
>>>
>>> class gen =
>>> object(self)
>>>  inherit Odoc_html.html
>>>
>>>  initializer
>>>character_encoding<-
>>>  ">>http-equiv=\"Content-Type\">\**n"
>>> end
>>>
>>> let () =
>>>  Odoc_args.set_doc_generator (Some(new gen :>  Odoc_args.doc_generator))
>>>
>>> Best,
>>> C.
>>>
>>>  Thank you Christophe for this quick answer. I had found the thread you
>> mention:
>>
>> http://caml.inria.fr/pub/ml-**archives/caml-list/2010/06/**
>> 5a947fba35df60a35bdc89a4bea1a8**69.fr.html<http://caml.inria.fr/pub/ml-archives/caml-list/2010/06/5a947fba35df60a35bdc89a4bea1a869.fr.html>
>>
>> and could check that Maxence Guesdon indeed added a -charset option, to
>> make this process easier. However, I'm under the impression that the
>> problem remains: I have to tell oasis to use ocamldoc with the custom
>> generator, which requires to customize the ocamldoc command. Did I miss
>> something?
>> Thanks again,
>> ph.
>>
>>
> You can add flags to the ocamldoc command by adding something like to the
> end
> of your myocamlbuild.ml:
>
> Ocamlbuild_plugin.dispatch (function
> | After_rules as e ->
>flag ["doc"; "ocaml"] &
>(S[A"-colorize-code";A"-stars"**;A"-charset";A"utf8"]);
>
>dispatch_default e
> | e ->
>dispatch_default e)
> ;;
>


This worked just fine, thanks a lot Edwin!



>
> Maybe oasis could offer a way to do this automatically (XocamlbuildFlags?).
>
In the meantime, I'll be happy with this.


ph.



>
> Best regards,
> --Edwin
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/**wws/info/caml-list<https://sympa-roc.inria.fr/wws/info/caml-list>
> Beginner's list: 
> http://groups.yahoo.com/group/**ocaml_beginners<http://groups.yahoo.com/group/ocaml_beginners>
> Bug reports: 
> http://caml.inria.fr/bin/caml-**bugs<http://caml.inria.fr/bin/caml-bugs>
>
>

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] ocamldoc option with oasis

2012-01-14 Thread Philippe Veber
2012/1/14 Christophe TROESTLER 

> On Sat, 14 Jan 2012 20:47:17 +0100, Philippe Veber wrote:
> >
> > Is there a way to pass an option (in my case -charset utf8) to ocamldoc
> > when using oasis? Said differently, I'd like to customize the command
> used
> > by oasis to generate the target of a Document section.
>
> This was discussed some time ago but I am not sure whether it was
> implemented.  You can use a custom generator to achieve the same thing
> however.
>
> class gen =
> object(self)
>  inherit Odoc_html.html
>
>  initializer
>character_encoding <-
>  "http-equiv=\"Content-Type\">\n"
> end
>
> let () =
>  Odoc_args.set_doc_generator (Some(new gen :> Odoc_args.doc_generator))
>
> Best,
> C.
>
Thank you Christophe for this quick answer. I had found the thread you
mention:

http://caml.inria.fr/pub/ml-archives/caml-list/2010/06/5a947fba35df60a35bdc89a4bea1a869.fr.html

and could check that Maxence Guesdon indeed added a -charset option, to
make this process easier. However, I'm under the impression that the
problem remains: I have to tell oasis to use ocamldoc with the custom
generator, which requires to customize the ocamldoc command. Did I miss
something?
Thanks again,
ph.

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



[Caml-list] ocamldoc option with oasis

2012-01-14 Thread Philippe Veber
Dear camlers,

Is there a way to pass an option (in my case -charset utf8) to ocamldoc
when using oasis? Said differently, I'd like to customize the command used
by oasis to generate the target of a Document section.

Cheers,
  Philippe.

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] Compiling the ocaml distribution under multiarched Debian/Ubuntu

2012-01-14 Thread Philippe Veber
Reported by Gerd:

http://caml.inria.fr/mantis/view.php?id=5477


Le 13 janvier 2012 17:53, Philippe Veber  a écrit
:

>
>
> Le 13 janvier 2012 17:47, Gerd Stolpmann  a écrit
> :
>
> Am Freitag, den 13.01.2012, 17:13 +0100 schrieb Adrien:
>> > On 13/01/2012, Gerd Stolpmann  wrote:
>> > > Am Freitag, den 13.01.2012, 15:17 +0100 schrieb Philippe Veber:
>> > >> pveber@gesundheit:~/usr/src/ocaml-3.12.1$ pkg-config --libs x11
>> > >> -lX11
>> > >
>> > > Traditionally, X11 came with its own system called imake, which is a
>> > > preprocessor for makefiles. If there is now pkg-config support, this
>> is
>> > > very new, or an extension by the distributor.
>> >
>> > I don't know how old this would be but it's upstream at least in
>> libX11-1.4.2.
>>
>> So far I can trace it the file x11.pc appeared in xorg's version of X.
>> So quite a time ago. Note that especially commercial OS are behind when
>> it comes to renewing X11. E.g. I saw complaints that MacOS 10.4 did not
>> ship it, and it was first available in 10.5 (2007). OpenSolaris fixed it
>> in 2008. The commercial Solaris probably still misses it.
>>
>> Anyway, I think we should use pkg-config if available.
>>
>> Philippe: Did you already file a bug?
>>
> Not yet, but I'd be happy to. Do you mean ocaml or godi's bug tracker? I
> must say I'm not exactly an expert on these issues so I'd understand if
> you'd rather file the bug yourself, for clarity's sake.
>
> ph.
>
>
>
>>
>> Gerd
>>
>> > Regards,
>> > Adrien Nader
>> >
>>
>> --
>> 
>> Gerd Stolpmann, Darmstadt, Germanyg...@gerd-stolpmann.de
>> Creator of GODI and camlcity.org.
>> Contact details:http://www.camlcity.org/contact.html
>> Company homepage:   http://www.gerd-stolpmann.de
>> *** Searching for new projects! Need consulting for system
>> *** programming in Ocaml? Gerd Stolpmann can help you.
>> 
>>
>>
>

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] Compiling the ocaml distribution under multiarched Debian/Ubuntu

2012-01-13 Thread Philippe Veber
Le 13 janvier 2012 17:47, Gerd Stolpmann  a écrit :

> Am Freitag, den 13.01.2012, 17:13 +0100 schrieb Adrien:
> > On 13/01/2012, Gerd Stolpmann  wrote:
> > > Am Freitag, den 13.01.2012, 15:17 +0100 schrieb Philippe Veber:
> > >> pveber@gesundheit:~/usr/src/ocaml-3.12.1$ pkg-config --libs x11
> > >> -lX11
> > >
> > > Traditionally, X11 came with its own system called imake, which is a
> > > preprocessor for makefiles. If there is now pkg-config support, this is
> > > very new, or an extension by the distributor.
> >
> > I don't know how old this would be but it's upstream at least in
> libX11-1.4.2.
>
> So far I can trace it the file x11.pc appeared in xorg's version of X.
> So quite a time ago. Note that especially commercial OS are behind when
> it comes to renewing X11. E.g. I saw complaints that MacOS 10.4 did not
> ship it, and it was first available in 10.5 (2007). OpenSolaris fixed it
> in 2008. The commercial Solaris probably still misses it.
>
> Anyway, I think we should use pkg-config if available.
>
> Philippe: Did you already file a bug?
>
Not yet, but I'd be happy to. Do you mean ocaml or godi's bug tracker? I
must say I'm not exactly an expert on these issues so I'd understand if
you'd rather file the bug yourself, for clarity's sake.

ph.



>
> Gerd
>
> > Regards,
> > Adrien Nader
> >
>
> --
> 
> Gerd Stolpmann, Darmstadt, Germanyg...@gerd-stolpmann.de
> Creator of GODI and camlcity.org.
> Contact details:http://www.camlcity.org/contact.html
> Company homepage:   http://www.gerd-stolpmann.de
> *** Searching for new projects! Need consulting for system
> *** programming in Ocaml? Gerd Stolpmann can help you.
> 
>
>

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] Compiling the ocaml distribution under multiarched Debian/Ubuntu

2012-01-13 Thread Philippe Veber
2012/1/13 Gerd Stolpmann 

> Am Freitag, den 13.01.2012, 14:18 +0100 schrieb Stéphane Glondu:
> > Le 13/01/2012 12:59, Philippe Veber a écrit :
> > > Debian and Ubuntu have not so recently switched to multiarch binaries
> > > (including libs, see http://wiki.debian.org/Multiarch/Implementation).
> > > This is an important change for ocaml C bindings since the libraries
> are
> > > now to be found in /usr/lib/ instead of /usr/lib. I
> > > was just bitten by this, when realizing that the ocaml configure script
> > > couldn't find libX11.so and wouldn't install graphics. A similar
> problem
> > > was handled by the people in charge of debian ocaml packages
> > > (http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=619344). Now my
> > > question is the following: will this evolution be a problem for
> GODI/odb
> > > packages (and more generally source distribution), and what is the
> > > advised fix for it?
> >
> > My advice would be to rely on pkg-config (a kind of ocamlfind for C
> > libraries), or similar scripts (pcre-config, etc.) provided by the
> > libraries. Otherwise, there is no good, portable (I mean, not
> > Debian-specific) way to guess where a library is, and the packager will
> > give an explicit path in his call to the configure script in
> > debian/rules. By the way, this is what we did for ocaml [1].
> >
> > [1]
> >
> http://anonscm.debian.org/gitweb/?p=pkg-ocaml-maint/packages/ocaml.git;a=commitdiff;h=1db9b654b7d8b702cddb44df5aea1982f3120883
>
> In GODI there is a library searcher for libs that do not support
> pkg-config et al. It just tries a list of typical paths used by various
> OS. The method works well if the library is not dependent on other
> libraries, and is quite portable. Of course, you cannot be sure to find
> the right library if several versions are installed (which is quite
> common on non-open-source OS where the developer has to do it on its
> own), but otherwise it is good enough for setting a default if the user
> does not have special wishes.
>
> So, e.g. for X11, there is no pkg-config, and GODI falls back to
> searching. Btw, we don't rely here on what the Ocaml configure script
> finds out, but have our own searcher, simply because this makes it
> easier to respect users' wishes.
>
'seems like pkg-config was updated:

pveber@gesundheit:~/usr/src/ocaml-3.12.1$ pkg-config --libs x11
-lX11

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] Compiling the ocaml distribution under multiarched Debian/Ubuntu

2012-01-13 Thread Philippe Veber
2012/1/13 Gerd Stolpmann 

> Am Freitag, den 13.01.2012, 12:59 +0100 schrieb Philippe Veber:
> > Dear camlers,
> >
> > Debian and Ubuntu have not so recently switched to multiarch binaries
> > (including libs, see http://wiki.debian.org/Multiarch/Implementation).
> > This is an important change for ocaml C bindings since the libraries
> > are now to be found in /usr/lib/ instead
> > of /usr/lib. I was just bitten by this, when realizing that the ocaml
> > configure script couldn't find libX11.so and wouldn't install
> > graphics. A similar problem was handled by the people in charge of
> > debian ocaml packages
> > (http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=619344). Now my
> > question is the following: will this evolution be a problem for
> > GODI/odb packages (and more generally source distribution), and what
> > is the advised fix for it?
>
> Good question. For GODI it means that the automatic library search is
> broken. You can set the library path in most cases manually, though. (So
> far I overlook it, this is only a problem for the libs
> in /usr/lib// but not for the ones in /usr/lib/ because
> the latter can be linked without -L switches.)
>
That's what I thought too, but I'm hurt even for libX11 which is in
/usr/lib/:

pveber@gesundheit:/usr/lib$ locate libX11.so
/usr/lib/x86_64-linux-gnu/libX11.so
/usr/lib/x86_64-linux-gnu/libX11.so.6
/usr/lib/x86_64-linux-gnu/libX11.so.6.3.0

This is related to ocaml configure script, which wants to see the lib
before trying to compile

for dir in \
$x11_lib_dir  \
$x11_try_lib_dir  \
  \
/usr/X11R6/lib64  \
/usr/X11R6/lib\
/usr/lib/X11R6\
/usr/local/X11R6/lib  \
/usr/local/lib/X11R6  \
/opt/X11R6/lib\
  \
/usr/X11/lib  \
/usr/lib/X11  \
/usr/local/X11/lib\
/usr/local/lib/X11\
/opt/X11/lib  \

; \
do
  if test -f $dir/libX11.a || \
 test -f $dir/libX11.so || \
 test -f $dir/libX11.dll.a || \
 test -f $dir/libX11.dylib || \
 test -f $dir/libX11.sa; then

So basically it may be an issue in all cases ...


>
> The question is how to generically work around this.

right.


> GODI could provide
> a variable $USR_LIB_ARCH for the architecture-specific path prefix
> corresponding to /usr/lib/, which is set if "dpkg-architecture
> -qDEB_HOST_MULTIARCH" returns something. All the conf packages would
> need to be updated.

I've already noticed that godi's smart enough to suggest debian packages in
the bootstrap phase, so yes, probably your (optional, OS-specific) approach
is the way to go (although it might be some work). Also notice with the
example of graphics that many packages will have to be modified in order to
propagate the information. In this particular example, one would have to
add a --x11lib on the configure command.



> In the future we will have many errors because not
> all package developers will test on multiarch-enabled systems.
>
Just curious: are there many others than debian/ubuntu?


>
> Don't know what else needs to be done.
>
Thanks for your input on this.

ph.



>
> Gerd
>
> > Cheers,
> >   Philippe.
> >
>
> --
> 
> Gerd Stolpmann, Darmstadt, Germanyg...@gerd-stolpmann.de
> Creator of GODI and camlcity.org.
> Contact details:http://www.camlcity.org/contact.html
> Company homepage:   http://www.gerd-stolpmann.de
> *** Searching for new projects! Need consulting for system
> *** programming in Ocaml? Gerd Stolpmann can help you.
> 
>
>

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



[Caml-list] Compiling the ocaml distribution under multiarched Debian/Ubuntu

2012-01-13 Thread Philippe Veber
Dear camlers,

Debian and Ubuntu have not so recently switched to multiarch binaries
(including libs, see http://wiki.debian.org/Multiarch/Implementation). This
is an important change for ocaml C bindings since the libraries are now to
be found in /usr/lib/ instead of /usr/lib. I was just
bitten by this, when realizing that the ocaml configure script couldn't
find libX11.so and wouldn't install graphics. A similar problem was handled
by the people in charge of debian ocaml packages (
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=619344). Now my question
is the following: will this evolution be a problem for GODI/odb packages
(and more generally source distribution), and what is the advised fix for
it?

Cheers,
  Philippe.

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] [ANN] ocamlbrew

2012-01-13 Thread Philippe Veber
Hi Hezekiah

I gave it a shot after a new install of debian wheezy, and it went really
smoothly. The install was not exactly fresh, as I had installed ocaml
packages first (old reflex), but anyway I found two deps that blocked the
installation : one on libev-dev (for lwt/utop I suppose) and libpcre3-dev
(for oasis?). As it's only two, maybe it'd be worth to add them on the
README.md.

ocamlbrew, combined with odb for installing libraries is obviously a nice
combo (at least for unix users) and seems less complex than GODI. However I
believe both tools adopt rather different strategies regarding maintenance.
GODI is good at updating packages to new versions, but up till now I am not
sure ocamlbrew/odb can do the same. It seems that with the latter, you'd
preferably start a new install from scratch rather than trying to find
what's to be updated and effectively update it. Did I miss something?

Anyway, thanks for this work, which was useful to me.
Philippe.

2012/1/8 Hezekiah M. Carty 

> I would like to announce ocamlbrew, a (very simple, very alpha) tool
> for automating and managing builds of OCaml, findlib, and other
> OCaml-related items under $HOME on Linux.  ocamlbrew takes it name and
> a bit of wrapper code from perlbrew[1].  ocamlbrew provides a thin
> bash wrapper around the standard OCaml + findlib build procedure,
> taking advantage of odb[2] for further library and tool installations.
>
> ocamlbrew currently lives on github:
> https://github.com/hcarty/ocamlbrew
>
> With one command[3] ocamlbrew can build OCaml, findlib, oasis, utop,
> Batteries, and ocamlscript from source, plus get an easily source-able
> file to set up your environment.  Everything will be built and
> installed under $HOME/ocamlbrew by default.
>
> ocamlbrew can also be used to build OCaml from any branch on the
> official Subversion server.  At this time I recommend using the "-f"
> ocamlbrew flag with builds coming from Subversion due to some
> incompatibilities between OCaml development versions and oasis.  The
> -f flag tells ocamlbrew to only install OCaml, findlib, and odb.ml,
> skipping other tools and libraries.  This will hopefully provide a
> simple way to test and provide feedback to the core OCaml development
> team when new releases or experimental branches are ready for testing.
>
> For more information, including ocamlbrew's requirements, see the
> README.md file at the link above.
>
> Enjoy!  Many thanks to Edgar/thelema and Adrien/adrien for taking the
> time to test ocamlbrew and provide feedback as I was playing around
> with the process.
>
> Hez
>
> [1] - http://search.cpan.org/~gugod/App-perlbrew/bin/perlbrew
> [2] - https://github.com/thelema/odb
> [3] - Well, one command and the availability of all non-OCaml build
> prerequisites...
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> 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 and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] Generic printer patch

2011-12-08 Thread Philippe Veber
And the SQL schema generation lib as well :o) ?

2011/12/8 Jonathan Protzenko 

> Do you plan on opening up your automated gui generation library and have
> it distributed so that other users can take advantage of it? Say, make it
> rely on lablgtk and bundle it as a semi-official 3rd-party library that
> other people can reuse :-).
>
> jonathan
>
>
> On Thu 08 Dec 2011 11:32:28 AM CET, Alain Frisch wrote:
>
>> On 12/08/2011 10:24 AM, Gerd Stolpmann wrote:
>>
>>> http://www.lexifi.com/blog/**runtime-types

  Want it! Want it! Want it!
>>>
>>> Any plans for including this into the official compiler?
>>>
>>
>> Since the reception was not bad when I presented it to the Caml
>> Consortium meeting, yes, I'm proposing this as an extension to the official
>> compiler. The plan is to create a branch in the OCaml SVN (I don't know
>> when I'll be able to do it, hopefully before end of January) and follow the
>> same approach as for GADTs (i.e. ask the community for some feedback, and
>> discuss the proposal amongst the core team). I cannot commit on the final
>> outcome, of course.
>>
>> -- Alain
>>
>>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/**wws/info/caml-list
> 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 and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] Re: oasis, inter-dependent libraries and syntax extension

2011-11-02 Thread Philippe Veber
Done:
https://forge.ocamlcore.org/tracker/index.php?func=detail&aid=1050&group_id=54&atid=291
I find oasis particularly useful, tell me if there is something else I can
do on this.
ph.


2011/11/2 Sylvain Le Gall 

> Hello,
>
> You are indeed right, syntax extensions remain a second class citizen.
> I'll need to fix that situation.
>
> Please report this problem to the bug tracker, along with your solution
> (which seems fine). I'll try to implement it in 0.3.
>
> Cheers
> Sylvain Le Gall
>
> On 01-11-2011, Philippe Veber  wrote:
> >
> > --20cf307abebda8d83d04b0a9e43e
> > Content-Type: text/plain; charset=ISO-8859-1
> > Content-Transfer-Encoding: quoted-printable
> >
> > I found a workaround in lwt, which is to add some code in
> myocamlbuild.ml,
> > outside the generated part, to define appropriate tags that can then be
> > used in _tags (more generally, lwt has several interesting tricks about
> > oasis). For the record, here is how you can use a syntax extension
> > internally, inside a package:
> >
> > open Ocamlbuild_plugin
> >
> > let () =3D
> >   dispatch
> > (fun hook ->
> >dispatch_default hook;
> >match hook with
> >  | Before_options ->
> >  Options.make_links :=3D false
> >
> >  | After_rules ->
> >  (* Internal syntax extension *)
> >  List.iter
> >(fun base ->
> >   let tag =3D "pa_" ^ base and file =3D "src/syntax/pa_"
> ^ =
> > base
> > ^ ".cmo" in
> >   flag ["ocaml"; "compile"; tag] & S[A"-ppopt"; A file];
> >   flag ["ocaml"; "ocamldep"; tag] & S[A"-ppopt"; A file];
> >   flag ["ocaml"; "doc"; tag] & S[A"-ppopt"; A file];
> >   dep ["ocaml"; "ocamldep"; tag] [file])
> >["syntax_ext1";"syntax_ext2"]; (* add your syntax
> extensions
> > here *)
> >  | _ ->
> >  ())
> >
> >
> >
> > 2011/10/31 Philippe Veber 
> >
> >> S=E9bastien's suggestion is indeed a good start but alas for me not
> enoug=
> > h.
> >> The build still fails at ocamldep time, because the library B (with the
> >> syntax extension) seems not to be taken into account. If I replace my
> >> syntax extension with some findlib package (say tyxml), the compilation
> >> works fine. So the question remains, how can I specify that a
> >> library/executable in a package depends on a syntax extension that is
> >> defined as a library of the same package?
> >>
> >> Thanks to oasisdb, I've browsed a couple of packages that could be in
> the
> >> same situation, like a test executable for a syntax extension, but found
> >> none. Maybe I'm not dealing correctly with the situation ?
> >>
> >> ph.
> >>
> >>
> >> 2011/10/31 Sebastien Mondet 
> >>
> >>>
> >>> Hi
> >>>
> >>>
> >>> I ran into the same problem last week.
> >>> I added a line to the _tags file after the OASIS-generated stuff:
> >>>
> >>>...
> >>> # OASIS_STOP
> >>>
> >>>: syntax_camlp4o
> >>>
> >>>
> >>> (found in the slide 18:
> >>> http://oasis.forge.ocamlcore.org/documentation.html )
> >>>
> >>>
> >>> Sebastien
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> On Mon, Oct 31, 2011 at 12:23, Philippe Veber <
> philippe.ve...@gmail.com>=
> > wrote:
> >>>
> >>>> Hi,
> >>>> I have an oasis project defining three inter-dependent libraries A, B
> >>>> and C. B is a syntax extension, and depends on A. C depends on both A
> a=
> > nd
> >>>> B. I have written an _oasis file for this, which works fine if I
> don't =
> > use
> >>>> the extension in C, but fails if I do, during ocamldep (ocamldep
> lacks =
> > the
> >>>> appropriate options to understand the new syntax). Has anybody run
> into
> >>>> this problem ?
> >>>>
> >>>> ph.
> >>>>
> >>>>
> >>>
> >>
> >
>

Re: [Caml-list] oasis, inter-dependent libraries and syntax extension

2011-11-01 Thread Philippe Veber
I found a workaround in lwt, which is to add some code in myocamlbuild.ml,
outside the generated part, to define appropriate tags that can then be
used in _tags (more generally, lwt has several interesting tricks about
oasis). For the record, here is how you can use a syntax extension
internally, inside a package:

open Ocamlbuild_plugin

let () =
  dispatch
(fun hook ->
   dispatch_default hook;
   match hook with
 | Before_options ->
 Options.make_links := false

 | After_rules ->
 (* Internal syntax extension *)
 List.iter
   (fun base ->
  let tag = "pa_" ^ base and file = "src/syntax/pa_" ^ base
^ ".cmo" in
  flag ["ocaml"; "compile"; tag] & S[A"-ppopt"; A file];
  flag ["ocaml"; "ocamldep"; tag] & S[A"-ppopt"; A file];
  flag ["ocaml"; "doc"; tag] & S[A"-ppopt"; A file];
  dep ["ocaml"; "ocamldep"; tag] [file])
   ["syntax_ext1";"syntax_ext2"]; (* add your syntax extensions
here *)
 | _ ->
 ())



2011/10/31 Philippe Veber 

> Sébastien's suggestion is indeed a good start but alas for me not enough.
> The build still fails at ocamldep time, because the library B (with the
> syntax extension) seems not to be taken into account. If I replace my
> syntax extension with some findlib package (say tyxml), the compilation
> works fine. So the question remains, how can I specify that a
> library/executable in a package depends on a syntax extension that is
> defined as a library of the same package?
>
> Thanks to oasisdb, I've browsed a couple of packages that could be in the
> same situation, like a test executable for a syntax extension, but found
> none. Maybe I'm not dealing correctly with the situation ?
>
> ph.
>
>
> 2011/10/31 Sebastien Mondet 
>
>>
>> Hi
>>
>>
>> I ran into the same problem last week.
>> I added a line to the _tags file after the OASIS-generated stuff:
>>
>>...
>> # OASIS_STOP
>>
>>: syntax_camlp4o
>>
>>
>> (found in the slide 18:
>> http://oasis.forge.ocamlcore.org/documentation.html )
>>
>>
>> Sebastien
>>
>>
>>
>>
>>
>>
>> On Mon, Oct 31, 2011 at 12:23, Philippe Veber 
>> wrote:
>>
>>> Hi,
>>> I have an oasis project defining three inter-dependent libraries A, B
>>> and C. B is a syntax extension, and depends on A. C depends on both A and
>>> B. I have written an _oasis file for this, which works fine if I don't use
>>> the extension in C, but fails if I do, during ocamldep (ocamldep lacks the
>>> appropriate options to understand the new syntax). Has anybody run into
>>> this problem ?
>>>
>>> ph.
>>>
>>>
>>
>

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] oasis, inter-dependent libraries and syntax extension

2011-10-31 Thread Philippe Veber
Sébastien's suggestion is indeed a good start but alas for me not enough.
The build still fails at ocamldep time, because the library B (with the
syntax extension) seems not to be taken into account. If I replace my
syntax extension with some findlib package (say tyxml), the compilation
works fine. So the question remains, how can I specify that a
library/executable in a package depends on a syntax extension that is
defined as a library of the same package?

Thanks to oasisdb, I've browsed a couple of packages that could be in the
same situation, like a test executable for a syntax extension, but found
none. Maybe I'm not dealing correctly with the situation ?

ph.

2011/10/31 Sebastien Mondet 

>
> Hi
>
>
> I ran into the same problem last week.
> I added a line to the _tags file after the OASIS-generated stuff:
>
>...
># OASIS_STOP
>
>: syntax_camlp4o
>
>
> (found in the slide 18:
> http://oasis.forge.ocamlcore.org/documentation.html )
>
>
> Sebastien
>
>
>
>
>
>
> On Mon, Oct 31, 2011 at 12:23, Philippe Veber wrote:
>
>> Hi,
>> I have an oasis project defining three inter-dependent libraries A, B and
>> C. B is a syntax extension, and depends on A. C depends on both A and B. I
>> have written an _oasis file for this, which works fine if I don't use the
>> extension in C, but fails if I do, during ocamldep (ocamldep lacks the
>> appropriate options to understand the new syntax). Has anybody run into
>> this problem ?
>>
>> ph.
>>
>>
>

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



[Caml-list] oasis, inter-dependent libraries and syntax extension

2011-10-31 Thread Philippe Veber
Hi,
I have an oasis project defining three inter-dependent libraries A, B and
C. B is a syntax extension, and depends on A. C depends on both A and B. I
have written an _oasis file for this, which works fine if I don't use the
extension in C, but fails if I do, during ocamldep (ocamldep lacks the
appropriate options to understand the new syntax). Has anybody run into
this problem ?

ph.

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] ocamlfind: When using -syntax, the META variable 'preprocessor' must be set

2011-10-09 Thread Philippe Veber
Hi Ashish

this often happens to me after reinstalling godi, if I forget to install one
syntax extension used in my project. Instead of having a more meaningful
message like 'missing package bidule', I've got the message you report.
Maybe you could double check whether you installed all extensions used in
sequme ?

2011/10/9 Ashish Agarwal 

> I get the error below after reinstalling OCaml with the latest version with
> GODI. My code has not changed, so I'm wondering if there is a change to
> ocamlbuild or ocamlfind that is causing this. The issue appears to be that
> -package camlp4 should be included in the ocamlfind command but it is not.
>
> The section "Does Findlib support camlp4" in the findlib User's Guide
> discusses the 'preprocessor' variable, but I can't figure out how exactly
> how to adjust my META file or whether I really need to since it was working
> before.
>
> ocamlbuild sequme.cma sequme.cmxa sequme.cmxs
> Finished, 0 targets (0 cached) in 00:00:00.
> + ocamlfind ocamldep -package batteries -package biocaml -package netclient
> -package netstring -package shell -package sqlite3 -syntax camlp4o -modules
> sequme/bowtie.mli > sequme/bowtie.mli.depends
> ocamlfind: When using -syntax, the META variable 'preprocessor' must be set
> Command exited with code 2.
>
> --- META ---
> requires = "netstring shell netclient batteries biocaml pgocaml"
> version = "0.0"
> archive(byte) = "sequme.cma"
> archive(native) = "sequme.cmxa"
>
>

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] pattern matching on strings

2011-09-17 Thread Philippe Veber
Thank you Raphael !
Indeed, keeping the C encoding underneath strings (and arrays) is a nice
property.
ph.

2011/9/14 Raphael Proust 

> Richard Jones described the internals of OCaml quite concisely. The
> difference between char arrays and strings is exposed in part two of
> his series of posts:
>
> https://rwmj.wordpress.com/2009/08/05/ocaml-internals-part-2-strings-and-other-types/
>
> There is a pointer to
>
> http://caml.inria.fr/pub/ml-archives/caml-list/2002/08/e109df224ff0150b302033e2002dbf87.en.html
> in the article.
>
> On 9/14/11, Philippe Veber  wrote:
> > Hi Walter,
> >
> > Contrary to Prolog or Haskell, strings in ocaml are not represented as
> char
> > lists. They are exactly like char array, but have their own type,
> operations
> > and syntax : strings are created with String.make (similar to
> Array.make),
> > their length is given by String.length (sim. to Array.length) and the
> chars
> > are accessed with the notation s.[i] (similar to t.(i)). Actually I don't
> > know why they are not defined like char arrays (anyone on this ?). Long
> > story short, recursive formulations on strings (likewise for array) will
> > often rely on indices (and thus, not much on pattern matching). Note that
> > you can use optional arguments to hide indices :
> >
> > let rec iter f ?(k = 0) s =
> >   if k < String.length s then (
> > f s.[k] ;
> > iter f ~k:(k + 1) s
> >   )
> >
> > let _ = iter print_char "abc";;
> >
> >
> > The closest to your request I see can be achieved using ocaml batteries
> (*),
> > by transforming your string into a list:
> >
> > let rec iter_aux f = function
> > [] -> ()
> >   | c :: s1 -> f c ; iter_aux f s1
> > let iter f s = iter_aux f (String.explode s)
> >
> > But this won't be very efficient !
> >
> > You won't find advanced string pattern matching in core ocaml. But
> micmatch
> > seems a nice way to go if that's what you're looking for.
> >
> > cheers,
> > Philippe.
> >
> > (*) http://batteries.forge.ocamlcore.org/
> >
> >
> > 2011/9/14 Walter Cazzola 
> >
> >> Hi all,
> >> I'm just trying to write a recursive function that iterates¹ on a string
> >> and I'd like to use pattern matching as in:
> >>
> >> let rec iter f s =
> >>  match s with
> >> | ""  -> unit;
> >> | c^s1 -> f c; iter f s1;;
> >>
> >> but the ^ concatenates 2 strings and not a char with a string and above
> >> all seems to be inadmissible in the patterns.
> >>
> >> Does this mean that I can't write a function on strings by pattern
> >> matching or is there something I don't know?²
> >>
> >> Thanks for the help
> >> Walter
> >>
> >> ¹ I know that exists String.iter but I'd like to improve my skill in
> >>  writing functions by using pattern matching
> >> ² I read about micmatch but I'd like to avoid non standard packages.
> >> --
> >> --
> >> Caml-list mailing list.  Subscription management and archives:
> >> https://sympa-roc.inria.fr/**wws/info/caml-list<
> https://sympa-roc.inria.fr/wws/info/caml-list>
> >> Beginner's list:
> >> http://groups.yahoo.com/group/**ocaml_beginners<
> http://groups.yahoo.com/group/ocaml_beginners>
> >> Bug reports:
> >> http://caml.inria.fr/bin/caml-**bugs<http://caml.inria.fr/bin/caml-bugs
> >
> >>
> >>
> >
> > --
> > Caml-list mailing list.  Subscription management and archives:
> > https://sympa-roc.inria.fr/wws/info/caml-list
> > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> > Bug reports: http://caml.inria.fr/bin/caml-bugs
> >
> >
>
>
> --
> ___
> Raphael
>

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] a push style event combinator

2011-09-15 Thread Philippe Veber
Thank you for releasing your library, it looks really interesting !
How would you compare it with react (http://erratique.ch/software/react)
which, AFAIU, can be used for similar purposes ? At least I can see there is
no notion of signal (continuous function of time) in PEC (or maybe signals
can be emulated somehow ?). Also could you comment on the 'no memory leaks'
feature ?

cheers,
  Philippe.


2011/9/15 Satoshi Ogasawara 

> Hello,
>
> I'd like to announce the release of PEC, a push style event combinator.
>
>  PEC : https://github.com/osiire/Pec
>
> This small module(about 350 LOC) provides
>
> - a composable event.
> - map, choose, never, join and several useful functions.
> - immediate reactions corresponds sending data to events.
> - no memory leaks.
>
> I think PEC is useful to write event driven systems. The signature is as
> follows.
>
> type 'a event
>
> (** [make ()] makes a new event and sender function.*)
> val make : unit -> 'a event * ('a -> unit)
> val map : ('a -> 'b) -> 'a event -> 'b event
>
> (** [choose l] is a event which will be raised when one of specified events
> occurred. *)
> val choose : 'a event list -> 'a event
> val never : 'a event
> (** [join ee] is a event which will be raised when a inner event occurred.
>"Inner event" is a event comes from outer event [ee]. *)
> val join : 'a event event -> 'a event
> (** [bind e f] is [join (map f e)] *)
> val bind : 'a event -> ('a -> 'b event) -> 'b event
> val scan : ('a -> 'b -> 'a) -> 'a -> 'b event -> 'a event
> val filter : ('a -> bool) -> 'a event -> 'a event
> val filter_map : ('a -> 'b option) -> 'a event -> 'b event
> val zip : 'a event -> 'b event -> ('a * 'b) event
> val take_while : ('a -> bool) -> 'a event -> 'a event
> val take_while_in : ('a -> bool) -> 'a event -> 'a event
> val take_n : int -> 'a event -> 'a event
> val once : 'a event -> 'a event
> val drop_while : ('a -> bool) -> 'a event -> 'a event
> val drop_n : int -> 'a event -> 'a event
> val delay : int -> 'a event -> 'a event
> val pairwise : 'a event -> ('a * 'a) event
>
> (** [subscribe f e] attaches the [f] to the specified event.
>The [f] will be called when the [e] will occurred. *)
> val subscribe : ('a -> unit) -> 'a event -> unit
>
> (** [value e] returns a reference cell which store a latest value *)
> val value : 'a -> 'a event -> 'a ref
>
> (** [run ()] runs PEC event system and returns a number of queuing size of
> sended data. *)
> val run : unit -> int
>
>
> e.g.
>  Using PEC, you can write a drag event from mouse events like this.
>
> let (+>) f g = g f
> (* E is PEC module *)
> let dragging mouse_down mouse_up mouse_move =
>  E.bind mouse_down (fun dloc -> E.choose [
>E.map (fun uloc -> `Drop (dloc, uloc)) mouse_up;
>E.map (fun mloc -> `Drag (dloc, mloc)) mouse_move;
>  ]
>  +> E.take_while_in (function `Drop _ -> false | _ -> true))
>
>
> Regards,
>  ogasawara
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> 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 and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] pattern matching on strings

2011-09-14 Thread Philippe Veber
Hi Walter,

Contrary to Prolog or Haskell, strings in ocaml are not represented as char
lists. They are exactly like char array, but have their own type, operations
and syntax : strings are created with String.make (similar to Array.make),
their length is given by String.length (sim. to Array.length) and the chars
are accessed with the notation s.[i] (similar to t.(i)). Actually I don't
know why they are not defined like char arrays (anyone on this ?). Long
story short, recursive formulations on strings (likewise for array) will
often rely on indices (and thus, not much on pattern matching). Note that
you can use optional arguments to hide indices :

let rec iter f ?(k = 0) s =
  if k < String.length s then (
f s.[k] ;
iter f ~k:(k + 1) s
  )

let _ = iter print_char "abc";;


The closest to your request I see can be achieved using ocaml batteries (*),
by transforming your string into a list:

let rec iter_aux f = function
[] -> ()
  | c :: s1 -> f c ; iter_aux f s1
let iter f s = iter_aux f (String.explode s)

But this won't be very efficient !

You won't find advanced string pattern matching in core ocaml. But micmatch
seems a nice way to go if that's what you're looking for.

cheers,
Philippe.

(*) http://batteries.forge.ocamlcore.org/


2011/9/14 Walter Cazzola 

> Hi all,
> I'm just trying to write a recursive function that iterates¹ on a string
> and I'd like to use pattern matching as in:
>
> let rec iter f s =
>  match s with
> | ""  -> unit;
> | c^s1 -> f c; iter f s1;;
>
> but the ^ concatenates 2 strings and not a char with a string and above
> all seems to be inadmissible in the patterns.
>
> Does this mean that I can't write a function on strings by pattern
> matching or is there something I don't know?²
>
> Thanks for the help
> Walter
>
> ¹ I know that exists String.iter but I'd like to improve my skill in
>  writing functions by using pattern matching
> ² I read about micmatch but I'd like to avoid non standard packages.
> --
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/**wws/info/caml-list
> 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 and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] Mutually recursive closures?

2011-09-09 Thread Philippe Veber
You may not need the -rectypes option if you add a thin layer around your
functions:

Objective Caml version 3.12.1

Findlib has been successfully loaded. Additional directives:
[...]
# type t = F of (unit -> t);;
type t = F of (unit -> t)
# let rec a = F (fun () -> print_endline "a" ; b)
  and b = F (fun () -> print_endline "b" ; a);;
val a : t = F 
val b : t = F 
# let ( ! ) (F f) = f ();;
val ( ! ) : t -> t = 
# let x1 = ! a;;
a
val x1 : t = F 
# ! x1;;
b
- : t = F 

It works in this version because you're defining a brand new type, and not
using a type alias (like in type t = unit -> t). I think a record would work
too, but I think either is needed to avoid using -rectypes.

cheers,
  Philippe.



2011/9/10 Anthony Tavener 

> Thanks Jonathan! I've seen -rectypes mentioned over the years and always
> glossed over it thinking "Ah, I'll never need that!" :P
>
> Understandable that it's a good default to have disabled. I'll experiment
> first and if I like the results I'll try to limit compiling with -rectypes
> to the smallest bit of code using it.
>
>
> On Fri, Sep 9, 2011 at 5:31 PM, Jonathan Protzenko <
> jonathan.protze...@gmail.com> wrote:
>
>> You can use equirecursive types, which can be enabled through the
>> -rectypes command-line switch. With that option, your example above
>> type-checks. However, these are not enabled by default for a variety of
>> reasons, the most important one being it makes it much easier to shoot
>> yourself in the foot.
>>
>> Cheers,
>>
>> jonathan
>>
>>
>> On Sat 10 Sep 2011 01:14:46 AM CEST, Anthony Tavener wrote:
>>
>>> I was considering returning a couple of closures to help organize my UI
>>> code, essentially representing current UI mode by one of these closures. But
>>> then I run into a problem because the types are infinite (returns a
>>> function, which returns a function, ...)
>>>
>>> A simplified example:
>>>
>>> # let rec a () = printf "state a\n"; b
>>>   and b () = printf "state b\n"; a
>>>
>>> Error: This expression has type unit -> unit -> 'a
>>>   but an expression was expected of type 'a
>>>
>>>
>>> Is there a way I can do this? To express (or 'hide') the cyclic nature of
>>> the type resolution?
>>>
>>> I've considered using continuations, but that seems heavy-weight for what
>>> I'm looking to do. And as far as I can tell I'd need to leverage Oleg's
>>> delimcc (which I'd love to start using and wrap my head around -- but for a
>>> task worthy of it!).
>>>
>>> I can use a variant to represent states/modes and have a dispatcher which
>>> runs the right code... but this introduces what feels like an unnecessary
>>> layer of distraction. Returning the closure of the "next state" seems
>>> straightforward, but introduces cycles into the typing. :(
>>>
>>> I'm hoping I'm missing something simple. Thank-you for any assistance!
>>>
>>>  -Tony
>>>
>>>
>

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] Odd failure to infer types

2011-09-03 Thread Philippe Veber
Hi, I'm really no typing expert and have not looked much into your code, so
sorry in advance if what I say is irrelevant. Christophe got it right I
think : I'd say that an array value cannot be polymorphic because it is
mutable. I've quickly searched the web and found that

http://mirror.ocamlcore.org/caml.inria.fr/pub/ml-archives/caml-list/2001/12/0dccd30f4582e551a674562e3ddcc03c.en.html

Quoting François Pottier:
"Any polymorphic, mutable structure is unsound and rightly rejected. A
monomorphic, mutable structure that contains polymorphic data is sound, but
cannot be expressed in ML's type system where universal quantification must
be prenex."

So it seems to me that whatever the way you try to achieve it, you simply
can't define a value state of type

val states : ('a list * (char * int * int) array * string) list array

(implicitely for all 'a). If the compiler is right, you'll always end up
with a weak type variable somewhere.

my 2 cent,

ph.


2011/9/3 Guillaume Yziquel 

> Le Saturday 03 Sep 2011 à 11:53:30 (+0200), Goswin von Brederlow a écrit :
> > Hi,
> >
> > I'm implementing a solver for the game Atomix. If you don't know it then
> > don't worry. It isn't relevant.
> >
> > I split things up into submodules and now one of the submodules does not
> > infere the right types:
> >
> > File "Atomix.ml", line 168, characters 11-876:
> > Error: The type of this module,
> >sig
> >  type dir = NORTH | SOUTH | WEST | EAST
> >  val max_moves : int
> >  val cache : (string, unit) Hashtbl.t
> >  val states :
> >('_a list * (char * int * int) array * string) list array
> >  val string_of_dir : dir -> string
> >  val print :
> >(int * int * dir) list * (char * int * int) array * string ->
> unit
> >  val num_states : int
> >end, contains type variables that cannot be generalized
> >
> > I believe this is wrong. In S.num_states the call to "print state"
> > fixates the type for state and the "states.(d) <- state::states.(d);"
> > should then fixate the missing '_a in the type for states.
> >
> > Anyone know why?
>
> It also seems quite wrong to me. You should perhaps file a bug into
> Mantis if no typing expert answers.
>
> Did you try adding type annotations one at a time near the call to print
> and the states.(d) assignment in your anonymous List.fold-ing function?
> To check precisely what the type inferencer gets right and what it gets
> wrong?
>
> I'd be curious to know whether annotating state in "states.(d) <-
> state::states.(d)" solves your problem. Since it's here that the '_a in
> the type of states should be fixated.
>
> --
>  Guillaume Yziquel
>
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> 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 and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] Labelled parameter bug?

2011-08-24 Thread Philippe Veber
Hello,

2011/8/24 Dmitry Bely 

> The following fragment compiles without a warning but produces strange
> results:
>
> let f ?(p1="p1") ~p2 p3 =
>  Printf.printf "p1=%s, p2=%s, p3=%s\n" p1 p2 p3
>
> let _ =
>  f "p2" "p3"; (* 1 *)
>  let f2 = f "p2" in
>  f2 "p3" (* 2 *)
>

The type of f is

val f : ?p1:string -> p2:string -> string -> unit = 

so f "p2" applies to the only anonymous parameter (third one) because it
cannot be applied to the first or second without label :

# f "p2";;
- : p2:string -> unit = 

This first application also applies optional arguments situated before the
anoymous argument, so it remains the second (labeled) argument only.

There is indeed a special case where you can drop labels if you provide the
exact number of arguments. This means that f "p2" "p3" is equivalent to f
~p2:"p2" "p3". This is written in the manual (
http://caml.inria.fr/pub/docs/manual-ocaml/manual006.html) :

"As an exception to the above parameter matching rules, if an application is
total, labels may be omitted. In practice, most applications are total, so
that labels can be omitted in applications. "

So this is actually the intended behavior, AFAIU

Philippe.



>
> Outputs:
>
> p1=p1, p2=p2, p3=p3 (1)
> p1=p1, p2=p3, p3=p2 (2)
>
> Why (1) and (2) are different? I assume f "p2" takes p3 instead of p2
> but then the compiler should issue at least a warning...
>
> - Dmitry Bely
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> 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 and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] Re: Oasis and camlp4of

2011-08-03 Thread Philippe Veber
2011/8/3 Sylvain Le Gall 

> Hello,
>
> On 02-08-2011, Philippe Veber  wrote:
> >
> > --bcaec54ee94203b60304a98d2f09
> > Content-Type: text/plain; charset=ISO-8859-1
> >
> > Well, it seems that I have a much simpler problem (and it is not related
> to
> > camlp4of specifically): the only thing I'm missing is a '-syntax camlp4o'
> > when compiling the library. Indeed, adding:
> >
> >: syntax_camlp4o
> >
> > at the end of _tags fixes the problem. I must have forgotten an option in
> > the _oasis file, but I can't see which. Anyway, many thanks William !
> > ph.
> >
>
>
> Indeed, you need syntax_camlp4o (which is one of the two allowed syntax
> tag with syntax_camlp4r, wrt to ocamlfind). You have done exactly what
> is needed to enable it (add it to _tags after OASIS section).
>
> In fact, camlp4of is just camlp4o with extra modules:
>
> gildor@yotta(sid-amd64/chroot):~$ camlp4of -loaded-modules
> Camlp4.Printers.OCaml
> Camlp4GrammarParser
> Camlp4ListComprenhsion
> Camlp4MacroParser
> Camlp4OCamlParser
> Camlp4OCamlParserParser
> Camlp4OCamlRevisedParser
> Camlp4OCamlRevisedParserParser
> Camlp4QuotationExpander
>
> gildor@yotta(sid-amd64/chroot):~$ camlp4o -loaded-modules
> Camlp4.Printers.OCaml
> Camlp4OCamlParser
> Camlp4OCamlParserParser
> Camlp4OCamlRevisedParser
> Camlp4OCamlRevisedParserParser
>
I see, thanks for the explanation.


>
> You can get this extra modules, using extra tags
>
> : syntax_camlp4o, pkg_camlp4.gramlib, pkg_camlp4.macro
>

Thanks William, Christophe and Sylvain !
The solution suggested by William is not that hackish, and I'm pretty happy
with it. That's incredible how oasis (with findlib and ocamlbuild) has made
starting an ocaml project easier.


>
> Full syntax support should be an oasis 0.3 feature.
>
That is very good news.
Many thanks again,
ph.



>
> Cheers,
> Sylvain Le Gall
> --
> My company: http://www.ocamlcore.com
> Linkedin:   http://fr.linkedin.com/in/sylvainlegall
> Start an OCaml project here: http://forge.ocamlcore.org
> OCaml blogs: http://planet.ocamlcore.org
>
>
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> 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 and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



Re: [Caml-list] Oasis and camlp4of

2011-08-02 Thread Philippe Veber
Well, it seems that I have a much simpler problem (and it is not related to
camlp4of specifically): the only thing I'm missing is a '-syntax camlp4o'
when compiling the library. Indeed, adding:

: syntax_camlp4o

at the end of _tags fixes the problem. I must have forgotten an option in
the _oasis file, but I can't see which. Anyway, many thanks William !
ph.


2011/8/2 William Le Ferrand 

> Hi
>
> I let Sylvain detailing how things should be done properly but as a
> quick hack you can add at the bottom of the _tags file :
> syntax_camlp4of , it should do the trick (and it won't be erased by
> oasis setup if you put it after the #OASIS_END line.
>
> Hope it helps
>
> William
>
>
>
> On Tue, Aug 2, 2011 at 1:32 PM, Philippe Veber 
> wrote:
> > Hello,
> > how can I tell oasis that my syntax extension needs camlp4of instead of
> > camlp4o ? I tried to add a ByteOpt line for this:
> >
> > Library pa_guizmin
> >   Path:   src/syntax
> >   Modules:Pa_guizmin
> >   FindlibParent:  guizmin
> >   FindlibName:syntax
> >   BuildDepends:   camlp4.lib, camlp4.quotations.o
> >   CompiledObject: byte
> >   ByteOpt:-pp camlp4of
> >
> > and indeed myocamlbuild.ml now contains:
> >
> > let package_default =
> >   {
> >  MyOCamlbuildBase.lib_ocaml =
> >[("src/syntax/pa_guizmin", ["src/syntax"]); ("src/guizmin",
> > ["src"])];
> >  lib_c = [];
> >  flags =
> >[
> >   (["oasis_library_pa_guizmin_byte"; "ocaml"; "link"; "byte"],
> > [(OASISExpr.EBool true, S [A "-pp"; A "camlp4of"])]);
> >   (["oasis_library_pa_guizmin_byte"; "ocaml"; "ocamldep";
> "byte"],
> > [(OASISExpr.EBool true, S [A "-pp"; A "camlp4of"])]);
> >   (["oasis_library_pa_guizmin_byte"; "ocaml"; "compile"; "byte"],
> > [(OASISExpr.EBool true, S [A "-pp"; A "camlp4of"])])
> >];
> >  }
> >   ;;
> >
> > But still, these options are not used when I compile using ocaml
> setup.ml
> > -build
> >
> > + ocamlfind ocamldep -package camlp4.quotations.o -package camlp4.lib
> > -package camlp4.extend -modules src/syntax/pa_guizmin.ml >
> > src/syntax/pa_guizmin.ml.depends
> > File "src/syntax/pa_guizmin.ml", line 22, characters 3-5:
> > Error: Syntax error
> >
> > Am I missing something ?
> >
> > Cheers,
> >   Philippe.
> >
>
>
>
> --
> William Le Ferrand
>
> Mobile : (+1) (415) 683-1484
> Web : http://williamleferrand.github.com/
>

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



[Caml-list] Oasis and camlp4of

2011-08-02 Thread Philippe Veber
Hello,
how can I tell oasis that my syntax extension needs camlp4of instead of
camlp4o ? I tried to add a ByteOpt line for this:

Library pa_guizmin
  Path:   src/syntax
  Modules:Pa_guizmin
  FindlibParent:  guizmin
  FindlibName:syntax
  BuildDepends:   camlp4.lib, camlp4.quotations.o
  CompiledObject: byte
  ByteOpt:-pp camlp4of

and indeed myocamlbuild.ml now contains:

let package_default =
  {
 MyOCamlbuildBase.lib_ocaml =
   [("src/syntax/pa_guizmin", ["src/syntax"]); ("src/guizmin",
["src"])];
 lib_c = [];
 flags =
   [
  (["oasis_library_pa_guizmin_byte"; "ocaml"; "link"; "byte"],
[(OASISExpr.EBool true, S [A "-pp"; A "camlp4of"])]);
  (["oasis_library_pa_guizmin_byte"; "ocaml"; "ocamldep"; "byte"],
[(OASISExpr.EBool true, S [A "-pp"; A "camlp4of"])]);
  (["oasis_library_pa_guizmin_byte"; "ocaml"; "compile"; "byte"],
[(OASISExpr.EBool true, S [A "-pp"; A "camlp4of"])])
   ];
 }
  ;;

But still, these options are not used when I compile using ocaml setup.ml-build

+ ocamlfind ocamldep -package camlp4.quotations.o -package camlp4.lib
-package camlp4.extend -modules src/syntax/pa_guizmin.ml >
src/syntax/pa_guizmin.ml.depends
File "src/syntax/pa_guizmin.ml", line 22, characters 3-5:
Error: Syntax error

Am I missing something ?

Cheers,
  Philippe.

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs