hhildebr (6) [Avatar] Offline
Hi I am just starting out with both Haskell and your book (I'm just in chapter 2). Really nice read so far! I'm using GHCi to follow along, but I've stumbled over two things:

  • In chapter 0 you state
    Defining variables or functions in GHCi is slightly
    different than in normal Haskell programs since they must be prefaces by the let keyword:
    but also use (simple) examples without let. So when do I have to use let in GHCi?

  • How do I use indentation in GHCi (and Haskell)? Maybe you explain this later in the book, but in the beginning it is unclear if I have to align e.g. the parts of an if-then-else, and if I have to indent the "where" (and by how much)? Also it would be good to know how I do these multi-line indented statements in GHCi.

  • aishaolang (4) [Avatar] Offline
    To indent within GHCi, use the :{ / :} command.

    For example, typing the Quick Check 2.2 example in GHCi would look like the following:
    Prelude> :{
    Prelude| doubleDouble x = dubs * 2
    Prelude|   where dubs = x * 2
    Prelude| :}
    Prelude> doubleDouble 1

    You can see the complete list of commands available in GHCi by typing smilie in GHCi.

    You need to indent by at least one whitespace character. However, that is considered a bad style. The answer at stackoverflow.com covers this in detail.