Functions in "where" block.
Hello everyone, I can't figure out why the following function does not work: myFun :: Integer -> Integer myFun x = op x + ep x where op x = 99 ep x = 1 -- squawks here Yeah it's a stupid function, but I was just trying to declare two functions in the "where" block. I expected this to work and always return 100. This is the error I get while compiling: ================== Prelude> :l fun.hs [1 of 1] Compiling Main ( fun.hs, interpreted ) fun.hs:4:15: parse error on input `=' Failed, modules loaded: none. ================== Could someone please tell me where I am going wrong? Thanks in advance. Regards, Venu Chakravorty.
On Thu, Jun 12, 2014 at 8:54 AM, Venu Chakravorty <c.venu@aol.com> wrote:
fun.hs:4:15: parse error on input `='
The problem wasn't obvious until I copy-pasted it into an editor: You have tabs instead of spaces for the line defining ep. The rule of thumb is that your editor must expand all tabs into matching spaces for whitespace-sensitive languages like haskell. Or else you'll waste time with this kind of parsing errors. -- Kim-Ee
On 06/12/2014 04:21 AM, Kim-Ee Yeoh wrote:
On Thu, Jun 12, 2014 at 8:54 AM, Venu Chakravorty <c.venu@aol.com> wrote:
fun.hs:4:15: parse error on input `='
The problem wasn't obvious until I copy-pasted it into an editor:
You have tabs instead of spaces for the line defining ep.
The rule of thumb is that your editor must expand all tabs into matching spaces for whitespace-sensitive languages like haskell. Or else you'll waste time with this kind of parsing errors.
-- Kim-Ee
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
For reference, GHC treats hard tabs as 8 spaces. Even in my mail client the problem is quite apparent[1]. Set your editor to use spaces only. I think [2] is the standard reference for whitespace style. [1]: http://fuuzetsu.co.uk/images/1402875503.png [2]: http://urchin.earth.li/~ian/style/haskell.html -- Mateusz K.
{- Hi Venu, the problem is incorrect indentation. The line that defines ep must have the same (or greater) indentation than the line that defines op. Also, it is recommended that you use strictly spaces for indentation. In some editors, for example Vim, you can set an option that automatically converts your tab keystrokes into spaces. Copy this email as is with the code below to see one possible convention for writing where clauses. To recreate the same error again, move the line that defines ep back one space. By the way, your email landed in my spam box for some reason, so you might not be getting any replies to subsequent emails. -} myFun :: Integer -> Integer myFun x = op x + ep x where op x = 99 ep x = 1 On 6/11/14, Venu Chakravorty <c.venu@aol.com> wrote:
Hello everyone, I can't figure out why the following function does not work:
myFun :: Integer -> Integer myFun x = op x + ep x where op x = 99 ep x = 1 -- squawks here
Yeah it's a stupid function, but I was just trying to declare two functions in the "where" block. I expected this to work and always return 100.
This is the error I get while compiling:
================== Prelude> :l fun.hs [1 of 1] Compiling Main ( fun.hs, interpreted )
fun.hs:4:15: parse error on input `=' Failed, modules loaded: none.
==================
Could someone please tell me where I am going wrong? Thanks in advance.
Regards, Venu Chakravorty.
participants (4)
-
Jacek Dudek -
Kim-Ee Yeoh -
Mateusz Kowalczyk -
Venu Chakravorty