Hi,
I created (with help) a function to test for prime numbers.
It worked well enough for now in ghci.
----------------
f x n y
| n>y = True
| rem x n == 0 = False
| otherwise = f x (n+1) y
primeQ x = f x 2 y
where
y = floor(sqrt(fromIntegral x))
---------------
I then wanted to create object code so that I could import
it. It seemed that I had to precede the above with the 2 lines:
----------------
module Prime
where
----------------
I ran:
ghc –c prime.hs, and created prime.o and prime.hi.
Next, I wanted to write a program to import and use this
function.
I wrote:
------------
module
import Prime
main = primeQ 123
------------
I tried to compile this with:
ghc –o test Main.hs prime.o
I got the following error:
Main.hs:5:0:
Couldn’t match expected type ‘IO t’
against inferred type ‘Bool’
In the expression: main
When checking the type of the function ‘main’
----------------
First I’d like a hint as to what I need to do to make
this work.
It’s pretty obvious that I don’t know what I’m
doing with regard to types. Also, I have no idea if I have to name this module
In the function that I think I had to re-write to make
object code, I wound up with 2 where statements, which worries me.
I’d really appreciate any help in getting me unraveled.
Mitchell