ocaml

Compiling multiple Ocaml files

ぃ、小莉子 提交于 2019-12-19 19:53:07
问题 I am new to Ocaml and trying to write some small example application. I am using ocamlc version 3.11.2 under Linux Ubuntu 10.04. I want to compile two files: a.ml b.ml File b.ml uses definitions from a.ml . As far as I understand, I can use ocamlc -c to perform compilation only. I can call ocamlc one final time when I have all the .cmo files to link them to an executable. Also, when compiling a file that uses definitions from another file, I have to tell the compiler in which .cmi file to

在 linux 上使用 rsync 实现文件同步

我是研究僧i 提交于 2019-12-19 10:02:04
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 1. 简介 rsync 是类 unix 系统下的数据镜像备份工具。一款支持快速完全备份和增量备份的工具,支持本地复制,远程同步等,类似 scp 命令; rsync 命令在同步文件之前要先登录目标主机进行用户身份认证,认证通过之后才能进行数据同步,身份认证方式取决于所使用的协议类型; rsync 一般使用两种协议进行数据同步:ssh 协议和 rsync 协议。 2. 特性 可以更新整个目录树和文件系统 有选择性的保留符号来接,硬连接,文件属性,权限,设备以及时间 对于安装来说,无任何特殊权限要求 对于多个文件来说,传输效率很高 能用 ssh 或自定义端口作为传入入口端口 3. 工作原理 rsync 在进行数据同步之前需要先验证用户身份,验证身份取决于连接方式: ssh 登录验证 使用 ssh 协议作为基础进行用户身份验证,然后进行数据同步。 rsync 登录验证 ( 比较麻烦 ) 使用 rsync 协议进行用户身份认证(非系统用户),然后进行数据同步 数据同步方式: 推送(上传,数据恢复)(rsync 服务器 向 其他服务器推送文件) 拉取(下载,数据备份)(其他服务器从 rsync 服务器下载文件) 4. 实战 使用 ssh 协议实现文件同步 准备工作 172.16.10.111(NFS 服务器) 新建

Will OCaml convert multi-argument function to currying or the other way around?

故事扮演 提交于 2019-12-19 07:57:28
问题 When I was learning OCaml essentials, I was told that every function in OCaml is actually a function with only one parameter. A multi-argument function is actually a function that takes one argument and returns a function that takes the next argumetn and returns .... This is currying, I got that. So my question is : case 1 if I do let plus x y = x + y Inside OCaml when it compiles, will OCaml change it to let plus = fun x -> fun y -> x + y ? or the other way around that case 2 If I do let

Will OCaml convert multi-argument function to currying or the other way around?

╄→尐↘猪︶ㄣ 提交于 2019-12-19 07:57:12
问题 When I was learning OCaml essentials, I was told that every function in OCaml is actually a function with only one parameter. A multi-argument function is actually a function that takes one argument and returns a function that takes the next argumetn and returns .... This is currying, I got that. So my question is : case 1 if I do let plus x y = x + y Inside OCaml when it compiles, will OCaml change it to let plus = fun x -> fun y -> x + y ? or the other way around that case 2 If I do let

Converting OCaml to F#: Differences between typing and type inference

混江龙づ霸主 提交于 2019-12-19 06:01:29
问题 In researching type inference differences between F# and OCaml I found they tended to focus on nominative vs. structural type system. Then I found Distinctive traits of functional programming languages which list typing and type inference as different traits. Since the trait article says OCaml and F# both use Damas-Milner type inference which I thought was a standard algorithm, i.e. an algorithm that does not allow for variations, how do the two traits relate? Is it that Damas-Milner is the

verbose error with ocamlyacc

*爱你&永不变心* 提交于 2019-12-19 04:17:05
问题 In bison, it is sufficient to add %verbose-error to the file to make the parser errors more verbose. Is there any way to gain similar functionality with ocamlyacc? Here is the answer for a similar question, but I could not make anything out of it. This is how I call the lexer and parser functions: let rec foo () = try let line = input_line stdin in (try let _ = (Parser.latexstatement lexer_token_safe (Lexing.from_string line)) in print_string ("SUCCESS\n") with LexerException s -> print

Memoization in OCaml?

情到浓时终转凉″ 提交于 2019-12-18 17:13:35
问题 It is possible to improve "raw" Fibonacci recursive procedure Fib[n_] := If[n < 2, n, Fib[n - 1] + Fib[n - 2]] with Fib[n_] := Fib[n] = If[n < 2, n, Fib[n - 1] + Fib[n - 2]] in Wolfram Mathematica. First version will suffer from exponential explosion while second one will not since Mathematica will see repeating function calls in expression and memoize (reuse) them. Is it possible to do the same in OCaml? How to improve let rec fib n = if n<2 then n else fib (n-1) + fib (n-2);; in the same

How to memoize recursive functions?

拥有回忆 提交于 2019-12-18 15:51:33
问题 Consider a recursive function, say the Euclid algorithm defined by: let rec gcd a b = let (q, r) = (a / b, a mod b) in if r = 0 then b else gcd b r (This is a simplified, very brittle definition.) How to memoize such a function? The classical approach of defining a high-order function memoize : ('a -> 'b) -> ('a -> 'b) adding memoization to the function is here useless, because it will only save time on the first call. I have found details on how to memoize such function in Lisp or Haskell:

See inferred types in complex OCaml code

我是研究僧i 提交于 2019-12-18 15:41:13
问题 I'm a OCaml newbie working with some pretty complex (at least for me) OCaml code I didn't write. It would help a lot to understand it if I could see the inferred types for some of the values, as I can do with F# and Visual Studio by hovering over any value, e.g.: (screenshot borrowed from http://theburningmonk.com/2010/01/learning-f-part-1/) I guess I could break down the code and feed it to the toplevel to get the types, but is there any other, simpler way? 回答1: First, you must compile your

How to get type information in interactive Ocaml?

假装没事ソ 提交于 2019-12-18 12:48:33
问题 I am using Ocaml of version 4. When I define interactively some type, the interpreter prints out string representation of the type immediately after that: # type foo = Yes | No;; <-- This is what I entered type foo = Yes | No <-- This is what interpreter bounced But after I type more definitions, sometimes I want to see the text representation of the type again. In Haskell, I could type ":t foo". How can I do this in Ocaml? 回答1: In utop you can use the #typeof directive: #typeof "list";; type