Install haskell koans on windows - haskell

I am trying to learn haskell using haskell koans https://github.com/HaskVan/HaskellKoans. The installation instructions found is not working and they look presumably for linux. I need help to get the koans working on windows.

If you look at the top of setup-koans, you'll see:
#!/usr/bin/env runhaskell
import Control.Monad (unless)
...etc
That first line with the hashbang indicates that a unix shell running this file as a program should pass everything that follows (the haskell source file, in this case) to the command specified (/usr/bin/env runhaskell in this case).
If you have a GHC installation, and runghc in your path, you should be able to remove that line and do runghc setup-koans.
You might also like to play with cygwin, or with a linux virtual machine (e.g. in docker) to familiarize yourself with this sort of thing.

Related

How can I use the command `runhaskell`?

I am trying to run the Haskell script in this StackOverflow answer. Pandoc appears to execute the runhaskell executable because I get the error
Could not find executable runhaskell
Seems like I need Haskell. So I google "install haskell", go to haskell.org, and follow the install instructions. It appears to install correctly. For example, I now have a $HOME/.ghcup/ directory and the stack command works. However, runhaskell still does not work. When I search Haskell Tool Stack, I don't see any meaningful hits. However, there is a stack command called runhaskell. When I add stack runhaskell to the top of chapter.hs from the previous post, I get the same error.
I even tried following a "hello world" for Haskell but the first step, using ghci, fails. So maybe I didn't even install the Haskell Platform correctly.
Feels like a really stupid issue, but I can't figure out how to install the executable runhaskell which, I assume, will run a Haskell program.
looks like runhaskell is not in your $PATH

Specify Python3 to Atom on Windows 10

In advance, sorry if this is question ought be on SuperUser or another site
The python3 shebang doesn't seem to work on win10. (I cant check right now, but I believe the analogous approach worked on MacOS for me last night). Consider the following
#!/usr/bin/env python3
print("hello world")
Leads to the error 'python' is not recognized as an internal or external command,
operable program or batch file. This makes sense because I only have a python3 distro on my machine (which can only be called like python3). However, Atom seems to be ignoring the shebang altogether. FYI, I'm running the script with the popular "script" atom package.
I've tried the permutation, #!/usr/bin python3, but this doesn't work either.
I've tried permutations
I'm still interested in how shebangs work within the Atom environment, but as far as getting python3 up and running, you dont need a shebang. You can simply change a config file (python.coffee) from within Atom, then relaunch. See Daniel Chamorro's excellent answer here: How to setup Atom's script to run Python 3.x scripts? May the combination with Windows 7 Pro x64 be the issue?

Compiling Haskell programs in Windows: is it possible without downloading something such as Cygwin?

I am reading "Learn you a Haskell for great good", and have reached the chapter on I/O actions. I am using Windows, and have downloaded GHCi and WinGHCi.
I'm trying to compile a simple program and have saved a file on emacs as helloworld.hs with main = putStrLn "hello, world" in it.
The book says
Open your terminal, navigate to the directory where helloworld.hs is located, and enter the following:
$ ghc --make helloworld
However, if I enter $ ghc --make helloworld onto GHCi and WinGHCi I receive errors such as the one below, perhaps because I need to enter $ ghc --make helloworld elsewhere:
<interactive>:7:1: error:
parse error on input ‘$’
Perhaps you intended to use TemplateHaskell
In fact, in the online edition of the book (here: http://learnyouahaskell.com/input-and-output), the author remarks that:
For the purposes of this chapter, I'm going to assume you're using a unix-y environment for learning Haskell. If you're in Windows, I'd suggest you download Cygwin, which is a Linux-like environment for Windows, A.K.A. just what you need.
Question 1: Is it necessary for me to download Cygwin, or some other such thing, in order to be able to compile the program by entering $ ghc --make helloworld?
I ask this, since if there were some other way of compiling the program it would be very useful to know, since I am on a university computer and cannot download things like Cygwin without permission. (and even with permission it might not be possible, depending on what Cygwin requires)
Question 2: Given that only the technicians of my university are away for Easter, and only they can download things on this computer, how can I proceed with the chapter in I/O actions? Is it possible just to continue, but ignore the sections involving compiling programs?
In many Unix and Linux shells (at least in Bash with which I'm most familiar) the default prompt is $. That's what the shell displays.
On Windows, when you open a Command Prompt, you'll typically see something like this instead:
C:\Users\mark>
(That's my prompt.)
While instructions often include the $ prompt in order to indicate that the code is something that you're expected to enter at a command prompt, you're not expected to type the $. Just type ghc --make helloworld and hit Enter.
Also, you're not expected to do this from within GHCi, but from the command line. ghc is a command-line executable (an .exe), just like e.g. git. It has to be in your path, though, or otherwise, you'll have to type the full path the executable every time you want to run it.
You have downloaded ghci, which is interpreter. It is, by my opinion, totally enough to learn with it (it can :load sources as well), but you need to run a bit other commands. I don't know if your installation include compiler, I would not assume anything about it.
btw, you are typing command inside the interpreter already, the error message is specific for that
ps: to do same as "ghc --make" from the interpreter, run:
:load <file>
Yes, it will recurse to depenzecies automatically. You could use :help to learn other commands

Haskell "Could not find module ---" Quipper

I am extremely new to haskell and I have been searching all over the web but I haven't been able to solve my problem. I downloaded the Quipper package but I have not been able to get haskell to recognize where all of the modules and files are and how to properly link everything.
I have downloaded all of the files and programs and installed them properly, I just dont know how to get haskell to recognize the quipper libraries and templates. Evey time I try:
:load And_gate.hs or some other file.
I get:
Could not find module "Quipper" or its respective modules it requires.
I don't think it is an error or anything, I think it is just my lack of knowledge on how haskell works.
I'm using windows 7.
So I emailed Peter Selinger, one of the professors who created Quipper.
The only thing I need to do extra was inside MSYS:
ghci -iC:/quipper -iC:/quipper/quipper
This complies everything correctly and the files run properly.
Here is his email to me:
Dear -----,
thanks for writing. Let me see if I can help.
Are you following the instructions in the README file? Under "Building
the various algorithms and programs", the instruction is to run
"make". This would build all of the tests in the "tests" directory
automatically.
Next, to compile a Quipper program, you should use the "quipper"
script that is located in quipper/scripts. It works just like "ghc",
except that it automatically includes the correct directories for
Quipper's files in the search path. On Windows, you would be using
"quipper.bat".
Quipper is not really meant to be run interactively, i.e., from ghci.
However, if you do need to run Quipper interactively, I recommend
using the "quipperi" script, also in quipper/scripts. This too would
set the load paths correctly. In Windows, use "quipperi.bat".
Finally, if you need to include Quipper stuff from ghci, but for some
reason can't or don't want to use the quipperi script, you need to
specify those directories with the "-i" option, for example
ghci -iC:/quipper -iC:/quipper/quipper
It could be that in Windows, you need to use "\" instead of "/", but I
am not sure if this is necessary.
I hope this helps, -- Peter
When compiling and exe with ghc just make sure you include the commands:
-iC:/quipper -iC:/quipper/quipper.
If you use the quipper script as suggested by Professor Selinger, inside of MSYS do the following:
Navigate to the folder in which all of the Quipper files are held, this was my case:
cd C:/quipper/quipper/scripts
Then type quipper and your file's location in MSYS to compile an exe like so:
quipper C:/quipper/tests/And_gate.hs
The file will compile and should print updates like so:
[1 of 22] Compiling Libraries.Typeable (......
[2 of 22] Compiling Libraries.Tuple (......
and so on.
The exe (in this case And_gate.exe) will be inside the folder it was compiled from (C:/quipper/tests). You'll need to move it to a folder that contains the acroread.bat which comes in quipper/scripts for it to work properly.
For some reason, this code isn't packaged as a standard Haskell package. It if were, installing it would be fairly simple. As it is, the instructions in the README file look awful (especially under Windows, where it looks like you need MSYS to run the makefile).
Your problem might be as simple as telling GHCi which folder to look in to find the files; you can do that using the :cd command. Since you're on Windows, I'd suggest trying WinGHCi, which should allow you to browse to the right folder using the GUI.
If it isn't that simple... really, as a Haskell beginner, you're probably going to struggle to get this working. The documentation looks pretty minimal.
If you red both README and INSTALLING.windows and did everything as well, then you should add a path to Quipper's script folder to environment variable. Here is the path:
quipper-*/quipper/scripts/
where quipper-* is a <distribution name>-<version>.
There are two important scripts in that folder. The first one is quipper.bat which runs a ghc compiler to run Quipper's modules. The second one is quipperi.bat which is a ghci analogue for Quipper.
Now, when you added a path to variable, you can run And_gate.hs in Quipper's interpreter as follows:
quipperi And_gate.hs

How to determine the directory in which a running Haskell script or application lives?

I have a Haskell script that runs via a shebang line making use of the runhaskell utility. E.g...
#! /usr/bin/env runhaskell
module Main where
main = do { ... }
Now, I'd like to be able to determine the directory in which that script resides from within the script, itself. So, if the script lives in /home/me/my-haskell-app/script.hs, I should be able to run it from anywhere, using a relative or absolute path, and it should know it's located in the /home/me/my-haskell-app/ directory.
I thought the functionality available in the System.Environment module might be able to help, but it fell a little short. getProgName did not seem to provide useful file-path information. I found that the environment variable _ (that's an underscore) would sometimes contain the path to the script, as it was invoked; however, as soon as the script is invoked via some other program or parent script, that environment variable seems to lose its value (and I am needing to invoke my Haskell script from another, parent application).
Also useful-to-know would be whether I can determine the directory in which a pre-compiled Haskell executable lives, using the same technique or otherwise.
As I understand it, this is historically tricky in *nix. There are libraries for some languages to provide this behavior, including FindBin for Haskell:
http://hackage.haskell.org/package/FindBin
I'm not sure what this will report with a script though. Probably the location of the binary that runhaskell compiled just prior to executing it.
Also, for compiled Haskell projects, the Cabal build system provides data-dir and data-files and the corresponding generated Paths_<yourproject>.hs for locating installed files for your project at runtime.
http://www.haskell.org/cabal/release/cabal-latest/doc/users-guide/authors.html#paths-module
There is a FindBin package which seems to suit your needs and it also works for compiled programs.
For compiled executables, In GHC 7.6 or later you can use System.Environment.getExecutablePath.
getExecutablePath :: IO FilePathSource
Returns the absolute pathname of the current executable.
Note that for scripts and interactive sessions, this is the path to the
interpreter (e.g. ghci.)
There is executable-path which worked with my runghc script. FindBin didn't work for me as it returned my current directory instead of the script dir.
I could not find a way to determine script path from Haskell (which is a real pity IMHO). However, as a workaround, you can wrap your Haskell script inside a shell script:
#!/bin/sh
SCRIPT_DIR=`dirname $0`
runhaskell <<EOF
main = putStrLn "My script is in \"$SCRIPT_DIR\""
EOF

Resources