/ Functional Programming

Solving HackerRank's Functional Challenges in F#: Solve Me First FP

My F# skills are need to be refreshed. Couple of years ago I had a good time practicing Go by solving a number of programming challenges on Hackerrank. This time I will try solve functional challenges using F#.

There is the first one:

Your task is to scan two numbers, A and B from STDIN, and print the sum A+B on STDOUT.

Screen-Shot-2017-08-20-at-03.11.54

It is just a basic challenge to get convenient with solution submision and language basics. The code looks pretty much C#:

open System

[<EntryPoint>]
let main argv = 
    let a = Console.ReadLine() |> int
    let b = int(Console.ReadLine())
    printfn "%d" (a+b)
    0 // return an integer exit code

Console.ReadLine() |> int and int(Console.ReadLine()) are equivalent forms. a |> b is just b(a).

Alex Netkachov

Alex Netkachov

Alex Netkachov is a Senior Software Developer, currently working in Central London on new generation of energy trading solutions for brokers, traders and exchanges.

Read More

Why not to chat about this post? Join Telegram group Alex@Net or message on Twitter to alex_at_net. Alternatively, use the comments form below.