Skip to content

Instantly share code, notes, and snippets.

@Gab-km
Last active December 17, 2015 08:39
Show Gist options
  • Save Gab-km/5582054 to your computer and use it in GitHub Desktop.
Save Gab-km/5582054 to your computer and use it in GitHub Desktop.
人様の作品をいじっているだけです
open System
//============================================
// IOモナド
//============================================
module IO =
type IO<'a> = IO of (unit -> 'a)
type IOBuilder() =
member this.Bind (IO x, f) = f (x())
member this.Return x = x
member this.Delay (f : unit -> 'a) = IO f
let io = new IOBuilder()
let run (IO i) = i()
let read = io { return Console.ReadLine() }
let putStr str = io { return printf "%s" str }
let putStrn str = io { return printf "%s\n" str }
let waitKey = io { return Console.ReadKey true |> ignore }
open IO
//============================================
// エントリポイント
//============================================
let mainIO =
io {
do! putStrn "Input your name."
let! name = read
do! putStrn ("Hello " + name)
do! waitKey
}
[<EntryPoint>]
let main argv =
run mainIO
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment