ocaml

Redundancy in OCaml type declaration (ml/mli)

Hello, I'm trying to understand a specific thing about ocaml modules and their compilation: am I forced to redeclare types already declared in a .mli inside the specific .ml implementations? Just to give an example: (* foo.mli *) type foobar = Bool of bool | Float of float | Int of int (* foo.ml *) type baz = foobar option This, ac...

How do I read this OCaml type signature?

I'm currently experimenting with using OCaml and GTK together (using the lablgtk bindings). However, the documentation isn't the best, and while I can work out how to use most of the features, I'm stuck with changing notebook pages (switching to a different tab). I have found the function that I need to use, but I don't know how to use...

Is OCaml suitable to write networking servers?

Hello, I was wondering if OCaml will perform well in terms of performance and ease of implementation while dealing with typical client/server interactions over TCP in a multi threaded environment.. I mean something really typical like having a thread per client that receives data, operated changes on game states and send them back to cli...

Learning .NET from F# without C#

Hello, I'm a Java/C++ developer that never spent time in learning C# and the relative .NET foundation. Then I learned OCaml because I had to use it for my master thesis so I heard about F# and wondered: will F# allows me to use easily the .NET API to build fully featured applications (that may involve GUIs, sockets, whatever) without an...

Matching with functions in OCaml?

Is it possible to use pattern matching over specified functions directly or with some exploits that don't involve specifying a type for every function I need? Just to explain things better suppose I have a type like type BBoolOp = (bool->bool->bool)*term*term and suppose that the bool->bool->bool functions are some quite simple like ...

How stable and widespread is "OCaml Batteries Included" and is it recommended?

I'm just getting back into OCaml for a new small research project after many years of SML, Haskell and F#. I quickly found myself missing some things when using the OCaml libraries, and I also missed having a syntax for monadic comprehensions. OCaml Batteries Included seems to fill exactly these gaps. But I'm a little unsure whether i...

Benefits and uses of a functional programming language

Possible Duplicate: Why functional languages? I began programming with C/C++, VB, and eventually Python - all imperative languages. I took a course about programming languages and learned my first functional language - OCaml. It was terrible. Syntax and other horrors aside, OCaml took my imperative thought process and threw i...

Understanding functors in OCaml

Hello, I'm quite stuck with the following functor problem in OCaml. I paste some of the code just to let you understand. Basically I defined these two modules in pctl.ml: module type ProbPA = sig include Hashtbl.HashedType val next: t -> (t * float) list val print: t -> float -> unit end module type M = sig type s val s...

OCaml pattern matching on builtin types

I'm trying to write a polymorphic function, which needs to do something slightly different depending on the type of the parameter. Is there any way that I can do a pattern match on the type of the object, using the builtin types? I'm thinking of something along these lines: let to_string v = match v with | string -> v | in...

What are good uses of OCaml packaged modules?

The recent OCaml 3.12 introduces a feature of first-class packaged modules: First-class packages modules. New kind of type expression, for packaged modules: (module PT) New kind of expression, to pack a module as a first-class value: (module MODEXPR : PT). New kind of module expression, to unpack a first-class value as ...

Haskell or Ocaml with OpenGL and SDL precompiled distribution for Windows

I want to learn Ocaml or Haskell and I want to do it by writing a simple game. Apparently, there's one small problem: nobody cares about Windows and I want to do it on Windows, natively. Haskell has Cabal, which has SDL, but it doesn't build due to a trivial problem with no workarounds (order of parameters passed to gcc). Ocaml doesn't ...

Pattern Matching, F# vs Erlang

In Erlang, you are encouraged not to match patterns that you do not actually handle. For example: case (anint rem 10) of 1 -> {ok, 10} 9 -> {ok, 25} end; is a style that is encouraged, with other possible results resulting in a badmatch result. This is consistant with the "let it crash" philosophy in Erlang. On the other hand...

Purely functional soft heap

Are there any implementations of a purely functional soft heap data structure in any language? ...

How practical is it to embed the core of a language with an effectful function space (like ML) into Haskell?

As Moggi proposed 20 years ago, the effectful function space -> of languages like ML can be decomposed into the standard total function space => plus a strong monad T to capture effects. A -> B decomposes to A => (T B) Now, Haskell supports monads, including an IO monad that appears sufficient for the effects in ML, and it has a ...

Using functors as interfaces in OCaml

Hello, I'm developing some algorithms in OCaml which need some parts to be "pluggable" so that part of the computation is left to specific computators. Just to make an example suppose I have a signature like this one: module type Algorithm = sig val feed : float -> unit val nth : int -> (float -> float) end And two different ...

Return multiple tokens in ocamllex

Is there any way to return multiple tokens in OCamlLex? I'm trying to write a lexer and parser for an indentation based language, and I would like my lexer to return multiple DEDENT tokens when it notices that the indentation level is less than it previously was. This will allow it to notify the parser when multiple blocks have ended...

Mixing OCaml and C: is it worth the pain?

Hi all, I am faced with the task of building a new component to be integrated into a large existing C codebase. The component is essentially a kind of compiler, and will be complicated enough that I would like to write it in OCaml (for reasons along the lines of those given here). I know that OCaml-C interaction is possible (as per th...

Why does pressing numlock crash OCaml opengl program?

I don't have any experience with openGL, so maybe I'm just missing something. I have this ocaml code using lablGL. To compile I use ocamlopt -I +lablGL lablglut.cmxa lablgl.cmxa gl.ml -o gl.opt or ocamlc -I +lablGL lablglut.cma lablgl.cma gl.ml -o gl.byte let keyboard ~key ~x ~y = match key with | 27 -> exit 0 | _ -> ignor...

Why do some OCaml funtions take () as a parameter?

Example in Unix module: val environment : unit -> string array Why not just: val environment : string array ? ...

Why there is no binary distribution for OCaml on Win64?

The OCaml download page is announcing that there is four Windows ports available: Cygwin, Mingw, native Win32, and native Win64. However the latest one is in fact not available and must be compiled from sources only. Given that the Windows/x86_64 port has been done since a few years, I was wondering why the binary distribution process i...