3

I'm learning haskell by going through learn you a haskell for great good and one of the functions in the tutorials doesn't seem to compile. I can't figure out why, I thought it might be the indenting but it doesn't seem to make a difference. Most of the SE questions seems to be referring to the ghci and trying to set variables.

describeList :: [a] -> String
describeList xs = "The list is " ++ case xs of [] -> "empty."
                                               [x] -> "a singleton list."
                                               xs -> "a longer list."

The error I get is:

describeList.hs:4:95: parse error on input '->'
Failed, modules loaded: none.
Achaldo
  • 163
  • 8
  • Works [fine on ideone](http://ideone.com/tucBMB). I would suggest you to check indentation. – Sibi Aug 25 '14 at 09:55
  • 6
    Did you mix tabs and spaces? – Zeta Aug 25 '14 at 10:01
  • turns out it was it was the tab settings in my vimrc that were screwing me up. I used the settings [here](http://www.haskell.org/haskellwiki/Vim) and now it works ok. – Achaldo Aug 25 '14 at 11:20
  • 2
    @Achaldo: In this case you should either a) answer your own question, b) find a duplicate to this question and vote to close it or c) delete this question. – Zeta Aug 25 '14 at 13:22

1 Answers1

3

Turns out the problem was with my tab settings on VIM. Turns out Haskell is quite particular with the indentations. I changed my vimrc file to these settings.

" Tab specific option
set tabstop=8                   "A tab is 8 spaces
set expandtab                   "Always uses spaces instead of tabs
set softtabstop=4               "Insert 4 spaces when tab is pressed
set shiftwidth=4                "An indent is 4 spaces
set shiftround                  "Round indent to nearest shiftwidth multiple

Source: http://www.haskell.org/haskellwiki/Vim

Achaldo
  • 163
  • 8