OCaml cant get array length
I'm trying to make shifting of array.But I'm getting syntax error on arr.length. (2nd line)let shift (arr : array) (k : int) = let size = arr.length;; let shifted = Array.make size 0;; for i = 0 to...
View ArticleAdding graphics to a ReasonML project
I've looked at this question -- How do I add an OCaml library reference to a Reason code file? -- which shows how to add an OCaml library to a ReasonML project. But it doesn't seem to be working for...
View ArticleWhy my little monad in OCaml doesn't compile?
I'm learning Monad in OCaml, but it doesn't compile.I reduced the code to reproduce the problem at easiest way :file try.ml:module type TRY = sig type 'a t val return : 'a -> 'a tendmodule Try : TRY...
View ArticleNot sure why I'm getting unbound value when used with List.iter
I'm writing test code for my OCaml project and when using the below code, it works fine.open Printfopen Ip2location(* query IP2Location BIN datababase *)let meta = Database.open_db...
View ArticleModule type semantics in OCaml
I am new to OCaml and I am struggling a bit with understanding how module types work.module type I = sig type tendmodule EQ (M : I) = struct let equal (x : M.t) (y : M.t) = x = yend(* Explicitly type...
View ArticleWhat is the OCaml idiom equivalent to Python's range function?
I want to create a list of integers from 1 to n. I can do this in Python using range(1, n+1), and in Haskell using: take n (iterate (1+) 1).What is the right OCaml idiom for this?
View ArticleWhat do you call a set of OCaml classes? [closed]
If an OCaml package is a set of OCaml modules, what do you call a set/group/collection of OCaml classes?In Java, a package is a set of Java classes.Reference:...
View ArticleLocally abstract type VS explicit polymorphism in polymorphic recursion context
Could you explain me why this program does typechecklet rec plop1 : 'a 'b 'c. 'a -> 'b * 'c = fun x -> (fst (plop1 ""), snd (plop1 1))while this one does not?let rec plop2 (type a b c) (x : a) :...
View Articleocaml tail-recursive functions
I'm running Ocaml using utop, when I run the below function on a very long input:let string_to_list str = let rec loop i limit = if i = limit then [] else (String.get str i) :: (loop (i + 1) limit) in...
View ArticleThis expression has type 'a ->'a array array but an expression was expected...
How is it possible to correctly manipulate a matrix in Ocaml?What am I missing here, when assigning a value to a position on the matrix?let dynamic arraymoedas valor len = let arrayAux =...
View ArticleHow to split a list in two list
I have to make a function who splits a number list int two list:[Int(17);Float(18.9);Int(777);Float(15.5)] -> [Int(17);Int(777)] , [Float(18.9);Float(15.5)]type number = | Int of int | Float of...
View ArticleOCaml - a function which returns all the prefixes of a list
For [1;2;3] , I want to return [[]; [1]; [1; 2]; [1; 2; 3]] . I have hit a wall and i need help, this is what i have done so farlet rev list = let rec aux acc = function | [] -> acc | h::t -> aux...
View ArticleCombine two lists while removing duplicates
The goal is to combine (append) two lists while removing the duplicates.let rec find_dup a lst = match lst with | [] -> false | hd::tl -> if (hd == a) then true else find_dup a tl;;let rec app...
View Articletail-recursive maximum element in a binary tree in OCaml
I am practicing tail-recursion and I want to, given the typetype 'a tree = Leaf of 'a | Pair of 'a tree * 'a treeand a function that that finds the maximum element in a binary treelet rec tree_max t =...
View ArticleTail-recursively, maximum element in a binary tree in OCaml
I am practicing tail-recursion and I want to, given the typetype 'a tree = Leaf of 'a | Pair of 'a tree * 'a treeand a function that that finds the maximum element in a binary treelet rec tree_max t =...
View ArticleOCaml higher order functions
Somebody please explain the algorithm in this problem for OCaml.I have the solution but I do not understand it.Define iterup: (int * 𝛼→𝛼) → int → int →𝛼→𝛼. Iterup takes a function which receives the...
View ArticleFunction doesn't print correctly
So I have to create a "lights out" game. I have to create two functions. One function "flip"val flip : bool array array -> int -> int -> bool array array = <fun>that given a bool matrix...
View ArticleWhy this recursion example in ocaml doesn't work for negative number?
In the Think Ocaml book the author gave this example:let rec countdown n = if n <= 0 then ( print_string "Blastoff!"; print_newline()) else ( print_int n; print_newline(); countdown (n-1); ());;The...
View ArticleCan you compile an OCaml project natively as a windows library?
I am new to OCaml (but I have used SML in the past) and I want to know two things:1- Can OCaml programs be compiled as libraries at all?2- If so, can they be compiled as native Windows dlls.What I want...
View ArticleUsing the OCaml reverse application operator |> to construct a function...
I often find myself using the |> operator when constructing functions to pass as parameters to methods like List.find. For example, I have this code snippet:let parse_test_header (header : string...
View Article