modules and programs in Haskell - first steps [closed] - haskell

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.

Related

Expected variable or procedure, not module [closed]

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 2 years ago.
Improve this question
I have been trying to sort this error and can't understand why it is happening. tried changing name of the sub and check many times to make sure the spelling is exactly the same but the error keeps ocurring and i can't understand why. Can someone help?
You should not use the same name the module and the procedure. This will cause a conflict.
So if you Call SortDataSource it will find the module name first and of course it cannot call a module (only a procedure or function within a module).
So if you use the same names you need to Call SortDataSource.SortDataSource to make it call the procedure SortDataSource inside the module SortDataSource:
Syntax is like
Call ModuleName.MethodName(Argument1, Argment2)
or without Call which is not needed.
ModuleName.MethodName Argument1, Argment2
But I highly recommend not to use the same name for a module and a procedure. As you can see it can cause errors that can easily be avoided by choosing different names.

Haskell interpreted mode for real world app [closed]

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.

How can I change the way GHC compiler error messages are printed out? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am not fully satisfied with the format of GHC error messages. How can I make a custom print function?
You want to modify GHC? well, it's open-source so you can change it however you wish and recompile but that would probably be a gigantic overkill.
If I really really wanted to, I'd make a program that calls GHC with the arguments it receives, read back the output, process it, then print it.
You can do it with System.Process.readProcessWithExitCode, specifically.
You might be tempted to use readProcess for its easier API, but it will only read from stdout and you're almost certainly want stderr too.
Plus the exit-code in the former function could be very helpful too: you could know if compilation succeeded or not without even parsing, but by just seeing if the exit code = 0.

How to effectively work with leksah? [closed]

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 8 years ago.
Improve this question
How can I effectively work with the leksah haskell IDE?
For a start, I am very thankful for all the work that the leksah people put in. It's great!
However, I have trouble working effectively in leksah.
mymain :: IO ()
mymain = do
myData <- getMyData
...
...
How can I show the type of some variable in a do-expression, like myData? When I right click on it and then go to type, the error message gets <interactive>:1:1: Not in scope: 'myData'. Also after I do something with ghci in leksah, build (CtrlB) no longer compiles my project but suddenly does something else.
How can I effectively use leksah in general and especially concerning ghci in leksah (like display a type of something that is not toplevel but nested)? What are the top 5 things you would suggest?

Haskell ghc main [closed]

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.

Resources