ocaml

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

烂漫一生 提交于 2020-01-24 18:26:46
目录 上一篇博文 下一篇博文 介绍Reason Reason的优势 如何学习Reason? 介绍Reason的部分知识点 大家好,本文介绍Reason语言以及学习Reason的方法。 上一篇博文 从0开发3D引擎(六):函数式反应式编程及其在引擎中的应用 下一篇博文 从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

In OCaml using Base, how do you construct a set with elements of type `int * int`?

陌路散爱 提交于 2020-01-24 17:09:12
问题 In F#, I'd simply do: > let x = Set.empty;; val x : Set<'a> when 'a : comparison > Set.add (2,3) x;; val it : Set<int * int> = set [(2, 3)] I understand that in OCaml, when using Base, I have to supply a module with comparison functions, e.g., if my element type was string let x = Set.empty (module String);; val x : (string, String.comparator_witness) Set.t = <abstr> Set.add x "foo";; - : (string, String.comparator_witness) Set.t = <abstr> But I don't know how to construct a module that has

In OCaml using Base, how do you construct a set with elements of type `int * int`?

一个人想着一个人 提交于 2020-01-24 17:08:29
问题 In F#, I'd simply do: > let x = Set.empty;; val x : Set<'a> when 'a : comparison > Set.add (2,3) x;; val it : Set<int * int> = set [(2, 3)] I understand that in OCaml, when using Base, I have to supply a module with comparison functions, e.g., if my element type was string let x = Set.empty (module String);; val x : (string, String.comparator_witness) Set.t = <abstr> Set.add x "foo";; - : (string, String.comparator_witness) Set.t = <abstr> But I don't know how to construct a module that has

What are the rules for equality of types and modules in OCaml

两盒软妹~` 提交于 2020-01-23 12:42:33
问题 I cannot wrap my head around equality of modules in OCaml. Functors are supposed to be applicative (that's what the Internet claims), but this seems to fail sometimes, and I cannot quite see the general rule behind it. That's my example code: module type PT = sig end module P = struct end let () = Random.self_init () module OrigHashtbl = Hashtbl module Hashtbl = struct module Make(Hash: OrigHashtbl.HashedType) = struct let random = Random.int 1000000 type 'a t = { t_list: (Hash.t * 'a) list }

What are the rules for equality of types and modules in OCaml

蓝咒 提交于 2020-01-23 12:41:07
问题 I cannot wrap my head around equality of modules in OCaml. Functors are supposed to be applicative (that's what the Internet claims), but this seems to fail sometimes, and I cannot quite see the general rule behind it. That's my example code: module type PT = sig end module P = struct end let () = Random.self_init () module OrigHashtbl = Hashtbl module Hashtbl = struct module Make(Hash: OrigHashtbl.HashedType) = struct let random = Random.int 1000000 type 'a t = { t_list: (Hash.t * 'a) list }

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

雨燕双飞 提交于 2020-01-23 11:06:19
目录 上一篇博文 介绍Reason Reason的优势 如何学习Reason? 介绍Reason的部分知识点 大家好,本文介绍Reason语言以及学习Reason的方法。 上一篇博文 从0开发3D引擎(六):函数式反应式编程及其在引擎中的应用 介绍Reason Reason又叫Reasonml,是在Ocaml语言的基础上修改而来,由Facebook ReactJs的开发组开发和维护。 Reason是函数式编程语言,由Bucklescript编译器将其编译为javascript语言。 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是强类型语言

Unbound module Png - Png.load

梦想与她 提交于 2020-01-22 02:30:08
问题 I am currently trying to load a png image file into OCaml . I am trying to use the Png.load function but when I use it OCaml gives me the error: Unbound module Png merlin. I have CamlImages downloaded. I am using OCaml version 4.08.1 camlimages version 5.0.1 and I'm on macOS Catalina version 10.15.1 . I'd really appreciate any help or any information anyone could give me. I've been trying to fix solve this issue for weeks. 回答1: To use a package in OCaml you have to perform two actions:

How to call two functions and use their results as arguments for each other?

泄露秘密 提交于 2020-01-17 11:17:12
问题 I have code: let join a ~with':b ~by:key = let rec a' = link a ~to':b' ~by:key and b' = link b ~to':a' ~by:(Key.opposite key) in a' and compilation result for it is: Error: This kind of expression is not allowed as right-hand side of `let rec' build complete I can rewrite it to: let join a ~with':b ~by:key = let rec a'() = link a ~to':(b'()) ~by:key and b'() = link b ~to':(a'()) ~by:(Key.opposite key) in a'() It is compilable variant, but implemented function is infinitely recursive and it is

Waiting for Writer.write to complete in Caml Async

旧时模样 提交于 2020-01-15 12:47:34
问题 I have the following simple OCaml Async job which is supposed to write to a file and terminate the process. Unix.openfile "foobar" ~mode:[`Creat;`Rdwr] >>= fun fd -> let wr = Writer.create fd in Writer.write wr "this is a test"; Unix.close fd >>= fun () -> exit 0 However, it seems that fd gets closed before the write is performed (part of displayed sexp is "writer fd unexpectedly closed"). Is there a way to wait for write to complete before closing the file descriptor? Actually, I don't

Basic ocaml program not compiling

一个人想着一个人 提交于 2020-01-15 10:28:08
问题 I was trying to write a piece of code that checks if a sentence is a palindrome (if we don't consider spaces and case) but my code won't compile. I get the following error : File "main.ml", line 12, characters 0-2: Error: Syntax error This error corresponds to the second program, line 12 being where the ;; are at. Entire program let scan_word () = Scanf.scanf " %s" (fun x -> x) in let scan_int () = Scanf.scanf " %d" (fun x -> x) in let scan_float () = Scanf.scanf " %f" (fun x -> x) in let