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

Related

Can using a math interpreter be potentially dangerous? [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 1 year ago.
Improve this question
I want the user to be able to write their own math functions in my program. And these functions could possibly be shared with someone else, and run natively on their machine. Algebra is Turing complete. Does it mean I should warn users of my program about potential danger of running math? Sorry if this is a silly question :)
Edit:
I am making a simple diary, but the entries have dynamically calculated properties. I am thinking of using bc for running the user defined functions. It's rather easy to fix things for user if the expression does not end since they can modify the expression outside of the program. But let's say user A sends user B their diary. Should I warn user B that it's not safe to open their diary?
For example, you can have a Turing-complete language with recursion, but limit the stack size and run time (to kill the busy beavers) for each user script. If it's implemented as some kind of a VM it'll be very easy to do. You can also have a total functional language to ensure termination (but that won't solve the busy beavers problem).

What are some intuitions that support calling the Maybe constructor in Haskell "Just"? [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 5 years ago.
Improve this question
The intuition of an optional type like Maybe Int is that either there is no Int (thus, there's Nothing there) or that there is some Int; there is something there.
It makes sense to me that we call the type constructor for the "negative" case Nothing, since it means exactly that -- that there's no Int there. But why use the word Just in the case where the emphasis is on something actually being there?
To me, the word "Just" carries the connotation that the thing it's describing is less than the alternative; the opposite of something actually being there; for example,
A: Are you doing anything tonight?
B: No; I'm just gonna stay in and watch TV.
A: Did you investigate the creepy ghost sounds around your house?
B: yeah, turns out it was actually just an owl.
Clearly I'm lacking whatever intuition this naming choice was based on. What is it? Because to me, the word Just means the opposite of how it's used in the Maybe type.

Searching for simple problems naturally solved using stacks [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 5 years ago.
Improve this question
I would like to know about simple problems that can be naturally solved using stacks with the usual interface (emptyS, isEmptyS, push, pop, top).
The complexity asociated to the context of the problem should be null. I can't touch topics like parsing, compiling or search algorithms at this moment. This discards many classical examples.
The most beautiful example I found so far is checking for balanced parenthesis in strings. In very few lines, without any other background, the exercise shows the utility of the data structure:
Another good example is procesing a string where the asterisk means to pop an item from the stack and a letter means to push it into the stack. The function must return the stack after the operations described in the string are applied to an empty stack.
If you can share some others problems, I will apreciate it very much.
Thank you in advance.
Though this question is too broad, I am going to give some other applications. Some of other common applications are -
Parsing
Recursive Function
Calling Function
Expression Evaluation
Expression Conversion
Infix to Postfix
Infix to Prefix
Postfix to Infix
Prefix to Infix
Towers of Hanoi
Some details can be found here.

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 can I get at the cleverest optimizations that GHC makes? [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 9 years ago.
Improve this question
Because I can see it coming: this is a different question than What optimizations can GHC be expected to perform reliably? because I'm not asking for the most reliable optimizations, just the most clever/powerful.
I'm specifically looking for non-intuitive optimizations that GHC makes that can have serious impacts on performance and demonstrate the power of compiler optimizations related to lazy evaluation or purity. And direct explanations about how to get at them.
The best answers will have:
An explanation of the optimization and why it is so clever or powerful
Why the optimization improves performance
How GHC recognizes when it can use this optimization
What the optimization actually transforms the code into
Why this optimization requires lazy evaluation or purity
Stream fusion is probably the biggest one. It turns something like sum . map (+1) . filter (>5), which nominally allocates two new lists, into a simple loop that operates in constant space.

Resources