ocaml

从0开发3D引擎(七):学习Reason语言

大城市里の小女人 提交于 2020-02-05 08:57:10
目录 上一篇博文 介绍Reason Reason的优势 如何学习Reason? 介绍Reason的部分知识点 大家好,本文介绍Reason语言以及学习Reason的方法。 上一篇博文 从0开发3D引擎(六):函数式反应式编程及其在引擎中的应用 介绍Reason Reason又叫Reasonml,是在Ocaml语言的基础上修改而来,由Facebook ReactJs的开发组开发和维护。 Reason是函数式编程语言,由Bucklescript编译器将其编译为 java script语言。 Reason是专门提供给前端开发者使用的,相对于Ocaml,语法上与javascript更为接近。 Reason的优势 1、从“发展前景”来说: 1)大公司Facebook出品,质量、稳定性、后续维护升级有保证 2)Reason是基于OCaml的,因此随着Ocaml的版本更新,Reason和Bucklescript也会支持Ocaml的新特性 3)函数式编程越来越火,它也在3D引擎中越来越多地使用(如Frostbite公司提出的Frame Graph架构和Data Oriented思想都需要结合函数式编程) 2、从“性能”来说: 1)Reason支持mutable的操作和数据结构 可在性能热点处使用它们,提高性能 2)对浏览器的JIT编译友好,提升了运行时性能 因为Reason是强类型语言

OCaml: List that could contain two types?

∥☆過路亽.° 提交于 2020-02-04 05:24:05
问题 Instead of specifying a int list or string list, could I specify a list whose members must be either strings or ints, but nothing else? 回答1: You could do: type element = IntElement of int | StringElement of string;; and then use a list of element s. 回答2: One option is polymorphic variants. You can define the type of the list using: # type mylist = [`I of int | `S of string] list ;; type mylist = [ `I of int | `S of string ] list Then define values such as: # let r : mylist = [`I 10; `S "hello

OCaml mergesort and time

白昼怎懂夜的黑 提交于 2020-02-02 18:19:47
问题 I created a function (mergesort) in ocaml but when I use it, the list is inverted. In addition, I want to calculate the time the system takes to do the calculation, how can I do it? let rec merge l x y = match (x,y) with | ([],_) -> y | (_,[]) -> x | (h1::t1, h2::t2) -> if l h1 h2 then h1::(merge l t1 y) else h2::(merge l x t2);; let rec split x y z = match x with | [] -> (y,z) | x::resto -> split resto z (x::y);; let rec mergesort l x = match x with | ([] | _::[]) -> x | _ -> let (pri,seg) =

OCaml mergesort and time

孤人 提交于 2020-02-02 18:19:05
问题 I created a function (mergesort) in ocaml but when I use it, the list is inverted. In addition, I want to calculate the time the system takes to do the calculation, how can I do it? let rec merge l x y = match (x,y) with | ([],_) -> y | (_,[]) -> x | (h1::t1, h2::t2) -> if l h1 h2 then h1::(merge l t1 y) else h2::(merge l x t2);; let rec split x y z = match x with | [] -> (y,z) | x::resto -> split resto z (x::y);; let rec mergesort l x = match x with | ([] | _::[]) -> x | _ -> let (pri,seg) =

编译coccinelle-1.0.0-rc24时的错误"Error: Unbound module Parmap"以及解决方法

你离开我真会死。 提交于 2020-02-02 03:34:02
今天在编译一个老版的openwrt时,发现有如下的错误。 File "./main.ml", line 777, characters 22-49: Warning 52: Code should not depend on the actual values of this constructor's arguments. They are only for information and may change in future versions. (See manual section 8.5) File "./main.ml", line 956, characters 35-60: Error: Unbound module Parmap Makefile:656: recipe for target 'main.cmo' failed 后发现是ocaml的版本太新了,我的openwrt太古老了。将ocaml降到4.02.3,就可以解决了。 opam switch 4.02.3 eval $(opam config env) opam install ocamlfind opam install camlp4 来源: CSDN 作者: 断了线的程序猿 链接: https://blog.csdn.net/tianlu1001/article/details

What is the difference between 'a and '_l?

倾然丶 夕夏残阳落幕 提交于 2020-01-26 17:17:52
问题 What is the difference between 'a and '_l ? I was looking at this error, and couldn't comprehend it: Error: This expression has type ('a -> float polynomial) list but an expression was expected of type float polynomial list derivlist: ('_l → float polynomial) list 回答1: _ denotes a weakly polymorphic variable : it is in a position where it cannot be generalized. There are two explanations related to weak polymorphism in the OCaml FAQ: see A function obtained through partial application is not

Should an if statement be associated with else statement in ocaml?

人盡茶涼 提交于 2020-01-25 10:05:45
问题 In ocaml, I want to have many nested if statements and a return value on each of the conditions. The code is becoming complicated like this. let func arg1 arg2 = if condition1 then arg1+arg2 else ( //code1 if condition2 then arg1*arg2 else ( //code2 if condition3 then arg1+arg2 else ( //code3 ) ) ) Instead of such nested statements can I have code like this? let func arg1 arg2 = if condition1 then arg1+arg2 //code1 if condition2 then arg1*arg2 //code2 if condition3 then arg1+arg2 //code3 回答1:

Should an if statement be associated with else statement in ocaml?

佐手、 提交于 2020-01-25 10:05:32
问题 In ocaml, I want to have many nested if statements and a return value on each of the conditions. The code is becoming complicated like this. let func arg1 arg2 = if condition1 then arg1+arg2 else ( //code1 if condition2 then arg1*arg2 else ( //code2 if condition3 then arg1+arg2 else ( //code3 ) ) ) Instead of such nested statements can I have code like this? let func arg1 arg2 = if condition1 then arg1+arg2 //code1 if condition2 then arg1*arg2 //code2 if condition3 then arg1+arg2 //code3 回答1:

Can't open Llvm in ocaml

别等时光非礼了梦想. 提交于 2020-01-25 04:55:08
问题 I'm trying to use llvm binding in ocaml, in my file test.ml, I have one line of code: open Llvm When I run the command ocamlbuild -use-ocamlfind test.byte -package llvm I get this result: + ocamlfind ocamldep -package llvm -modules test.ml > test.ml.depends ocamlfind: Package `llvm' not found Command exited with code 2. Compilation unsuccessful after building 1 target (0 cached) in 00:00:00. What did I do wrong in this? Thanks. BTW, the _tag file contains: "src": traverse <src/{lexer,parser}

Permutations of two lists

断了今生、忘了曾经 提交于 2020-01-24 22:01:13
问题 I have a char list in OCAML. I would like to create a ( (char * bool) list) list of every combination of the char s with true and false . What I have guess I have to do is something like a List.fold_left , but I am not quite sure how to pull it off. This is the outline that I tried (OCAML syntax, but not run-able): let rec var_perm var_list options = match var_list with | [] -> options | x :: v' -> ((x, true) :: (var_perm_intern v')) :: ((x, false) :: (var_perm_intern v')) ;; let all_options