Questions tagged [ocaml]

1

votes
2

answer
62

Views

OCaml Marshal very large data structure

I would like to send a very large (~8GB) datastructure through the network, so I use the Marshal module to transform it into Bytes. My problem is that the memory doubles, because we need to store both representations (initial data and Marshaled data). Is there a simple way to Marshal into a Stream i...
Anthony Scemama
1

votes
1

answer
59

Views

Adding parametrically a `Null constructor to polymorphic variants

The following type declarations do not work: type 'a or_null = [ 'a | `Null ] and type 'a or_null = [ 'a | `Null ] constraint 'a = [> `A | `B ] With the message: Error: The type 'a does not expand to a polymorphic variant type Hint: Did you mean `a I would like to achieve this without using another...
byako
0

votes
0

answer
3

Views

Getting a random number in a function in OCAML OR Telling compiler to evaluate function each time

I'm new to OCAML and was playing around with putting a marker on a random 5X5 square. I've written the example program below. 'silly_method1' works but notice that it takes an argument. I don't really have argument to pass in for what I want. I'm just asking for a random number to create my robo...
Dave
6

votes
7

answer
218

Views

Which programming languages support functions that take themselves as arguments?

I'm doing an academic exercise (for personal growth). I want to find programming languages that allow you to define functions that are capable of accepting themselves (i.e., pointers to themselves) as arguments. For example, in JavaScript: function foo(x, y) { if (y === 0) return; x(x, y - 1); } foo...
Joshua Wise
1

votes
2

answer
46

Views

cleanest partial application of subtraction operator

If I want a function that subtracts an int argument from the number 2, I can do let two_minus = (-) 2 But what if I want a function that subtracts 2 from an int argument? In Haskell, I can do let minus2 = flip (-) 2 But in Ocaml 4.02, flip is not part of the standard library. For now, I've settled o...
Captain_Obvious
1

votes
1

answer
86

Views

Fluent Interface in ReasonML

Is there a way to get a module to return its own type using a functor submodule? Example module type A = {}; module type B = { let varB: int; }; module AMod : A = {}; module BMod : B = { let varB = 42; }; module Fn = (A: A, B: B) => A; /* Lets say this does some complex function that returns Type A...
GTDev
1

votes
1

answer
53

Views

How to coerce object parameters in OCaml

I've been playing around with the OCaml object system and typing in general. Recently I've been playing with polymorphic variants and objects and I've run into some trouble getting the type system to do what I want. Here's what I've gotten to work, and makes sense Given some type and function defini...
OcamlUser412
1

votes
2

answer
69

Views

OCaml : how to install pretty printer and use it in the code?

In the OCaml's top-level and debugger one can register a pretty printer via install_printer printer-name. Is there any way to achieve the same, but in the OCaml code ? More concretely, I need a logging facility that does not require to explicitly specify a pretty-printer for each invocation of log...
eupp
1

votes
1

answer
48

Views

How to wrap an OCaml expression with unit ()?

The following expression 3 ; () in utop results in the below response utop # 3 ; ();; Characters 0-1: Warning 10: this expression should have type unit. Characters 0-1: Warning 10: this expression should have type unit. - : unit = () How can we make a non-unit expression (like 3) return unit to work...
James Mishra
1

votes
1

answer
53

Views

Tell ocamlbuild where to find module

I have an OCaml project, for which I use ocamlbuild. In this project, I have two subprojects, subproject1 and subproject2. subproject2 needs to use a module called Module from subproject1. To sum up, I have the following structure: project/ | |-- subproject1 | | | |-- module.ml | |-- subproject2...
Right leg
1

votes
1

answer
40

Views

Running `ocsigen` gives linking error: `dllssl_threads_stubs.so` image not found

I'm currently fighting with a strange linker issue from ocsigenserver. It's apparently looking for ocaml-related openssl dynamic libraries. I have both done a brew install openssl (at latest version) and also an opam install openssl. But I still get the following error: ocsigenserver -c /usr/local/...
Kristopher Micinski
1

votes
1

answer
594

Views

Why can't opam install the graphics package?

I tried to install the ocaml graphics package, but it fails. Any suggestions for how I can fix it? ~/Documents/Work/Code/OCaml with graphics: opam update =-=- Updating package repositories =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 🐫 [default: http] Command started [default: http] Command starte...
Tim Leonard
1

votes
0

answer
44

Views

How can I see the size a package will require to download?

I'm on a restricted bandwidth and would like to see how much an opam install some-package would require to download. Any such option with opam?
Olle Härstedt
1

votes
0

answer
52

Views

Tk on OCaml, How does 'Button.flash' work ?

I am a new person to OCaml GUI programming. I would like to know how 'Button.flash' on Tk module works. Here is my code; open Tk open Printf (* * +--------------------------------------------+ * | Window | * +--------------------------------------------+ *...
shin1h
1

votes
1

answer
96

Views

Hashtables in llvm using ocaml

I'm working on a toy programming language/compiler using ocaml and its llvm bindings. I want to have hashtables/hashmaps as a built in data structure for my language however I'm confused as to how to go about them. I know the llvm c++ api has an ADT directory with a bunch of data structures that wo...
wow
1

votes
1

answer
61

Views

Block all signals in OCaml

I want to block all signals in OCaml using Unix.sigprocmask. In C, I would do this using the function sigfillset, which is not available in the Unix module. So how do I get a list of all signals in OCaml, that I can then pass to sigprocmask?
user4759923
1

votes
1

answer
60

Views

recursive function that iterates through a list of tuples (int * int) and adds the second value

I want to write a function that iterates through a list of tuples (int * int) and adds the second value of the tuple if the first value of the tuple is the int 0. I came up with the following code however, it raises exception for every case, could anyone point out what is the error in the function?...
JackWu
1

votes
1

answer
64

Views

How to move the OPAM root?

Is it possible to move the OPAM root? Or, to create a 'portable' (in the sense of e.g. 'firefox portable') version of an OPAM root? That is, install a bunch of packages via opam --root=/PATH/TO/A, then move /PATH/TO/A to /ANOTHER/PATH/TO/B, and run everything from there. A naive try led to a small e...
vog
1

votes
1

answer
85

Views

What is the best data structure to model a path through an undirected graph?

I'm working on modeling a path search and deduction board game, to practice some concepts I am learning in school. This is a first attempt at analyzing graphs for me, and I would appreciate some advice on what kind of data structure might be appropriate for what I am trying to do. The game I am mode...
Christian Kaas
1

votes
1

answer
99

Views

Load ml files dynamically in OCaml toplevel?

As all we know, in we can use #use directive in OCaml toplevel to load ml files then execute. And we can also use ocaml.exe to load and execute ml files. Here my requirement has some changes to these two situations: I have a main process, who creates a ocaml toplevel to execute scripts, the two pro...
Enzojz
1

votes
1

answer
72

Views

Turn on stack traces for exceptions in bucklescript

I'm trying to port some OCaml tests from OUnit2 to bs-jest, but I get a Not_found exception raised from some test and I don't know where it's coming from; is there a way to enable stack traces in bucklescript? In OCaml, I would pass the -g option to the compiler, but it doesn't seem to do anything w...
LP_
1

votes
2

answer
75

Views

How to fully match a dereferenced pointer with CIL module?

I'm working with https://people.eecs.berkeley.edu/~necula/cil/api/Cil.html and would like to match the pointers and extract the variable name in a certain expression Example (assume this is correct) int **p0, *p1, **p2, ***p3; my expression : **p0 + *p1 + **p2 + **p3 I would like to match the ent...
Oleg
1

votes
0

answer
46

Views

Using C library in mirageos

I need to do U2F in a mirageos project, and as far as I can tell there are no ocaml implementations of it. I've read this article on the blog and it sounds like it should be possible to use the C library provided by yubico for this, but the article doesn't really explain how to even compile that in...
Ulrar
1

votes
0

answer
64

Views

Python+ocaml TCPServer, TIME_WAIT

I'm trying to have an ocaml (client) process communicate with a python (server) process over a TCP socket; they are both pretty simple and just need to send lots of little json messages to each other. But, after a while -- after having made many connections -- the client is no longer able to connect...
Kevin Ellis
1

votes
2

answer
179

Views

Installing ocamlfind.1.8.0 on macOS Sierra

I'm follwing dev.realworldocaml.org to learn OCaml. I'm stuck at installing where I can't get access to the ocamlfind library. My default ocaml is 4.07.0 installed via homebrew: PrisBook:~ prisc_000$ brew list ocaml /usr/local/Cellar/ocaml/4.07.0_1/bin/ocaml Opam is opam V2: PrisBook:~ prisc_000$ op...
idkjs
1

votes
2

answer
61

Views

How to use fold on an elaborate function in ocaml

As the title suggests, I want to use fold. If I understand correctly, it it used to apply a function to every item in a list. That's what I want to do with my function, but I don't know how to format it. Here is the function I want to use with fold : let pairing list = let rec aux counter length pai...
John Doe
1

votes
0

answer
55

Views

How install ocp-indent with git bash in windows 7

I have installed git bash with this link and Ocaml with this link (click on the Installer for 64-bit OCaml 4.02.3 + OPAM button). Then I have type opam install ocp-indent in git bash and see the result The following actions will be performed: - install ocamlfind 1.8.0...
Et7f3XIV
1

votes
1

answer
73

Views

ocamlc - compiling ocaml-wasm - Error: /usr/lib/ocaml/bigarray.cma is not a bytecode object file

I'm trying to make install ocaml-wasm 1. Unfortunately the build is failing with the error-message: Error: /usr/lib/ocaml/bigarray.cma is not a bytecode object file Here's a Dockerfile so you may reproduce the error: FROM base/archlinux RUN pacman -Sy --noconfirm ocaml ocamlbuild wget unzip make RUN...
ambiso
1

votes
1

answer
66

Views

behavior explanation for higher order functions and labeled argument in OCaml

Taking an exemple derived from RWOCaml : utop # let divide ~first ~second = first / second;; val divide : first:int -> second:int -> int = utop # let apply_to_tuple_3 f (first,second) = f second first;; val apply_to_tuple_3 : ('a -> 'b -> 'c) -> 'b * 'a -> 'c = utop # apply_to_tuple_3 divide;; Err...
nicolas
1

votes
1

answer
101

Views

How to use OCaml libraries in Swift?

I have a library developed in OCaml. I need to call functions of the library from my Swift code. Is it possible to do? How?
Valentine Zakharenko
1

votes
0

answer
62

Views

Register allocation optimization in a C compiler written in ocaml

What is the fastest graph implementation for removing and adding vertices? It seems like this part of my C compiler is the slowest, and can take up to 9/10 ms per vertex removed (which is a really long time when there are something like 60,000 vertices in the graph). If not is there some way to do m...
real_father
1

votes
0

answer
41

Views

Source location for a type definition from utop

In utop, can I get the source location for the definition of the type, say, result ? utop # #show_type result;; type nonrec ('a, 'b) result = ('a, 'b) result = Ok of 'a | Error of 'b (defined in pervasives Result type type ('a, 'b) result = | Ok of 'a | Error of 'b Since 4.03.0 but I am not sur...
nicolas
1

votes
1

answer
76

Views

permutation in a list with repetition ocaml

I have a function that makes combinations of K distinct objects chosen from the N elements of a list, the problem is doesn't permute with repetition, for example: extract 2 ['a';'b';'c';'d'];; - : string list list = [['a'; 'b']; ['a'; 'c']; ['a'; 'd']; ['b'; 'c']; ['b'; 'd']; ['c'; 'd']] Here is my...
Toshiconzas
1

votes
0

answer
38

Views

Fatal error: unknown C primitive `Base_am_testing'

After building Flow with make like make build-flow-debug and running it with ocamlrun like ocamlrun bin/flow check local-test/test.js I'm getting following error Fatal error: unknown C primitive `Base_am_testing' I think the error has something to do with ocaml base, but I'm not sure. I'm thinking o...
Ville
1

votes
1

answer
49

Views

failure to install ocaml-top on mac

I'm attempting to install ocaml-top on a mac but receiving the following failure message. Any idea? Thanks! I tried: opam install ocaml-top And received the following `∗ install ocaml-top 1.1.5 Gathering sources > 🐫 [ocaml-top.1.1.5] found in cache Processing actions 🐫 [ERROR] The co...
Danny
1

votes
0

answer
34

Views

How to run dune build @doc with arguments

I have an ocaml project using Dune. I want to generate documentation using Odoc. Currently, running dune build @doc works, but I want to pass in the -short-functors option to Odoc. How do I pass options to Odoc through Dune?
nosman
1

votes
0

answer
41

Views

OCaml: dune missing library, opam says its there

I have a dependency called 'sets', which has been build in a local directory 'dep/sets'. opam list gives the following: sets 1.0.0 pinned to version 1.0.0 at file:///... opam pin gives: sets.1.0.0 rsync file:///... But dune utop gives Error: Library 'sets' not found. I've seen https://github.com...
vcapra1
1

votes
1

answer
42

Views

How to generate a proper makefile for an Ocaml project

I am learning how to compilers work. I read a tutorial on how to use Ocamllex and Ocamlyacc to read an input from a source code, generate the tokens and generate a syntatic tree in order to compute the execution of the program later. I had to recompile the code often while I was on the learning proc...
Thiago Sev
1

votes
1

answer
198

Views

GODI installation error

I'm running Fedora 9 x86_64 and am more or less a Linux newbie (not using it, but installing and such). The error occurs in the second stage of the bootstrap (i.e. './bootstrap_stage2'). It does a whole lot fo stuff and then these errors start happening: Fatal error: exception Out_of_memory make[8]:...
1

votes
2

answer
298

Views

How to copy Gdk.image?

Is it possible to make a copy of Gdk.image object using lablgtk2 for Ocaml? I tried to find 'copy' or 'clone' methods but failed.
Alfa07

View additional questions