2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

F#で標準入出力を扱う時にSystemは不要

Posted at

.NET Core CLIでF#のプロジェクトを作成すると必ずopen Systemの一行があり、標準入力から入力を受け付けたいという時、下記のように書きたくなってしまいがちです。というか書いてました。

open System
let input = Console.ReadLine()

しかし、Fsharp.CoreにはConsole.In, Console.Outをラップしたstdin, stdoutという関数があり、これらを使用すればわざわざSystemをOpenする必要がありません。

let input = stdin.ReadLine()

標準出力を扱う時はprintfnを扱うことが多いかもしれませんが、以下のように書くことも可能です

"Hello, World!" |> stdout.WriteLine()

参考など

https://fsharp.github.io/fsharp-core-docs/reference/fsharp-core-operators.html#stdin
https://docs.microsoft.com/ja-jp/dotnet/api/system.console.in?view=netcore-3.1

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?