From c2ce219850aa3c880587e585b88718a3a25630a5 Mon Sep 17 00:00:00 2001 From: muqiuhan Date: Tue, 23 Jan 2024 12:34:19 +0000 Subject: deploy: 850faf4c6934ac6a7bd99a26948c2e3f7bed6c9a --- 2024/01/08/OCaml-News-2024-1/index.html | 283 ++++++++++++++++++++ 2024/01/18/OCaml-News-2024-2/index.html | 293 +++++++++++++++++++++ 2024/01/22/Rescript-React-Native/index.html | 255 ++++++++++++++++++ 2024/01/23/G-Machine/index.html | 240 +++++++++++++++++ .../index.html" | 2 +- .../index.html" | 5 + 6 files changed, 1077 insertions(+), 1 deletion(-) create mode 100644 2024/01/08/OCaml-News-2024-1/index.html create mode 100644 2024/01/18/OCaml-News-2024-2/index.html create mode 100644 2024/01/22/Rescript-React-Native/index.html create mode 100644 2024/01/23/G-Machine/index.html (limited to '2024/01') diff --git a/2024/01/08/OCaml-News-2024-1/index.html b/2024/01/08/OCaml-News-2024-1/index.html new file mode 100644 index 00000000..13a70b6c --- /dev/null +++ b/2024/01/08/OCaml-News-2024-1/index.html @@ -0,0 +1,283 @@ + + + + + + + + + + + + + + + + + + + + + +OCaml News 2024-1 | 暮秋小屋 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+
+
+ + + +
+
+
+ + +
+
+
+ + +
+ +
+ +
+ +
+
+
+

News

+

Videos

+

Blogs

+

Highlighted Projects

+

New Releases

+ +
+ + + + + +
+ + + + + + + +
+ + +
+
+
+ + + +
+ + + + + + diff --git a/2024/01/18/OCaml-News-2024-2/index.html b/2024/01/18/OCaml-News-2024-2/index.html new file mode 100644 index 00000000..a97be6e9 --- /dev/null +++ b/2024/01/18/OCaml-News-2024-2/index.html @@ -0,0 +1,293 @@ + + + + + + + + + + + + + + + + + + + + + +OCaml News 2024-2 | 暮秋小屋 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+
+
+ + + +
+
+
+ + +
+
+
+ + +
+ +
+ +
+ +
+
+
+

News

+

Discussion

+

Videos

+

Blogs

+

Highlighted Projects

+

New Releases

+ +
+ + + + + +
+ + + + + + + +
+ + +
+
+
+ + + +
+ + + + + + diff --git a/2024/01/22/Rescript-React-Native/index.html b/2024/01/22/Rescript-React-Native/index.html new file mode 100644 index 00000000..47775070 --- /dev/null +++ b/2024/01/22/Rescript-React-Native/index.html @@ -0,0 +1,255 @@ + + + + + + + + + + + + + + + + + + + + + +Rescript React Native | 暮秋小屋 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+
+
+ + + +
+
+
+ + +
+
+
+ + +
+ +
+ +
+ +
+
+
+

Rescript 对 React Native 的支持还算可以,但如今的 RN 已经是 Expo 的 RN 了,所以仍然有些落后,在这个 template 中,我测试了 rescript + rescript-react-native + expo + nativewind 的组合,可以跑起来:

+ +

其中有两个问题,一是 rescript-expo 对 rescript v11 的兼容性,我通过简单的注释让其通过编译:

+ +

二是对于 nativewind 的支持,编写的 binding 非常丑陋:

+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
type default_style = {
className?: string,
children?: React.element,
}

@module("nativewind")
external styled: React.component<'a> => React.component<default_style> = "styled"

module StyledText = {
let make = styled(ReactNative.Text.make)
}

module StyledView = {
let make = styled(ReactNative.View.make)
}

module StyledImage = {
type props = {
source?: string,
...default_style,
}

@module("nativewind")
external styled: React.component<'a> => React.component<props> = "styled"

let make: React.component<props> = styled(ReactNative.Image.make)
}
+ +

而这似乎并没有好的解决方案,理想中的实现应该是:

+
1
2
3
4
5
6
7
8
9
10
11
12
13
module Styled = (Component: {
type params // or type params = 'a
let make: React.component<props>
}) => {
type props = {
...Component.props, // This can't work as it is not defined as record
className?: string
}
@module("nativewind")
external styled: React.component<Component.props> => React.component<props> = "styled"

let make: React.component<props> = styled(Component.make)
}
+ +

或者退一步:

+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
type styledProps = {
className?: string,
// ...
}

@module("nativewind")
external styled: React.component<'a> => React.component<'b> = "styled"

module StyledText = {
type props = {
...ReactNative.Text.props,
...styledProps
}

let make: React.component<props> = styled(ReactNative.Text.make)
}
+ +

但这在当前的 rescript 中,根本无法实现。

+

详细的讨论看这个帖子:

+ + +
+ + + + + +
+ + + + + + + +
+ + +
+
+
+ + + +
+ + + + + + diff --git a/2024/01/23/G-Machine/index.html b/2024/01/23/G-Machine/index.html new file mode 100644 index 00000000..ff1d742e --- /dev/null +++ b/2024/01/23/G-Machine/index.html @@ -0,0 +1,240 @@ + + + + + + + + + + + + + + + + + + + + + +G-Machine | 暮秋小屋 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+
+
+ + + +
+
+
+ + +
+
+
+ + +
+ +
+ +
+ +
+
+
+ +

G-Machine 是一种通过图规约来对函数式语言程序求值的抽象架构。
与组合子规约不同,组合子规约的control是从表达式图本身动态导出的,而G-Machine是由通过编译Application表达式导出的指令序列指定的。

+
+

FP的程序基本上都可以用一个表达式的图表示,图计算机就是对这个图求值的机器,总的说来对图的求值是一个不停合并图上的节点生产新节点的过程。

+

例如:

+
1
2
let x = 2 + 3 in 
x * x
+ +

先计算出5,然后创建一个新的节点 5 * 5,然后再对这个节点求值,于是求值过程中就产生了很多临时的节点,这些中间节点也被叫做是 spine,求值过程是沿着 spine 进行的。

+

但是这样就产生了很多额外的开销,lambda lifting 里提到:可以把程序里,很多捕捉了外围绑定的闭包函数中的这些绑定,转换成函数的参数,从而消除闭包,得到的这个函数就可以自由脱离作用域,被静态的编译到机器码里。这些被 float out 的函数也叫 supercombinator.

+

在上面的代码中,如果不创建新的节点,顺序计算完了第一个 x,第二个 x 还会再被算一遍。

+

Spineless reduction 的概念:只有当面临需要重复计算的情况时,才去创建节点,不然就一路顺序算下去

+ + +
+ + + + + +
+ + + + + + + +
+ + +
+
+
+ + + +
+ + + + + + diff --git "a/2024/01/23/\344\272\214\343\200\207\344\272\214\345\233\233\345\271\264\344\270\200\346\234\210\344\272\214\345\215\201\344\270\211\346\227\245/index.html" "b/2024/01/23/\344\272\214\343\200\207\344\272\214\345\233\233\345\271\264\344\270\200\346\234\210\344\272\214\345\215\201\344\270\211\346\227\245/index.html" index b41da268..62bf3ade 100644 --- "a/2024/01/23/\344\272\214\343\200\207\344\272\214\345\233\233\345\271\264\344\270\200\346\234\210\344\272\214\345\215\201\344\270\211\346\227\245/index.html" +++ "b/2024/01/23/\344\272\214\343\200\207\344\272\214\345\233\233\345\271\264\344\270\200\346\234\210\344\272\214\345\215\201\344\270\211\346\227\245/index.html" @@ -195,7 +195,7 @@
- Next + Next
diff --git "a/2024/01/23/\346\205\242\346\200\247\350\202\272\346\272\220\346\200\247\345\277\203\350\204\217\347\227\205/index.html" "b/2024/01/23/\346\205\242\346\200\247\350\202\272\346\272\220\346\200\247\345\277\203\350\204\217\347\227\205/index.html" index 93def6d0..91a5abba 100644 --- "a/2024/01/23/\346\205\242\346\200\247\350\202\272\346\272\220\346\200\247\345\277\203\350\204\217\347\227\205/index.html" +++ "b/2024/01/23/\346\205\242\346\200\247\350\202\272\346\272\220\346\200\247\345\277\203\350\204\217\347\227\205/index.html" @@ -237,6 +237,11 @@