
OCaml » Stack Overflow
1,000 FOLLOWERS
Stack Overflow is the largest, most trusted online community for developers to learn, share their programming knowledge, and build their careers. OCaml is a strict statically-typed functional programming language, focusing on expressivity, correctness, and efficiency.
OCaml » Stack Overflow
5h ago
I am trying to run OCaml here and when I type 2;; I get nothing, I used utop interpreter before, but I am confused now ..read more
OCaml » Stack Overflow
5h ago
To use an infix operator as a prefix function in OCaml, you can put parenthesis around it. for example, 1 + 2 is equivalent to (+) 1 2.
How do you do the opposite?
For example, in Haskell, a prefix function taking two parameters can be used as an infix operator by wrapping it in backticks. prefixFunction x y is equivalent to x `prefixFunction` y. Is there an equivalent in OCaml ..read more
OCaml » Stack Overflow
2d ago
I'm looking at the List documentation. 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, because if it's O(n), I would rather have to write it in a less concise way.
I'm wondering why didn't they provide List.sublist func, if List.nth is not O(1), because it's such a quite common operation ..read more
OCaml » Stack Overflow
4d ago
I need to install unison on a mac M1 Ventura that follows the same specs of the one installed on a Debian Buster server (where I am just an user).
I tried to install unison using homebrew but the version is not compatible. I also tried to follow the instructions on a similar question but I couldn't pass the first command (something to do with ocam that is not installed on my mac).
Could somebody out there help me out?
Many thanks ..read more
OCaml » Stack Overflow
4d ago
In OCaml, there is a construct called univ_map.t. The idea is you can create unique ids, that are genericed over a type 'a. Then, the univ_map allows you to map from those keys to values also of type 'as. Here is an example.
The thing that makes these univ_maps special is that they allow you to store values with many different types in the same dictionary, where you retain type safety because the key of the dictionary tells you what type you're getting out.
Is there a construct that would allow me to do something similar in Rust? I know in OCaml they are implemented with open variants, which I ..read more
OCaml » Stack Overflow
4d ago
I'm trying to write a program using the OCaml language, but am experiencing problems utilizing nested functions. Here's the code I wrote:
let prime : int -> bool
= fun x ->
if x > 2 then
let a = x - 1 in
let rec checkZero a x =
if a > 1 then
match x mod a with
0 -> false
|_ -> checkZero (a - 1) x
else if a = 1 then
true
else if x = 2 then
true
else
false
;;
To briefly explain my code, I'm using a nested function called checkZero to determine whether or not x is divisible by a value a which star ..read more
OCaml » Stack Overflow
4d ago
Hi I am kind of confused about substitution in Ocaml.
I know something like v[15/v] would evaluate to 15 because it is replacing all free variable in the expression v, but for a function like fun v -> v [15/v], what would the answer be? would it be fun v -> 15? or simply fun v -> v, because I thought fun v -> v is a closed expression, so there is no free variable in it ..read more
OCaml » Stack Overflow
5d ago
The Ocaml 5 manual section 11.4 says a typeexpr can have the form typexpr as ' ident.
What are these as aliases for?
Here are some examples that compile:
type 'a x = 'a as int
type y = 'a as int`
At first I thought as aliases were like type-level lets, but I couldn't figure out how to use the new type variable, or how this would differ from constraint:
type x = 'a as int in ('a, 'a) (* doesn't compile ..read more
OCaml » Stack Overflow
5d ago
I just want to code OCaml on VSC, with my Mac and I can't despite installing the extensions necessary on VSC, and installing OCaml language, opam and dune on the terminal, I still can't run on VSC.
I was expecting to code OCaml on VSC and then run, but I can´t run it and when I try to run with compiler on the console, but the feedback is not the best so I was really wanting to be able to work fluently but i can´t ..read more
OCaml » Stack Overflow
1w ago
New to ocaml world, I have installed Chamo all seams ok but I can't start it, whats wrong??
~/opam list
# Packages matching: installed
# Name # Installed # Synopsis
astring 0.8.5 Alternative String module for OCaml
base-bigarray base
base-bytes base Bytes library distributed with the OCaml compiler
base-domains base
base-nnp base Naked pointers prohibited in the OCaml heap
base-threads base
base-unix base
cairo2 0.6.4 Binding to Cairo, a 2D Vector Graphics Librar ..read more