I often use ghci for little calculations and stack ghci to work on my actual projects.
To make the first easier I have written a .ghci file with a lot of imported modules in it, but some of these modules aren't present in my stack project and I get nasty errors.
At the moment I use a alias stackghci="stack ghci --ghci-options -ignore-dot-ghci", but then I have the default prompt again and so on..
Is there a way of specifying two .ghci files; one for stack and one for ghci?
ghci supports the --ghci-script flag for specifying additional scripts to read at startup.
Docs for --ghci-script: (link)
I have a set of libraries that live in another folder and syntastic is trying to look for this libraries in the same folder where program lives. For example, the program I have, let's call it, myprogr.d is in c:\programming\myprogr.d. There are libraries inside that program that are address as this
private import jic.libs.myLibs;
and this library exists in C:\D\Import\jic\libs\mylibs.d. When I compile this program, I pass -IC:\D\Import option to the compiler whom finds the entry point for the mentioned library and continues one without a problem. How can I make Syntastic not give me this error?
When I run my file using a foreign import for a C function I made, I get this error.
ByteCodeLink: can't find label
During interactive linking, GHCi couldn't find the following symbol:
richards
This may be due to you not asking GHCi to load extra object files,
archives or DLLs needed by your current session. Restart GHCi, specifying
the missing library using the -L/path/to/object/dir and -lmissinglibname
flags, or simply by naming the relevant files on the GHCi command line.
Alternatively, this link failure might indicate a bug in GHCi.
If you suspect the latter, please send a bug report to:
glasgow-haskell-bugs#haskell.org
After creating a .cabal file and loading it in GHCi from there, I still get this error.
Any ideas?
Is there a command in Haskell which displays (or get as a list of) all the user defined functions which have been loaded/defined in the GHCi? Thanks
To see bindings you've made at the ghci prompt (e.g. with let or <-), try :show bindings.
If you've loaded some modules, you can use :show modules to get the names of loaded modules and then :browse ModuleName to list everything in scope from that module.
When in ghci, use :browse or just :bro after loading the file. You may also browse unloaded modules via :browse Foo.Bar.Baz.
When working in the ocaml or ghci toplevels I often build up a significant "context" for want of a better word, values bound, functions, modules loaded, and so on. Is there a way to save all of that and reload it later so I can continue exactly where I left off? Or better yet, dump out the entire lot as a text file that could be reloaded or be trivially modified into code that I could compile into an executable (e.g. by adding a Main)?
Users of HOL light have had similar needs, and they use a checkpointing program to save a snapshot of the toplevel. See this message on the caml mailing-list, or page 8 of this HOL tutorial.
In general it is better to keep the definitions as source code, rather than a binary toplevel snapshot. Numerous tools allow to quickly load a .ml file into the toplevel for easy experimentation (emacs modes, etc.). See the warning in the HOL tutorial:
When developing large proofs in HOL, you should always keep the proof script as
an OCaml file ready to reload, rather than relying on ckpt. This will allow the proofs
to be later modified, used by others etc. However, it can be very convenient to make
intermediate snapshots so you do not have to load large files to work further on a proof.
This is analogous to the usual situation in programming: you should always keep your
complete source code, but don’t want to recompile all the sources each time you use
the code.
At least in OCaml there's no built-in support for that. On solution is to use rlwrap or any other readline wrapper to record your input's history to a file. For example :
> rlwrap -H mysession.ml ocaml
The drawback is that this will also record the input that had syntax errors so you'll have to clean that out. Note that by default rlwrap will automatically save your input in ~/.ocaml_history if you invoke it without the -H option.
In Haskell, just use :e file. This opens the standard editor and lets you edit some file. Afterwards, use :r to reload it. It will be automatically recompiled.
Please notice, that all your "ad-hoc" defined functions will be lost after this. Refer to the doc for more information.
ghci uses haskeline for commandline input history, so you can scroll up to repeat/edit inputs. Your input history is usually recorded in a file, which you can find as ghci_history in the directory given by
System.Directory.getAppUserDataDirectory "ghc"
There are various commands to explore the 'context' (:show bindings, :show modules, :def, ..) but their output won't suffice to reproduce your session (though it is worth knowing about them anyway).
In general, the advice to combine your ghci session with an open editor window is sound: if it is more than a throwaway definition, even if just for debugging purposes, better include it in a module to be loaded into ghci, so that you can reuse it.
Oh, and if by 'context', you mean some default settings or modules you want loaded, on a per-project basis, there is also ghci's configuration file. Also handy for defining your own ghci commands.
In ocaml, you can build your own top-level. It solves problem with loaded modules at least.
http://caml.inria.fr/pub/docs/manual-ocaml/toplevel.html#sec278
The ocamlmktop command builds OCaml toplevels that contain user code
preloaded at start-up.
The ocamlmktop command takes as argument a set of .cmo and .cma files,
and links them with the object files that implement the OCaml
toplevel. The typical use is:
ocamlmktop -o mytoplevel foo.cmo bar.cmo gee.cmo
This creates the bytecode file mytoplevel, containing the OCaml
toplevel system, plus the code from the three .cmo files. This
toplevel is directly executable and is started by:
./mytoplevel
This enters a regular toplevel loop, except that the code from
foo.cmo, bar.cmo and gee.cmo is already loaded in memory, just as if
you had typed:
#load "foo.cmo";;
#load "bar.cmo";;
#load "gee.cmo";;
on entrance to the toplevel. The modules Foo, Bar and Gee are not
opened, though; you still have to do
open Foo;;
yourself, if this is what you wish.
This has always bothered me too, so I wrote a quick python/expect script to replay ghci_history at the beginning of each ghci session.
It's not very polished. For example it always replays the whole history and that could be slow.