小编Dai*_*wen的帖子

如何在Erlang的标准输入上读取字符

我正在尝试编写一个基本的视频游戏,并希望从键盘输入输入.因此,我需要在生成标准输入时读取字符.由于缓冲,io:get_chars,io:fread只有在按下返回键后才会返回.

  1. 是否可以在生成标准输入时访问这些字符?
  2. 我该怎么办?

项目的目的不是制作真实的游戏,它只是学习Erlang的一种方式.因此,性能不是问题.

编辑:这个项目似乎提供了我正在寻找的功能.但是,如果我没有弄错的话,代码的一部分是用C语言编写的,并通过消息传递将字符发送到Erlang部分.对于这种方法,是否存在Erlang原生的替代方案,或者这是唯一可行的方法吗?

erlang io-buffering

5
推荐指数
1
解决办法
515
查看次数

有人可以解释这个OCaml程序中使用的类型语法吗?

以下类型取自此问题

(* 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)

polymorphism ocaml variant gadt

4
推荐指数
1
解决办法
242
查看次数

扩展相互递归的仿函数

我正在编写一个编译器,需要表示几个共同递归的结构,并依赖于表示表达式的数据结构.在编译开始时,我的表达式没有输入,但我会在稍后阶段输入它们.

我编写了以下仿函数,以便在此过程中重用代码:

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)

recursion ocaml functor

4
推荐指数
1
解决办法
84
查看次数

标签 统计

ocaml ×2

erlang ×1

functor ×1

gadt ×1

io-buffering ×1

polymorphism ×1

recursion ×1

variant ×1