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

How to convert 'module type' with 'non-generic type' to 'module type' with...

I have a module type with three non-generic types:module type LAYER = sig type cytoplasm_t type nucleus_t type t val cytoplasm : int -> t -> cytoplasm_t val nucleus : int -> t -> nucleus_t...

View Article


Unable to use Core on Windows

I'm trying to use the Core package in OCaml, and I cannot seem to get it working. I have installed the core package using opam install core, which worked just fine. However, when I try to load the...

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

Cartesian Product of modules

Trying to create a functor which would, given 2 modules of signature Set.OrderedType, create a module of signature Set.OrderedType representing objects of type the product of the two types, (Not really...

View Article

Ocaml where and how to define a function that only returns a value

I have the following codelet mymain origarg = let results = helperfunc origarg in (results, origarg)let rec helperfunc newarg = match newarg with | [] -> [] | h::t -> h :: helperfunc...

View Article


How to count records of a list with a specific property in OCaml?

Lets say we have a record which defines a person type with the properties name and age:type person = {name:string ; age:int };;and initialize a list with different types:let personlist =...

View Article

F# changes to OCaml [closed]

F# is derived from OCaml, but what major items are missing or added? Specifically I'm curious as to whether the resources available for learning OCaml are also useful to someone who wants to learn F#.

View Article

OCaml: Type mismatch error between modules

ast.mltype fundef = FunDef of string * string list * exprinterpreter.mllet interp_fundef (d: Ast.fundef) (g: FStore.t) : FStore.t = match d with | Ast.FunDef (x, pl, e) -> (FStore.add x (pl * e)...

View Article


How do I determine what modules an OCaml library provides?

I'm just starting a project to analyze C programs using goblint-cil.I know I needed to use a library to import it. The README for goblint-cil says the following:# #use "topfind";;# #require...

View Article


Appending elements to a map

let interp_fundef (d: Ast.fundef) (g: FStore.t) : FStore.t = match d with | Ast.FunDef (x, pl, e) -> (FStore.add x (pl, e) g)let interp (p: Ast.prog) : Value.t = let g = FStore.empty in let s =...

View Article

Print a List in OCaml

I want to do something as simple as this:Print a list.let a = [1;2;3;4;5]How can I print this list to Standard Output?

View Article

OCaml Type Mismatch Error with Functor-Based Dictionary Insertion

I'm working on an OCaml project where I've defined a functor-based dictionary using modules and functors. I've encountered a type mismatch error when trying to insert elements into the dictionary. I've...

View Article

Exception Handling in OCaml

Say we have these two functions:let divide_and_match x y = match y with | 0 -> raise (Failure "Division by zero") | _ -> x / ylet divide_ten x y = match x with | 10 -> let result =...

View Article


OCaml 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 Article

OCaml map of int keys :: where is the 'simple' int module to use with the...

I need an OCaml map with keys of type int so I am using Map.Make to create one. However it seems that the standard modules'only' provide modules like Big_int, Int32, Int64 and Nativeint which require...

View Article


Syntax error regarding line 15 characters 27-34 in an OCaml tree search function

I wrote the function below to look through a tree and return a list in increasing order that contains all the indexes/subscripts of even elements in the tree. However I am getting a syntax error at the...

View Article

OCaml list flattening using a recursive function

I am trying to get a recursive function to flatten lists where I am not allowed a helper function. I can only use @. And I'm trying to use "match with"I tried this waylet rec flatten lst1 = match lst1...

View Article


Trying to get the number of even and odd integers in a list

I am trying to write a recursive function that takes in a list as argument and returns the number of even and odd numbers in tuple (number_of_even, number_of_odd)let rec countEvenOdd lst e o = match...

View Article

How to push (which is not related to any symbol) a synthetic token in Menhir...

I am parsing the Elm lang-like syntax. And look at the pattern matching (inside pattern matching)case a of 1 -> case b of"hello" -> 'h' _ -> 'w' _ -> 'e'We see there is a significant...

View Article

Append a list on to another in oCaml

I need a tail recursive function that appends a list1 infront of list2.I tried it this waylet rec append lst1 lst2 acc = match lst1 with | [] -> acc @ lst2 | hd::tl -> append lst1 tl...

View Article
Browsing all 518 articles
Browse latest View live


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