/ Functional Programming

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

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.


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

open System

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 likes functional programming, algorithms and code reviews. Apart from programming, his favourites are walking with his family in the parks and national trails and reading books.

Read More

Why not to stay updated if the subject is interesting? Join Telegram channel Alex@Net or follow alex_at_net on Twitter. Or just, use the comments form below.