Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell error: parse error on input '='

Tags:

haskell

I created a new quick.hs file in the ghci.exe directory. And the content is

quicksort::(Ord a)=>[a]->[a]  
quicksort []=[]  
quicksort (x:xs)=  
    let smaller = [a |a<-xs,a<=x]  
        larger = [a |a<-xs,a>x]  
    in  quicksort smaller ++ [x] ++ quicksort larger 

When I issue :l quick in the ghci command lline, the output is

Prelude> :l quick
[1 of 1] Compiling Main             ( quick.hs, interpreted )

quick.hs:5:17: error:
    parse error on input ‘=’
    Perhaps you need a 'let' in a 'do' block?
    e.g. 'let x = 5' instead of 'x = 5'
Failed, modules loaded: none.

I have concured this kind of problems many times. What's wrong on earth?

like image 843
Julian20151006 Avatar asked Apr 26 '26 06:04

Julian20151006


2 Answers

You say in the comments that you are sure there are no tab characters in the source file, but inspecting the source of your question, indeed there is one right before the in token. Replace that with the appropriate number of spaces and you'll be all good.

like image 101
amalloy Avatar answered Apr 28 '26 10:04

amalloy


You have to remove all tabs and change it by spaces. I hope that this instruction helps you.

like image 24
Cris Avatar answered Apr 28 '26 09:04

Cris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!