I tried to better understand the functional way of coding and simply wrote a small program to print the factorial of a user-entered number:
open System
let fact n = let rec factiter init acc =
if init = 0 then acc
else factiter (init - 1) init*acc
factiter n 1
let dropStrArr (argv: string []) = ignore argv
let factComp = Console.ReadLine >> Int32.Parse >> fact >> Console.WriteLine >> fun () -> 0
[<EntryPoint>]
let main argv = (dropStrArr >> factComp) argv
This worked well, but then I thought that mainyou can determine purely in composition and try:
let main = dropStrArr >> factComp
which I thought would work, but although it compiles, it just exits right after launch.
There are different types in two scenarios: unit -> int
when the main one is determined by its argument, compared to (unit -> int)
when using composition.
I probably miss the type system, so my question is why the main meaning cannot be determined using composition here?