ocaml

Type sharing in OCaml - typechecker error

江枫思渺然 提交于 2020-01-02 07:07:14
问题 When compiling this program: module type Inc = sig type t val inc : t -> t end module type Dec = sig type t val dec : t -> t end module Merger (I : Inc) (D : Dec with type t = I.t) = struct let merge x = x |> I.inc |> D.dec end module IntInc : Inc = struct type t = int let inc x = x + 10 end module IntDec : Dec = struct type t = int let dec x = x - 8 end module Combiner = Merger (IntInc) (IntDec) I get the following error: File "simple.ml", line 30, characters 35-41: Error: Signature mismatch

Are custom blocks ever copied by OCaml?

[亡魂溺海] 提交于 2020-01-02 04:44:11
问题 Imagine I've a C library called libcat for interacting with my cat fluffy. I'm therefore writing bindings for OCaml to simplify interactions with fluffy. module type CAT = sig type cat val find : ... -> cat val feed : cat -> unit ... end ;; module Cat : CAT = ... There is considerable memory management already built into libcat, like say caching, freeing destroyed toys, and maybe even a limited scope garbage collector for emptying the litter. Yet, overall libcat requires that users explicitly

How to use modules with js_of_ocaml?

本秂侑毒 提交于 2020-01-02 03:14:07
问题 I am currently working on a website project written in OCaml and compiled to javascript using js_of_ocaml. It works pretty well as long as I have only one source file using the command ocamlfind ocamlc -package js_of_ocaml -package js_of_ocaml.syntax -syntax camlp4o -linkpkg -o file.byte file.ml but I would like to include several modules in my project. How can I do that ? The other modules are actually a lexer and a parser poduced by ocamllex and menhir. I have read a tutorial on how to use

Converting OCaml strings to format6

倖福魔咒の 提交于 2020-01-02 02:03:32
问题 The following code does not compile: let x = "hello" in Printf.printf x The error is: Error: This expression has type string but an expression was expected of type ('a, out_channel, unit) format = ('a, out_channel, unit, unit, unit, unit) format6 1) Can someone give an explanation of the error message? 2) And why would a string cannot be passed to printf ? 回答1: The first argument to printf must be of type ('a, out_channel, unit) format not string. String literals can be automatically

Cross-compiling ocaml apps for ARM

天涯浪子 提交于 2020-01-02 01:47:34
问题 I'm cross-compiling a touchscreen driver, which comes with an ocaml calibration application. I'm trying to compile the driver and the application for ARM, in particular, the Beagleboard, running Angström. It goes like this: ^_^[raziel@Bebop zytouch-driver-20081121]$ source /usr/local/angstrom/arm/environment-setup ^_^[raziel@Bebop zytouch-driver-20081121]$ make CC=arm-angstrom-linux-gnueabi-gcc arm-angstrom-linux-gnueabi-gcc -std=gnu99 -g -O2 -Wall -Wextra -Werror -Wstrict-prototypes

Working with ocaml Lwt sockets

荒凉一梦 提交于 2020-01-02 00:31:12
问题 I have been on learning Ocaml for a week, some things got clear, the others rather not. I'm trying to compose a simple Tic-Tac-Toe server accepting connections via telnet. Just for a word. I have to use Lwt and rigth now it seems for me a darken place because I had faced too much of language pecularities. The begining of the code: let sock = Lwt_unix.socket Unix.PF_INET Unix.SOCK_STREAM 0 let setting_up_server_socket = let sockaddr = (Unix.ADDR_INET(Unix.inet_addr_of_string "127.0.0.1", 23233

How to get the line number of an exception in OCaml without debugging symbols?

試著忘記壹切 提交于 2020-01-01 12:36:06
问题 Is there a good way to get the line number of exception in OCaml without debugging symbols? Certainly, if we turn on debugging symbols and run with OCAMLRUNPARAM=b , we can get the backtrace. However, I don't really need the whole backtrace and I'd like a solution without debugging symbols. At the moment, we can write code like try assert false with x -> failwith (Printexc.to_string x ^ "\nMore useful message") in order to get the file and line number from assert, but this seems awkward. Is

OCaml: Can't run utop after installing it

依然范特西╮ 提交于 2020-01-01 08:52:21
问题 I'm trying to learn OCaml through the Real World OCaml book. They have a guide by which I am supposed to install the Core package and utop. However, while I seem to be successfully installing both of these using Opam, neither of them works when I try to use them. I know that they're installed, because when I try to install them again, I get this message: $ opam install utop core [NOTE] Package utop is already installed (current version is 1.10). [NOTE] Package core is already installed

OCaml: Can't run utop after installing it

谁都会走 提交于 2020-01-01 08:52:03
问题 I'm trying to learn OCaml through the Real World OCaml book. They have a guide by which I am supposed to install the Core package and utop. However, while I seem to be successfully installing both of these using Opam, neither of them works when I try to use them. I know that they're installed, because when I try to install them again, I get this message: $ opam install utop core [NOTE] Package utop is already installed (current version is 1.10). [NOTE] Package core is already installed

Sleeping less than a second in OCaml

拥有回忆 提交于 2020-01-01 08:17:08
问题 The Unix.sleep function can suspend the program for whole seconds, but how can you suspend it for less than a second? 回答1: The classical Unix solution for this is to use select() with no file descriptors: let minisleep (sec: float) = ignore (Unix.select [] [] [] sec) 回答2: The Thread.delay function pauses the thread for the given number of seconds, but it takes a float, allowing you to pause the thread for less than a second. 回答3: from Unix module val sleepf : float -> unit Stop execution for