0

I am trying out my hands on Haskell.

I wrote the code and saved it as : boolean.hs

The code is:

let area r = pi * r ^ 2
main = print(area 5 < 50)

When I do, ghc -o boolean boolean.hs

I get an error message :

[1 of 1] Compiling Main             ( boolean.hs, boolean.o )

boolean.hs:2:1:
    parse error (possibly incorrect indentation or mismatched brackets)

It would be great if somebody helped me see how this error can be tackled.

I went through Haskell|Wikibooks|Identation, and changed the code to :

let 
    area r = pi * r ^ 2
main = 
    print(area 5 < 50)

And still got :

[1 of 1] Compiling Main             ( boolean.hs, boolean.o )

boolean.hs:3:1:
    parse error (possibly incorrect indentation or mismatched brackets)

Regards. :)

Pragyaditya Das
  • 1,648
  • 6
  • 25
  • 44
  • related question about [let](http://stackoverflow.com/questions/8274650/in-haskell-when-do-we-use-in-with-let) – wizzup Jan 21 '17 at 08:14

1 Answers1

3

You don't need to use let. Just define the function and call it in main i.e.

area r = pi * r ^ 2

main = print (area 5 < 50)
chi
  • 111,837
  • 3
  • 133
  • 218
shree.pat18
  • 21,449
  • 3
  • 43
  • 63
  • Got it...thanks :) Can you tell me why this happens? Or can you point me into the direction into how can I learn more? – Pragyaditya Das Jan 21 '17 at 07:43
  • 1
    Sure, here's the link: https://www.haskell.org/tutorial/patterns.html. Look at section 4.5 – shree.pat18 Jan 21 '17 at 07:43
  • 2
    @PragyadityaDas Bare `let` expressions are not allowed to appear at the top level of a module but they can appear inside expressions (`let x = 42 in x * x`) or `do` blocks (`do { let x = 42; print x; }`). – Rufflewind Jan 21 '17 at 08:22