ocaml

OCaml non-blocking client socket

末鹿安然 提交于 2019-12-25 12:34:29
问题 Is there a way to use a client socket in a non blocking way. For example, if I create a socket for a client to connect on a server and that I do recursive recv on that socket, the last call of Unix.recv will block when no data is send and if the connection is not closed by the server. In C, you can specify flags for both : socket() and use the SOCK_NONBLOCK flag ORed with the socket type or receiv() with the MSG_DONTWAIT flags. I have looked here : http://caml.inria.fr/pub/docs/manual-ocaml

create a register

徘徊边缘 提交于 2019-12-25 11:44:07
问题 I have to create a type tree which would be used to store words, like every node of the tree would hold a letter and the list of the next characters (so words with the same root would share the same "part/branch of the tree). the tree is basically a n-ary one, used as a dictionnary. All using Caml language 回答1: Well, I don't know if it's a homework or not but I'll still answer : First, we need to define a signature type for letters . module type LS = sig type t val compare : t -> t -> int end

OCaml: how to count substring in a string

三世轮回 提交于 2019-12-25 08:16:20
问题 I am fairly new to OCaml but I have this project that i'm working on, I don't really understand the concept of immutable objects and was wondering if i could get some help, I am doing this through a text editor and have tried String.iter and explode but still can't manage to figure it out. Description: You are given a DNA sequence: a string that contains only characters 'A', 'C', 'G', and 'T'. Your task is to calculate the number of substrings of sequence, in which each of the symbols appears

How can I represent an automaton graphically from a list of int*char*int representing the transitions without using loops

穿精又带淫゛_ 提交于 2019-12-25 07:47:14
问题 I made a record called automaton containing the 5 fields required to represent an automaton I'm supposed to use graphics to represent every state and transition from the transitions list without using for or while loops only recursive functions transitions :(int*char*int) list; 回答1: It might be easiest to use graphviz to do the actual drawing. It automatically draws a graph from a list of nodes and edges, which is exactly what your input is. The function fmt_transition generates one edge, the

LLVM tutorial OCaml Compilation Assembler Error

断了今生、忘了曾经 提交于 2019-12-25 07:22:04
问题 I have been working through the LLVM Kaleidoscope Tutorial for OCaml. On the third part of the tutorial, I have navigated to the example code in the folder OCaml-Kaleidoscope\Chapter3 I am encountering an issue when compiling with ocamlbuild toy.byte on cygwin. This is the code given in the tutorial to compile. The error I am getting is mkdir 'C:\Users\setup\Compiler\llvm\examples\OCaml-Kaleidoscope\Chapter3\_build' ''ocamlopt.opt unix.cmxa -I 'C:\OCaml\lib\ocamlbuild' 'C:\OCaml\lib

How can I check two “pointers” meet each other when going through a list?

时光总嘲笑我的痴心妄想 提交于 2019-12-25 05:32:21
问题 For example, I have a list [1; 2; 1; 3; 2; 4; 1; 5; 6; 8;...] . The list has duplicate elements. Then we go through the list by two virtual pointers. One pointer a goes from the beginning and has speed of 2 . The other pointer b goes from somewhere in the middle of list and has speed of 1 . So how can I check whether a meeting with b ? For example: a starts from [1; 2; 1; 3; 2; 4; 1; 5; 6; 8;...] b starts from index 1 , which is [2; 1; 3; 2; 4; 1; 5; 6; 8;...] So after one time move, both a

How can I check two “pointers” meet each other when going through a list?

被刻印的时光 ゝ 提交于 2019-12-25 05:32:11
问题 For example, I have a list [1; 2; 1; 3; 2; 4; 1; 5; 6; 8;...] . The list has duplicate elements. Then we go through the list by two virtual pointers. One pointer a goes from the beginning and has speed of 2 . The other pointer b goes from somewhere in the middle of list and has speed of 1 . So how can I check whether a meeting with b ? For example: a starts from [1; 2; 1; 3; 2; 4; 1; 5; 6; 8;...] b starts from index 1 , which is [2; 1; 3; 2; 4; 1; 5; 6; 8;...] So after one time move, both a

Call a function in OCaml based on a string variable storing the function name

江枫思渺然 提交于 2019-12-25 05:22:54
问题 Is there such a mechanism in OCaml, such that I could invoke a function dynamically based on a variable storing the function name, like what I can do in other scripting languages? For example, I have written a function foo(). And I store the String constants "foo" somewhere in a variable "x". In JavaScript I'm able to do something like this window[x](arguments); to dynamically invoke the method foo(). Can I do something similar in OCaml? 回答1: No, this is not the kind of thing that OCaml lets

Ocaml: This expression has type 'a list * 'a list -> bool but an expression was expected of type bool

邮差的信 提交于 2019-12-25 04:54:13
问题 I just started learning Ocaml and am playing around with recursive functions. Ocaml Compiler is telling me that recursively calling helper in "if h1=h2 then helper t1 t2" causes an error: This expression has type 'a list * 'a list -> bool but an expression was expected of type bool. I understand that it is telling me that the compiler is expecting a boolean but instead gets a function that returns the boolean. But I have no idea how I can fix this. Any help is appreciated let rec a_func l =

What is causing the syntax error here?

限于喜欢 提交于 2019-12-25 04:26:49
问题 I'm trying to implement this algorithm but I keep getting a syntax error on the 12th line but I cannot pinpoint what is causing it. I'm new to ocaml and any help would be greatly appreciated. "To find all the prime numbers less than or equal to a given integer n by Eratosthenes' method: Create a list of consecutive integers from 2 through n: (2, 3, 4, ..., n). Initially, let p equal 2, the first prime number. Starting from p, enumerate its multiples by counting to n in increments of p, and