Hi, I'm looking at the List document. It seems the library does not provide a sublist function.
I'm trying to get list of elements from i to j. Now I have to write it as:
let rec sublist list i j = if i > j then [] else (List.nth list i) :: (sublist list (i+1) j)
which is quite concise but I'm questioning the efficiency of List.nth, b...
I have two functions f and g and I am trying to return f(g(x)) but I do not know the value of x and I am not really sure how to go about this.
A more concrete example: if I have functions f = x + 1 and g = x * 2 and I am trying to return f(g(x)) I should get a function equal to (x*2) + 1
...
Is there a way to get pattern matching to match my value with any negative number? It does not matter what the negative number is I just need to match with any negative.
I have accomplished what I want with this simple code:
let y = if(n < 0) then 0 else n in
match y with
0 -> []
| _ -> [x] @ clone x (n - 1)
But I want to e...
Hi All,
Here is the code on sorting any given list:
let rec sort lst =
match lst with
[] -> []
| head :: tail -> insert head (sort tail)
and insert elt lst =
match lst with
[] -> [elt]
| head :: tail -> if elt <= head then elt :: lst else head :: insert elt tail;;
[Source: Code
However, I am getting an Unbound...
Say I want to create a source code editor for ocaml programming language, where do I start? I am looking to create an editor for the Windows platform as a hobby project. My primary skill is in web development. I have developed windows apps long time ago. I have no clue how it is done with todays available tools. I have visual studio 2008...
In OCaml 3.11, I want to "extend" an existing module using the include directive, like so:
module MyString = struct
include String
let trim s = ...
end
No problem. But now I want to expose this module's type explicitly (i.e. in a .mli file). I want something like this:
module MyString : sig
include String
val trim : string ...
Hello Guys,
i'm trying to learn ocaml right now and wanted to start with a little program, generating all bit-combinations:
["0","0","0"]
["0","0","1"]
["0","1","0"]
... and so on
My idea is the following code:
let rec bitstr length list =
if length = 0 then
list
else begin
bitstr (length-1)("0"::list);
bitstr (length-...
I'm trying to work out how to use ocamlfind to compile a C library and an OCaml executable using that C library.
I put together a set of rather silly example files.
% cat sillystubs.c
#include <stdio.h>
#include <caml/mlvalues.h>
#include <caml/memory.h>
#include <caml/alloc.h>
#include <caml/custom.h>
value
caml_silly_silly( value u...
Most of the problems I have to solve in my job as a developer have to do with data modeling.
For example in a OOP Web Application world I often have to change the data properties that are in a object to meet new requirements.
If I'm lucky I don't even need to programmatically add new "behavior" code (functions,methods). Instead I can de...
I'm looking for an implementation to the Minimum Cost Flow graph problem in OCaml.
OCaml library ocamlgraph has Goldberg algorithm implementation.
The paper called Efficient implementation of the Goldberg-Tarjan minimum-cost flow algorithm is noting that Goldberg-Tarjan algorithm can find minimum cost graph. Question is, does ocamlgrap...
Hi,
I m very new to ocaml and i m facing the problem below,
In a.ml a record type t is defined and is also defined transparently
in a.mli, i.e. in d interface so that the type definition is available
to all other files.
a.ml also has a function, func, which returns a list of t.
Now in another file, b.ml i m calling func, now obvious...
When looking at F#, Ocaml and other functional language code examples I notice that the let keyword is used very often.
Why do you need it? Why were the languages designed to have it?
Why can't you just leave it out? e.g: let x=4 becomes x=4
...
I'm OCaml newbie and I'm trying to write a simple OCaml-like grammar, and I can't figure this out. My grammar allows something like this:
let sub = fun x -> fun y -> x - y;;
However, if I want to use the function so defined, I can write: (sub 7) 3 but I can't write sub 7 3, which really bugs me. For some reason, it gets interpreted as...
I'm trying to write something like this:
type 'a 'b xxx = {aaa: 'a: bbb: 'b: ccc: int};;
It does not compile. Is it just syntax error, or they don't allow multiple paramters on type ? Then why ?
...
Hello all,
I've been thinking of this question very long, but really couldn't find the answer on Google as well a similar question on Stackoverflow. If there is a duplicate, I'm sorry for that.
A lot of people seem to say that writing compilers and other language tools in functional languages such as OCaml and Haskell is much more effi...
Which language would you propose for solving a system with:
first order differential equations
complex variables
N-dimensions
using 4th order Runge Kutta or the like.
Speed matters a lot but would sacrifice for:
Elegant (clean and short) code
Flexibility + scalability
I'm mostly between a Lisp and OCaml but any other suggestion...
When people refer to the "revised syntax" in OCaml, do they mean that this will become a new syntax for the language, or is it just an alternative syntax created in CamlP4? If it's the former, then when does the "revised syntax" become the "official syntax" of OCaml?
...
Hi all,
Trying to build the OCaml Win32 API binaries for OCaml 3.11.0 on Win 7 and I consistently get a message when I try nmake dynamic: 'cannot open input file "ocamlrun.lib"'. My google skills seem to be failing me--is there something I need to do to get this .lib file? It doesn't seem to be part of the libraries which are included...
How can I determine the mime-type of a file (in OCaml)?
I am trying to set the language for a GtkSourceView control, but to do that, I need to first determine the language. The only way I can see of doing this is using the mime-type - there is a function that will return the correct language as follows:
GSourceView.source_languages_ma...
I want nice operators for complex arithmetic to make my code more readable. Ocaml has a Complex module, so I just want to add operators that call those functions.
The most intuitive way for me is to make a new complex operator from all of the usual operators by appending '&' to the operator symbol. Thus +& and *& will be complex additi...