formatting?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

formatting?

Alexander Chen
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!!

best,

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: formatting?

Magnus Therning

Alexander Chen <[hidden email]> 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: [hidden email]
twitter: magthe              http://magnus.therning.org/

If you can tell the truth, you don't have to remember anything.
     — Mark Twain

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

signature.asc (847 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: formatting?

Frank
In reply to this post by Alexander Chen
Vim (https://wiki.haskell.org/Vim) It takes a little getting used to but you’ll never go back. You’ll use it for so many thing.

If Vim really isn’t to your liking, Emacs might. (https://wiki.haskell.org/Emacs) It’s more of an operating system cleverly disguised as a text editor.

Both of these should be your first choice, in my opinion and experience.

On Thu, May 7, 2020 at 13:02 Alexander Chen <[hidden email]> wrote:
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!!

best,
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
--
P.S.: I prefer to be reached on BitMessage at BM-2D8txNiU7b84d2tgqvJQdgBog6A69oDAx6

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners