ocaml

How to return the instance of first-class module's nested type from a function?

∥☆過路亽.° 提交于 2020-06-16 18:36:35
问题 Context: I am trying to implement something like OOP observable pattern in OCaml with using first-class modules. I have a project with a list of modules and want to extend them with observation without changing. To minimize code duplication I created Subject module and plan to use it as a part of the common way (in the project context) for this extending. I declared three module types: OBSERVER: module type OBSERVER = sig type event type t val send : event -> t -> t end OBSERVABLE: module

How to return the instance of first-class module's nested type from a function?

百般思念 提交于 2020-06-16 18:36:16
问题 Context: I am trying to implement something like OOP observable pattern in OCaml with using first-class modules. I have a project with a list of modules and want to extend them with observation without changing. To minimize code duplication I created Subject module and plan to use it as a part of the common way (in the project context) for this extending. I declared three module types: OBSERVER: module type OBSERVER = sig type event type t val send : event -> t -> t end OBSERVABLE: module

How to return the instance of first-class module's nested type from a function?

不羁的心 提交于 2020-06-16 18:36:07
问题 Context: I am trying to implement something like OOP observable pattern in OCaml with using first-class modules. I have a project with a list of modules and want to extend them with observation without changing. To minimize code duplication I created Subject module and plan to use it as a part of the common way (in the project context) for this extending. I declared three module types: OBSERVER: module type OBSERVER = sig type event type t val send : event -> t -> t end OBSERVABLE: module

How do I make a simple GET request in OCaml?

让人想犯罪 __ 提交于 2020-06-13 15:37:32
问题 I'm trying to do something that should be simple: make a GET request to a url. However, when I search for examples of how to do this I often wind up with near-gibberish like this. Does anyone know how to make a simple HTTP request using OCaml? I'm an OCaml newbie with some Haskell exp. NOTE: A solution using the lowest possible level OCaml would be ideal. I've seen the Cohttp library used, but I'm more interested in a native (?) HTTP OCaml lib or something along those lines. In response to

Print certain lines only if it is not an empty string

六月ゝ 毕业季﹏ 提交于 2020-06-01 07:41:31
问题 Assume that type house = {name: string; nb_windows: int; nb_doors: int; nb_cars: int; nb_rooms: int};; house1 = {name="house1", nb_windows = 10; nb_doors = 50; nb_cars = 3; nb_rooms= 10};; I want to print each element of record house1 . Name : house1 Number of windows : 10 Number of doors : 50 Number of cars : 3 Number of rooms : 10 A way I have define the function is let test (lch: house) = begin print_string ("Name : " ^ lch.name ^ "\n"); print_string ("Number of windows : " ^ string_of_int

OCaml as C library, hello world example

核能气质少年 提交于 2020-06-01 06:40:09
问题 I wish to call OCaml code through C++ by compiling OCaml to a static or shared library that contains a C interface. This page seems to explain how to create a C interface for OCaml. But how do I do it and compile it? And how do I obtain the .h file to load in my C++ code? Also, could someone explain to be this part: The OCaml runtime system comprises three main parts: the bytecode interpreter, the memory manager, and a set of C functions that implement the primitive operations. Some bytecode

How to make OCaml compiler report unused functions?

走远了吗. 提交于 2020-05-30 04:26:20
问题 I wonder if is there any ways to make OCaml compiler report warnings about unused functions ? I googled but there are not much topics discussed about this feature. In particular, in the following program, there are two functions "foo" and "bar" which are declared but "bar" is not used in the "_" function. So I think that the OCaml compiler should report "bar" as an unused function. let foo x y = x + y let bar x y z = x + y + z (* should be reported unused *) let _ = let x = foo 1 2 in x 回答1:

How to make OCaml compiler report unused functions?

人走茶凉 提交于 2020-05-30 04:25:49
问题 I wonder if is there any ways to make OCaml compiler report warnings about unused functions ? I googled but there are not much topics discussed about this feature. In particular, in the following program, there are two functions "foo" and "bar" which are declared but "bar" is not used in the "_" function. So I think that the OCaml compiler should report "bar" as an unused function. let foo x y = x + y let bar x y z = x + y + z (* should be reported unused *) let _ = let x = foo 1 2 in x 回答1:

Append an element at the end of a list [duplicate]

拥有回忆 提交于 2020-05-16 07:42:16
问题 This question already has an answer here : how to populate existing list / array (1 answer) Closed 2 years ago . How to append an element at the end of a list in ReasonML (the equivalent of Array.concat in JavaScript)? 回答1: While Neil's answer is technically correct, it glosses over some details that you might want to consider before reaching for append ; specifically that while adding an element to the beginning of a list is very cheap, adding an element to the end is very expensive. To

2020年编程语言排行榜!

假如想象 提交于 2020-04-18 23:35:01
小伙伴们,大家好,今天给大家分享的是全球最受欢迎的编程语言,到2020年4月18日。看看你用的语言上榜了吗? 最受欢迎的前20名 其他编程语言 未来可能受欢迎的语言(排名不分先后,使用字母排序) (Visual) FoxPro, ABC, ActionScript, Alice, Arc, ATLAS, Awk, bc, Bourne shell, C shell, CL (OS/400), Clojure, Common Lisp, Crystal, cT, Elixir, Forth, Hack, Icon, Inform, Io, J, Korn shell, Ladder Logic, LiveCode, Maple, Mercury, MQL4, NATURAL, Object Pascal, OCaml, OpenCL, OpenEdge ABL, Oz, PL/I, PostScript, Programming Without Coding Technology, Pure Data, Q, Red, Ring, S, Smalltalk, Solidity, SPARK, Tcl, Vala/Genie, Verilog, VHDL, Whitespace 长期以来受欢迎的编程语言 编程语言名人堂 ps.由权威机构 TIOBE 发布。 今天的推荐不知道大家喜欢吗