我正在尝试编写一个基本的视频游戏,并希望从键盘输入输入.因此,我需要在生成标准输入时读取字符.由于缓冲,io:get_chars,io:fread只有在按下返回键后才会返回.
项目的目的不是制作真实的游戏,它只是学习Erlang的一种方式.因此,性能不是问题.
编辑:这个项目似乎提供了我正在寻找的功能.但是,如果我没有弄错的话,代码的一部分是用C语言编写的,并通过消息传递将字符发送到Erlang部分.对于这种方法,是否存在Erlang原生的替代方案,或者这是唯一可行的方法吗?
以下类型取自此问题
(* contains an error, later fixed by the OP *)
type _ task =
| Success : 'a -> 'a task
| Fail : 'a -> 'a task
| Binding : (('a task -> unit) -> unit) -> 'a task
| AndThen : ('a -> 'b task) * 'a task -> 'b task
| OnError : ('a -> 'b task) * 'a task -> 'b task
type _ stack =
| NoStack : 'a stack
| AndThenStack : …Run Code Online (Sandbox Code Playgroud) 我正在编写一个编译器,需要表示几个共同递归的结构,并依赖于表示表达式的数据结构.在编译开始时,我的表达式没有输入,但我会在稍后阶段输入它们.
我编写了以下仿函数,以便在此过程中重用代码:
module type Exp = sig
type t
end
module type IR = sig
type exp
type ty =
| Unknown
| Typed of exp
type exp_descr =
| Leaf
| Node of exp
end
module MyIR (E: Exp) = struct
type ty =
| Unknown
| Typed of E.t
type exp_descr =
| Leaf
| Node of E.t
type exp = E.t
end
module UntypedExp (TD: IR) : (Exp with type t = TD.exp_descr) = struct
type t …Run Code Online (Sandbox Code Playgroud)