Understanding through exploration with GHCI

Here are some questions you can answer with GHCI

"What can I do with a list?"

It may also be useful to know how to Find modules that deal with X since that's how you would even know which module to :browse the data types and functions of.

TODO I could manually add color coating so it's easier to parse the brows list below, and it's actually probably a good idea to try and get that change in ghi and contribute that

  $ ghci
  GHCi, version 8.10.4: https://www.haskell.org/ghc/  :? for help
    ... snip ...
  > :browse Data.List
  Data.List.isSubsequenceOf :: Eq a => [a] -> [a] -> Bool
  (!!) :: [a] -> Int -> a
  (++) :: [a] -> [a] -> [a]
  (base-4.14.1.0:Data.OldList.\\) :: Eq a => [a] -> [a] -> [a]
    ... snip ...

NOTE Keep in mind that each function should only be on one line, So making visual sense of this list is just an exercise in repeating what was learned in Basic understanding of how to parse a type signature.

The important thing here is to not let your eyes glaze over and just pick one that either looks familiar or interesting.

I'll choose (!!).

> :type (!!)
(!!) :: [a] -> Int -> a

Make some guesses and ghci yourself as you follow along here, noting down mistakes you made.

TODO make something so that the rest of the page could be hidden and they would have to hide it by clicking a link that says "I've tried it in ghci and noted down my mistakes"

> :type (!!) [0]
(!!) [0] :: Num a => Int -> a
> :type (!!) [0] 1
(!!) [0] 1 :: Num a => a

What the heck is Num?? You have two options here:

> (!!) [0] 1
 Exception: Prelude.!!: index too large

Let's pretend we didn't see that... or if you can't wait check out Navigating sharp edges of the base library.

That last example might have helped you understand what exactly that function is. If so, you may be Understanding haskell by comparison to other languages.

To Relate haskell concepts to programming languages you already know you should know that (!!) is the indexing operator and is commonly used in infix style like:

> [0,1,2] !! 0
0
> [0,1,2] !! 1
1
> [0,1,2] !! 2
2
> [0,1,2] !! 3
 Exception: Prelude.!!: index too large

Before we used it in prefix style, but you don't have to worry too much about those distinctions rather than knowing they exist for now. It is easier to discover the type of functions using their prefix style. (probably worth linking to a Converting back and forth between prefix and infix style here)

"Some other likely and relatable scenario someone might ask "

extended prerequisites

what is GHCI?

it is a REPL that provides fast feedback loop to experiment with both large and small haskell concepts

basic understanding of command line prompts

Especially entering programs which contain their own prompts and provide their own commands to execute