简体   繁体   English

如何在F#上运行IO操作

[英]How IO operations working on F#

There were IO monad on haskell to keep it pure. 在haskell上有IO monad以保持纯净。 I know f#/ocaml supports mutable state but how IO operations works actually. 我知道f#/ ocaml支持可变状态,但IO操作实际上是如何工作的。 What is corresponding concept to haskell's IO monad. haskell的IO monad的相应概念是什么?

F# is not pure. F#并不纯粹。 It inherits the Caml tradition of allowing IO and state changes (eg assignment to mutable variables) everywhere. 它继承了Caml传统,即允许IO和状态更改(例如,分配给可变变量)。 For instance: 例如:

let f : int -> int =
   fun x -> 
      printf "Hello\n";
      x+1

printf "%d\n" (f 1 + f 2)      (* prints Hello twice, then 5 *)

Monads can still be found in F#, though, if you want to use them. 但是,如果要使用它们,仍然可以在F#中找到Monads。 Computation expressions correspond to monads, roughly. 计算表达式大致对应于monad。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM