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

How to access private definition from other library for testing

I have two libraries: lib/ dune src.ml src.mli test/ dune test.mlboth are libraries and I am testing in the test library with ppx_inline_test as i do not want them to be included in the librarydune...

View Article


I want to do 2 things after a "then" statement in a "if.. then.. else" statement

let rec filtersList2fromList1 (List1:string list) (List2:string list) : string list = let finalList = [] in match List1 with | s :: tl -> if List.mem s List2 = true then finalList @ [s] else...

View Article


Could anyone explain this OCAML syntax to me

I am trying to append a string to an existing string.I came across this thread here which explains it.Just for reference I am pasting the content here from that pagelet (^$) c s = s ^ Char.escaped c (*...

View Article

Iterating through a string using For loop

I am trying to iterate through the characters of string using for loop however I get the following errorlet str = "Hello"for var=0 to (String.length str -1) do let temp = String.get str vardone;;Error...

View Article

Lookup tables in OCaml [closed]

I would like to create a lookup table in OCaml. The table will have 7000+ entries that, upon lookup (by int), return a string. What is an appropriate data structure to use for this task? Should the...

View Article


How to append to string in ocaml?

I don't know how to add some string to itself in loop.let parameters = [| [| ("name", "fdjks"); ("value", "dsf") |]; [| ("name", "&^%"); ("value", "helo") |] |] ;;let boundary =...

View Article

Removing duplicates from a list while maintaining order from the right

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...

View Article

How to find the index of the first non-zero element in an array

I am trying to find the index of the first non-zero number in an array.Consider an array: [0;0;1;2;0;4;5;6]The expected result will be index of number 1 which should return the index result of 2.It...

View Article


Sorting by alphabetical order

I would like to create a function which will add a registration number plus a certain negative time. Here is an example : # enter_car "DEF456" (−4) [("ABC13", −2); ("GHI789", −3)];;− : (string∗int)...

View Article


OCaml initializing list in loop for

I am a beginner with OCaml. I would like to skip the first element of my list.Here is my list:let l = [1;2;3;4;5;6;7;2;1];;I want to use this in my FOR:let l = List.tl l;here is my full code:let l =...

View Article

OCaml matching tuples? Why is this match case unused?

I have the following bit of code in OCaml: let matchElement x y= match x with | (y,_) -> true | _ -> false;;and I'm getting a warning that the case _ will always be unused. My intention was that...

View Article

How to delete all occurrences of an item in a list?

So...I have a few problems with that,my goal is to delete items from a list as follows.For example,I have a list like that:let list = [1;2;4;5;1;1;6]And when i do some like this:remove_from_list 1...

View Article

Why can I not print this input a second time in OCaml?

I am very new to OCaml and am attempting to learn and write a program at the same time. I am writing a palindrome program. I am attempting to get a string from the user such as d e v e d or Hello...

View Article


Checking if all elements are equal with map/fold

Given a list of elements, like [1, 1, 1] or ["a", "a", "a"], how can I check if they're all equal using map/fold?I tried to do something like this:let eq lst = fold (=) lstwhich doesn't compile because...

View Article

OCaml: Effective Path to GUI Programming?

I have seen a few threads that touch on GUI programming in OCaml but I don't feel they clearly lead to a clear-cut solution when a GUI interface is needed.My question, to be more specific, is as...

View Article


Effective Path to GUI Programming? [closed]

I have seen a few threads that touch on GUI programming in OCaml but I don't feel they clearly lead to a clear-cut solution when a GUI interface is needed.My question, to be more specific, is as...

View Article

Can someone explain OCaml Tail Recursion Like I am five?

I cant wrap my brain around tail recursion specifically in ocaml also explain why one calls the "in" function at the end. P.S. I am talking most basic tail recursive function.

View Article


Flattening a Nested List in OCaml

I'm doing problem 7 of the OCaml exercises. It basically asks given a nested list as defined:type 'a node = | One of 'a | Many of 'a node listWrite a function function flatten that flattens it:assert (...

View Article

OCaml `Map.Make` input module

I am following the example here.module IntPairs =struct type t = int * int let compare (x0,y0) (x1,y1) = match Stdlib.compare x0 x1 with | 0 -> Stdlib.compare y0 y1 | c -> cendmodule PairsMap =...

View Article

Tail call optimization with a function returning a tuple

I have a simple function that splits a list at an index:let rec split_at ls i = match i with | 0 -> ([], ls) | _ -> match ls with | [] -> raise Not_found | h::t -> match split_at t (i - 1)...

View Article
Browsing all 518 articles
Browse latest View live


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