0

So I'm trying to learn haskell.
I got this code:

main = putStrLn "Hello World!"

And I'm compiling it using the Script plugin for Atom (Whitch in turn uses Cabal).
And i get this error:

<interactive>:1:6: parse error on input ‘=’

Also there is nothing printed to the console.
What am I missing?

NOTE:
I'm trying to follow the Happy Learn Haskell Tutorial

1
  • The GHCi interactive environment isn't quite normal Haskell. It requires the syntax let main = putStrLn "Hello World!". Commented Aug 20, 2016 at 17:17

2 Answers 2

1

That code is correct if you're putting it in a file. I'm not familiar with that atom plugin, but it sounds like it's trying to put it's input through ghci (basically the Haskell repl) where that code isn't valid.

Have you tried compiling the file by hand, using ghc or even cabal? It should work if there's nothing else wrong in the file.

Sign up to request clarification or add additional context in comments.

Comments

0

Turns out that trying to run a piece of Haskell, using Script, without saving the code to a file causes some strange error (Although it never once actually told me to save the file).

Saving the code to a file however changed things.

The code:

main = putStrLn "Hello World"

The error:

Top-level binding with no type signature: main :: IO ()

How ever, this time i got an output:

Hello World

2 Comments

That's not an error, that's just a warning. Type signatures are optional in Haskell (except for corner cases), but it's good style to have signatures for top level items.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.