GithubHelp home page GithubHelp logo

ihaskell / ihaskell Goto Github PK

View Code? Open in Web Editor NEW
2.5K 51.0 257.0 7.26 MB

A Haskell kernel for the Jupyter project.

License: MIT License

Haskell 41.16% JavaScript 0.34% Jupyter Notebook 57.18% Nix 0.97% TypeScript 0.05% Dockerfile 0.20% Shell 0.09%
haskell jupyter

ihaskell's Introduction

jupyter IHaskell Build Status Binder

IHaskell

You can now try IHaskell directly in your browser at CoCalc or mybinder.org.

Alternatively, watch a talk and demo showing off IHaskell features.

IHaskell is a kernel for the Jupyter project, which allows you to use Haskell inside Jupyter frontends (including the console and notebook). It currently supports GHC 8.0 through 9.0. For GHC 7.10 support please use the GHC7 tag.

For a tour of some IHaskell features, check out the demo Notebook. More example notebooks are available on the wiki. The wiki also has more extensive documentation of IHaskell features.

IPython Console IPython Notebook

Interactive In-Browser Notebook

Installation

Linux

Some prerequisites; adapt to your distribution.

sudo apt-get install -y python3-pip git libtinfo-dev libzmq3-dev libcairo2-dev libpango1.0-dev libmagic-dev libblas-dev liblapack-dev

Install stack, clone this repository, install Python requirements, install ihaskell, and install the Jupyter kernelspec with ihaskell.

These instructions assume you don't already have Stack or a Jupyter installation, please skip the relevant steps if this is not the case.

curl -sSL https://get.haskellstack.org/ | sh
git clone https://github.com/gibiansky/IHaskell
cd IHaskell
pip3 install -r requirements.txt
stack install --fast
ihaskell install --stack

Run Jupyter.

stack exec jupyter -- notebook

Mac

You need to have Homebrew installed. If you do not have it yet run /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" in your terminal.

You also need the Xcode command line tools. You can install them by running xcode-select --install in the terminal and following the prompts.

These instructions assume you don't already have Stack or a Jupyter installation, please skip the relevant steps if this is not the case.

brew install python3 zeromq libmagic cairo pkg-config haskell-stack pango
git clone https://github.com/gibiansky/IHaskell
cd IHaskell
pip3 install -r requirements.txt
stack install --fast
ihaskell install --stack

If you have Homebrew installed to a location that stack does not expect (e.g. /opt/homebrew), you'd need to specify --extra-include-dirs ${HOMEBREW_PREFIX}/include --extra-lib-dirs ${HOMEBREW_PREFIX}/lib to the stack command.

Run Jupyter.

stack exec jupyter -- notebook

Tested on macOS Sierra (10.12.6)

Windows

IHaskell does not support Windows, however it can be used on Windows 10 via Windows Subsystem for Linux (WSL). If WSL is not installed, follow the Installation Guide for Windows 10. The following assumes that Ubuntu is picked as the Linux distribution.

In the Ubuntu app, follow the steps above for Linux.

Jupyter Notebook is now ready to use. In the Ubuntu app, launch a Notebook Server, without opening the notebook in a browser:

jupyter notebook --no-browser

Returning to Windows 10, open a browser and copy and paste the URL output in the step above (the token will differ).

Or copy and paste one of these URLs:
     http://localhost:8888/?token=9ca8a725ddb1fdded176d9e0e675ba557ebb5fbef6c65fdf

Tested on Windows 10 (build 18362.175) with Ubuntu 18.04 on WSL

Alternatively, install Virtualbox, install Ubuntu or another Linux distribution, and proceed with the install instructions.

Docker

To quickly run a Jupyter notebook with the IHaskell kernel, try the Dockerfile in the top directory.

docker build -t ihaskell:latest .
docker run --rm -p 8888:8888 ihaskell:latest

Or use the continuously updated Docker image on Docker Hub.

docker run --rm -p 8888:8888 gibiansky/ihaskell

In order to mount your own local files into the Docker container use following command:

docker run --rm -p 8888:8888 -v "$PWD":/home/jovyan/src gibiansky/ihaskell

Be aware that the directory you're mounting must contain a stack.yaml file. A simple version would be:

resolver: lts-16.23
packages: []

It's recommended to use the same LTS version as the IHaskell image is using itself (as can be seen in its stack.yaml). This guarantees that stack doesn't have to first perform a lengthy installation of GHC before running your notebook.

You can also use the following script to run IHaskell in Docker: https://gist.github.com/brandonchinn178/928d6137bfd17961b9584a8f96c18827

Nix

If you have the nix package manager installed, you can create an IHaskell notebook environment with one command. For example:

$ nix-build -I nixpkgs=https://github.com/NixOS/nixpkgs/tarball/nixos-23.05 release.nix --argstr compiler ghc928 --arg packages "haskellPackages: [ haskellPackages.lens ]"
<result path>
$ <result path>/bin/jupyter notebook

It might take a while the first time, but subsequent builds will be much faster. You can use the https://ihaskell.cachix.org cache for prebuilt artifacts.

The IHaskell display modules are not loaded by default and have to be specified as additional packages:

$ nix-build -I nixpkgs=https://github.com/NixOS/nixpkgs/tarball/nixos-23.05 release.nix --argstr compiler ghc928 --arg packages "haskellPackages: [ haskellPackages.ihaskell-blaze haskellPackages.ihaskell-charts ]"

For more examples of using IHaskell with Nix, see https://github.com/vaibhavsagar/notebooks.

Developing

IHaskell is regularly updated to work with the latest version of GHC. To read how this is done, and how the development environment is set up, please see this blog post.

Nix flake

There is also a Nix flake that provides a developer environment. For details on Nix flakes, please see the documentation at https://nixos.wiki/wiki/Flakes.

After this, IHaskell can be compiled as follows:

nix develop # This opens a new shell with all dependencies installed
cabal update # Make sure Cabal's package index is up-to-date
cabal build # Builds IHaskell

Note that this shell also provides haskell-language-server, which can be used in your editor if it supports it. Opening your editor from within the nix develop shell should allow it to see haskell-language-server.

Troubleshooting

Where are my packages? (IHaskell + Stack)

Stack manages separate environments for every package. By default your notebooks will only have access to a few packages that happen to be required for IHaskell. To make packages available add them to the stack.yaml in the IHaskell directory and run stack install --fast.

Packages should be added to the packages: section and can take the following form (reproduced here from the stack documentation). If you've already installed a package by stack install you can simply list its name even if it's local.

- package-name
- location: .
- location: dir1/dir2
- location: https://example.com/foo/bar/baz-0.0.2.tar.gz
- location: http://github.com/yesodweb/wai/archive/2f8a8e1b771829f4a8a77c0111352ce45a14c30f.zip
- location:
    git: [email protected]:commercialhaskell/stack.git
    commit: 6a86ee32e5b869a877151f74064572225e1a0398
- location:
    hg: https://example.com/hg/repo
    commit: da39a3ee5e6b4b0d3255bfef95601890afd80709

The kernel keeps dying (IHaskell + Stack)

The default instructions globally install IHaskell with support for only one version of GHC. If you've e.g. installed an lts-10 IHaskell and are using it with an lts-9 project the mismatch between GHC 8.2 and GHC 8.0 will cause this error. Stack also has the notion of a 'global project' located at ~/.stack/global-project/ and the stack.yaml for that project should be on the same LTS as the version of IHaskell installed to avoid this issue.

ihaskell's People

Contributors

aavogt avatar abarbu avatar artuuge avatar bgamari avatar brandon-leapyear avatar carreau avatar cje avatar daviddavo avatar dependabot[bot] avatar dispanser avatar edechter avatar erikd avatar fptje avatar franklinchen avatar gibiansky avatar gregoryschwartz avatar gregwebs avatar houshuang avatar jamesdbrock avatar kfiz avatar leftaroundabout avatar mmesch avatar nicluo avatar pavelkogan avatar razzius avatar smarthypercube avatar teto avatar thomasjm avatar thomaspeiselt-tomtom avatar vaibhavsagar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ihaskell's Issues

Exiting IHaskell does not close process

On OS X (10.8), closing the IHaskell console does not close the process:

edechter@helmholtz IHaskell (master) $ IHaskell console
Python 2.7.2 (default, Oct 11 2012, 20:14:37)
Type "copyright", "credits" or "license" for more information.

IPython 1.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

IPython profile: haskell

In [1]:
Do you really want to exit ([y]/n)? y
edechter@helmholtz IHaskell (master) $ IHaskell console
Python 2.7.2 (default, Oct 11 2012, 20:14:37)
Type "copyright", "credits" or "license" for more information.

IPython 1.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

IPython profile: haskell

In [1]:
Do you really want to exit ([y]/n)? y
edechter@helmholtz IHaskell (master) $ top -ncols 5

<snip>
PID    COMMAND          %CPU TIME     #TH
90656  top              0.0  00:00.13 1/1
90383  IHaskell         0.0  00:00.12 3
90371  IHaskell         0.0  00:00.12 3
<snip>

Separate IHaskell.GHC.HaskellParser into separate package

Keeping it produces very long compilation times, and the package may be useful to other people.

Thus separate it into a ghc-parser package that is separate and provides the various parsers, and then don't compile it every time.

Implement ":info" like in GHCi

Use getInfo from GHC API InteractiveEval module to do this. The GetInfo directive type is already parsed in IHaskell.Eval.Parser, so this will just consist of generating the proper DisplayData in evalCommand in IHaskell.Eval.Evaluate.

Handle Multi-Line Functions

Currently, defining a function on multiple lines causes only the last definition to hold:

f 3 = 2
f 2 = 3

f 2 -- returns 3
f 3 -- errors out

This is the same thing that GHCi does. However, it should be possible to detect that consecutive statements are defining the same function and join them.

ZMQ issues -- solved

Hi, I have tried to build on my Mac and on a linux box running Linux Mint 15. On both I get the error

/home/tom/.cabal/lib/zeromq3-haskell-0.5/ghc-7.6.2/HSzeromq3-haskell-0.5.o: unknown symbol `zmq_ctx_new'

with libzmq 3.2.x and many undeclared errors with 3.1.x on linux.

Which version of zmq should I use?

EDIT: I forgot to

sudo ldconfig

after installing zmq. Now everything works.

Installation problems when following instructions in README

When installing according to the instructions in the README I run into problems with the zeromq3-haskell package. This is with an up to date Ubuntu 13.04. Error messages and package details below.

 ╰─➤  cabal install zeromq3-haskell          1 ↵
Resolving dependencies...
Notice: installing into a sandbox located at
/home/icarus/code/IHaskell/.cabal-sandbox
Configuring zeromq3-haskell-0.5...
Building zeromq3-haskell-0.5...
Failed to install zeromq3-haskell-0.5
Last 10 lines of the build log ( /home/icarus/code/IHaskell/.cabal-sandbox/logs/zeromq3-haskell-0.5.log ):
Base.hsc:134:5: error: ‘ZMQ_EVENT_CLOSED’ undeclared (first use in this function)
Base.hsc:137:5: error: ‘ZMQ_EVENT_CLOSE_FAILED’ undeclared (first use in this function)
Base.hsc:140:5: error: ‘ZMQ_EVENT_DISCONNECTED’ undeclared (first use in this function)
Base.hsc:143:5: error: ‘ZMQ_EVENT_ALL’ undeclared (first use in this function)
Base.hsc:128:5: error: unknown type name ‘zmq_event_t’
Base.hsc:129:5: error: unknown type name ‘zmq_event_t’
Base.hsc:133:5: error: ‘ZMQ_MORE’ undeclared (first use in this function)
Base.hsc:139:5: error: ‘ZMQ_DONTWAIT’ undeclared (first use in this function)
compiling dist/dist-sandbox-3053154b/build/System/ZMQ3/Base_hsc_make.c failed (exit code 1)
command was: /usr/bin/gcc -c dist/dist-sandbox-3053154b/build/System/ZMQ3/Base_hsc_make.c -o dist/dist-sandbox-3053154b/build/System/ZMQ3/Base_hsc_make.o -fno-stack-protector -Wl,--hash-size=31 -Wl,--reduce-memory-overheads -D__GLASGOW_HASKELL__=706 -Dlinux_BUILD_OS=1 -Dx86_64_BUILD_ARCH=1 -Dlinux_HOST_OS=1 -Dx86_64_HOST_ARCH=1 -Idist/dist-sandbox-3053154b/build/autogen -include dist/dist-sandbox-3053154b/build/autogen/cabal_macros.h -Idist/dist-sandbox-3053154b/build/autogen -include dist/dist-sandbox-3053154b/build/autogen/cabal_macros.h -Idist/dist-sandbox-3053154b/build/autogen -include dist/dist-sandbox-3053154b/build/autogen/cabal_macros.h -Idist/dist-sandbox-3053154b/build/autogen -include dist/dist-sandbox-3053154b/build/autogen/cabal_macros.h -Idist/dist-sandbox-3053154b/build/autogen -include dist/dist-sandbox-3053154b/build/autogen/cabal_macros.h -Idist/dist-sandbox-3053154b/build/autogen -include dist/dist-sandbox-3053154b/build/autogen/cabal_macros.h -I/usr/lib/ghc/bytestring-0.10.0.2/include -Idist/dist-sandbox-3053154b/build/autogen -include dist/dist-sandbox-3053154b/build/autogen/cabal_macros.h -Idist/dist-sandbox-3053154b/build/autogen -include dist/dist-sandbox-3053154b/build/autogen/cabal_macros.h -Idist/dist-sandbox-3053154b/build/autogen -include dist/dist-sandbox-3053154b/build/autogen/cabal_macros.h -Idist/dist-sandbox-3053154b/build/autogen -include dist/dist-sandbox-3053154b/build/autogen/cabal_macros.h -Idist/dist-sandbox-3053154b/build/autogen -include dist/dist-sandbox-3053154b/build/autogen/cabal_macros.h -Idist/dist-sandbox-3053154b/build/autogen -include dist/dist-sandbox-3053154b/build/autogen/cabal_macros.h -Idist/dist-sandbox-3053154b/build/autogen -include dist/dist-sandbox-3053154b/build/autogen/cabal_macros.h -Idist/dist-sandbox-3053154b/build/autogen -include dist/dist-sandbox-3053154b/build/autogen/cabal_macros.h -I/usr/lib/ghc/base-4.6.0.1/include -Idist/dist-sandbox-3053154b/build/autogen -include dist/dist-sandbox-3053154b/build/autogen/cabal_macros.h -Idist/dist-sandbox-3053154b/build/autogen -include dist/dist-sandbox-3053154b/build/autogen/cabal_macros.h -Idist/dist-sandbox-3053154b/build/autogen -include dist/dist-sandbox-3053154b/build/autogen/cabal_macros.h -I/usr/lib/ghc/include -Idist/dist-sandbox-3053154b/build/autogen -include dist/dist-sandbox-3053154b/build/autogen/cabal_macros.h -I/usr/lib/ghc/include/
cabal: Error: some packages failed to install:
zeromq3-haskell-0.5 failed during the building phase. The exception was:
ExitFailure 1



╭─icarus@urth ~/code/IHaskell  ‹master*› 
╰─➤  dpkg -s libzmq1
Package: libzmq1
Status: install ok installed
Priority: optional
Section: libs
Installed-Size: 279
Maintainer: Ubuntu Developers <[email protected]>
Architecture: amd64
Multi-Arch: same
Source: zeromq
Version: 2.2.0+dfsg-2ubuntu1
Depends: libc6 (>= 2.15), libgcc1 (>= 1:4.1.1), libpgm-5.1-0 (>= 5.1.116~dfsg), libstdc++6 (>= 4.2.1), libuuid1 (>= 2.16)
Pre-Depends: multiarch-support
Description: lightweight messaging kernel (shared library)
 ØMQ is a library which extends the standard socket interfaces with features
 traditionally provided by specialised messaging middleware products.
 .
 ØMQ sockets provide an abstraction of asynchronous message queues, multiple
 messaging patterns, message filtering (subscriptions), seamless access to
 multiple transport protocols and more.
 .
 This package contains the ZeroMQ shared library.
Homepage: http://www.zeromq.org/
Original-Maintainer: Alessandro Ghedini <[email protected]>
╭─icarus@urth ~/code/IHaskell  ‹master*› 
╰─➤  dpkg -s libzmq-dev
Package: libzmq-dev
Status: install ok installed
Priority: optional
Section: libdevel
Installed-Size: 870
Maintainer: Ubuntu Developers <[email protected]>
Architecture: amd64
Multi-Arch: same
Source: zeromq
Version: 2.2.0+dfsg-2ubuntu1
Depends: libzmq1 (= 2.2.0+dfsg-2ubuntu1)
Description: lightweight messaging kernel (development files)
 ØMQ is a library which extends the standard socket interfaces with features
 traditionally provided by specialised messaging middleware products.
 .
 ØMQ sockets provide an abstraction of asynchronous message queues, multiple
 messaging patterns, message filtering (subscriptions), seamless access to
 multiple transport protocols and more.
 .
 This package contains the ZeroMQ development libraries and header files.
Homepage: http://www.zeromq.org/
Original-Maintainer: Alessandro Ghedini <[email protected]>

IPython.hs parse version

IHaskell setup fails with IHaskell : Prelude.read: no parse

I've tracked it down to the following:

IPython version are major.minor.patch(-extra).
Like I am on 2.0.0-dev that will become 2.0.0-alpha, then 2.0.0-beta then 2.0.0-rcx finally 2.0.0.

IPython.hs does not parse like that IIUC.

Parsing issue

Hi,

I run into an error when I try to input several statements separated by empty lines:

a = 1
b = 1

is fine, but

a = 1

b = 1

is not. Error reported:

Parse error (line 1, column 1): parse error (possibly incorrect indentation or mismatched brackets)

Adding let keyword does not change the result

BTW, nice logo 👍

Infinite list does not print incrementally

Currently, infinite lists do not print incrementally.

In [3]: [1..]
["[1..]\n"]
Statement: [1 ..]
^CRunException: user interrupt

In GHCi, they do. But they flood the console. I think it would be nice to have a max output size in the configurations and then snip any very long output to that length.

Any ideas on how to tackle this?

Update to ZMQ 4

Installation fails for me, as I already moved forward to ZeroMQ version 4. Thus, I get:

IHaskell-0.1.0.0 depends on zeromq3-haskell-0.5.1 which failed to install.

Use typeclass for DisplayData

It would be great to allow library writers to define their own DisplayData representations via some typeclass.

Current ideas:

  1. Create a typeclass IHaskellData:
class IHaskellData a where
    display :: a -> [DisplayData]
  1. Create a single IHaskell module that library writers will import. This will export the typeclass as well as all the type information relevant to DisplayData.
  2. Require that all such packages be named ihaskell-* and contain a unique module IHaskell.Display.Something, where Something is equal to a capitalized version of whatever is after ihaskell in the package name. For instance, ihaskell-repa would have the module IHaskell.Display.Repa in it.
  3. Upon notebook or console startup, use ghc-pkg (or equivalent GHC api call, hopefully) to find all ihaskell-* packages that are available. Inside the interpreter, try to use display (from the IHaskellData) typeclass in order to generate the display results. We could potentially use exprType to check if the data belongs to the typeclass; or just try it and handle the exceptions. I'm not totally sure on this bit.

Add tests for evaluation

Add tests for evalCommand to make sure that evaluation is running properly after testing. Start by adding everything from the test notebook, but make sure to test more beyond that.

Update building README

Building IHaskell now requires cpphs and happy, since it uses the GHC grammar for parsing Haskell.

Update the README in order to reflect this.

Completion for :extension directive

Implement a special form of completion for lines starting with :e or :extension or other substrings which autocompletes different GHC extensions.

Updated data declarations do not properly take effect

If you update and re-evaluate a data declaration which adds a new typeclass, it does not properly take effect:

screenshot 2013-12-22 at 1 07 49 am

The proper behaviour is what GHCi does:

Prelude> data Thing = One Int
Prelude> One 3

<interactive>:3:1:
    No instance for (Show Thing) arising from a use of `print'
    Possible fix: add an instance declaration for (Show Thing)
    In a stmt of an interactive GHCi command: print it
Prelude> data Thing = One Int deriving Show
Prelude> One 3
One 3

Notebook running python not haskell with older iPython

If I start the notebook in the example and run the first command:

data Value = X Int
       | Y String
       | Z Float
       deriving Show

let values = [X 20,
          Y "Test",
          Z 0.5]
mapM_ print values

File "<ipython-input-1-9354cdf9baf6>", line 1
    data Value = X Int
         ^
SyntaxError: invalid syntax

However running
def a(): return 3

is fine, so it seems to be just running python.

iPython 0.13.2

The type signature for `...' lacks an accompanying binding

Hi,
Trying to learn a bit of haskell while reading what you did
The following does not seem to work for me, is this normal ?

doubleIt:: Int -> Int
doubleIt x = x*2  
The type signature for `doubleIt' lacks an accompanying binding

(BTW the message appear to be in HTML, it seem to me that IPython should have a stderr channel, that in the notebook put things in red by default without having you to explicitely push a rich display type )

Mark Completions aware of Modules

If I am completing something after a period as in

import Text.<cursor>

and the word before the period starts with a capital letter, then this is likely a module, and we should look inside the module namespace to check what can be completed.

IPython profile_haskell

Hi,

Really happy to see that, You should definitively make an announcement on IPython-dev mailing list (on top of Hacker news thread)!

As you might, or might not be aware, we are trying to add the ability to select from many kernel in IPython notebook, and as Fernando Perez wrote to you, we'll be happy to get your feed back.

I personally have no experiences with Haskell, but as I'm currently tweeking IJulia and IRuby custom profiles to have better integration with the notebook (correct syntax highlighting and all that), I'm proposing myself to help writing IHaskell custom profile.

Here are the custom files that IJulia replaces in .ipython/profile_julia , where should I put the equivalent in IHaskell repository and how to get them copied in the right place (is there an install script) ?

(NB, I'm also mostly in charge of nbviewer, so If you have a notebook you want to put on the frontpage, I'll be happy to do so)

IHaskell kernel chosen can be different from the executable you start

Does it make sense to overwrite the exe = ... in ~/.config/ipython/profile_haskell/ipython_config.py. When I run a ./dist/build/IHaskell/IHaskell I expect the kernel selected should be that same binary, not whatever IHaskell is in the PATH (currently), or whatever IHaskell binary was used to make the setup (if you merge that commit of mine).

IHaskell doesn't accept Haskell input on Ubuntu 12.10 / IPython 1.1.0

I just installed IHaskell according to your README.
Sadly I get SyntaxErrors both in the console and the notebook for valid Haskell input…

Please ask if you need more info…

$ IHaskell console
Python 2.7.3 (default, Sep 26 2013, 16:35:25) 
Type "copyright", "credits" or "license" for more information.

IPython 1.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

IPython profile: haskell

In [1]: putStrLn "IHaskell!"
  File "<ipython-input-1-c1ebef2f31ed>", line 1
    putStrLn "IHaskell!"
                       ^
SyntaxError: invalid syntax

Notebook hangs on any cell execution

When I type the following (whether or not surrounded as :{ code :}) into the console, it works:

data Value = X Int
           | Y String
           | Z Float
           deriving Show

let values = [X 20,
              Y "Test",
              Z 0.5]
mapM_ print values

...
Out[7]:
X 20
Y "Test"
Z 0.5

and same with a simple print statement putStr "Hi".
However, the notebook just freezes when I try and execute either code snippet in the cell with Ctrl- or Shift-Enter. Also, nothing prints to the terminal screen (after loading with Kernel started...Connecting to... info). There is only a "busy" In [*]: next to the cell.

Also, while hanging with the busy sign, occasionally Shift-Enter in a different cell will create a new line instead of trying to run it (normal behavior in IPython I think is to always go to the next cell, even while another cell is busy, so that both are marked as busy). I'm not sure how to reproduce this, though, it's currently marking both cells as busy.

Mac OS 10.8.5, I'm at 97e5335
(I use IPython (1.0.0) regularly, but I'm completely new to Haskell)

Bad import declarations cause kernel to die

IHaskell console does not recover from bad import declarations. For example:

edechter@helmholtz IHaskell (completions) $ IHaskell console
Python 2.7.2 (default, Oct 11 2012, 20:14:37)
Type "copyright", "credits" or "license" for more information.

IPython 1.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

IPython profile: haskell

In [1]: import
["import"]
Import: import
IHaskell: parse error (possibly incorrect indentation or mismatched brackets)


kernel died, restart ([y]/n)?

In [1]: import Data.Lizt
["import Data.Lizt"]
Import: import Data.Lizt
IHaskell: Failed to load interface for `Data.Lizt'
Perhaps you meant
  Data.List (from base)
  Data.DList (from dlist-0.5)
  Data.List (needs flag -package haskell2010-1.1.1.0)
Use -v to see a list of the files searched for.

kernel died, restart ([y]/n)?

support variables from previous calculations

ghci defines an it which refers to the last result, which doesn't refer to the right thing yet. The ipython notebook does something odd with Out[2] before ghc has a chance to choke on that missing constructor Out.

selection_024

/usr/local/lib/ghc-7.6.3/settings: openFile: does not exist

$ ipython -V
1.1.0

$ IHaskell console
IHaskell: /usr/local/lib/ghc-7.6.3/settings: openFile: does not exist (No such file or directory)
Python 2.7.5+ (default, Sep 19 2013, 13:48:49) 
Type "copyright", "credits" or "license" for more information.

IPython 1.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

IPython profile: haskell
ERROR: Kernel did not respond

Any ideas?

IHaskell [notebook | console] fail to run

I'm running Gentoo (current) on 3.11.6 kernel x86_64
ipython version 1.0 (I think)

$ cat ~/.config/ipython/profile_haskell/ipython_config.py
c = get_config()
exe = '/home/jon/.config/bin/IHaskell'.replace(' ', '\ ')
c.KernelManager.kernel_cmd = [exe, 'kernel', '{connection_file}']
c.Session.key = b''
c.Session.keyfile = b''

$ IHaskell setup
~/.cabal/bin/IHaskell

This ran the first time with a warning about default settings being used.

running:
$ IHaskell notebook
or:
$ IHaskell console

produces output:
http://pastebin.com/sQn4DUur

Json Config

Just to keep you guys posted also, you can now express most of config in json file.
Same name that usual config file but .py-> .json.
Json take precedence on .py and are just required to have a top lever "version":1 key.

Maybe it will help you to maintain custom IHaskell profile by processing json.

cf ipython/ipython#4265

Issues running notebook

Hi,

First, many thanks for this project.

I'm running into issues when using the default port 8778 for IHaskell notebooks. If I comment that line the config_notebook.py, it runs fine. Basically, the notebook refuses to work on any port other than 8888: the cells are never evaluated (ie stay with a *)

Any idea what could be going wrong ?

Haskell profile isn't used

Very interesting project)
But I'm little bit confused - after program setup the haskell profile isn't used.

Python 2.7.3 (default, Feb 15 2013, 22:30:16) 
Type "copyright", "credits" or "license" for more information.

IPython 1.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

IPython profile: haskell

In [1]: Just 17
  File "<ipython-input-1-6d14678af56a>", line 1
    Just 17
          ^
SyntaxError: invalid syntax


In [2]: print "aaa"
aaa

I have Gentoo with IPython 1.1.0 (with the 1.0 there is the same trouble) and ghc-7.6.3
What I'm doing wrong?

The one thing was strange,

IHaskell: 
log of commands saved to: /home/erthalion/coding/haskell/IHaskell/.shelly/6.txt
Exception: /home/erthalion/.ipython/profile_haskell/ipython_config.py: openFile: does not exist (No such file or directory)

but after creation of the corresponding directory the setup was completed successfully

Add 'set' (or similar) directive

Allow modification of GHC options via set, in the same way as GHCi:

:set -XDataKinds

Potentially, do something slightly different and specialized for extensions:

:extension + DataKinds OverloadedStrings

in the vein of GHCi's :m + ModuleName

$(ipython locate) instead of `.ipython/`

Sorry, those might be be trivial to fix, but as my Hakell knowledge is ~0.
I'll prefer to open issues that trying to fix it myself.

Just home -> do
          dotIpython <- test_d . fromText $ home ++ "/.ipython"
          dotConfigIpython <- test_d . fromText $ home ++ "/.config/ipython"

          when (not dotIpython && not dotConfigIpython) $ do
            putStrLn "Could not find ~/.ipython or ~/.config/ipython."
            error "Could not find IPython directory."

          return $ home ++ (if dotIpython
                          then "/.ipython"
                          else "/.config/ipython")

You can just execute in a subshell ipython locate it will give you where ipython is expecting its conf to live and will work more reliably on some platform.

Create testing suite

Create a testing suite using hspec. Move all the parser tests from IHaskell.Eval.Parser doctests info the new testing suite, and add everything from the test notebook to the test suite.

No such file or directory: "b''"

Appearently Python misinterprets the c.Session.keyfile = b'' line in ipython_config.py, after commenting out that line everything works as expected. Maybe this is because I'm running Python3?

> IHaskell console 
Traceback (most recent call last):
  File "/usr/lib/python3.3/site-packages/IPython/utils/traitlets.py", line 294, in __get__
    value = obj._trait_values[self.name]
KeyError: 'session'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/ipython", line 9, in <module>
    load_entry_point('ipython==1.1.0', 'console_scripts', 'ipython3')()
  File "/usr/lib/python3.3/site-packages/IPython/__init__.py", line 118, in start_ipython
    return launch_new_instance(argv=argv, **kwargs)
  File "/usr/lib/python3.3/site-packages/IPython/config/application.py", line 544, in launch_instance
    app.initialize(argv)
  File "<string>", line 2, in initialize
  File "/usr/lib/python3.3/site-packages/IPython/config/application.py", line 89, in catch_config_error
    return method(app, *args, **kwargs)
  File "/usr/lib/python3.3/site-packages/IPython/terminal/ipapp.py", line 312, in initialize
    super(TerminalIPythonApp, self).initialize(argv)
  File "<string>", line 2, in initialize
  File "/usr/lib/python3.3/site-packages/IPython/config/application.py", line 89, in catch_config_error
    return method(app, *args, **kwargs)
  File "/usr/lib/python3.3/site-packages/IPython/core/application.py", line 362, in initialize
    self.parse_command_line(argv)
  File "/usr/lib/python3.3/site-packages/IPython/terminal/ipapp.py", line 307, in parse_command_line
    return super(TerminalIPythonApp, self).parse_command_line(argv)
  File "<string>", line 2, in parse_command_line
  File "/usr/lib/python3.3/site-packages/IPython/config/application.py", line 89, in catch_config_error
    return method(app, *args, **kwargs)
  File "/usr/lib/python3.3/site-packages/IPython/config/application.py", line 474, in parse_command_line
    return self.initialize_subcommand(subc, subargv)
  File "<string>", line 2, in initialize_subcommand
  File "/usr/lib/python3.3/site-packages/IPython/config/application.py", line 89, in catch_config_error
    return method(app, *args, **kwargs)
  File "/usr/lib/python3.3/site-packages/IPython/config/application.py", line 412, in initialize_subcommand
    self.subapp.initialize(argv)
  File "<string>", line 2, in initialize
  File "/usr/lib/python3.3/site-packages/IPython/config/application.py", line 89, in catch_config_error
    return method(app, *args, **kwargs)
  File "/usr/lib/python3.3/site-packages/IPython/terminal/ipapp.py", line 323, in initialize
    self.init_shell()
  File "/usr/lib/python3.3/site-packages/IPython/terminal/console/app.py", line 107, in init_shell
    IPythonConsoleApp.initialize(self)
  File "/usr/lib/python3.3/site-packages/IPython/consoleapp.py", line 391, in initialize
    self.init_kernel_manager()
  File "/usr/lib/python3.3/site-packages/IPython/consoleapp.py", line 347, in init_kernel_manager
    self.kernel_manager.start_kernel(extra_arguments=self.kernel_argv)
  File "/usr/lib/python3.3/site-packages/IPython/kernel/manager.py", line 196, in start_kernel
    self.write_connection_file()
  File "/usr/lib/python3.3/site-packages/IPython/kernel/connect.py", line 474, in write_connection_file
    transport=self.transport, ip=self.ip, key=self.session.key,
  File "/usr/lib/python3.3/site-packages/IPython/utils/traitlets.py", line 298, in __get__
    value = obj._trait_dyn_inits[self.name](obj)
  File "/usr/lib/python3.3/site-packages/IPython/kernel/manager.py", line 59, in _session_default
    return Session(parent=self)
  File "/usr/lib/python3.3/site-packages/IPython/kernel/zmq/session.py", line 419, in __init__
    super(Session, self).__init__(**kwargs)
  File "/usr/lib/python3.3/site-packages/IPython/config/configurable.py", line 99, in __init__
    self.config = config
  File "/usr/lib/python3.3/site-packages/IPython/utils/traitlets.py", line 320, in __set__
    obj._notify_trait(self.name, old_value, new_value)
  File "/usr/lib/python3.3/site-packages/IPython/utils/traitlets.py", line 469, in _notify_trait
    c(name, old_value, new_value)
  File "/usr/lib/python3.3/site-packages/IPython/config/configurable.py", line 171, in _config_changed
    self._load_config(new, traits=traits, section_names=section_names)
  File "/usr/lib/python3.3/site-packages/IPython/config/configurable.py", line 155, in _load_config
    setattr(self, name, deepcopy(config_value))
  File "/usr/lib/python3.3/site-packages/IPython/utils/traitlets.py", line 320, in __set__
    obj._notify_trait(self.name, old_value, new_value)
  File "/usr/lib/python3.3/site-packages/IPython/utils/traitlets.py", line 469, in _notify_trait
    c(name, old_value, new_value)
  File "/usr/lib/python3.3/site-packages/IPython/kernel/zmq/session.py", line 348, in _keyfile_changed
    with open(new, 'rb') as f:
FileNotFoundError: [Errno 2] No such file or directory: "b''"

:t works but :type does not

:type should work and do the same thing as :t. There should be an organized system for adding directives such as :type and allowing all their shortened names as well as the full name.

Not obvious how to install cabal

Hi,

I suppose it will be something obvious for haskell programer,
But the readme does not say how to get cabal.

I supposed it comes with ghc in homebrew, but up until now, no luck.

Do not use Show if IHaskellDisplay is available

The following fails:

import Text.Blaze.Html4.Strict hiding (map)

p "This is an example of BlazeMarkup syntax."

Because blaze-html's Markup type doesn't implement Show. We shouldn't need it to, though, if we implement IHaskellDisplay for it.

This requires evaluating the display first, and if it fails, resorting to print.

Implement type defaulting for Show

When using IHaskellDisplay, types that are not monomorphic cannot be unified with most IHaskellDisplay instances, as they require Show. Implement defaulting for types that require Show in a GHCi-like fashion, so that those types are just set to unit.

(Example: Maybe a should be unified with Show a => IHaskellDisplay (Maybe a) so that Nothing can print fancily.)

This might be a bad idea in the long run, but it's better to have a feature and later get rid of it than to never have it, right?

unnecessary blank line before errors

When making a mistake, there is an extra empty line:

selection_023

perhaps the markup can be adjusted somehow? Compare with how the python backend looks (no Out[])

selection_025

support multiple modules and compiled code

There are a couple reasons for wanting to split your code into modules:

  • keep namespaces small and under control
  • speed (-O2 doesn't apply to functions you've typed at the interpreter)
  • avoid template-haskell stage restriction

I made a sketch for knitr, but I think the same design questions apply here.

syntax errors trash state

Hi,

If I define a function, and call it, that works. If I make a typo and then call the wrong function, then everything after that breaks. If I restart (but skip the trouble lines) then it works fine. Is there any way to prevent an errant call from trashing the current state of the code, the way an instance of GHCi would be able to continue?

Best,
traviscj

screen shot 2013-10-22 at 4 29 46 pm

Do not suppress stdout when in console mode

When using IHaskell console, it may be preferable to let IHaskell print to stdout instead of trying to capture the output. Currently, the output is

In [1]: print 3
Out[1]: 
3

This implies that the output was 3, but the actual output was (), so this is misleading. Instead, we should just have it print the 3, and not have any Out[...], as IPython itself does:

In [2]: print(3)
3

support "complete_request"

If you press tab, this causes a pattern match failure in instance FromJSON MessageType. Ideally the ghc api could provide a completion.

Completion inserts some logging text into console

Hitting tab where cursor is at the pipe produces the following in the console.

In [2]: putS|CompleteRequest {header = MessageHeader {identifiers = ["c2a53fee-d3d6-4094-a6fb-fd4d229c2627"], parentHeader = Nothing, metadata = fromList [], messageId = 52226c10-5720-4281-9c2a-7ea63f687c77, sessionId = c2a53fee-d3d6-4094-a6fb-fd4d229c2627, username = "uname", msgType = complete_request}, getCode = "", getCodeLine = "putS", getCursorPos = 4}

putStr    putStrLn

Typing the whole command without completion works correctly, sometimes, but with log messages. First attempt kills the kernel:

In [2]: putStrLn "hi"
kernel died, restart ([y]/n)? y
()
ExecuteRequest {header = MessageHeader {identifiers = ["c2a53fee-d3d6-4094-a6fb-fd4d229c2627"], parentHeader = Nothing, metadata = fromList [], messageId = 06e7ee7b-210f-4748-b60b-a797308601fb, sessionId = c2a53fee-d3d6-4094-a6fb-fd4d229c2627, username = "uname", msgType = execute_request}, getCode = "putStrLn \"hi\"\n", getSilent = False, getStoreHistory = True, getAllowStdin = True, getUserVariables = [], getUserExpressions = []}
("putStrLn \"hi\"\n",[])
Statement: putStrLn "hi"
Names: ["it"]
Statement: let it1 = it
Names: ["it1"]
KernelInfoRequest {header = MessageHeader {identifiers = ["c2a53fee-d3d6-4094-a6fb-fd4d229c2627"], parentHeader = Nothing, metadata = fromList [], messageId = fb979b2d-4c6a-48a2-9844-197b3faf58e0, sessionId = c2a53fee-d3d6-4094-a6fb-fd4d229c2627, username = "uname", msgType = kernel_info_request}}

Second attempt works:

In [2]: putStrLn "hi"
ExecuteRequest {header = MessageHeader {identifiers = ["c2a53fee-d3d6-4094-a6fb-fd4d229c2627"], parentHeader = Nothing, metadata = fromList [], messageId = ddc8d66b-feb1-4619-afd1-2562f0a437c5, sessionId = c2a53fee-d3d6-4094-a6fb-fd4d229c2627, username = "uname", msgType = execute_request}, getCode = "putStrLn \"hi\"\n", getSilent = False, getStoreHistory = True, getAllowStdin = True, getUserVariables = [], getUserExpressions = []}
("putStrLn \"hi\"\n",[])
Statement: putStrLn "hi"
Names: ["it"]
Statement: let it2 = it
Names: ["it2"]
Out[2]:
hi

Not sure if the logging printed in the console is related to the kernel death.

I believe I installed correctly, but I'm not on Ubuntu (rather, Mac OS) so I didn't sudo apt-get install happy but did cabal install happy instead.

cabal install fails

sorry if this isn't your fault, but I don't know how to proceed here and could use some help.

$ cabal install
Resolving dependencies...
Configuring ihaskell-0.1.0.0...
Building ihaskell-0.1.0.0...
Preprocessing library ihaskell-0.1.0.0...
In-place registering ihaskell-0.1.0.0...
Preprocessing executable 'IHaskell' for ihaskell-0.1.0.0...

IHaskell/Eval/Parser.hs:32:8:
    Could not find module `IHaskell.GHC.HaskellParser'
    Use -v to see a list of the files searched for.
Failed to install ihaskell-0.1.0.0
cabal: Error: some packages failed to install:
ihaskell-0.1.0.0 failed during the building phase. The exception was:
ExitFailure 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.