Quantcast
Channel: Active questions tagged ocaml - Stack Overflow
Browsing all 518 articles
Browse latest View live
↧

How to detect Esc key using Unix module and raw mode?

This is the code in OCaml to detect keys using the Unix module and raw mode in the linux terminal.The only key I can't detect is ESC. There could be others, but my main goal is to detect ESC key.Here...

View Article


Just want choose some random elements of a list and return them in OCaml

I want to choose n distinct random elements in a list l and return them in choose_elements but I have a StackOverFlow error for sufficiently large lists!I tried to use a tail_recursive function...

View Article


How can I return an int variable after handling it several times in a function?

I'm writing a function in OCaml that reads a string, validates if it's an integer and converts it to such, then checks if it's included within a range [a,b]. The validations work fine, but I need the...

View Article

Counting frequency of char using switches

I am trying to count the amount of time each char appears in a string, I'm using switches and a for loop, however, they are not being incremented properly. Here is my codelet countChar x = match x...

View Article

About the complexity of Map.remove in OCaml

It seems Map.remove will return a new map structure, leaving the original map the same.How can the complexity still be O(lg n)?

View Article


Why can't dune recognize ppx_jane?

I am now writing a project in OCaml v4.06, and I have installed ppx_jane v0.11.0. Actually the environment is based on a docker image.Now here is the dune file(menhir (modules parser))(ocamllex...

View Article

OCaml This variant expression is expected to have type unit

I'm having a problem with if statements that I cannot figure out.My code:type chess_board = char array array;;type position = int * int;;let chess_board_1:chess_board = [| [|'';'';'';'';'';'';'';''|];...

View Article

Match inside match - ocaml raises syntax error

Does anyone know why this function raises the syntax error? I haven't provided my written side functions, since they are probably not that relevant here, since it's revolving around proper syntax.I...

View Article


What is wrong with this code for creating lists in OCaml?

I am trying to create a program in OCaml [randlist len max], which would generate an int list of length len with integers smaller than max.I am wondering what is wrong with the following code:let...

View Article


Construct a list of sublists of N*N elements

I'm trying to construct a list in OCaml only using List.map, List.filter, and anonymous functions.What I want to get is this:- : int list list = [[2; 2]; [5; 5; 5; 5; 5]; [7; 7; 7; 7; 7; 7; 7]; [3; 3;...

View Article

Tail recursive zip function

I have a function called zip_with_2_fs. I am trying to make it tail recursive (zip_with_2_fs_tr) but I don't really understand what I am doing. I am new to Ocaml and would like to develop a deeper...

View Article

Max int in list ocaml

I want to find the max element in a int list.The idea is to call find_max only once and let support do the dirty job.The function support returns an int, the first value is 0 then when a new max is...

View Article

Problem with a list in the form of [(key, [..]) ; ...]

I'm trying to learn OCaml since I'm new to the language and I stumbled across this problem where I can't seem to find a way to see, in a function where I need to merge 2 kinds of these lists, if there...

View Article


Keepsorted function

I'm trying to solve a problem on a function called "keepsorted";This function has to keep a sub-list of growing number form a list called l1.For example if I have let l1 = [1; 2; 0; 1; 2; 4; 3; 5; 3;...

View Article

Why does ocaml keep miss understanding type?

module Value =struct type t = Int of intendmodule M = Map.Make(String)type expr = | Num of int | Add of expr * exprtype t = Value.t M.t (* Value.t is Int of int *)let rec add_map (st: string list) (e:...

View Article


A list of types from modules sharing the same signature?

I'm trying to create a bunch of types to generate a MIDI file to be played in a separate audio player (yes, I know there are libraries available... I'm using this as a way to learn). I created a single...

View Article

why isn't my OCaml babbage program working?

code:let babbage = let n = read_int in let current = ref n in let square = ref !current in let mul = !current * !current in while ((square := mul) mod 1000000 != 269696) && (!square <...

View Article


Or-patterns in Haskell

In OCaml, I was used to writing code which looked like:let combine o1 o2 = match o1, o2 with | Valid, Invalid | Invalid, Valid -> Invalid | _ -> ...I didn't find a way to write or-patterns in...

View Article

Ocaml efficient quicksort

I'd like to know how can write an efficient version of quicksort where list is partitioned in one pass.I've this fragment of code,let rec quicksort' = function [] -> [] | x::xs -> let small =...

View Article

Ocaml extlib-1.4 installation

I've tried to install extlib-1.4 but got an error(i'm noob)I typed ocaml install.ml and got:File "bitSet.ml", line 23, characters 40-53:23 | let bcreate : int -> intern = Obj.magic String.create...

View Article
Browsing all 518 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>