How can I run a Haskell file using window's powershell? - powershell

I downloaded chocolatey and am able to load up ghci and get prelude on powershell.
I then cd into the directory where I have a haskell file I want to run, then I type ghci and then type:
load haskellprogram.hs
but then I get an error about it not being in scope.
Is this not how you run a Haskell program?

The GHCi command to load a file is :load, not load. You should write:
:load haskellprogram.hs
The command can also be abbreviated :l. You can find more information about the available commands in GHCi by entering :help. Also note that the prompt shows the modules you have imported; Prelude is just the name of the standard library module that gets imported by default. You can change the prompt with:
:set prompt "> "
:set prompt-cont "| "
(Where prompt-cont is the prompt for multi-line input, using the commands :{ and :} or the multi-line input mode enabled by :set +m.)
When you entered load haskellprogram.hs, it was interpreted as a Haskell expression: (load haskellprogram) . hs, which tries to use the (.) composition operator and three variables load, haskellprogram, and hs that are not defined.

Related

Coq & Emacs: Cannot compile Coq - No such file or directory

When I try to compile a Coq file using C-c in Emacs, I get this error:
Coq compilation error: ((coqdep -Q /home/****/cs54 DMFP /tmp/ProofGeneral-coqUMWPyn.v) No such file or directory
I'm on manjaro and have installed Emacs and Coq through the command line and don't know what's going on.
_CoqProject only contains these characters:
-Q . DMFP
In case this helps narrow it down, when I type coqc into the terminal, nothing happens and the prompt comes up again.
When I type coqtop the program starts but it does not evaluate anything. When I type something like "2" or "Check 2" it simply pulls up the prompt for the next input.

How to specify make program in emacs?

Vim has makeprg variable. This variable takes program name which will be executed if :make is entered. Is there something similar in emacs?
Thanks.
The variable compile-command specifies the compiler program, which you can customize as needed. Here's the manual page for M-x compile and family.
I'm not aware of a make command in Emacs, but there is compile:
Compile the program including the current buffer. Default: run `make'.
Runs COMMAND, a shell command, in a separate process asynchronously
with output going to the buffer `*compilation*'.
The command that gets run by compile is defined by the variable compile-command, which can be set like this:
(setq compile-command "some command")
compile-command's default value is "make -k ".

In IPython every shell command is run by prefixing it with "!" but few commands run without that, What is the reason behind it?

In case of "ls" command it runs with and without the prefix "!". In case of "cat fileName" it's the same, but when you consider "wc -l fileName" it works only with "!" prefix.
When you combine cat and wc command "cat fileName | wc -l" executed successfully without "!" prefix.
I don't understand the logic behind this prefix "!" in ipython.
Thank you in advance
(I am new to python programming, if it sounds silly question please forgive me.)
IPython tries to make interactive programming as comfortable as possible. Some shell builtins like ls, cd or cat are basic commands to navigate in unix shells. IPython, as a "Python Shell" provides the same functionally for convenience. Along with features like colored output, etc.
The !command is for executing arbitrary shell code and is much more powerful. It can be used to run any command you can type in a normal shell and can also catch its output.
Compare ls with !ls. The former will print the content in your current directory with nice coloring. The latter will print the same list, but just plain text.
But note that you can do really cool things with !command:
files = !ls
for f in files:
print("I like this file:", f)
Which reads the output of ls into a python array files which you can use in your code just like any other array.
To sum up: if you just want to navigate, you usually use the standard commands, if available. If you need to capture the output or run programs you have to use the !command syntax.

IPython | Unix commands not working in script but working in command line interpreter

Below lines when i put them in test.py and runs it, gives me error but runs fine when i run them from command line.
pyvar = 'Hello world'
!echo "A python variable: {pyvar}"
jitu#jitu-PC:~/ipython/python$ ipython test.py
File "/home/jitu/ipython/python/test.py", line 2
!echo "A python variable: {pyvar}"
^
SyntaxError: invalid syntax
Any idea why it is not working ?
.py file are python script, they are supposed to be pure python, IPython will not try to do some "magic" on it. You should rename your script to .ipy if you want to use the syntactic sugar IPython offers on top of pure python syntax.
Note that all IPython syntactic sugar can be transformed into pure python (cf %hist vs %hist -t) that will be valid python syntax, but still need to have access to an IPython instance.

How to run IPython script from the command line - syntax error with magic functions, %

I want to run IPython from the command line. However, I get a syntax error on the first line, importing pylab with the magic function %pylab is giving a syntax error on the %. The command I am using is simply ipython -i script.py.
Any ideas how to solve this?
You need to name your file script.ipy. When it ends in .ipy it can contain ipython syntax.
From ipython --help:
Usage
ipython [subcommand] [options] [files]
If invoked with no options, it executes all the files listed in sequence
and exits, use -i to enter interactive mode after running the files. Files
ending in .py will be treated as normal Python, but files ending in .ipy
can contain special IPython syntax (magic commands, shell expansions, etc.)