Consider the following code:
import Data.Char
numToReal::Integral a => [a] -> [Double]
numToReal l = map (\x -> fromIntegral x) l
ordList::[Char] -> [Int]
ordList l = map ord l
squareList::Num a => [a] -> [a]
squareList l = map (\x -> x * x) l
main::IO()
main = do
print(squareList [1..10])
print(numToReal [1..10])
print(ordList ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'])
Written as it is, the GHC complains the following error:
• Couldn't match expected type ‘(a2 -> IO ()) -> [Int] -> IO ()’
with actual type ‘IO ()’
• The function ‘print’ is applied to three arguments,
but its type ‘[Double] -> IO ()’ has only one
In a stmt of a 'do' block:
print
(numToReal [1 .. 10]) print (ordList ['a', 'b', 'c', 'd', ....])
In the expression:
do print (squareList [1 .. 10])
print (numToReal [1 .. 10]) print (ordList ['a', 'b', ....])
But if I do this:
import Data.Char
numToReal::Integral a => [a] -> [Double]
numToReal l = map (\x -> fromIntegral x) l
ordList::[Char] -> [Int]
ordList l = map ord l
squareList::Num a => [a] -> [a]
squareList l = map (\x -> x * x) l
main::IO()
main = do
print(squareList [1..10])
print(numToReal [1..10]);
print(ordList ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']);
It compiles and runs just fine, aside from complaining that I'm using tabs instead of spaces. The question is, why the semicolon solves this error? Is there something to do how the compiler is parsing the file on those 2 last lines?