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

Obtain an interpretation of unbounded variables using Z3 in OCaml

ProblemI am trying to use the Z3 optimization capabilities to take into account some objectives when checking satisfiability. When I ask Z3 to minimize x + y with x > 0 and y > 0, the obtained...

View Article


What is the right way to put type declarations in OCaml signatures

I have written the following two files, and although it works, it feels odd that the code would duplicate these long type declarations. On the other hand, if I remove either module type declaration...

View Article


How to print unsigned 64 bit integer

I'm tackling this smallest multiple problem on Kattis.I've solved it in Python and C++, but now I want to do OCaml.Here's my code:open Printf;;let rec gcd (a : int64) (b : int64) : int64 = if not...

View Article

What causes this type mismatch when applying a functor?

I have the following files:SetMaker.mlimodule type Element = sig type t val create : 'a -> t val compare : t -> t -> int val to_string : t -> stringendmodule type Set = sig type t val empty...

View Article

matching multiple patterns at once in ocaml

Having a custom variant type as below:type yolo = | A of string| B of yolo| C of yolo * yolo| D of yolo * yoloI also have a function that performs some operations on instances of yolo similar to...

View Article


Access float in (int * float) list in OCaml

I have a list of type (int * float) list.So, as far as I understand it (I'm new to OCaml/Functional Programming)the list is structured like this: [(3, 1.0); (4, 2.0); (6, 0.1)].Now I want to access the...

View Article

Why is my implementation of "map" processing elements in reverse order?

This is my implementation of map:let rec map f lst = match lst with | [] -> [] | hd :: tl -> f hd :: map f tlI tried to run it like this:(* Print the given int, then return the given int. *)let...

View Article

How to add a library dependency in a dune project that manages the .opam file...

dune will generate and update a project's .opam file when you run dune build, letting you just manage the project's dependencies in dune-project.However, this seems to require an awkward step when...

View Article


How to use menhir to pasrse into a GADT expression?

I have just learned something about GADT in OCaml through Real World OCaml, and want to try to transfer the first little language there into a interpreter, thus using menhir.The ast definition is...

View Article


How to generate Menhir .automaton files with dune in OCaml?

I'm trying to generate .automaton files I added this to the dune file inside lib/ folder(menhir (flags --explain --dump) (modules parser))Then I run dune build, if I do find . -name '*.automaton', it...

View Article

how to check if list has consecutive powers

I am new to ruby and working on a problem but I don't know how to figure it out.I want to write a function that return true if each consecutive element is a power of the previous element, otherwise...

View Article

how to search for OCaml functions by name and type [closed]

In Haskell, there are two main ways to look up information on functions.Sites like Hoogle and Stackage. These sites provide two main types of searching:Searching for the name of a function. For...

View Article

How to use menhir to parse into a GADT expression?

I have just learned something about GADT in OCaml through Real World OCaml, and want to try to transfer the first little language there into a interpreter, thus using menhir.The ast definition is...

View Article


Is there a function that returns a list of values with specific type in OCaml?

In Haskell, using listify with Data can extract values of a specific type from a deeply nested structure without lots of getters. For example, with the following code:{-# LANGUAGE DeriveDataTypeable...

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


Making a list of rows to a set in ocaml [closed]

I am supposed to make this table:( ["Id"; "Name"; "Gender"; "Course"], [ ["2"; "Jim"; "Male"; "Geography"]; ["4"; "Linnea"; "Female"; "Economics"]; ["7"; "Steve"; "Male"; "Informatics"]; ["9";...

View Article

LLVM API produces invalid IR for ptr type

I am using LLVM 15 and I am trying to compile a language of my own (pretty much like Pascal in terms of syntax) to LLVM IR and I am using Ocaml.When I try to create a struct and set its body to have...

View Article


Downgrade Dune/Opam OR workaround for dune build

I have just installed ocaml, opam and dune on my computer and tried to run a new project using$ dune init project calculator$ cd calculator/$ code .which creates the project and opens it in VS Code....

View Article

Why does my recursion never terminate in OCaml?

let qrec=Queue.create ()let rec queueaddrec1 n= if n==1 then Queue.add 1 qrec else Queue.add n qrec; queueaddrec1 (n-1)let ()= queueaddrec1 5; Queue.iter print_int qrec;VScode told me the following...

View Article

List.map returns an unexpected type

I'm learning OCaml (OCaml 5.0.0).I defined the function below.let make_pair x ls = List.map (fun y -> (x,y)) ls;;I expected make_pair 1 ["a","b"];; returns [(1,"a");(1,"b")], but actually the...

View Article
Browsing all 518 articles
Browse latest View live


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