Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why am I getting parse error on input "{"

I am trying to run the very first example in this tutorial:

Call JVM Methods from Haskell

module Main where

{-# LANGUAGE QuasiQuotes #-}
{-# OPTIONS_GHC -fplugin=Language.Java.Inline.Plugin #-}
import Language.Java (withJVM)
import Language.Java.Inline

main :: IO ()
main = withJVM [] [java| { System.out.println("Hello Java!"); } |]

and I get this error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

app\Main.hs:8:26: error: parse error on input `{'
  |
8 | main = withJVM [] [java| { System.out.println("Hello Java!"); } |]
  |                          ^

What am I doing wrong?

>Solution :

The {-# LANGUAGE … #-} and {-# OPTIONS_GHC … #-} pragmas need to be defined before the module Main declaration. Otherwise it will not enable the QuasiQuotes language extension, and thus not understand the quasiquotes used in the program.

If you install the inline-java and put the language pragmas before the module Main:

{-# LANGUAGE QuasiQuotes #-}
{-# OPTIONS_GHC -fplugin=Language.Java.Inline.Plugin #-}

module Main where

import Language.Java (withJVM)
import Language.Java.Inline

main :: IO ()
main = withJVM [] [java| { System.out.println("Hello Java!"); } |]

It should normally interpret the quasiquotes properly.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading