ocaml,ocaml-lwt , How to use Lwt_pool


How to use Lwt_pool

Question:

Tag: ocaml,ocaml-lwt

I want to have a pool of Redis database connections with a max number of connections. It looks like Lwt_pool is the solution I am looking for, but I don't quite grasp how it should work. For example, some questions I have:


Answer:

Related:


Ocsigen/Eliom: How to remove unnecessary JavaScript?


ocaml,ocsigen
I'm taking my first steps in web programming with the Ocsigen framework. I can build simple apps, but I've noticed that Ocsigen generates loads of unnecessary JavaScript code. Even the Hello world example, which has no interactive components at all, generates and includes a 400 KB JavaScript file. Is there...

Error: Reference to undefined global `Num'


ocaml,bignum
I'm trying to use the Num module in OCaml (bignums and big fractions). Some things seem to be working, while others seem not to, and I'm not able to generate a single, complete example. For instance: # Num.Int(234);; - : Num.num = Num.Int 234 # Num.mult_num;; Characters -1--1: Num.mult_num;; Error:...

Using ocamlbuild to build SDL and OpenGL application


opengl,compiler-errors,ocaml,sdl,ocamlbuild
I am trying to create an OCaml program utilizing both ocamlsdl and lablgl, but I can not figure out how to compile it. The relevant information is below: Note: ocamlsdl is not found by ocamlfind. When I go to the lib directory of .opam, I find an ocamlsdl folder, but...

How to correctly start a process from a specific directory with Lwt


ocaml,ocaml-lwt
It is easy to start a process from a specific directory with Lwt using the functions Sys.getpwd, Lwt_unix.chdir and Lwt_process.exec: Use Sys.getpwd to save the current working directory Use Lwt_unix.chdir to change to the specific directory Use Lwt_process.exec to start the external process Use Lwt_unix.chdir to change to the saved...

Determining in emacs the module in which function is defined?


emacs,ocaml
Say I have the following open A open List let double = map (fun x -> 2*x) [1;2;3] In emacs with merlin-mode I can place the cursor on map and execute merlin-type-enclosing to get the type of map. Is there a similar command (in merlin, tuareg, or others) that can...

Three-address code and symbol tables


compiler-construction,ocaml,abstract-syntax-tree,intermediate-language,symbol-table
I am working on a hobby retargetable C compiler in OCaml and I'm building it bottom up. So far I have an annotated AST type, abridged: type 'e expr = | Int of 'e * int | Var of 'e * var | Neg of 'e * 'e expr |...

Compiling an OCaml Book example on Hashtbl


ocaml
I've tried to compile the following example open Core.Std module Foo_and_bar : sig type t = S of string | I of int include Hashable.S with type t := t end = struct module T = struct type t = S of string | I of int with sexp, compare...

OCaml - Accessing absolute paths


ocaml,filepath,qtquick2
I'm developing an application where I implement the GUI in QtQuick and the logic in OCaml, using lablqt. In QtQuick I use a FileDialog to select a file. I need to use the path that the FileDialog returns in my OCaml program but I get an error every time I...

OCaml: Removing duplicates from a list while maintaining order from the right


ocaml
I just read this thread and find it interesting. I implement the remove from the left function in a few minutes: (* * remove duplicate from left: * 1 2 1 3 2 4 5 -> 1 2 3 4 5 * *) let rem_from_left lst = let rec is_member...

why the interpreter tell me “This kind of expression is not allowed as right-hand side of `let rec'”


functional-programming,ocaml
I write a ocaml program that parse an arithmetic expression by parser combinator. type 'a parser = char list -> ('a * (char list)) list let return (x: 'a): 'a parser = fun input -> [x, input] let fail: 'a parser = fun _ -> [] let ( >>= )...

Is there a good OCaml lib for creating a web service like pyramid in python?


ocaml
The question title says itself. I find pyramid in python is quite easy to use. In OCaml, I know Eliom, but guess it too heavy. And also in client side, I will use angular js and don't need to write browser page in OCaml. Any suggestions?...

Call Rmath via Ctypes from Ocaml on OS X


r,osx,ocaml,dylib
I want to use R's mathematical functions as provided in libRmath from Ocaml. I successfully installed the library via brew tap homebrew science && brew install --with-librmath-only r. I end up with a .dylib in /usr/local/lib and a .h in /usr/local/include. Following the Ocaml ctypes tutorial, i do this in...

ocaml regex issue on “{{”


regex,ocaml
I am trying to match "{{" in a string: let regexp = Str.regexp_string "{{" let _ = if Str.string_match regexp "a{{hello}}" 0 then print_string "yes" else print_string "no" This prints "no". Why is this not matching? "{" is not a special character: $^.*+?[] Unless I am reading the manual incorrectly,...

Base64 encode/decode issue


openssl,hex,base64,ocaml
I have two functions to convert to and from base64 using openssl: (* base64 encode *) let encode_base64 msg = let open_ssl_arg = "echo -n '" ^ msg ^ "' | openssl enc -base64" in let ic = Unix.open_process_in open_ssl_arg in let rec output s = try let new_line =...

OCaml native executable with linked C library


ocaml
What's the simplest command line to produce a native OCaml executable from a set of OCaml and C sources which use a C library that needs to be included via -l<lib>, such as -lm? For instance, the following code illustrates a (contrived) example where it would be necessary: // test.c...

ocamlbuild specify output location/name


ocaml,ocamlbuild
Can I specify the build location and file name with the ocamlbuild tool? I would like to be able to say (in pseudocode): ocamlbuild myapp.ml -b native -o bin/myapp ...

OCaml record acceding itself


ocaml,record
I'm reading an OCaml code where lots of record are defined. These record are defining functions for an interactive command line tool. Type for these records is: { name : string ; help : string ; run : string list -> unit } where name is the name of the...

Pack consecutive duplicates of list elements into sublists in Ocaml


ocaml
I found this problem in the website 99 problems in ocaml. After some thinking I solved it by breaking the problem into a few smaller subproblems. Here is my code: let rec frequency x l= match l with |[]-> 0 |h::t-> if x=[h] then 1+(frequency x t) else frequency x...

Performance difference between pattern matching and if-else


performance,pattern-matching,ocaml
Why can OCaml generate efficient machine code for pattern matching and not for if-else tests? I was reading Real World OCaml and I came across this section where they compared the performance of pattern matching to the performance of if-else tests. It turned out that pattern matching in their example...

Modify a matrix in ocaml


matrix,ocaml
I want to write a function that is modify every elements inside a matrix. But I have some problem when compiling. Warning 10: this expression should have type unit. I think because all function in ocaml need to return to a value or unit, so if I implement two tasks...

OCaml Unbound value List.assoc


ocaml
I'm compiling a module with a function that calls List.assoc, it fails to build giving me "Unbound value List.assoc" ... i've tried other List functions and they work fine, it also works fine in utop. I can reproduce this by compiling an ml file using corebuild and this code open...

Ocaml Product of two polynomials


ocaml,polynomial-math
How to compute the product of two polynomials ? For example: x^3 + 3x^2 +0.2x and 2x^4 + 3 First I made a type Type term = {coefficient:int; name:string; exponent:int};; Type polynomials = term list;; then I made a function calculate coefficient let product l l' = List.concat (List.map (fun...

Ocaml how to call a method in one class from another class


class,object,ocaml
I'm having some truble with objects and classes. I'm trying to call a method from the class kid in the class family to add a kid in the family anytime I want but I get an error I don't quiet understand. class virtual person name lastName sex = object val...

Ocamlfind command not found


centos,make,ocaml,opam,ocamlfind
I'm running into an issue installing a package that's reliant on ocamlfind but I'm getting an ocamlfind: command not found error when making. I have installed ocamlfind with the ocaml package manager and have tried reinstalling using "opam reinstall ocamlfind". I have also tried the 'eval opam config env' command...

Run bash script from ocaml


ocaml
I think that what i mean is in the title. I have tried to search if it is possible to run bash script from ocaml like from java or from php but i could not find. i know that we can use ocaml as a scripting language but it is...

What are the most common bugs in OCaml/Haskell/Scala programs? [closed]


scala,haskell,types,ocaml
Now when we have these fancy type-systems to prevent null-pointer bugs and memory bugs and all, what common bugs are left? Can these bugs be prevented with different type-systems or further programming language research? Edit: Do we know what bugs are common in functional programming? Edit 2: -3 question with...

OCaml error in basic loop


ocaml
I'm new with OCaml. I'm making a function working this way : I have "tab" in the scope which represents a 2D map, and three parameters, x, y and u. x and y represent the position of the player, and u the direction of the bomb (right, top left etc.)....

Pretty-print in js-of-ocaml


ocaml,pretty-print,js-of-ocaml
I have the following OCaml program open Js let lex s = Compiler.Parse_js.lexer_from_file s let parse s = lex s |> Compiler.Parse_js.parse let buffer_pp program = let buf = Buffer.create 10 in let pp = Compiler.Pretty_print.to_buffer buf in Compiler.Js_output.program pp program; Buffer.contents buf |> print_endline let () = parse "test.js"...

Function applied to too many arguments in lablgtk


gtk,ocaml
I need some help understanding why the following code will not compile. I am attempting to place a GSourceView2 inside a vertical box in lablgtk. I've adapted the code from this Ocaml article open GMain open GdkKeysyms let locale = GtkMain.Main.init () let main () = let window = GWindow.window...

OCaml |> operator


ocaml
Could someone explain what the |> operator does? This code was taken from the reference here: let m = PairsMap.(empty |> add (0,1) "hello" |> add (1,0) "world") I can see what it does, but I wouldn't know how to apply the |> operator otherwise. For that matter, I have...

Function getting called asynchronously in OCaml


ocaml
I am modifying the facebook/pfff tool, specifically this file. I am appending details (nodes and edge), in graph_code_java.ml, as and when as nodes and vertices are encountered to two separate files: Edges.json and GraphSON.json. In the end, after execution of everything I call function cleanup_graphson, which merges Edges.json and GraphSON.json....

Unit testing OCaml modules with pa_ounit


unit-testing,ocaml,ounit
I have a simple module to test with a few inline pa_ounit tests, i've setup the directory in the oasis style and got it all to build. For a reference I've been using: https://github.com/janestreet/textutils How would one execute the unit-tests for the above repo? I'm assuming there's an executable .ml...

OCaml, Sync on two events simultaneous with “and”


multithreading,events,synchronization,ocaml
I wrote an short program with 6 threads and 3 channels. 3 Threads are sending on 2 channels simultaneous and the other 3 are receiving. The problem is now, that it seems, that a sending thread takes one channel, but if it can't take the second one, it keeps the...

How to create a record type more than one polymorphic variables


types,polymorphism,ocaml,record
type 'a item = { name:string; quantity:'a };; This is a polymorphic type definition taught in Ocaml class. I'm trying extend this type have more than one polymorphic variables in item type like: type 'a item = { name:string; quantity:'a; price:'b };; But, I'm getting an error with unbound value...

C99-style hexadecimal floating-point constants in OCaml


floating-point,ocaml,floating-point-conversion
In OCaml, how can I parse C99-style floating-point constants (either as literals or inside strings) in hexadecimal, such as 0x1.b000000000000p4? It seems that they are not valid literals: # let c = 0x1.b000000000000p4;; Characters 12-27: let c = 0x1.b000000000000p4;; ^^^^^^^^^^^^^^^ Error: Unbound record field b000000000000p4 And there seems to be...

Print tokenization of a string


ocaml,ocamllex
I'm currently working on a programming language as a hobby. It would make lexing errors massively easier to debug if it was possible to have ocamllex print out the tokens it matches as it finds them, I occasionally just add print statements to my rules manually but there should be...

Cartesian (outer) product of lists in OCaml


list,polymorphism,tuples,ocaml
I would like to iterate over all combinations of elements from a certain number of lists which have the same length but not necessarily the same type. First I tried to write a general cartesian (outer) product function which takes a list of lists and returns a list of tuples,...

Struct member selected from type, it is not visible and will not be selected


unix,ocaml
I have a function that uses the Unix lib for its time functions: let rfc822 (t: Unix.tm) : string = Printf.sprintf "%s, %s %s %d %s:%s:%s %s" (List.nth short_days t.tm_wday) (padInt t.tm_yday 2 "0") (List.nth short_month t.tm_mon) (t.tm_year + 1900) (padInt t.tm_hour 2 "0") (padInt t.tm_min 2 "0") (padInt t.tm_sec...

Is there an OCaml equivalent of the [] attribute for DUs in F#?


f#,ocaml,discriminated-union
In F# programs I prefer to use [<RequireQualifiedAccess>] type MyType = | FirstOption of string | SecondOption of int so that in code that uses MyType I am forced to write MyType.FirstOption instead of just FirstOption. Is there any way to force this in OCaml?...

Are streams in ocaml really used?


stream,ocaml,ocaml-lwt
Looking at different ocaml projects, I don't see the built-in Streams in the language ever used. Even in the recent Real World Ocaml book, Streams are not mentioned at all, which is odd. What's the reason for that? Is it because Lwt or Core superseed them?...

In Opam how do I tell which package owns a given file?


ocaml,opam
In Opam how do I tell which package owns a given file under ${OPAMROOT}/system? If there is no direct mean to achieve this, is it possible to list files owned by a given package?

What is the use of eval `opam config env`?


ocaml
After the installation of opam, it asks to do eval `opam config env`. What is the exact usage of it?...

replace camlp4 with camlp5 in utop


ocaml,camlp4,ocamlfind,utop
I'm working with OCaml code that needs camlp5; however, the toplevel (I'm using utop) automatically loads the newer, incompatible camlp4. These are the startup messages: 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)...

Functional Breadth First Search


python,haskell,functional-programming,ocaml,sml
Functional depth first search is lovely in directed acyclic graphs. In graphs with cycles however, how do we avoid infinite recursion? In a procedural language I would mark nodes as I hit them, but let's say I can't do that. A list of visited nodes is possible, but will be...

What does float->float mean in OCaml?


ocaml,ml
I have this type, which defines an expression. I know that * symbol lets me add pairs, but what is the -> for? # type expression = Value of float | Sum of (expr*expr) | Subtraction of (expr*expr) | Fc1 of ((float->float)*expr) ...

Does OCaml have C-like round() and trunc() functions?


floating-point,ocaml
OCaml's standard library includes several floating-point functions equivalent to C ones, such as mod_float for C's fmod(), the exponentiation operator ** for C's pow(), and other functions such as ceil, log, etc. But does it also include equivalents for round() and trunc()? There is truncate/int_of_float, but their type is float...

#use “str.cma” and #use “name.mli” in Eclipse


ocaml
How do I use "str.cma" in Eclipse? Also, how do I link name.ml to name.mli? I would usually do #use "name.mli" in "name.ml" when using Emacs....

Making socket communication using bin_prot


sockets,ocaml,communication
I want to make Socket communication using bin_prot in OCaml. However, I can't find any detailed explanation or example to do that. I made Socket communication in the other way before, so I know the flow of it. Do you have good explanations or examples to make Socket communication using...