Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I look up Haskell commands and keywords?

Tags:

haskell

ghci

I'm teaching myself Haskell but one problem I'm running into a lot with haskell is that it's really hard to find the definitions of Haskell keywords, syntax and commands. I've gone through some Haskell tutorials and that dispelled a lot of them for me, and in general using the ":t" command in ghci is helpful to see the types of functions.

But in general, how the heck am I supposed to know what these do: (.), (>>=), (=<<), ! or \\

I know what they do now, but in the future if I run into some symbol that I've never seen before, how am I supposed to know what it does or how to use it? Googling these things obviously doesn't work!

Right now, I'm trying to figure out what the 'it' command is supposed to do in ghci. Again, I can't find this on Google, and all I know how to do is get type information via ":t it" in ghci. This is very frustrating for someone new to the language...

like image 205
bhh1988 Avatar asked Dec 11 '22 18:12

bhh1988


2 Answers

You can get some mileage using Hoogle:

  • http://www.haskell.org/hoogle/

or by searching the Prelude source code:

  • http://www.haskell.org/onlinereport/standard-prelude.html

  • https://stackoverflow.com/questions/11776269/where-can-i-find-the-source-code-for-haskell-prelude-functions

These resources will help with function names and operators, but not necessarily with learning syntax. To learn the syntax you will need other resources, or a book. Luckily though, most "syntax" at face value is in fact just a function defined in Prelude.

like image 89
DuckMaestro Avatar answered Dec 30 '22 02:12

DuckMaestro


For GHCi commands, type :help in GHCi. This will give you a list of all the available commands. Some of them are probably going to come in useful, like the debugging ones.

I don't know where it is documented. In GHCi, it is just a variable bound to the result of the last expression you evaluated. E.g.:

λ>1 + 2 * 3
7
λ>it
7
λ>:t it
it :: Integer
λ>"foo"
"foo"
λ>it
"foo"
like image 43
Tikhon Jelvis Avatar answered Dec 30 '22 00:12

Tikhon Jelvis