
Hello, After days of effort, I finally managed to compile and install a Haskell compiler. The one I have is NHC98. So now, with my new toy, I am eager to compile my very first Haskell program (I've been using 'runhugs' so far). But I'm having problems: ---<quote>---- $ nhc98 prng.hs -o prng I/O error (user-defined), call to function `userError': In file ./RC4.hi: 1:1-1:6 Found _module_ but expected a interface ---<quote>---- Okay, so I need to learn what an interface is. It looks like Hugs and NHC98 have idfferent ideas of what's acceptable. The file prng.hs starts with: ---<quote>---- module Main where import RC4 .... ---<quote>---- And the file RC4.hs contains all the interesting code. So that's where I am. I'm not clear what it is NHC98 is complaining about or how to fix it. It looks like it doesn't like modules and it wants an interface instead. Can someone point me to where I can learn what an interface is? and how to turn my module into one? Or else, how to make NHC98 accept the module. Any help would be much appreciated. Cheers, Daniel.

Daniel Carrera
$ nhc98 prng.hs -o prng I/O error (user-defined), call to function `userError': In file ./RC4.hi: 1:1-1:6 Found _module_ but expected a interface
GHC and NHC confuse each other with prng.hi files they produce and examine, in incompatible formats. You can delete them; they are needed to compile other modules which use that module. -- __("< Marcin Kowalczyk \__/ qrczak@knm.org.pl ^^ http://qrnik.knm.org.pl/~qrczak/

Marcin 'Qrczak' Kowalczyk wrote:
$ nhc98 prng.hs -o prng I/O error (user-defined), call to function `userError': In file ./RC4.hi: 1:1-1:6 Found _module_ but expected a interface
GHC and NHC confuse each other with prng.hi files they produce and examine, in incompatible formats.
You can delete them; they are needed to compile other modules which use that module.
No look, I don't have /any/ .hi files. I don't know what a .hi file is. I don't have GHC either, I've never managed to make it compile. I just got my very first Haskell compiler (literally 10min ago). Cheers, Daniel.

No look, I don't have /any/ .hi files. I don't know what a .hi file is. I don't have GHC either, I've never managed to make it compile. I just got my very first Haskell compiler (literally 10min ago).
Cheers, Daniel.
Just out of curiosity, what platform are you on? There seem to be builds of GHC available for most common ones. Compiling GHC when binaries are available and you're not intent on changing anything really isn't worth the trouble. (Especially so if you don't already have a previous version of GHC to compile it with). - Cale

Cale Gibbard wrote:
Just out of curiosity, what platform are you on? There seem to be builds of GHC available for most common ones.
Solaris :-( I hate Solaris. No, I didn't choose it; this is what the school provides. But if all goes well, I'll have my very own Ubuntu Linux box within a month or so. :-D Cheers, Daniel.

Daniel Carrera writes:
Hello,
After days of effort, I finally managed to compile and install a Haskell compiler. The one I have is NHC98.
So now, with my new toy, I am eager to compile my very first Haskell program (I've been using 'runhugs' so far). But I'm having problems:
---<quote>---- $ nhc98 prng.hs -o prng I/O error (user-defined), call to function `userError': In file ./RC4.hi: 1:1-1:6 Found _module_ but expected a interface ---<quote>----
*.hi files are analogous to C's *.h files, except that the compiler
generates them.
You mentioned later that you don't have any *.hi files, so I'm guessing
you didn't compile RC4.hs before you compiled prng.hs.
If I'm right, you need to do something like this first:
$ nhc98 -c RC4.hs
This will create an object file (probably RC4.o) containing compiled
code and an interface file (RC4.hi) that the compiler will use when it
compiles prng.hs. The -c option tells nhc that you don't want to link
anything yet.
Once that step is done, you should be able to compile prng.hs.
Incidentally, if you aren't already familiar with "make" or some other
build system, I strongly recommend looking into one. Even for a project
with only two files, having a build system keep track of compilation
dependencies makes things a lot less tedious.
--
David Menendez

Incidentally, if you aren't already familiar with "make" or some other build system, I strongly recommend looking into one. Even for a project with only two files, having a build system keep track of compilation dependencies makes things a lot less tedious. In random addition to this... hmake will automatically keep track of Haskell dependencies, and will also allow you to easily compile your code to work with the hat (hmake -hat) tracing suite.
Bob

David Menendez wrote:
*.hi files are analogous to C's *.h files, except that the compiler generates them.
Thanks, I learned something new today.
You mentioned later that you don't have any *.hi files, so I'm guessing you didn't compile RC4.hs before you compiled prng.hs.
Correct. I didn't know I had to :-)
If I'm right, you need to do something like this first:
$ nhc98 -c RC4.hs
Okay, I did that and I see a .hi file now. Thanks!
Once that step is done, you should be able to compile prng.hs.
Interestingly, I get a different error now: $ nhc98 prng.hs -o prng Undefined first referenced symbol in file FN_RC4_46rand ./prng.o ld: fatal: Symbol referencing errors. No output written to prng collect2: ld returned 1 exit status Oh well, I'll figure this out later. For now I'll just have everything in one big file. At least that compiles cleanly.
Incidentally, if you aren't already familiar with "make" or some other build system, I strongly recommend looking into one. Even for a project with only two files, having a build system keep track of compilation dependencies makes things a lot less tedious.
Ok. I played with make once upon a time. Thanks for the advice. Cheers, Daniel.

Daniel Carrera writes:
David Menendez wrote:
You mentioned later that you don't have any *.hi files, so I'm guessing you didn't compile RC4.hs before you compiled prng.hs.
Correct. I didn't know I had to :-)
Yeah, that's one of the major differences between using an interpreter like Hugs or ruby and a compiler. (GHC does offer a --make option that chases down dependencies for you.)
Once that step is done, you should be able to compile prng.hs.
Interestingly, I get a different error now:
$ nhc98 prng.hs -o prng Undefined first referenced symbol in file FN_RC4_46rand ./prng.o ld: fatal: Symbol referencing errors. No output written to prng collect2: ld returned 1 exit status
I haven't used NHC so I can't guarantee this will work, but try doing
something like this:
$ nhc98 -c RC4.hs
$ nhc98 -c prng.hs
$ nhc98 RC4.o prng.o -o prng
The first two steps will create (unlinked) object files, and the third
step should link them together into an executable file "prng".
--
David Menendez

David Menendez wrote:
I haven't used NHC so I can't guarantee this will work, but try doing something like this:
$ nhc98 -c RC4.hs $ nhc98 -c prng.hs $ nhc98 RC4.o prng.o -o prng
Yay! It does. And I just put it in a makefile:
---

I haven't used NHC so I can't guarantee this will work, but try doing something like this:
$ nhc98 -c RC4.hs $ nhc98 -c prng.hs $ nhc98 RC4.o prng.o -o prng
Yay! It does. And I just put it in a makefile:
---
---- COMPILER=nhc98 RC4.o: $(COMPILER) -c RC4.hs prng.o: $(COMPILER) -c prng.hs prng: RC4.o prng.o $(COMPILER) RC4.o prng.o -o prng
I strongly recommend using 'hmake' (which is supplied with nhc98, but also works with ghc) in preference to 'make'. It tracks the dependencies between haskell source files automatically (no Makefile), so there is no chance for the dependencies to get out of sync with reality.. Hmake was the inspiration for ghc's recently added '--make' option. However, hmake is more flexible, because it automatically handles the invocation of many common preprocessors, besides working with multiple compilers. Regards, Malcolm

Daniel Carrera wrote:
I haven't used NHC so I can't guarantee this will work, but try doing something like this:
$ nhc98 -c RC4.hs $ nhc98 -c prng.hs $ nhc98 RC4.o prng.o -o prng
Yay! It does. And I just put it in a makefile:
---
---- COMPILER=nhc98 RC4.o: $(COMPILER) -c RC4.hs
prng.o: $(COMPILER) -c prng.hs
prng: RC4.o prng.o $(COMPILER) RC4.o prng.o -o prng ---
----
This can fail with a parallel make, which may try to compile RC4.hs
and prng.hs concurrently. It can also fail if you rebuild after
modifying any of the files, as it won't realise that it needs to
re-compile. To handle that, you need to be more precise about the
dependencies, i.e.:
RC4.o RC4.hi: RC4.hs
$(HC) -c RC4.hs
prng.o prng.hi: prng.hs RC4.hi
$(HC) -c prng.hs
prng: RC4.o prng.o
$(HC) RC4.o prng.o -o prng
With most make programs (e.g. GNU make), you can use pattern rules to
avoid repeating the commands, e.g.:
# how to compile any .hs file to produce .o and .hi files
%.o %.hi: %.hs
$(HC) -c $<
# how to build the prng program
prng: RC4.o prng.o
$(HC) -o $@ $+
# note that prng.o depends upon RC4.hi
prng.o: RC4.hi
--
Glynn Clements
participants (7)
-
Cale Gibbard
-
Daniel Carrera
-
David Menendez
-
Glynn Clements
-
Malcolm Wallace
-
Marcin 'Qrczak' Kowalczyk
-
Thomas Davie