Haskell interpreted mode for real world app [closed] - 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
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.

Related

Is main = return () a program? [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
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.

modules and programs in Haskell - first steps [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 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.

What exactly is executable code? [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 7 years ago.
Improve this question
I know about executable code, but I don't know what it exactly is.(for the system)
(I'm thinking about .sh or something else)
I tried to find something out with www.google.com but there was no result.
Can anyone explain it to me?
This is kind of a loose term but I would interpret this as a program that can be executed.
For example, if we have a Java file it is not directly executable...it's just a bunch text to the end user. You can't run the file directly like:
./foo.java # bad
Conversely, if you had a sh script that could be interpreted by your shell (and it has the proper permissions set, such as the executable bit) then it is executable. For example you could do:
./foo.sh # good
Another example would be code that has been compiled. If that foo.java file had been compiled into byte code then (assuming it had a main function) it could be executed directly (not the .java file, but the output of the build).
java foo # good
So, I think in this context, executable code means a file with code in it that can be executed directly by an end user.
To put it simply, "executable code" is any sequence of program instructions which is intended to be executed in some environment without prior translation. For example, a "binary executable" contains instructions which can be carried out by an appropriate microprocessor. An "executable shell script" contains instructions which are meant to be executed as-is by a shell program; from the shell's perspective, the script contains executable code, but from the processor's perspective it doesn't.

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.

Differences Between Hugs, Yhc and GHCi [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 4 years ago.
Improve this question
There are differences between Hugs, Yhc and GHCi? If there are differences, What are they?
Update: Hugs is unmaintained.
They are all just different implementations. I would try and explain the differences but this article does a much better job.
First: you want GHC/GHCi. And you want it via the Haskell Platform. Then, for more info on the other implementations of Haskell, read Bartek's link.
Usually people use Hugs for small, testing-type prototypes (analogously to how Ruby users would use irb and Python users would use the interpreter), but for actual shipping code, GHC is by far the most popular target (analogous to how Python users would compile import modules to cpython).
They're all pretty much standards-compliant, its a matter of speed of performance vs speed of compilation.
(Dunno much about Yhc)
These days people kind of converge to using GHC, as it's the de facto standard.
Hugs is a version of Haskell that started out on Linux and is therefore better optimised for it.

Resources