ocaml

Functors with multiple arguments in OCaml

Hello, I've the following situation: module type M = sig type s = ... end module Make(P: Something) : (M with type s = P.t) = struct type s = P.t ... end that works fine to generate modules of M type that use specific implementation of modules of type Something inside their implementation. Now suppose I have another module de...

Ocaml: how to pattern match on an arbitrary number of arguments?

Hi all, is there an OCaml equivalent to Haskell's pattern matching on an arbitrary number of arguments? For example, can I have something resembling: merge [] lst = lst merge lst [] = lst merge l1 @ (n : ns) l2 @ (m : ms) = if n < m then n : merge ns l2 else m : merge l1 ms (The example's lifted from Developing Applications with O...

Implementing a direct-threaded interpreter in a functional language like OCaml

In C/C++ you can implement a direct threaded interpreter with an array of function pointers. The array represents your program - an array of operations. Each of the operation functions must end in a call to the next function in the array, something like: void op_plus(size_t pc, uint8_t* data) { *data += 1; BytecodeArray[pc+1](pc+1...

Conditional compiling in OCaml

Hello, suppose I have a long algorithm which I would like to be optionally verbose to debug it. So far I just added many if verbose then printf "whatever" all around the code but this forces the code to execute many useless tests if I don't want to have it in the verbose mode. Is there a way to obtain a simple conditional compilation wh...

Calling Mathematica from OCaml program

I am writing OCaml code. In part of it, I want to examine whether two arithmetic expression are equal (like x+2+y == x+2*y-y+2). Implemeting this in mathematica is straightforward, so all I want some help on executing Mathematica and get the result back in OCaml. My OS platform is Linux. Cheers, Z. ...

OCaml Tree Tutorial

Hello, I'm searching for an good OCaml Tree tutorial... ...I need a few examples of how to remove elements, add elements, remove subtrees... Br, Wolfy ...

Ocaml lablgtk2 custom widget?

Hi everyone. I've been learning Ocaml with lablgtk2 for a while and still searching for a tutorial in which describe a way to create a custom widget (I want to make this widget as a circle filled with color and some text in the center). And this custom widget can be set ~width, ~height, ~label, ~packing,... to another container (as anoth...

Functional programming languages introspection

I'm sketching a design of something (machine learning of functions) that will preferably want a functional programming language, and also introspection, specifically the ability to examine the program's own code in some nicely tractable format, and preferably also the ability to get machine generated code compiled at runtime, and I'm won...

ocaml Unix.system call to pdflatex

I'm having a problem calling an outside application from a compiled ocaml application, pdflatex. I'm using the proper string as an argument, when I run it from the toplevel I get the expected results, Unix.system "pdflatex -interaction batchmode -output-directory res ALGO_GEN.tex";; And it generates the proper output, This is pdfTeX...

Guarantying assignment to a function's return value in OCaml

Coming to OCaml from Lisp, I find myself very confused about when functions return and when they don't. I miss my magic Quote! Thankfully, most of the time, OCaml appears to automagicly know when I want a function evaluated and when I don't. However, I frequently find myself trying to assign the return value of a function in a let exp...

install Ocamlgraph on window?

Anyone know how to install Ocamlgraph library on Window? I am using Ocaml install on Mingw port. Can't figure a way to do this? ...

problem with compilation of program in ocaml

I have a problem with compiling a program written in ocaml, the error appears to me is: Error: Unbound module Basics, how can I solve this problem? I state that the beginner with this language. libraries used throughout the code are: open Basics ;; open Paritygame ;; open Univsolve;; open Solvers;; f...

Tools to monitor the RAM occupied

Hello, I wrote an application that needs to be compared with another one that does the same job.. mine is in OCaml while other one is in Java. I would like to make two runs on the programs and monitor the RAM usage during the time elapsed by these executions. Both programs are really memory and cpu intensive so I'll have enough data to ...

OCaml semantics of merge in functor Map.make?

Hi, I am writing an OCaml function where I need to merge two maps. I have not been able to figure out the semantics of the merge function provided by functor Map.Make (found in version 3.12.0 of OCaml). Could someone provide me with a more detailed explanation than the OCaml manual? An example would probably enough for me to figure it o...

Why is an int in OCaml only 31 bits?

Haven't seen this "feature" anywhere else. I know that the 32nd bit is used for garbage collection. But why is it that way only for ints and not for the other basic types? ...

Which of these DLLs are the "right" ones?

On a fresh Debian system (Squeeze/Sid) I have installed the following packages using apt-get: ocaml-batteries-included libpcre-ocaml-dev libcamlnet-ssl-ocaml-dev libldap-ocaml-dev When compiling code I get errors such as: ocamlfind: [WARNING] The DLL dllnetaccel_c.so occurs in multiple directories: /usr/lib/ocaml/stublibs ocamlfind:...

2 ocaml modules with same (file)name

What I want is to have the following source tree layout: src/ a.ml b.ml ... tests/ a.ml b.ml ... Is it possible to distinct these modules and access src/a.ml module as A and tests/a.ml module as something like Tests.A ? Actually, there also is a problem with ocamlfind (UPD: omake) it thinks that tests/a.ml...

Unbound modules in OCaml

My problem is that ocamlc and ocamlopt apear to be refusing to find third party libraries installed through apt-get. I first started having this problem when I tried to incorporate third-party modules into my own OCaml programs, and quickly wrote it off as a personal failing in understanding OCaml compilation. Soon-- however-- I found my...

Adding to a string map in OCaml

Hi, I have been trying to figure out what I figure is a pretty simple task, namely adding entries to a map of Strings in OCaml from within a function. The relevant elements are below: module StringMap = Map.Make (String);; let m = StringMap.empty;; let rec count ke = match ke with |[] -> [] |hd::tl -> begin let m = StringMap.add hd...

What are the pros and cons of Batteries and Core?

Hi, In the OCaml world at present there appear to be a number of competing extensions to the standard library, Batteries and Jane Street Core being the major ones as far as I can determine (I understand that ExtLib has been subsumed into Batteries?). What are the pros and cons of each one? Are they equivalent? Can they coexist? Does it ...