Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell Interactive

I am a bit rusty on my Haskell and am looking to ramp back up. One thing I enjoy from F# is the F# Interactive shell integrated with Visual Studio: I can evaluate virtually anything (including function and class definitions) and use F# as a shell. Is there an equivalent in Haskell? When I use ghci, I cannot evaluate function definitions. How do you work around that?

My current preferred setting is using Emacs with haskell-mode and opening an interactive ghi interpreter. However, is there a way to evaluate just region of a file?

like image 973
namin Avatar asked Dec 04 '08 20:12

namin


People also ask

What is the difference between GHC and ghci?

GHCi is the interactive interface to GHC. From the command line, enter "ghci" (or "ghci -W") followed by an optional filename to load. Note: We recommend using "ghci -W", which tells GHC to output useful warning messages in more situations. These warnings help to avoid common programming errors.

How do I use Haskell online?

You can use this feature to share your Haskell Code with your teachers, classmates and colleagues. Just click Share Button and it will create a short link, which can be shared through Email, WhatsApp or even through Social Media. A shared link will be deleted if it has been passive for almost 3 months.

What is REPL Haskell?

A read–evaluate–print loop (REPL) environment takes single user inputs, executes them, and returns the result to the user. GHCi is GHC's interactive environment. The stack ghci or stack repl commands, which are equivalent, allow you to load components and files of your project into GHCi.

How do I run Haskell with ghci?

If you have installed the Haskell Platform, open a terminal and type ghci (the name of the executable of the GHC interpreter) at the command prompt. Alternatively, if you are on Windows, you may choose WinGHCi in the Start menu. And you are presented with a prompt. The Haskell system now attentively awaits your input.


1 Answers

You can define a function using 'let':

$ ghci
Prelude> let double n = n + n
Prelude> double 42
84

Also, I won't quite recommend this, since (A) I wrote it, and (B) it's terribly undeveloped, but Halp can be handy in Emacs -- it's a little bit like a spreadsheet for Haskell code integrated right into your source-code buffer. You can have a set of expressions you're interested in and with one keystroke see how all their values change depending on your edits since the last reevaluation.

like image 55
Darius Bacon Avatar answered Oct 14 '22 11:10

Darius Bacon