Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I am trying to run a haskell script using ghc, however, compiler returns:
The function main is not defined in module Main
Any ideas why this is or what should I do to fix?
Cheers!
ghc is a compiler, so needs a single entry point to run your code.
This is the main function, which should have type IO () and live in your Main module (a module without a module declaration at the top is auto-named Main).
WinHugs is an interpreter - you can run any function you like with any arguments you like.
If you want to use ghc like that, you should use ghci instead - it's ghc's interpreter.
(WinHugs will load your code faster, and ghc will run your code faster.)
To load the script and call functions in an interactive way, run ghci, and then type :load MyScript.hs.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
One can run Haskell Code with runhaskell ... or compile it with ghc .... It's clear that there are performance differences between interpreted code and an executable.
But is it common to use interpreted Haskell code in real world applications?
Or does this feature only exists for development purposes?
EDIT:
Is it common practice to run real world apps in interpreted mode like i would do with, for example, Node.js?
$ node './app.js'
$ runhaskell './Main.hs'
Define "common".
I have a program that I consider "production code" that takes a specification for a web page and generates the appropriate static HTML. The specification isn't external; it's just a chunk of Haskell source code in the program. About once a month, I update the specification and run the program. I run it with runghc and the run time is a tiny fraction of a second, so compiling would be a waste of keystrokes.
Out in the broader world, the popular stack tool comes with script support. If you write a program like this:
#!/usr/bin/env stack
{- stack script --resolver lts-14.17 -}
main = putStrLn "Interpreted code is awesome!"
and run it, it basically uses a version of runghc to run the script. So, this is at least one sanctioned method for writing and running interpreted, production scripts for Haskell.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I can't fit the definition of Wikipedia with Haskell code:
main = return ()
or
main = undefined
Above all, "A computer program is a collection of instructions1" where instructions are defined like that.
Taking those two definition, is main = return () a computer program? Is the definition quoting to machine code?
If it is... Why?
If it's not, what is considered a program in Haskell?
Nothing about the definition of a program requires it to have explicit I/O. For example, consider /bin/sleep. It does literally nothing besides doing nothing for a fixed period of time. Ultimately, it does kind of have input/output, in that it "causes" (in a weak sense of the term) a change in the time.
Another example might be a Python program like:
while True:
pass
All it does is create heat, literally, but there's no reason to think it's not a program.
An unoptimized build of your program might actually contain the machine instructions to load an immediate value 5 into some register, followed by program termination. However, an optimizing compiler like Haskell's would deduce that the value is never used, and will gladly cull it entirely (and it's more than free to do so, since it won't have any observable effect. The machine instructions for program termination would still exist, though.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am studying the example in section 3 on this page:
https://wiki.haskell.org/State_Monad
Basically, I would like to play with this example but I do not know how to make the code do anything. I take it that this is a "module", and that some modules are "programs" in Haskell, but I don't understand why this module has a function called "main" (I thought it would also have to be called "Main" to be a program, but I tried changing it and it failed to compile). If it is not a program, then what I am supposed to do with a module sitting all by itself? Am I supposed to import it into ghci and then type > main? If so, I tried but I can't make it happen.
The code in the sections titled "complete and concrete example" are complete and concrete examples. You can put the code in these into files with the same name as the module name (i.e. the StateGame module should go into a file called StateGame.hs).
You can then compile that with ghc ghc StateGame.hs -main-is StateGame. Alternatively you can rename that module to Main, then you don't need the -main-is part.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I am writing a haskell module for hugs and i get the error shown in the title.
What does this mean and how do i fix this?
the code in question is the second line
and1 :: [Bool] -> Bool
and1 [] = True
This is the first part of the module after the module declaration itself.
The error says that you're trying to use a Bool as an integral, a typeclass allowing most of the operations you'd expect to be on Integer. However, the code you've posted is error free.
Without the rest of the code this is impossible to diagonose. But did you perhaps add a space between and and 1? Eg and 1 [] = True
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
Does anyone know of any software like Google Docs, or collabedit that allows you to edit realtime collaboratively and even compile a .cpp or other program over the web?
I haven't used this website, but seems like http://codebunk.com/ does the job.
It doesn't work for Java though.
I know of this website that will compile the code for you:
http://ideone.com/
Unfortunately, I cannot help in the real time editing front.
I wrote a little webapp that does exactly that, i.e. it lets you compile Google Docs documents: http://compiler.m01.eu
You can write C++ code into a Google Document (and do that collaboratively if you like), and then click on a bookmark (provided on the site) to compile your code, which will either start the download of your binary or show a compiler error message.