79331

Haskell - parse error on input `=' [duplicate]

Question:

This question already has an answer here:

<ul><li> <a href="/questions/24372766/parse-error-in-valid-code" dir="ltr" rel="nofollow">Parse error in valid code [duplicate]</a> <span class="question-originals-answer-count"> 1 answer </span> </li> </ul>

when implementing the code for the "Towers of Hanoi" problem I get the following error message:

hanoi.hs:4:24: parse error on input `=' Failed, modules loaded: none. <hr />

Here is the code:

hanoi 1 i j = [(i, j)] hanoi n i j = hanoi n' i otherT ++ [(i,j)] ++ hanoi n' otherT j where n' = n-1 otherT = 1+2+3-i-j <hr />

Any Ideas?

Answer1:

Your editor and the compiler see the tabs differently. Avoid using tabs and indent with spaces:

hanoi 1 i j = [(i, j)] hanoi n i j = hanoi n' i otherT ++ [(i,j)] ++ hanoi n' otherT j where n' = n-1 otherT = 1+2+3-i-j

Good editors can be set up to do the right number of spaces automatically when you press tab.

Recommend

  • Hanoi Towers - iterative, using lists
  • '('(LIST) 'NIL 'NIL) should be a lambda expression in (hanoi('('(list)
  • Scheme: Towers of Hanoi (recursion)
  • Not in scope: type constructor or class ‘-’ (and other errors while reversing a list)
  • Haskell: Non-exhaustive pattern - Checking if list is ascending
  • Simple type error on parsing the result of getArgs
  • Merging two figures in Matlab
  • Wait for angular to finish updating the DOM
  • Special chars in Amazon S3 keys?
  • How to use : function in H2O ddply, R?
  • Redirect to trailng slash (htaccess)
  • Jenkins: could not create Android emulator failed to parse AVD config file
  • what is the purpose of “export as namespace foo”?
  • Why are YouTube videos using 'youtube.com/v' not loading
  • Struts 2 TextField Tag with an attribute and no value
  • Android Google Maps API v2 start navigation
  • Problems installing Yesod for Haskell
  • Unable to install Git-core+svn by MacPorts
  • why xml file does not aligned properly after append the string in beginning and end of the file usin
  • Date Conversion from yyyy-mm-dd to dd-mm-yyyy
  • VSO Build — Response status code does not indicate success: 404 (Not Found)
  • Dialing with Intent.ACTION_CALL stopps at # in phone number
  • NHibernate Validation Localization with S#arp Architecture
  • FFmpeg Conversion Error
  • ilmerge with a PFX file
  • Is there a javascript serializer for JSON.Net?
  • Java Scanner input dilemma. Automatically inputs without allowing user to type
  • How can I send an e-mail from a vbs script
  • Master page gives error
  • Accessing IRQ description array within a module and displaying action names
  • Join two tables and save into third-sql
  • How to model a transition system with SPIN
  • what is the difference between the asp.net mvc application and asp.net web application
  • ORA-29908: missing primary invocation for ancillary operator
  • Matrix multiplication with MKL
  • Getting Messege Twice Using IMvxMessenger
  • Can't mass-assign protected attributes when import data from csv file
  • sending mail using smtp is too slow
  • Binding checkboxes to object values in AngularJs
  • Converting MP3 duration time