ocaml

How to synchronously execute an Lwt thread

佐手、 提交于 2021-01-29 21:37:23
问题 Is there any way to synchronously execute a thread made with Lwt library? To be specific, I am trying to run a series of post requests to a server that compute some value and returns a result. Based on answers provided to this question: How do I make a simple GET request in OCaml? I can make it with either low level approach (sockets) or using the Cohttp library. The low level approach has the advantage of being immediate and straightforward but I would rather stick to the Cohttp (no need for

Can't get newest why3 version from opam

*爱你&永不变心* 提交于 2021-01-29 13:24:58
问题 I am using Linux Slackware 14.2, opam version 1.2.2, ocaml 4.03.0 and wanted to install why3 module. As far as I can see in the Internet, the last version of why3 package is 1.2.0. But even after I ran opam update It still suggests my to install why3 1.0.0. What should I do to update the packages list? How can I install why3 module system wide as root? Is it safe enough? 回答1: Your opam and ocaml installations are both seriously out of date. The latest version of OCaml is 4.07.1, and the

How do I implement instantaneous, yet buffered output in OCaml?

回眸只為那壹抹淺笑 提交于 2021-01-29 05:01:09
问题 I am writing a Prolog interpreter in OCaml and I want it to offer the following feature: Character-based output is buffered . Output appears instantaneously , say, within 0.05 seconds. There is no need to use explicit flush_output/0 operations. Buffer flushing operations are done automatically, but not at every put_char . Here's what I came up with: Upon program startup I ... ... install a signal handler for SIGALRM and ... ... use Unix.setitimer for starting a periodic timer. The timer is a

Ocaml: Longest path using bfs

荒凉一梦 提交于 2021-01-29 01:49:14
问题 The problem is as follow: Given an oriented weighted graph, a start node, an end node and a number k, verify if exist a path from the start node to the end node with at least length k. This is the code i wrote and it's correct but only in specific graph. For example g1 with weights1 is as follows: let weights1 = [(2,1,1);(2,1,3);(2,1,4);(1,1,5);(5,1,2);(5,1,6);(3,1,6);(6,1,7);(4,1,3)];; let f1 = function 1 -> [5] | 2 -> [1;3;4] | 3 -> [6] | 4 -> [3] | 5 -> [2;6] | 6 -> [7] | _ -> [];; type 'a

Ocaml: Longest path using bfs

陌路散爱 提交于 2021-01-29 01:44:21
问题 The problem is as follow: Given an oriented weighted graph, a start node, an end node and a number k, verify if exist a path from the start node to the end node with at least length k. This is the code i wrote and it's correct but only in specific graph. For example g1 with weights1 is as follows: let weights1 = [(2,1,1);(2,1,3);(2,1,4);(1,1,5);(5,1,2);(5,1,6);(3,1,6);(6,1,7);(4,1,3)];; let f1 = function 1 -> [5] | 2 -> [1;3;4] | 3 -> [6] | 4 -> [3] | 5 -> [2;6] | 6 -> [7] | _ -> [];; type 'a

OCaml read pressed key without graphical window

喜欢而已 提交于 2021-01-28 04:05:50
问题 Edit. I am working in a Windows environment. I want to write a simple game in console output with OCaml. I need to be able to use a 'read_key' function. But : The graphics module throws an error : Exception: Graphics.Graphic_failure "graphic screen not opened". But I do not want to open the graphic window. The function read_line forces the user to press "return" after every key press... 回答1: It is not possible to implement such function using pure OCaml. You will need to call to platform

Immutable variables in OCaml

不羁的心 提交于 2021-01-27 06:33:11
问题 I'm learning OCaml, and I'm a bit confused with the immutability of variables. According to the book I'm reading, variables are immutable. So far so good, but why on Earth can I do this: let foo = 42 let foo = 4242 What am I missing?? 回答1: I think the best way to explain is with an example. Consider this code (executed in the OCaml REPL): # let foo = 42;; val foo : int = 42 # let return_foo () = foo;; val return_foo : unit -> int = <fun> # let foo = 24;; val foo : int = 24 # return_foo ();; -

Immutable variables in OCaml

梦想与她 提交于 2021-01-27 06:32:12
问题 I'm learning OCaml, and I'm a bit confused with the immutability of variables. According to the book I'm reading, variables are immutable. So far so good, but why on Earth can I do this: let foo = 42 let foo = 4242 What am I missing?? 回答1: I think the best way to explain is with an example. Consider this code (executed in the OCaml REPL): # let foo = 42;; val foo : int = 42 # let return_foo () = foo;; val return_foo : unit -> int = <fun> # let foo = 24;; val foo : int = 24 # return_foo ();; -

九问 Gopher China 2020 讲师之毛康力:从 Go 1.0 使用至今的鲜肉老司机

南笙酒味 提交于 2020-11-13 11:45:55
本期嘉宾:毛康力 PingCAP 研发工程师。目前从事数据库内核开发相关的工作,是 TiDB 项目的核心开发者之一。从 Go 1.0 版本发布时开始接触这门语言,并且在之后的工作中一直使用 Go 作为主力开发语言。早期写过关于 Go 的底层实现的开源电子书《深入解析 Go》,对 Go 的 Runtime 层有比较多的研究。业余喜欢折腾各种编程语言,尤其是 lisp,设计过自己的 lisp 方言并翻译成 Go。其它的关注点,主要还是在分布式系统以及基础架构相关的领域。 目前 Go 语言更新到 1.15 版本,已经是一门11岁的语言了,你觉得 Go 语言依然保持活力的核心竞争力是什么?有什么不足是需要在后续的版本迭代中改进的? 01 Go 语言本身设计得简洁易上手,基础库和核心项目让生态搭建起来了,我认为这是它能保持活力和竞争力的关键因素。 对当前的版本迭代已经挺满意了,感受得到 Go 官方团队的持续努力。 最初是如何接触到 Go 的呢?在使用 Go 之前都写过哪些语言,请谈谈对他们差异的感受。 02 Go 语言 1.0 版本发布的时候,无意中看了一下,然后就爱上这门语言了。 在 Go 之前,算正儿八经写过代码的,就只有 C 吧,C++ 学过但没学会。C 很能够锻炼基础素质,这是一些高级语言里面不容易学到的东西。接触过的其它语言就太多了,从汇编到 C,到 lua,lisp,F#