How to import a .hs file in Haskell

Viewed 49028

I have made a file called time.hs. It contains a single function that measures the execution time another function.

Is there a way to import the time.hs file into another Haskell script?

I want something like:

module Main where
import C:\Haskell\time.hs

main = do
    putStrLn "Starting..."
    time $ print answer
    putStrLn "Done."

Where time is defined in the 'time.hs' as:

module time where
Import <necessary modules>

time a = do
start <- getCPUTime
v <- a
end   <- getCPUTime
let diff = (fromIntegral (end - start)) / (10^12)
printf "Computation time: %0.3f sec\n" (diff :: Double)
return v

I don't know how to import or load a separate .hs file. Do I need to compile the time.hs file into a module before importing?

3 Answers
Related