[Haskell-beginners] formatting?

Magnus Therning magnus at therning.org
Thu May 7 17:23:55 UTC 2020


Alexander Chen <alexander at chenjia.nl> writes:

> Hi,
>
> tensDigit.hs
>
> tensDigit :: Integral a => a ->a
> tensDigit x = d
>   where xLast = x `div` 10
>             d         = xLast `mod` 10
>
> prelude> load tensDigit.hs
> parse error on input ‘=’
> Perhaps you need a 'let' in a 'do' block?
> e.g. 'let x = 5' instead of 'x = 5'
> 4 |             d         = xLast `mod` 10   |                       ^
> [1 of 1] Compiling Main             ( chapter7_8.hs, interpreted )
> Failed, no modules loaded.
>
> I suspect this has something to do with the spacing (since this is
> example code) if so could someone explain to me what the rules on
> spacing are so I can get past this. I am using a simple text editor so
> if someone has a recommendation for an IDE that simply takes care of
> this, much obliged!!
>

Try lining up the definitions in the where-clause. That'll do it.

tensDigit :: Integral a => a ->a
tensDigit x = d
  where xLast = x `div` 10
        d     = xLast `mod` 10

/M

--
Magnus Therning              OpenPGP: 0x927912051716CE39
email: magnus at therning.org
twitter: magthe              http://magnus.therning.org/

If you can tell the truth, you don't have to remember anything.
     — Mark Twain
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20200507/e72cf536/attachment.sig>


More information about the Beginners mailing list