Created
March 6, 2020 19:19
-
-
Save OnurGumus/a68e228bff9c12f20106a9338a83ff21 to your computer and use it in GitHub Desktop.
Functional_excercise_1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
type ReadInput = unit -> int | |
type ReadInputR = unit -> Result<int,string> | |
type Process = int -> int | |
type ProcessR = Result<int,string> -> Result<int,string> | |
type WriteOutput = int -> unit | |
type WriteOutputR = Result<int, string> -> unit | |
type Program = unit -> unit | |
type ProgramList = int -> unit | |
type CreateProgram = ReadInput -> Process -> WriteOutput -> Program | |
type CreateProgramR = ReadInputR -> ProcessR -> WriteOutputR -> Program | |
type ReadInputRList = int -> Result<int,string> list | |
type ProcessRList = Result<int,string> list -> Result<int,string> list | |
type WriteOutputRList = Result<int, string> list -> unit | |
type CreateProgramRList = ReadInputRList -> ProcessRList -> WriteOutputRList -> ProgramList | |
let createProgram : CreateProgram = | |
fun readInput proc writeOutput -> | |
readInput >> proc >> writeOutput | |
let createProgramR : CreateProgramR = | |
fun readInput proc writeOutput -> | |
readInput >> proc >> writeOutput | |
let createProgramRList : CreateProgramRList = | |
fun readInput proc writeOutput -> | |
readInput >> proc >> writeOutput | |
let readInput : ReadInput = Console.ReadLine >> int | |
let proc : Process = fun i -> i * 2 | |
let writeOutput : WriteOutput = Console.WriteLine | |
let prog1 = createProgram readInput proc writeOutput | |
let readInputR : ReadInputR = | |
fun () -> | |
let input = Console.ReadLine() | |
match Int32.TryParse input with | |
| true , v -> Ok v | |
| false , _ -> Error "not an integer" | |
let procR : ProcessR = Result.map proc | |
let writeOutpuR : WriteOutputR = | |
fun r -> | |
match r with | |
| Error e -> Console.WriteLine e | |
| Ok i -> writeOutput i | |
//let prog = createProgramR readInputR procR writeOutpuR | |
let readInputRList : ReadInputRList = | |
fun n -> | |
List.init n ( fun _ -> ()) | |
|> List.map readInputR | |
let procRList = List.map procR | |
let writeOutputRList : WriteOutputRList = | |
fun rList -> | |
List.map writeOutpuR rList |> ignore | |
let programRList = createProgramRList readInputRList procRList writeOutputRList | |
programRList 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment