Home > Net >  Running this Haskell code in Powershell does nothing
Running this Haskell code in Powershell does nothing

Time:02-21

I'm learning Haskell for a school project and am going through Hudak's Haskell School of Expression. I have written the following test code:

main :: IO ()
main = return ()

p :: Float
p = 3.14159

totalArea :: Int -> Int -> Int -> Float
totalArea r1 r2 r3 =
    let 
        circleArea r = p*r^2 
    in
        circleArea (fromIntegral r1)   circleArea (fromIntegral r2)   circleArea (fromIntegral r3)

This compiles fine, but how do I actually run it? I type into Powershell ./test.exe totalArea 5 6 7, and nothing happens. I know this is a total noob question, so I'm sorry in advance and thanks for the help!

CodePudding user response:

main = return (), so that means the program is not doing anything: you just defined a constant and function, but you do not do anything with these.

You can implement the main to print the result of totalArea 5 6 7:

main :: IO ()
main = print (testArea 5 6 7)

or for example parse program parameters:

import System.Environment(getArgs)

main :: IO ()
main = do
    (ra : rb : rc : _) <- getArgs
    print (testArea (read ra) (read rb) (read rc))

then you can call the program with:

./test.exe 5 6 7
  • Related