ocaml

CLI shell script code generation from compiled executable? [closed]

一笑奈何 提交于 2019-12-09 15:59:01
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . Question, topic of discussion I am very interested in generation of command line shell scripting source code from code written in a

Polymorphism in OCaml - ad hoc,parametric, inclusion/subtyping

孤人 提交于 2019-12-09 13:19:20
问题 I am having a problem understanding the different types of polymorphism, specifically in regards to OCaml. I understand that polymorphism allows for multiple types in OCaml denoted as 'a, but I do not understand what the different types of polymorphism are. If someone could give me an explanation with relatively low-level language that would be awesome! ad hoc, parametric, inclusion/subtyping 回答1: Here's an approximation. Ad-hoc polymorphism usually refers to being able to declare the same

How to decide whether to parameterize on the type-level or the module-level when designing modules?

丶灬走出姿态 提交于 2019-12-09 11:54:46
问题 I'm working towards a deep understanding of ML-style modules: I think the concept is important and I love the kind of thinking they encourage. I am just now discovering the tension that can arise between parametric types and parametric modules. I am seeking tools for thinking about the matter that will help me make smart design decisions as I build up my programs. Fist I will try to describe my question in general. Then I will provide a concrete example from a learning project I am working on

What's the difference between -> and |> in reasonml?

蓝咒 提交于 2019-12-09 08:40:35
问题 A period of intense googling provided me with some examples where people use both types of operators in one code, but generally they look just like two ways of doing one thing, they even have the same name 回答1: tl;dr: The defining difference is that -> pipes to the first argument while |> pipes to the last. That is: x -> f(y, z) <=> f(x, y, z) x |> f(y, z) <=> f(y, z, x) Unfortunately there are some subtleties and implications that makes this a bit more complicated and confusing in practice.

In OCaml, what type definition is this: 'a. unit -> 'a

≯℡__Kan透↙ 提交于 2019-12-09 04:21:29
问题 Questions It was my first time I saw a type definition like 'a. unit -> 'a in Explicit polymorphic type in record Q1 : What is this 'a. (notice the dot)? Q2 : What is the terminology for this kind of type definition? If I do let f:'a. 'a list -> int = fun l -> List.length l;; utop shows val f : 'a list -> int = <fun> Q3 : Why doesn't utop shows the type 'a. 'a list -> int ? Q4 : When should I use this kind of type definition? In addition, I can use this kind of definition in record: type t =

Using Opam to manage project dependencies

左心房为你撑大大i 提交于 2019-12-09 04:20:19
问题 I am a complete newbie to OCaml. Other languages I have used (for instance Scala, Clojure, Javascript on Node.js) have package managers that allow one to start a project as a clean slate that has a declared set of dependencies of known versions. I am trying to do something of the sort with Opam. Ideally, I would like to have a file that lists dependencies (and possibly OCaml version) so that a collaborator can start a project with git clone myproject <magic opam command> ocamlbuild and have a

Can't load batteries using FindLib in Ocaml TopLevel

妖精的绣舞 提交于 2019-12-09 03:35:28
I successfully installed ocaml-batteries-included and findlib . I can do 'ocamlfind ocamlc -package batteries -c mycode.ml` without problems. Also, if I do ocamlfind list , I get $ ocamlfind list batteries (version: 2.0) batteries.pa_comprehension (version: 2.0) batteries.pa_comprehension.syntax (version: 2.0) batteries.pa_llist (version: 2.0) batteries.pa_llist.syntax (version: 2.0) batteries.pa_string (version: 2.0) batteries.pa_string.syntax (version: 2.0) batteries.syntax (version: 2.0) bigarray (version: [distributed with Ocaml]) camlp4 (version: [distributed with Ocaml]) ... The problem

How do you inspect the type of (*) on OCaml's toplevel?

ⅰ亾dé卋堺 提交于 2019-12-09 03:34:29
问题 I wanted to see the type of the multiplication function (*), so I tapped it into the OCaml toplevel. # (*) However, the toplevel echoed: (*);; 1: this is the start of a comment. and then consumed any further input I put in. I figured that I had to get out of the comment mode by pressing Ctrl+d to send EOF. Great. But surely, I should be able to query the type of any function, including our mysterious multiplication function (*) ?! I would be incredibly disappointed if that is a limitation of

ocamlyacc parse error: what token?

可紊 提交于 2019-12-09 02:22:12
问题 I'm using ocamlyacc and ocamllex. I have an error production in my grammar that signals a custom exception. So far, I can get it to report the error position: | error { raise (Parse_failure (string_of_position (symbol_start_pos ()))) } But, I also want to know which token was read. There must be a way---anyone know? Thanks. 回答1: Tokens are generated by lexer, hence you can use the current lexer token when error occurs : let parse_buf_exn lexbuf = try T.input T.rule lexbuf with exn -> begin

Stack performance in programming languages

你说的曾经没有我的故事 提交于 2019-12-08 23:33:00
问题 Just for fun, I tried to compare the stack performance of a couple of programming languages calculating the Fibonacci series using the naive recursive algorithm. The code is mainly the same in all languages, i'll post a java version: public class Fib { public static int fib(int n) { if (n < 2) return 1; return fib(n-1) + fib(n-2); } public static void main(String[] args) { System.out.println(fib(Integer.valueOf(args[0]))); } } Ok so the point is that using this algorithm with input 40 I got