The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

hhildebr (6) [Avatar] Offline
#1
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 (6) [Avatar] Offline
    #2
    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
    4
    Prelude>
    


    You can see the complete list of commands available in GHCi by typing :? 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.
    aishaolang (6) [Avatar] Offline
    #3
    aishaolang wrote: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
    4
    Prelude>
    


    You can see the complete list of commands available in GHCi by typing :? 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.
    103210 (3) [Avatar] Offline
    #4
    The stack overflow answer is ok but I think this wikibooks article is clearer:
    [url= https://en.wikibooks.org/wiki/Haskell/Indentation]

    Note that the key to keeping indentation simple is to set your editor to indent using spaces instead of tabs
    have it convert any existing tabs to spaces if you are struggling.

    The definitive explanation on layout seems to be:
    [url = https://www.haskell.org/onlinereport/haskell2010/haskellch2.html#x7-210002.7]